148247Sbostic /*-
248247Sbostic * %sccs.include.proprietary.c%
348247Sbostic */
448247Sbostic
59075Srrh #ifndef lint
6*61978Sbostic static char sccsid[] = "@(#)outp.c 8.1 (Berkeley) 06/06/93";
748247Sbostic #endif /* not lint */
89075Srrh
99081Srrh #include <stdio.h>
109081Srrh #include <ctype.h>
119075Srrh #include "style.h"
129075Srrh #include "names.h"
139075Srrh #include "conp.h"
149075Srrh char *names[] = {
159075Srrh "noun", "verb", "interjection", "adjective", "adverb", "conjunction", "possessive",
169081Srrh "pronoun", "article", "preposition", "auxiliary", "tobe", "", "subordinate conjunction", "expletive"
179075Srrh };
189081Srrh extern int barebones;
outp()199075Srrh outp(){
209075Srrh struct ss *st;
219075Srrh char *ssp;
229075Srrh char *spart, ff;
239075Srrh int index, lverbc;
249075Srrh int nn, sc, f, kk,comp, begsc;
259075Srrh int conjf, verbf,lpas,bflg,lexp,olvb;
269081Srrh int nom;
279075Srrh int infinf, ovflg;
289075Srrh int lvowel,nlet;
299075Srrh int imper;
309075Srrh float rd;
319081Srrh extern FILE *deb;
329081Srrh extern int nosave;
339075Srrh
349081Srrh if(barebones){
359081Srrh for(sentp=sent;sentp->cc != END;sentp++)
369081Srrh printf("%s %c %c\n",sentp->sp,sentp->ic,sentp->cc);
379081Srrh printf("%s %c %c\n",sentp->sp,sentp->ic,sentp->cc);
389081Srrh return;
399081Srrh }
409081Srrh if(topic){
419081Srrh for(sentp=sent;sentp->cc != END;sentp++){
429081Srrh if(sentp->cc==ADJ && (sentp+1)->cc==NOUN){
439081Srrh printf("%s ",sentp->sp);
449081Srrh sentp++;
459081Srrh printf("%s\n",sentp->sp);
469081Srrh }
479081Srrh else if(sentp->cc==NOUN)printf("%s\n",sentp->sp);
489081Srrh }
499081Srrh return;
509081Srrh }
519075Srrh if(style){
529075Srrh nn = kk = 0;
539075Srrh for(sentp=sent;sentp->cc != END;sentp++){
549075Srrh if(sentp->cc != ',' && sentp->cc != '"')nn++;
559075Srrh if(sentp->cc == VERB || sentp->cc == BE || sentp->cc == AUX)kk++;
569075Srrh }
579075Srrh if(nn < 4 && kk == 0)return;
589075Srrh }
599075Srrh
609081Srrh imper = lexp = lpas = index = lverbc = nom = 0;
619075Srrh conjf = verbf = kk = nn = sc = comp = begsc = 0;
629075Srrh bflg = olvb = infinf = ovflg = 0;
639075Srrh nlet = 0;
649075Srrh f = 1;
659075Srrh sentp=sent;
669075Srrh while(sentp->cc != END){
679075Srrh /* printf("%c:",sentp->ic); */
689075Srrh if(sentp->cc == ';')comp++;
699075Srrh else {
709075Srrh if((sentp->cc != ',') && (sentp->cc != '"')){
719075Srrh if(*sentp->sp != 'x'){
729075Srrh nn++;
739075Srrh nlet += sentp->leng;
749075Srrh }
759075Srrh kk++;
769075Srrh }
779075Srrh }
789075Srrh switch(sentp->cc){
799075Srrh case NOUN:
809075Srrh spart ="noun";
819075Srrh if(f)index=0;
829081Srrh if((sentp->ic==NOM)||(sentp->ic==PNOUN && islower(*(sentp->sp)))){
839081Srrh sentp->ic = NOM;
849081Srrh nom++;
859081Srrh if(nosave && (deb != NULL)) /* SAVE NOM */
869081Srrh fprintf(deb,"%s\n",sentp->sp);
879081Srrh }
889075Srrh if(*sentp->sp != 'x'){
899075Srrh noun++;
909075Srrh numnonf++;
919075Srrh letnonf += sentp->leng;
929075Srrh }
939075Srrh bflg = infinf = ovflg = 0;
949075Srrh break;
959075Srrh case VERB:
969075Srrh spart = "verb";
979075Srrh if(f)index=1;
989075Srrh if(sentp->ic==TO){
999075Srrh infin++;
1009075Srrh infinf=1;
1019075Srrh lverbc++;
1029075Srrh }
1039075Srrh else {
1049075Srrh if(f)imper=1;
1059075Srrh if(ovflg == 0 && infinf == 0){
1069075Srrh ovflg = 1;
1079075Srrh lverbc++;
1089075Srrh olvb++;
1099075Srrh }
1109075Srrh numnonf++;
1119075Srrh letnonf += sentp->leng;
1129075Srrh if(infinf == 0){
1139075Srrh if(verbf == 0)verbf++;
1149075Srrh else if(conjf)comp++;
1159075Srrh }
1169081Srrh if(bflg && sentp->ic == ED){lpas++; ++passive;}
1179075Srrh }
1189075Srrh break;
1199075Srrh case INTER:
1209075Srrh spart = "interj";
1219075Srrh if(f)index=2;
1229075Srrh bflg = infinf = ovflg = 0;
1239075Srrh break;
1249075Srrh case ADJ:
1259075Srrh spart = "adj";
1269075Srrh if(f)index=3;
1279075Srrh adj++;
1289075Srrh numnonf++;
1299081Srrh if(sentp->ic == NOM){
1309081Srrh nom++;
1319081Srrh if(nosave && (deb != NULL)) /* SAVE NOM */
1329081Srrh fprintf(deb,"%s\n",sentp->sp);
1339081Srrh }
1349075Srrh letnonf += sentp->leng;
1359075Srrh bflg = infinf = ovflg = 0;
1369075Srrh break;
1379075Srrh case ADV:
1389075Srrh spart = "adv";
1399075Srrh if(f)index=4;
1409075Srrh adv++;
1419075Srrh numnonf++;
1429075Srrh letnonf += sentp->leng;
1439075Srrh break;
1449075Srrh case CONJ:
1459075Srrh spart = "conj";
1469075Srrh conjc++;
1479075Srrh if(f)index=5;
1489075Srrh if(infinf && (sentp+1)->cc == VERB);
1499075Srrh else {
1509075Srrh if(verbf)conjf++;
1519075Srrh bflg = infinf = ovflg = 0;
1529075Srrh }
1539075Srrh break;
1549075Srrh case POS:
1559075Srrh spart = "pos";
1569075Srrh if(f)index=6;
1579075Srrh bflg = infinf = ovflg = 0;
1589075Srrh break;
1599075Srrh case PRONS:
1609075Srrh case PRONP:
1619075Srrh spart = "pron";
1629075Srrh pron++;
1639075Srrh if(f){
1649075Srrh index=7;
1659075Srrh if((sentp+1)->cc == BE){
1669075Srrh if(sentp->leng == 5 && *(sentp->sp) == 't' && *((sentp->sp)+3)=='r'){index=14;lexp=1;}
1679075Srrh else if(sentp->leng ==2&& *(sentp->sp) == 'i' ){index=14;lexp=1;}
1689075Srrh }
1699075Srrh }
1709075Srrh bflg = infinf = ovflg = 0;
1719075Srrh if(sentp->ic == THAT || sentp->ic == WHO)sc++;
1729075Srrh break;
1739075Srrh case ART:
1749075Srrh spart = "art";
1759075Srrh if(f)index=8;
1769075Srrh bflg = infinf = ovflg = 0;
1779075Srrh break;
1789075Srrh case PREP:
1799075Srrh spart = "prep";
1809075Srrh if(f)index=9;
1819075Srrh prepc++;
1829075Srrh bflg = infinf = ovflg = 0;
1839075Srrh break;
1849075Srrh case AUXX:
1859075Srrh spart = "aux";
1869075Srrh if(ovflg == 0 && infinf == 0){
1879075Srrh ovflg = 1;
1889075Srrh lverbc++;
1899075Srrh olvb++;
1909075Srrh aux++;
1919075Srrh }
1929075Srrh if(f)index=10;
1939075Srrh break;
1949075Srrh case BE:
1959075Srrh if(ovflg == 0 && infinf == 0){
1969075Srrh ovflg = 1;
1979075Srrh lverbc++;
1989075Srrh olvb++;
1999075Srrh }
2009075Srrh spart = "be";
2019075Srrh if(f)index=11;
2029075Srrh tobe++;
2039075Srrh bflg = 1;
2049075Srrh if(verbf == 0)verbf++;
2059075Srrh else if(conjf)comp++;
2069075Srrh break;
2079075Srrh case SUBCONJ:
2089075Srrh spart = "subcj";
2099075Srrh if(f){
2109075Srrh index=13;
2119075Srrh begsc++;
2129075Srrh }
2139075Srrh sc++;
2149075Srrh if((sentp-1)->cc != CONJ)
2159075Srrh verbf = conjf = 0;
2169075Srrh bflg = infinf = ovflg = 0;
2179075Srrh break;
2189075Srrh default:
2199075Srrh if(sentp->cc == ','){
2209075Srrh if(begsc)conjf=verbf=0;
2219075Srrh }
2229075Srrh spart = sentp->sp;
2239075Srrh }
2249075Srrh if(part){
2259075Srrh printf("%s %s\n",spart,sentp->sp);
2269075Srrh }
2279075Srrh if(style){
2289075Srrh ssp=sentp->sp;
2299075Srrh lvowel = 0;
2309075Srrh while(*ssp != '\0'){
2319075Srrh if(*ssp >= '0' && *ssp <= '9'){
2329075Srrh lvowel=0;
2339075Srrh break;
2349075Srrh }
2359075Srrh switch(*(ssp++)){
2369075Srrh case 'a':
2379075Srrh case 'e':
2389075Srrh case 'i':
2399075Srrh case 'o':
2409075Srrh case 'u':
2419075Srrh case 'y':
2429075Srrh case 'A':
2439075Srrh case 'E':
2449075Srrh case 'I':
2459075Srrh case 'O':
2469075Srrh case 'U':
2479075Srrh case 'Y':
2489075Srrh lvowel++;
2499075Srrh continue;
2509075Srrh }
2519075Srrh }
2529075Srrh if(lvowel != 0){
2539075Srrh vowel += lvowel;
2549075Srrh twds++;
2559075Srrh }
2569075Srrh }
2579075Srrh if(f){
2589075Srrh ff=sentp->cc;
2599075Srrh f=0;
2609075Srrh }
2619075Srrh sentp++;
2629075Srrh }
2639075Srrh if(part){
2649081Srrh printf(". %s\n",sentp->sp);
2659081Srrh if(sentno < MAXPAR && nn > 0)
2669081Srrh leng[sentno++] = nn;
2679075Srrh }
2689081Srrh if(nn == 0)return;
2699075Srrh numsent++;
2709075Srrh numlet += nlet;
2719075Srrh tverbc += lverbc;
2729075Srrh verbc += olvb;
2739075Srrh if(*(sentp->sp) == '?'){
2749075Srrh if(sc > 0)sc -= 1;
2759075Srrh qcount++;
2769075Srrh }
2779075Srrh else if(*(sentp->sp) == '/')icount++;
2789075Srrh else if(imper)icount++;
2799075Srrh if(rstyle||pstyle)rd = 4.71*((float)(nlet)/(float)(nn))+.5*(float)(nn)-21.43;
2809081Srrh if(pstyle ||
2819081Srrh (rstyle&& rd>=rthresh)||(lstyle&&nn >= lthresh)||(pastyle&&lpas)||(estyle&&lexp)
2829081Srrh || (nstyle && (nom > 1 || (nom && lpas)))|| (Nstyle && nom)){
2839075Srrh if(!part){
2849075Srrh for(st=sent, kk=0;st->cc != END;st++){
2859081Srrh if(st->ic == NOM)
2869081Srrh printf("*%s* ",st->sp);
2879081Srrh else printf("%s ",st->sp);
2889075Srrh if(kk++ >= 15){
2899075Srrh kk=0;
2909075Srrh printf("\n");
2919075Srrh }
2929075Srrh }
2939075Srrh }
2949075Srrh kk=1;
2959075Srrh }
2969075Srrh else kk=0;
2979075Srrh if(pstyle || kk){
2989075Srrh if(!part)printf("%s\n",sentp->sp);
2999075Srrh printf(" sentence length: %d ",nn);
3009075Srrh if(sc == 0){
3019075Srrh if(comp == 0)printf("SIMPLE ");
3029075Srrh else printf("COMPOUND ");
3039075Srrh }
3049075Srrh else if(comp == 0)printf("COMPLEX ");
3059075Srrh else printf("COMPOUND-COMPLEX ");
3069075Srrh if(index==14)printf(":expletive:");
3079075Srrh if(lpas)printf(":passive:");
3089075Srrh if(rstyle||pstyle)printf(" readability %4.2f ",rd);
3099075Srrh printf(": begins with %s\n\n",names[index]);
3109075Srrh }
3119075Srrh if(index < 15)beg[index]++;
3129075Srrh if(nn > maxsent){
3139075Srrh maxsent=nn;
3149075Srrh maxindex=numsent;
3159075Srrh }
3169075Srrh if(nn < minsent ){
3179075Srrh minsent = nn;
3189075Srrh minindex=numsent;
3199075Srrh }
3209075Srrh numwds += nn;
3219075Srrh if(nn > 49)nn=49;
3229075Srrh sleng[nn]++;
3239075Srrh if(sc == 0){
3249075Srrh if(comp == 0)simple++;
3259075Srrh else compound++;
3269075Srrh }
3279075Srrh else if(comp == 0)complex++;
3289075Srrh else compdx++;
3299075Srrh }
330