Commit | Line | Data |
---|---|---|
ba6b4afe BJ |
1 | #include "style.h" |
2 | #include "names.h" | |
3 | #include "conp.h" | |
4 | char *names[] = { | |
5 | "noun", "verb", "interjection", "adjective", "adverb", "conjunction", "possessive", | |
6 | "pronoun", "article", "preposition", "auxiliary", "tobe", "subordinate conjunction", "", "expletive" | |
7 | }; | |
8 | outp(){ | |
9 | struct ss *st; | |
10 | char *ssp; | |
11 | char *spart, ff; | |
12 | int index, lverbc; | |
13 | int nn, sc, f, kk,comp, begsc; | |
14 | int conjf, verbf,lpas,bflg,lexp,olvb; | |
15 | int infinf, ovflg; | |
16 | int lvowel,nlet; | |
17 | int imper; | |
18 | float rd; | |
19 | ||
20 | if(style){ | |
21 | nn = kk = 0; | |
22 | for(sentp=sent;sentp->cc != END;sentp++){ | |
23 | if(sentp->cc != ',' && sentp->cc != '"')nn++; | |
24 | if(sentp->cc == VERB || sentp->cc == BE || sentp->cc == AUX)kk++; | |
25 | } | |
26 | if(nn < 4 && kk == 0)return; | |
27 | } | |
28 | ||
29 | imper = lexp = lpas = index = lverbc = 0; | |
30 | conjf = verbf = kk = nn = sc = comp = begsc = 0; | |
31 | bflg = olvb = infinf = ovflg = 0; | |
32 | nlet = 0; | |
33 | f = 1; | |
34 | sentp=sent; | |
35 | while(sentp->cc != END){ | |
36 | /* printf("%c:",sentp->ic); */ | |
37 | if(sentp->cc == ';')comp++; | |
38 | else { | |
39 | if((sentp->cc != ',') && (sentp->cc != '"')){ | |
40 | if(*sentp->sp != 'x'){ | |
41 | nn++; | |
42 | nlet += sentp->leng; | |
43 | } | |
44 | kk++; | |
45 | } | |
46 | } | |
47 | switch(sentp->cc){ | |
48 | case NOUN: | |
49 | spart ="noun"; | |
50 | if(f)index=0; | |
51 | if(*sentp->sp != 'x'){ | |
52 | noun++; | |
53 | numnonf++; | |
54 | letnonf += sentp->leng; | |
55 | } | |
56 | bflg = infinf = ovflg = 0; | |
57 | break; | |
58 | case VERB: | |
59 | spart = "verb"; | |
60 | if(f)index=1; | |
61 | if(sentp->ic==TO){ | |
62 | infin++; | |
63 | infinf=1; | |
64 | lverbc++; | |
65 | } | |
66 | else { | |
67 | if(f)imper=1; | |
68 | if(ovflg == 0 && infinf == 0){ | |
69 | ovflg = 1; | |
70 | lverbc++; | |
71 | olvb++; | |
72 | } | |
73 | numnonf++; | |
74 | letnonf += sentp->leng; | |
75 | if(infinf == 0){ | |
76 | if(verbf == 0)verbf++; | |
77 | else if(conjf)comp++; | |
78 | } | |
79 | if(bflg && sentp->ic == ED)lpas = ++passive; | |
80 | } | |
81 | break; | |
82 | case INTER: | |
83 | spart = "interj"; | |
84 | if(f)index=2; | |
85 | bflg = infinf = ovflg = 0; | |
86 | break; | |
87 | case ADJ: | |
88 | spart = "adj"; | |
89 | if(f)index=3; | |
90 | adj++; | |
91 | numnonf++; | |
92 | letnonf += sentp->leng; | |
93 | bflg = infinf = ovflg = 0; | |
94 | break; | |
95 | case ADV: | |
96 | spart = "adv"; | |
97 | if(f)index=4; | |
98 | adv++; | |
99 | numnonf++; | |
100 | letnonf += sentp->leng; | |
101 | break; | |
102 | case CONJ: | |
103 | spart = "conj"; | |
104 | conjc++; | |
105 | if(f)index=5; | |
106 | if(infinf && (sentp+1)->cc == VERB); | |
107 | else { | |
108 | if(verbf)conjf++; | |
109 | bflg = infinf = ovflg = 0; | |
110 | } | |
111 | break; | |
112 | case POS: | |
113 | spart = "pos"; | |
114 | if(f)index=6; | |
115 | bflg = infinf = ovflg = 0; | |
116 | break; | |
117 | case PRONS: | |
118 | case PRONP: | |
119 | spart = "pron"; | |
120 | pron++; | |
121 | if(f){ | |
122 | index=7; | |
123 | if((sentp+1)->cc == BE){ | |
124 | if(sentp->leng == 5 && *(sentp->sp) == 't' && *((sentp->sp)+3)=='r'){index=14;lexp=1;} | |
125 | else if(sentp->leng ==2&& *(sentp->sp) == 'i' ){index=14;lexp=1;} | |
126 | } | |
127 | } | |
128 | bflg = infinf = ovflg = 0; | |
129 | if(sentp->ic == THAT || sentp->ic == WHO)sc++; | |
130 | break; | |
131 | case ART: | |
132 | spart = "art"; | |
133 | if(f)index=8; | |
134 | bflg = infinf = ovflg = 0; | |
135 | break; | |
136 | case PREP: | |
137 | spart = "prep"; | |
138 | if(f)index=9; | |
139 | prepc++; | |
140 | bflg = infinf = ovflg = 0; | |
141 | break; | |
142 | case AUXX: | |
143 | spart = "aux"; | |
144 | if(ovflg == 0 && infinf == 0){ | |
145 | ovflg = 1; | |
146 | lverbc++; | |
147 | olvb++; | |
148 | aux++; | |
149 | } | |
150 | if(f)index=10; | |
151 | break; | |
152 | case BE: | |
153 | if(ovflg == 0 && infinf == 0){ | |
154 | ovflg = 1; | |
155 | lverbc++; | |
156 | olvb++; | |
157 | } | |
158 | spart = "be"; | |
159 | if(f)index=11; | |
160 | tobe++; | |
161 | bflg = 1; | |
162 | if(verbf == 0)verbf++; | |
163 | else if(conjf)comp++; | |
164 | break; | |
165 | case SUBCONJ: | |
166 | spart = "subcj"; | |
167 | if(f){ | |
168 | index=13; | |
169 | begsc++; | |
170 | } | |
171 | sc++; | |
172 | if((sentp-1)->cc != CONJ) | |
173 | verbf = conjf = 0; | |
174 | bflg = infinf = ovflg = 0; | |
175 | break; | |
176 | default: | |
177 | if(sentp->cc == ','){ | |
178 | if(begsc)conjf=verbf=0; | |
179 | } | |
180 | spart = sentp->sp; | |
181 | } | |
182 | if(part){ | |
183 | printf("%s %s\n",spart,sentp->sp); | |
184 | } | |
185 | else if(pstyle){ | |
186 | printf("%s ",sentp->sp); | |
187 | if(kk == 15){ | |
188 | printf("\n"); | |
189 | kk=0; | |
190 | } | |
191 | } | |
192 | if(style){ | |
193 | ssp=sentp->sp; | |
194 | lvowel = 0; | |
195 | while(*ssp != '\0'){ | |
196 | if(*ssp >= '0' && *ssp <= '9'){ | |
197 | lvowel=0; | |
198 | break; | |
199 | } | |
200 | switch(*(ssp++)){ | |
201 | case 'a': | |
202 | case 'e': | |
203 | case 'i': | |
204 | case 'o': | |
205 | case 'u': | |
206 | case 'y': | |
207 | case 'A': | |
208 | case 'E': | |
209 | case 'I': | |
210 | case 'O': | |
211 | case 'U': | |
212 | case 'Y': | |
213 | lvowel++; | |
214 | continue; | |
215 | } | |
216 | } | |
217 | if(lvowel != 0){ | |
218 | vowel += lvowel; | |
219 | twds++; | |
220 | } | |
221 | } | |
222 | if(f){ | |
223 | ff=sentp->cc; | |
224 | f=0; | |
225 | } | |
226 | sentp++; | |
227 | } | |
228 | if(part){ | |
229 | printf(". %s\n",sentp->sp); | |
230 | } | |
231 | numsent++; | |
232 | numlet += nlet; | |
233 | tverbc += lverbc; | |
234 | verbc += olvb; | |
235 | if(*(sentp->sp) == '?'){ | |
236 | if(sc > 0)sc -= 1; | |
237 | qcount++; | |
238 | } | |
239 | else if(*(sentp->sp) == '/')icount++; | |
240 | else if(imper)icount++; | |
241 | if(rstyle||pstyle)rd = 4.71*((float)(nlet)/(float)(nn))+.5*(float)(nn)-21.43; | |
242 | if((rstyle&& rd>=rthresh)||(lstyle&&nn >= lthresh)||(pastyle&&lpas)||(estyle&&lexp)){ | |
243 | if(!part){ | |
244 | for(st=sent, kk=0;st->cc != END;st++){ | |
245 | printf("%s ",st->sp); | |
246 | if(kk++ >= 15){ | |
247 | kk=0; | |
248 | printf("\n"); | |
249 | } | |
250 | } | |
251 | } | |
252 | kk=1; | |
253 | } | |
254 | else kk=0; | |
255 | if(pstyle || kk){ | |
256 | if(!part)printf("%s\n",sentp->sp); | |
257 | printf(" sentence length: %d ",nn); | |
258 | if(sc == 0){ | |
259 | if(comp == 0)printf("SIMPLE "); | |
260 | else printf("COMPOUND "); | |
261 | } | |
262 | else if(comp == 0)printf("COMPLEX "); | |
263 | else printf("COMPOUND-COMPLEX "); | |
264 | if(index==14)printf(":expletive:"); | |
265 | if(lpas)printf(":passive:"); | |
266 | if(rstyle||pstyle)printf(" readability %4.2f ",rd); | |
267 | printf(": begins with %s\n\n",names[index]); | |
268 | } | |
269 | if(index < 15)beg[index]++; | |
270 | if(nn > maxsent){ | |
271 | maxsent=nn; | |
272 | maxindex=numsent; | |
273 | } | |
274 | if(nn < minsent ){ | |
275 | minsent = nn; | |
276 | minindex=numsent; | |
277 | } | |
278 | numwds += nn; | |
279 | if(nn > 49)nn=49; | |
280 | sleng[nn]++; | |
281 | if(sc == 0){ | |
282 | if(comp == 0)simple++; | |
283 | else compound++; | |
284 | } | |
285 | else if(comp == 0)complex++; | |
286 | else compdx++; | |
287 | } |