void read_grammar(char *filename) { char buffer[1000]; FILE *file; init_lexicons(); if(GDEBUG) fprintf(stderr,"Initialised lexicons\n"); init_grammar(); if(GDEBUG) fprintf(stderr,"Initialised grammar\n"); strcpy(buffer,filename); strcat(buffer,".nts"); file = fopen(buffer,"r"); read_nonterminals(file); file = fopen(buffer,"r"); read_nonterminals2(file); if(GDEBUG) fprintf(stderr,"Loaded non-terminals\n"); strcpy(buffer,filename); strcat(buffer,".lexicon"); file = fopen(buffer,"r"); read_lexicon(file); if(GDEBUG) fprintf(stderr,"Loaded lexicon\n"); strcpy(buffer,filename); strcat(buffer,".grm"); file = fopen(buffer,"r"); read_grm(file); if(GDEBUG) fprintf(stderr,"Loaded grammar\n"); }
int main(int argc, char **argv) { char ch[TailleLigne]; int nb,nbentries,i,j; lia_avl_t t_lexique, t_unknown,*table; FILE *file; unsigned long total; if (argc<=2) { fprintf(stderr,"Syntaxe : %s <lexicon> <name report>\n",argv[0]); exit(0); } t_lexique=read_lexicon(argv[1]); t_unknown=checking_corpus(stdin,t_lexique); fprintf(stderr,"- report OOV words\n"); sprintf(ch,"%s.oov",argv[2]); if (!(file=fopen(ch,"wt"))) ERREUR("can't write in :",ch); table=lia_avl_tree2table_freq(t_unknown,&nb); fprintf(stderr,"\t-> %d entree inconnues dans le corpus\n",nb); for(i=0;i<nb;i++) fprintf(file,"\t%5d \t %s\n",table[i]->nb,table[i]->info); fclose(file); free(table); fprintf(stderr,"done\n"); fprintf(stderr,"- report ZEROTON words\n"); sprintf(ch,"%s.zeroton",argv[2]); if (!(file=fopen(ch,"wt"))) ERREUR("can't write in :",ch); table=lia_avl_tree2table_freq(t_lexique,&nb); for(i=j=0;i<nb;i++) if (table[i]->nb==1) { j++; fprintf(file,"%s\n",table[i]->info); } fclose(file); fprintf(stderr,"\t-> %d ZEROTON dans le corpus\n",j); fprintf(stderr,"done\n"); fprintf(stderr,"- report words from the lexicon in the corpus\n"); sprintf(ch,"%s.occ",argv[2]); if (!(file=fopen(ch,"wt"))) ERREUR("can't write in :",ch); for(nbentries=0,i=0,total=0;i<nb;i++) if (table[i]->nb>1) { nbentries++; total+=(unsigned long)(table[i]->nb-1); fprintf(file,"\t%5d \t %s\n",table[i]->nb-1,table[i]->info); } free(table); fclose(file); fprintf(stderr,"\t-> %ld occurences for %d entries\n",total,nbentries); fprintf(stderr,"done\n"); exit(0); }
int main(int argc, char **argv) { char ch[TailleLigne],*pt,*ptbak1,*ptbak2,test[TailleLigne]; int nb; lia_avl_t t_lexique; if (argc<2) { fprintf(stderr,"Syntaxe : %s <lexicon>\n",argv[0]); exit(0); } t_lexique=read_lexicon(argv[1]); while(fgets(ch,TailleLigne,stdin)) { ptbak2=ptbak1=NULL; for(pt=strtok(ch," \t\n");(ptbak2!=pt)||(ptbak1!=pt);) { if ((ptbak1)&&(ptbak1[strlen(ptbak1)-1]=='\'')) { if ((ptbak2)&&(ptbak1[0]=='\'')) { sprintf(test,"%s'%s",ptbak2,pt); /*fprintf(stderr,"test=[%s]\n",test);*/ if (lia_recherche_avl(t_lexique,test,&nb)) { printf(" %s",test); /*fprintf(stderr,"test=[%s]\n",test);*/ /* ptbak2=strtok(NULL," \t\n"); if (ptbak2) ptbak1=strtok(NULL," \t\n"); else ptbak1=NULL; if (ptbak1) pt=strtok(NULL," \t\n"); else pt=NULL; */ ptbak2=NULL; ptbak1=strtok(NULL," \t\n"); if (ptbak1) pt=strtok(NULL," \t\n"); else pt=NULL; } else { sprintf(test,"%s'",ptbak2); /*fprintf(stderr,"test=[%s]\n",test);*/ if (lia_recherche_avl(t_lexique,test,&nb)) { printf(" %s",test); ptbak2=NULL; ptbak1=pt; if (pt) pt=strtok(NULL," \t\n"); } else { printf(" %s",ptbak2); ptbak2=ptbak1; ptbak1=pt; if (pt) pt=strtok(NULL," \t\n"); } } } else { sprintf(test,"%s%s",ptbak1,pt); /*fprintf(stderr,"test=[%s]\n",test);*/ if (lia_recherche_avl(t_lexique,test,&nb)) { /*fprintf(stderr,"\tOK\n");*/ if (ptbak2) printf(" %s",ptbak2); printf(" %s",test); /* ptbak2=strtok(NULL," \t\n"); if (ptbak2) ptbak1=strtok(NULL," \t\n"); else ptbak1=NULL; if (ptbak1) pt=strtok(NULL," \t\n"); else pt=NULL; */ ptbak2=NULL; ptbak1=strtok(NULL," \t\n"); if (ptbak1) pt=strtok(NULL," \t\n"); else pt=NULL; } else { if (ptbak2) printf(" %s",ptbak2); ptbak2=ptbak1; ptbak1=pt; if (pt) pt=strtok(NULL," \t\n"); } } } else { if (ptbak2) printf(" %s",ptbak2); ptbak2=ptbak1; ptbak1=pt; if (pt) pt=strtok(NULL," \t\n"); } } printf("\n"); } exit(0); }