Annotation of researchv8dc/cmd/wwb/mkstand.c, revision 1.1.1.1

1.1       root        1: /* NOTICE-NOT TO BE DISCLOSED OUTSIDE BELL SYS EXCEPT UNDER WRITTEN AGRMT */
                      2: /* Writer's Workbench version 2.0, January 1981 */
                      3: #include <stdio.h>
                      4: #include <ctype.h>
                      5: #include <math.h>
                      6: #define MAXDOCS 75
                      7: #define NVAR 10
                      8: #define MINSENT 90
                      9: #define MINWDS 1900
                     10: #define FALSE 0
                     11: #define TRUE 1
                     12: #define MINN 20
                     13: 
                     14: char filen[MAXDOCS][15], extra[MAXDOCS], extra2[MAXDOCS];
                     15: float kindex[MAXDOCS], avw[MAXDOCS],snonf[MAXDOCS],  simple[MAXDOCS],complex[MAXDOCS], compound[MAXDOCS],  compdx[MAXDOCS];
                     16: float ppron[MAXDOCS],padj[MAXDOCS];
                     17: float passive[MAXDOCS],explet[MAXDOCS];
                     18: int nomin[MAXDOCS],x[MAXDOCS];
                     19: int maxsent[MAXDOCS], numsent[MAXDOCS], numwds[MAXDOCS],qcount[MAXDOCS], icount[MAXDOCS],numnonf[MAXDOCS],ml[MAXDOCS],lsum[MAXDOCS],mg[MAXDOCS],gsum[MAXDOCS];
                     20: int maxindex[MAXDOCS],minindex[MAXDOCS],minsent[MAXDOCS];
                     21: float aindex[MAXDOCS],cindex[MAXDOCS],fgrad[MAXDOCS],findex[MAXDOCS],avl[MAXDOCS],fnumnonf[MAXDOCS],centlsum[MAXDOCS],centgsum[MAXDOCS];
                     22: int nsimple[MAXDOCS],ncomplex[MAXDOCS],ncompound[MAXDOCS],ncompdx[MAXDOCS],ntobe[MAXDOCS];
                     23: int npassive[MAXDOCS],pron[MAXDOCS],pos[MAXDOCS],adj[MAXDOCS],art[MAXDOCS],beg[MAXDOCS],begadv[MAXDOCS],begprep[MAXDOCS],begverb[MAXDOCS],begscon[MAXDOCS];
                     24: int begconj[MAXDOCS], begexp[MAXDOCS],noun[MAXDOCS];
                     25: float ptobe[MAXDOCS],paux[MAXDOCS],pinfin[MAXDOCS],padv[MAXDOCS],pconjc[MAXDOCS],pprepc[MAXDOCS],pnoun[MAXDOCS],pnomin[MAXDOCS],tot[MAXDOCS];
                     26: float pbegprep[MAXDOCS],pbegadv[MAXDOCS],pbegverb[MAXDOCS],pbegscon[MAXDOCS],pbegconj[MAXDOCS],pbegexp[MAXDOCS];
                     27: int tobe[MAXDOCS],aux[MAXDOCS],infin[MAXDOCS],prepc[MAXDOCS],conjc[MAXDOCS],adv[MAXDOCS];
                     28: 
                     29: FILE *fopen(), *stylout, *out, *scores, *tmp;
                     30: 
                     31: 
                     32: main(argc, argv)
                     33: int argc;
                     34: char *argv[];
                     35: {
                     36:        int n, i, j, x;
                     37:        int aok,ok,once,lmesg;
                     38:        int number, orignum;
                     39:        float m[NVAR], sd[NVAR];
                     40:        float *score[NVAR], mm2[NVAR], mm1[NVAR], mp1[NVAR], mp2[NVAR];
                     41:        char *file[MAXDOCS];
                     42:        float mean(), sdev();
                     43:        float smpmcmp[MAXDOCS], cmpcmdx[MAXDOCS];
                     44:        int nvar;
                     45:        char name[14], *pid;
                     46: 
                     47:        /*  Begin  */
                     48: 
                     49:        number = *argv[1];
                     50:        number=number-'0';
                     51:        if(isdigit(*(argv[1]+1)))number=10*number+(*(argv[1]+1)-'0');
                     52:        orignum=number;
                     53:        pid=argv[2];
                     54:        sprintf(name,"/tmp/%sstat.out",pid);
                     55:        if((stylout=fopen(name,"r"))==NULL) {
                     56:                fprintf(stderr, "Can't read %s.\n",name);
                     57:                exit(2);
                     58:        }
                     59:        if((out=fopen("stand.out","w"))==NULL) {
                     60:                printf("Can't write \"stand.out\".\n");
                     61:                exit(2);
                     62:        }
                     63:        if((scores=fopen("styl.scores","w"))==NULL) {
                     64:                printf("Can't write \"styl.scores\".\n");
                     65:                exit(2);
                     66:        }
                     67: 
                     68:        aok=FALSE;
                     69:        once=FALSE;
                     70:        lmesg=FALSE;
                     71: 
                     72:        /*  Read style scores  */
                     73: 
                     74:        for(n=0; n<number; n++) {
                     75:                fscanf(stylout,"%s %s %s\n", extra[n],extra2[n],filen[n]);
                     76:                fscanf(stylout,"readability grades:\n");
                     77:                fscanf(stylout,"        (Kincaid) %f  (auto) %f  (Coleman-Liau) %f  (Flesch) %f (%f)",&kindex[n],&aindex[n],&cindex[n],&fgrad[n],&findex[n]);
                     78:                fscanf(stylout," sentence info:");
                     79:                fscanf(stylout," no. sent %d no. wds %ld",&numsent[n],&numwds[n]);
                     80:                fscanf(stylout," av sent leng %f av word leng %f",&avw[n],&avl[n]);
                     81:                fscanf(stylout," no. questions %d no. imperatives %d",&qcount[n],&icount[n]);
                     82:                fscanf(stylout," no. content wds %d  %f%%   av leng %f",&numnonf[n],&fnumnonf[n],&snonf[n]);
                     83:                fscanf(stylout," short sent (<%d)%f%% (%d) long sent (>%d) %f%% (%d)",&ml[n],&centlsum[n],&lsum[n],&mg[n],&centgsum[n],&gsum[n]);
                     84:                fscanf(stylout," longest sent %d wds at sent %d; shortest sent %d wds at sent %d",&maxsent[n],&maxindex[n],&minsent[n],&minindex[n]);
                     85:                fscanf(stylout," sentence types:");
                     86:                fscanf(stylout," simple %f%% (%d) complex %f%% (%d)",&simple[n],&nsimple[n],&complex[n],&ncomplex[n]);
                     87:                fscanf(stylout," compound %f%% (%d) compound-complex %f%% (%d)",&compound[n],&ncompound[n],&compdx[n],&ncompdx[n]);
                     88:                fscanf(stylout," word usage:");
                     89:                fscanf(stylout," verb types as %% of total verbs");
                     90:                fscanf(stylout," tobe %f%% (%d) aux %f%% (%d) inf %f%% (%d)",&ptobe[n],&tobe[n],&paux[n],&aux[n],&pinfin[n],&infin[n]);
                     91:                fscanf(stylout," passives as %% of non-inf verbs %f%% (%d)",&passive[n],&npassive[n]);
                     92:                fscanf(stylout," types as %% of total");
                     93:                fscanf(stylout," prep %f%% (%d) conj %f%% (%d) adv %f%% (%d)",&pprepc[n],&prepc[n],&pconjc[n],&conjc[n],&padv[n],&adv[n]);
                     94:                fscanf(stylout," noun %f%% (%d) adj %f%% (%d) pron %f%% (%d)",&pnoun[n],&noun[n], &padj[n],&adj[n],&ppron[n],&pron[n]);
                     95:                fscanf(stylout," nominalizations %f %% (%d)",&pnomin[n],&nomin[n]);
                     96:                fscanf(stylout," sentence beginnings:");
                     97:                fscanf(stylout," subject opener: noun (%d) pron (%d) pos (%d) adj (%d) art (%d) tot %f%%",&noun[n],&pron[n],&pos[n],&adj[n],&art[n],&tot[n]);
                     98:                fscanf(stylout," prep %f%% (%d) adv %f%% (%d) ",&pbegprep[n],&begprep[n],&pbegadv[n],&begadv[n]);
                     99:                fscanf(stylout," verb %f%% (%d) ",&pbegverb[n],&begverb[n]);
                    100:                fscanf(stylout,"  sub_conj %f%% (%d) conj %f%% (%d)",&pbegscon[n],&begscon[n],&pbegconj[n],&begconj[n]);
                    101:                fscanf(stylout," expletives %f%% (%d)",&pbegexp[n],&begexp[n]);
                    102:        }
                    103:        fclose(stylout);
                    104: 
                    105: 
                    106:        /*  Set file to point at filen  */
                    107:        for(n=0; n<number; n++) file[n]=filen[n];
                    108: 
                    109:        /*  Compute sentence variation and complexity scores  */
                    110: 
                    111:        for(n=0; n<number; n++) {
                    112:                smpmcmp[n] = simple[n] - complex[n];
                    113:                cmpcmdx[n] = compound[n] + compdx[n];
                    114:        }
                    115: 
                    116:        /*  Set score arrays  */
                    117: 
                    118:        score[0]=kindex;
                    119:        score[1]=snonf;
                    120:        score[2]=centlsum;
                    121:        score[3]=centgsum;
                    122:        score[4]=passive;
                    123:        score[5]=pnomin;
                    124:        score[6]=avw;
                    125:        score[7]=pbegexp;
                    126:        score[8]=smpmcmp;
                    127:        score[9]=cmpcmdx;
                    128:        nvar=NVAR;
                    129: 
                    130:        /*  Check file lengths  */
                    131:        n=0;
                    132:        while(n < number) {
                    133:                if(numsent[n] < MINSENT && numwds[n] < MINWDS) {
                    134:                        if(lmesg==FALSE) {
                    135:                                printf("Files must be at least 1900 words OR 90 sentences long,\nfor mkstand to compute reliable standards.\n");
                    136:                                lmesg=TRUE;
                    137:                        }
                    138:                        printf("File %s is too short, its scores will be excluded.\n", file[n]);
                    139:                        for(i=n; i<number-1; i++) {
                    140:                                file[i]=file[i+1];
                    141:                                kindex[i]=kindex[i+1];
                    142:                                snonf[i]=snonf[i+1];
                    143:                                centlsum[i]=centlsum[i+1];
                    144:                                centgsum[i]=centgsum[i+1];
                    145:                                passive[i]=passive[i+1];
                    146:                                pnomin[i]=pnomin[i+1];
                    147:                                avw[i]=avw[i+1];
                    148:                                pbegexp[i]=pbegexp[i+1];
                    149:                                smpmcmp[i]=smpmcmp[i+1];
                    150:                                cmpcmdx[i]=cmpcmdx[i+1];
                    151:                                numwds[i]=numwds[i+1];
                    152:                                numsent[i]=numsent[i+1];
                    153:                        }
                    154:                        number=number-1;
                    155:                }
                    156:                else n++;
                    157:        }
                    158: 
                    159:        /*  While aok = FALSE  */
                    160: 
                    161:        while(aok==FALSE) {
                    162:                ok=TRUE;
                    163: 
                    164:                /*  Check new number  */
                    165: 
                    166:                if(number<=1) {
                    167:                        if(number==0) printf("All the input files ");
                    168:                        if(number==1) printf("All the input files but one ");
                    169:                        printf("were too short\nfor mkstand to compute reliable standards.\n");
                    170:                        printf("Rerun mkstand with files that are longer than 1900 words or 90 sentences.\n");
                    171:                        exit(2);
                    172:                }
                    173:                if(number < MINN && orignum >= MINN) {
                    174:                        printf("Since some files had to be excluded,\nthere are no longer 20 files.\n");
                    175:                        printf("Mkstand will compute the standards,\n");
                    176:                        printf("but they would probably be more reliable.\n");
                    177:                        printf("if you run mkstand again with additional files\n");
                    178:                        printf("to replace those that were excluded.\n");
                    179:                }
                    180: 
                    181:                /*  Compute standards  */
                    182: 
                    183:                for(i=0; i<nvar; i++) {
                    184:                        m[i]=mean(score[i],number);
                    185: 
                    186:                        sd[i]=sdev(score[i],m[i],number);
                    187: 
                    188:                        mm2[i] = m[i] - 2 * sd[i];
                    189:                        mm1[i] = m[i] - sd[i];
                    190:                        mp1[i] = m[i] + sd[i];
                    191:                        mp2[i] = m[i] + 2 * sd[i];
                    192: 
                    193:                }
                    194: 
                    195:                /*  Check for outliers  */
                    196: 
                    197:                if(once==FALSE) {
                    198:                        n=0;
                    199:                        while(n < number) {
                    200:                                for(i=0; i<nvar; i++) {
                    201:                                        if(score[i][n] < mm2[i] || score[i][n] > mp2[i]) {
                    202:                                                ok=FALSE;
                    203:                                                once=TRUE;
                    204:                                                printf("File %s has a score more than 2 standard deviations from the mean,\nand will be excluded.\n", file[n]);
                    205:                                                for(j=n; j<number-1; j++) {
                    206:                                                        file[j]=file[j+1];
                    207:                                                        kindex[j]=kindex[j+1];
                    208:                                                        snonf[j]=snonf[j+1];
                    209:                                                        centlsum[j]=centlsum[j+1];
                    210:                                                        centgsum[j]=centgsum[j+1];
                    211:                                                        passive[j]=passive[j+1];
                    212:                                                        pnomin[j]=pnomin[j+1];
                    213:                                                        avw[j]=avw[j+1];
                    214:                                                        pbegexp[j]=pbegexp[j+1];
                    215:                                                        smpmcmp[j]=smpmcmp[j+1];
                    216:                                                        cmpcmdx[j]=cmpcmdx[j+1];
                    217:                                                }
                    218:                                                number=number-1;
                    219:                                                i=nvar;
                    220:                                        }
                    221:                                        else if(i==nvar-1) n++;
                    222:                                }
                    223:                        }
                    224:                        if(ok != FALSE) aok=TRUE;
                    225:                }
                    226:                else aok=TRUE;
                    227:        }
                    228: 
                    229:        /*  Print scores for examination  */
                    230: 
                    231:        printf("The style scores used to compile the standards\n");
                    232:        printf("are in a file named styl.scores.  Please examine\n");
                    233:        printf("this file for any scores that seem unusual or invalid.\n");
                    234:        printf("If you find any, rerun mkstand without the unusual\n");
                    235:        printf("document.\n");
                    236:        for(n=0;n<number; n++) {
                    237:                fprintf(scores,"Document %s:\n", file[n]);
                    238:                fprintf(scores,"\tKincaid readability  %4.1f\n", kindex[n]);
                    239:                fprintf(scores,"\tAve. length of non-function words  %4.1f\n", snonf[n]);
                    240:                fprintf(scores,"\t%% short sentences  %4.1f\n", centlsum[n]);
                    241:                fprintf(scores,"\t%% long sentences  %4.1f\n", centgsum[n]);
                    242:                fprintf(scores,"\t%% passives  %4.1f\n", passive[n]);
                    243:                fprintf(scores,"\t%% nominalizations  %4.1f\n", pnomin[n]);
                    244:                fprintf(scores,"\tAve. sentence length  %4.1f\n", avw[n]);
                    245:                fprintf(scores,"\t%% expletives as sentence beginners  %4.1f\n", pbegexp[n]);
                    246:                fprintf(scores,"\t%% simple sentences minus %% complex sentences  %4.1f\n", smpmcmp[n]);
                    247:                fprintf(scores,"\t%% compound sentences plus %% compound-complex sentences  %4.1f\n", cmpcmdx[n]);
                    248:                fprintf(scores,"\n");
                    249:        }
                    250: 
                    251:        /*  Write standards to stand.out  */
                    252: 
                    253:        for(i=0; i<nvar; i++) {
                    254:                fprintf(out,"%4.2f %4.2f %4.2f %4.2f\n", mm2[i], mm1[i], mp1[i], mp2[i]);
                    255:                if(i==3)
                    256:                        fprintf(out,"0.0 0.0 0.0 0.0\n0.0 0.0 0.0 0.0\n0.0 0.0 0.0 0.0\n0.0 0.0 0.0 0.0\n");
                    257:        }
                    258: }
                    259: float sdev(score,m,n)
                    260: float score[], m;
                    261: int n;
                    262: {
                    263:        float *sc, sumsq;
                    264: double sqrt();
                    265: 
                    266:        sumsq=0.0;
                    267:        for(sc = score; sc < score + n; sc++) sumsq += (*sc-m) * (*sc-m);
                    268:        return(sqrt(sumsq/(n-1)));
                    269: }
                    270: float mean(score,n)
                    271: float score[];
                    272: int n;
                    273: {
                    274: 
                    275:        float *sc, sum;
                    276: 
                    277:        sum=0.0;
                    278:        for(sc = score; sc < score +n; sc++) sum += *sc;
                    279:        return(sum/n);
                    280: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.