|
|
1.1 root 1: %{
2:
3: #ifndef lint
4: static char sccsid[] = "@(#)part.l 4.3 (Berkeley) 90/06/26";
5: #endif not lint
6:
7: #include "style.h"
8: #include "names.h"
9: #include "conp.h"
10:
11: #undef yywrap
12:
13: FILE *deb;
14: int nosave = 1;
15: int part = 0;
16: int barebones = 0;
17: int topic = 0;
18: int style = 1;
19: int pastyle = 0;
20: int pstyle = 0;
21: int lstyle = 0;
22: int rstyle = 0;
23: int estyle = 0;
24: int nstyle = 0;
25: int Nstyle = 0;
26: int lthresh;
27: int rthresh;
28: int nomin;
29: char s[SCHAR];
30: char *sptr = s;
31: struct ss sent[SLENG];
32: struct ss *sentp = sent;
33: float wperc();
34: float sperc();
35: float typersent();
36: float vperc();
37: int numsent = 0;
38: int qcount = 0;
39: int icount = 0;
40: long vowel = 0;
41: long numwds = 0;
42: long twds = 0;
43: long numnonf = 0;
44: long letnonf = 0;
45: int maxsent = 0;
46: int maxindex = 0;
47: int minsent = 30;
48: int minindex = 0;
49: int simple = 0;
50: int compound = 0;
51: int compdx = 0;
52: int prepc = 0;
53: int conjc = 0;
54: int complex = 0;
55: int tobe = 0;
56: int adj = 0;
57: int infin = 0;
58: int pron = 0;
59: int passive = 0;
60: int aux = 0;
61: int adv = 0;
62: int verbc = 0;
63: int tverbc = 0;
64: int noun = 0;
65: long numlet = 0;
66: int beg[15] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 };
67: int sleng[50];
68: int nsleng = 0;
69: int j,jj,i;
70: int comma = 0;
71: int cflg;
72: int question;
73: int quote = 0;
74: char *st;
75: int initf = 0;
76: int over = 1;
77: int nroff = 0;
78: int nrofflg = 0;
79: int leng[MAXPAR];
80: int sentno= 0;
81: %}
82: C [A-DF-Za-z]
83: %%
84: ^{C}:.+ {
85: collect:
86: sentp->cc = sentp->ic = yytext[0];
87: if(sentp->cc == NOM)
88: sentp->cc = NOUN;
89: collect1:
90: nsleng++;
91: sentp->leng = yyleng-2;
92: sentp++->sp = sptr;
93: if(sentp >= &sent[SLENG-1]){
94: if(over)fprintf(stderr,"sentence %d too many words\n",numsent+2);
95: over=0;
96: sentp--;
97: }
98: if(sptr+yyleng >= &s[SCHAR-1]){
99: if(over)fprintf(stderr,"sentence %d too many characters\n",numsent+2);
100: over=0;
101: }
102: else {
103: for(i=2;i<yyleng;i++)*sptr++=yytext[i];
104: *sptr++ = '\0';
105: }
106: }
107: ^";:".+ {
108: sentp->cc=END;
109: sentp->ic = ';';
110: goto collect1;
111: }
112: ^",:".+ {
113: comma++;
114: goto collect;
115: }
116: ^",:"[:,-]+ {
117: comma++;
118: goto collect;
119: }
120: [\n] ;
121: ^"\":".+ {
122: goto collect;
123: }
124: ^E:"/." {
125: cflg = 1;
126: goto sdone;
127: }
128: ^E:.+ {
129: cflg = 0;
130: sdone:
131: over=1;
132: sentp->cc=sentp->ic=END;
133: sentp++->sp = sptr;
134: for(i=2;i<yyleng;i++)*sptr++=yytext[i];
135: *sptr++='\0';
136: if(yytext[2]=='?')question=1;
137: else question=0;
138:
139: fragment:
140: jj=0;
141: if(quote == 1 && sent[jj].cc == ED){
142: sent[jj].cc = VERB;
143: quote = 0;
144: }
145: if(sent[jj].cc=='"')jj++;
146: if(sent[jj].cc==SUBCONJ){
147: if(sent[jj+1].cc == ','){
148: sent[jj].cc=ADV;
149: jj += 2;
150: comma--;
151: }
152: else {
153: jj=scan(1,',',0);
154: if(jj != -1)jj++;
155: comma--;
156: }
157: }
158: if(jj != -1){
159: if(sent[jj].cc==CONJ || sent[jj].cc=='"')jj++;
160: while((jj=scan(jj,END,cflg)) != -1){
161: jj++;
162: if(sent[jj].cc == SUBCONJ && sent[jj+1].cc == ','){
163: sent[jj].cc=ADV;
164: jj += 2;
165: comma--;
166: }
167: }
168: }
169: st = sent[i].sp;
170: if(*(st+1) == '"')
171: if(*st == '?' || *st == '!')quote = 1;
172: outp();
173: nsleng = 0;
174: if(nroff){
175: if(sentno > 0){
176: printf(".SL \"");
177: for(i=0;i<sentno;i++)
178: printf(" %d",leng[i]);
179: printf("\"\n");
180: sentno = 0;
181: }
182: printf("%s",&yytext[1]);
183: nroff = 0;
184: }
185: sptr=s;
186: sentp=sent;
187: comma=0;
188: }
189: ;.+ {
190: if(style){
191: nomin = atoi(&yytext[1]);
192: }
193: }
194: ^:.+[\n] {
195: nrofflg=1;
196: if(sentp != sent){
197: sentp->cc = sentp->ic = END;
198: sentp++->sp = sptr;
199: *sptr++ = '.';
200: *sptr++ = '\0';
201: over = 1;
202: nroff = 1;
203: goto fragment;
204: }
205: if(sentno > 0){
206: printf(".SL \"");
207: for(i=0;i<sentno;i++)
208: printf(" %d",leng[i]);
209: printf("\"\n");
210: sentno = 0;
211: }
212: printf("%s",&yytext[1]);
213: }
214: %%
215: yywrap(){
216: int ii;
217: int ml,mg,lsum,gsum;
218: float aindex, avl, avw;
219: float cindex,kindex,findex,fgrad;
220: float syl, avsy, adjs,snonf;
221: FILE *io;
222:
223: if(style){
224: if(numwds == 0 || numsent == 0)exit(0);
225: avw = (float)(numwds)/(float)(numsent);
226: avl = (float)(numlet)/(float)(numwds);
227: aindex = 4.71*avl + .5*avw -21.43;
228: syl = .9981*vowel-.3432*twds;
229: avsy = syl/twds;
230: kindex = 11.8*avsy+.39*avw-15.59;
231: findex = 206.835-84.6*avsy-1.015*avw;
232: if(findex < 30.)fgrad = 17.;
233: else if(findex > 100.) fgrad = 4.;
234: else if(findex > 70.)fgrad=(100.-findex)/10 +5.;
235: else if(findex > 60.)fgrad =(70.-findex)/10+8.;
236: else if(findex >50.)fgrad=(60.-findex)/5+10;
237: else fgrad=(50.-findex)/6.66 +13.;
238: adjs = 100 * (float)numsent/numwds;
239: cindex = 5.89*avl-.3*adjs-15.8;
240: printf("readability grades:\n (Kincaid) %4.1f (auto) %4.1f (Coleman-Liau) %4.1f (Flesch) %4.1f (%4.1f)\n",kindex,aindex,cindex,fgrad,findex);
241: printf("sentence info:\n");
242: printf(" no. sent %d no. wds %ld\n",numsent,numwds);
243: printf(" av sent leng %4.1f av word leng %4.2f\n",avw,avl);
244: printf(" no. questions %d no. imperatives %d\n",qcount,icount);
245: if(numnonf != 0){
246: snonf = (float)(letnonf)/(float)(numnonf);
247: }
248: printf(" no. nonfunc wds %ld %4.1f%% av leng %4.2f\n",numnonf,(float)(numnonf)*100/numwds,snonf);
249: mg = avw + 10.5;
250: if(mg > 49)mg = 49;
251: ml = avw - 4.5;
252: if(ml <= 0)ml = 1;
253: else if(ml > 49)ml=48;
254: gsum = lsum = 0;
255: for(ii=0;ii<50;ii++){
256: if(ii < ml)lsum += sleng[ii];
257: else if(ii > mg)gsum+= sleng[ii];
258: }
259: printf(" short sent (<%d)%3.0f%% (%d) long sent (>%d) %3.0f%% (%d)\n",ml,sperc(lsum),lsum,mg,sperc(gsum),gsum);
260: printf(" longest sent %d wds at sent %d; shortest sent %d wds at sent %d\n",maxsent,maxindex,minsent,minindex);
261: printf("sentence types:\n");
262: printf(" simple %3.0f%% (%d) complex %3.0f%% (%d)\n",sperc(simple),simple,sperc(complex),complex);
263: printf(" compound %3.0f%% (%d) compound-complex %3.0f%% (%d)\n",sperc(compound),compound,sperc(compdx),compdx);
264: printf("word usage:\n");
265: printf(" verb types as %% of total verbs\n");
266: printf(" tobe %3.0f%% (%d) aux %3.0f%% (%d) inf %3.0f%% (%d)\n",vperc(tobe),tobe,vperc(aux),aux,vperc(infin),infin);
267: if(verbc != 0)adjs = (float)(passive)*100/(float)(verbc);
268: else adjs=0;
269: printf(" passives as %% of non-inf verbs %3.0f%% (%d)\n",adjs,passive);
270: printf(" types as %% of total\n");
271: printf(" prep %3.1f%% (%d) conj %3.1f%% (%d) adv %3.1f%% (%d)\n",wperc(prepc),prepc,wperc(conjc),conjc,wperc(adv),adv);
272: printf(" noun %3.1f%% (%d) adj %3.1f%% (%d) pron %3.1f%% (%d)\n",wperc(noun),noun,
273: wperc(adj),adj,wperc(pron),pron);
274: printf(" nominalizations %3.0f %% (%d)\n",wperc(nomin),nomin);
275: printf("sentence beginnings:\n");
276: ii=beg[0]+beg[7]+beg[6]+beg[3]+beg[8];
277: printf(" subject opener: noun (%d) pron (%d) pos (%d) adj (%d) art (%d) tot %3.0f%%\n",
278: beg[0],beg[7],beg[6],beg[3],beg[8],sperc(ii));
279: printf(" prep %3.0f%% (%d) adv %3.0f%% (%d) \n",sperc(beg[9]),beg[9],sperc(beg[4]),beg[4]);
280: printf(" verb %3.0f%% (%d) ",sperc(beg[1]+beg[10]+beg[11]),beg[1]+beg[10]+beg[11]);
281: printf(" sub_conj %3.0f%% (%d) conj %3.0f%% (%d)\n",sperc(beg[13]),beg[13],sperc(beg[5]),beg[5]);
282: printf(" expletives %3.0f%% (%d)\n",sperc(beg[14]),beg[14]);
283: #ifdef SCATCH
284: if(nosave && (fopen(SCATCH,"r")) != NULL){
285: if(((io=fopen(SCATCH,"a")) != NULL)){
286: fprintf(io," read %4.1f %4.1f %4.1f %4.1f %4.1f\n",kindex, aindex, cindex, findex, fgrad);
287: fprintf(io," sentl %d %ld %4.2f %4.2f %d %d %ld %4.2f\n",numsent,numwds,avw,avl,qcount,icount,numnonf,snonf);
288: fprintf(io," l var %d %d %d %d %d\n",ml,lsum,mg,gsum,maxsent);
289: fprintf(io," t var %d %d %d %d\n",simple,complex,compound,compdx);
290: fprintf(io," verbs %d %d %d %d %d %d\n",tverbc,verbc,tobe,aux,infin,passive);
291: fprintf(io," ty %d %d %d %d %d %d %d\n",prepc,conjc,adv,noun,adj,pron,nomin);
292: fprintf(io," beg %d %d %d %d %d %d\n",beg[0],beg[7],beg[6],beg[3],beg[8],ii);
293: fprintf(io," sbeg %d %d %d %d %d %d\n",beg[9],beg[4],beg[1]+beg[10]+beg[11],beg[13],beg[5],beg[14]);
294: }
295: }
296: #endif
297: }
298: return(1);
299: }
300: float
301: wperc(a)
302: {
303: return((float)(a)*100/numwds);
304: }
305: float
306: sperc(a)
307: {
308: return((float)(a)*100/numsent);
309: }
310: float
311: typersent(a)
312: {
313: return((float)(a)/numsent);
314: }
315: float
316: vperc(a)
317: {
318: if(tverbc == 0)return(0);
319: return((float)(a)*100/tverbc);
320: }
321: main(argc,argv)
322: char **argv;
323: {
324: while(--argc > 0 && (++argv)[0][0] == '-' ){
325: switch(argv[0][1]){
326: case 'd': nosave = 0;
327: continue;
328: case 's': style=1;
329: continue;
330: case 'p': pastyle=style=1;
331: continue;
332: case 'a': pstyle=style=1;
333: continue;
334: case 'e': estyle = style = 1;
335: continue;
336: case 'n': nstyle = style = 1;
337: continue;
338: case 'N': Nstyle = style = 1;
339: continue;
340: case 'l': style=lstyle=1;
341: lthresh = atoi(*(++argv));
342: argc--;
343: continue;
344: case 'r':
345: style=rstyle=1;
346: rthresh = atoi(*(++argv));
347: argc--;
348: continue;
349: case 'P':
350: part = 1;
351: style = 0;
352: continue;
353: case 'b': /* print bare bones info rje */
354: barebones = 1;
355: style = 0;
356: continue;
357: case 'T': /*topic*/
358: style = 0;
359: topic = 1;
360: continue;
361: default:
362: fprintf(stderr,"unknown flag to part %s\n",*argv);
363: exit(1);
364: }
365: argv++;
366: }
367: #ifdef SNOM
368: if(fopen(SNOM,"r") != NULL){
369: deb = fopen(SNOM,"a"); /* SAVE NOM*/
370: }
371: #else
372: deb = NULL;
373: #endif
374: yylex();
375: if(nrofflg && sentno > 0){
376: printf(".SL \"");
377: for(i=0;i<sentno;i++)
378: printf(" %d",leng[i]);
379: printf("\"\n");
380: }
381: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.