0
|
1 |
#include "list.h"
|
|
2 |
#include "system.h"
|
|
3 |
#include "stdio.h"
|
|
4 |
|
|
5 |
Word::Word(char * word, int length)
|
|
6 |
/*--------------------------------------------------------------
|
|
7 |
Primary Purpose: Create a word without pointers to components
|
|
8 |
Arguments: word is the character string length is the length
|
|
9 |
Words created with this constructor have a null component pointer
|
|
10 |
Rev: 12/5/95
|
|
11 |
|
|
12 |
---------------------------------------------------------------*/
|
|
13 |
{
|
|
14 |
charCount = 1;
|
|
15 |
characters = new char[length];
|
|
16 |
strcpy(characters, word);
|
|
17 |
confid = 255;
|
|
18 |
ul = NOPNT;
|
|
19 |
lr = NOPNT;
|
|
20 |
character = NULL;
|
|
21 |
mispelled = 0;
|
|
22 |
}
|
|
23 |
|
|
24 |
|
|
25 |
Word::Word(ListElement * first, int length)
|
|
26 |
/*--------------------------------------------------------------
|
|
27 |
Primary Purpose:
|
|
28 |
Arguments: first is a pointer to a ListElement that contains
|
|
29 |
the first Component in the word. length is the number
|
|
30 |
of components in the word.
|
|
31 |
Effects: Sets all data members of the word class
|
|
32 |
Rev: 11/6/95
|
|
33 |
---------------------------------------------------------------*/
|
|
34 |
{
|
|
35 |
mispelled = 0;
|
|
36 |
Component * firstComp = (Component *) first->item;
|
|
37 |
Component * item;
|
|
38 |
int i;
|
|
39 |
ListElement * ptr;
|
|
40 |
|
|
41 |
|
|
42 |
characters = new char[length+1];
|
|
43 |
character = new (Component *)[length];
|
|
44 |
charCount = length;
|
|
45 |
ul = firstComp->ul();
|
|
46 |
|
|
47 |
confid = 256;
|
|
48 |
|
|
49 |
for (i = 0, ptr = first; i < length; ptr = ptr->next, i++)
|
|
50 |
{
|
|
51 |
item = (Component *)(ptr->item);
|
|
52 |
characters[i] = item->asciiId();
|
|
53 |
character[i] = item;
|
|
54 |
if (item->confid() < confid)
|
|
55 |
confid = item->confid();
|
|
56 |
if(item->ul().y() < ul.y())
|
|
57 |
ul.y() = item->ul().y();
|
|
58 |
if(i == length-1) // this is the last character
|
|
59 |
lr = item->lr();
|
|
60 |
}
|
|
61 |
|
|
62 |
|
|
63 |
characters[length] = '\0';
|
|
64 |
if(0)
|
|
65 |
printf("Identified a word: %s\n", characters);
|
|
66 |
|
|
67 |
};
|
|
68 |
|
|
69 |
|
|
70 |
Word::~Word()
|
|
71 |
{
|
|
72 |
if (characters != NULL)delete characters;
|
|
73 |
if (character != NULL) delete character;
|
|
74 |
};
|
|
75 |
|
|
76 |
|
|
77 |
Words::~Words()
|
|
78 |
{
|
|
79 |
for (ListElement *ptr = first; ptr != NULL; ptr = ptr->next) {
|
|
80 |
if (ptr->item != NULL)
|
|
81 |
delete (Word *) (ptr->item);
|
|
82 |
}
|
|
83 |
|
|
84 |
}
|
|
85 |
|
|
86 |
int Words::writeWordPos(char * filename)
|
|
87 |
/*--------------------------------------------------------------
|
|
88 |
Primary Purpose: Write word position, confidence length and string to file
|
|
89 |
Arguments: output file name
|
|
90 |
Return Value: 1 for success 0 for file
|
|
91 |
Effects: create and write out to filename each word in the following format
|
|
92 |
All numeric fields are in fixed columns 7 characters wide
|
|
93 |
upperleft x pos
|
|
94 |
upperleft y pos
|
|
95 |
word confidence
|
|
96 |
character count
|
|
97 |
string
|
|
98 |
\N
|
|
99 |
Rev: KM 11/25
|
|
100 |
---------------------------------------------------------------*/
|
|
101 |
{
|
|
102 |
FILE * outfile;
|
|
103 |
outfile = fopen(filename, "w");
|
|
104 |
if (outfile == NULL)
|
|
105 |
{
|
|
106 |
printf("Error openning %s", filename);
|
|
107 |
return 0;
|
|
108 |
}
|
|
109 |
|
|
110 |
for (ListElement * ptr = first; ptr !=NULL; ptr = ptr->next)
|
|
111 |
{
|
|
112 |
Word * word = (Word *) ptr->item;
|
|
113 |
if (word->ul.x() == -1) continue; // dont print new lines.
|
|
114 |
fprintf(outfile, " %6d %6d %6d %6d %s\n", word->ul.x(), word->ul.y(),
|
|
115 |
word->confid, word->charCount, word->characters );
|
|
116 |
}
|
|
117 |
fclose(outfile);
|
|
118 |
return 1;
|
|
119 |
}
|
|
120 |
|
|
121 |
|
|
122 |
int Words::writeAscii(char * filename)
|
|
123 |
/*--------------------------------------------------------------
|
|
124 |
Primary Purpose: Write word list to ascii file
|
|
125 |
Arguments: filename to write to
|
|
126 |
Return Value: 1 if successful 0 if unsuccessful
|
|
127 |
Effects: Writes words to fill in text format
|
|
128 |
|
|
129 |
Rev: 11/25 KM
|
|
130 |
---------------------------------------------------------------*/
|
|
131 |
{
|
|
132 |
FILE * outfile;
|
|
133 |
outfile = fopen(filename, "w");
|
|
134 |
Word * prev = (Word *) first->item;
|
|
135 |
if (outfile == NULL)
|
|
136 |
{
|
|
137 |
printf("Error openning %s", filename);
|
|
138 |
return 0;
|
|
139 |
}
|
|
140 |
|
|
141 |
for (ListElement * ptr = first; ptr !=NULL; ptr = ptr->next)
|
|
142 |
{
|
|
143 |
Word * word = (Word *) ptr->item;
|
|
144 |
fprintf(outfile, "%s ", word->characters );
|
|
145 |
|
|
146 |
}
|
|
147 |
fclose(outfile);
|
|
148 |
return 1;
|
|
149 |
|
|
150 |
}
|