diff --git a/american-english b/american-english index d36e3c7..3f9b27f 100644 --- a/american-english +++ b/american-english @@ -99152,20 +99152,20 @@ zwieback's zygote zygote's zygotes -zÅngström -zéclair -zéclair's -zéclairs -zéclat -zéclat's -zélan -zélan's -zémigré -zémigré's -zémigrés -zépée -zépée's -zépées -zétude -zétude's -zétudes +Ångström +éclair +éclair's +éclairs +éclat +éclat's +élan +élan's +émigré +émigré's +émigrés +épée +épée's +épées +étude +étude's +études diff --git a/dico_test b/dico_test index 50a708d..3e93355 100644 --- a/dico_test +++ b/dico_test @@ -1,2 +1 @@ -Il est l'acteur-phare de l'émission télévisée humoristique Serviteur du peuple. Sans aucune expérience politique, il se présente pour le parti homonyme à l’élection présidentielle de 2019, qu'il remporte au second tour avec 73,2 % des voix, face au chef de l'État sortant, Petro Porochenko. À 41 ans, il est le plus jeune président élu en Ukraine. -test \ No newline at end of file +Although testing can determine the correctness of software under the assumption of some specific hypotheses (see the hierarchy of testing difficulty below), testing cannot identify all the defects within the software. Instead, it furnishes a criticism or comparison that compares the state and behavior of the product against test oracles principles or mechanisms by which someone might recognize a problem. These oracles may include (but are not limited to) specifications, contracts, comparable products, past versions of the same product, inferences about intended or expected purpose, user or customer expectations, relevant standards, applicable laws, or other criteria. 111 \ No newline at end of file diff --git a/main.c b/main.c index 3450670..3ee226c 100644 --- a/main.c +++ b/main.c @@ -3,33 +3,32 @@ int main() { setlocale(LC_ALL, ""); - //FILE* fp = fopen("american-english","r"); - FILE* fp = fopen("dico_test","r"); + FILE* fp = fopen("american-english","r"); + FILE* fp2 = fopen("dico_test","r"); if(fp == NULL) return 1 ; //File is not readable - struct node* tab[26]; - for(int i=0;i<26;i++) - { - tab[i]=NULL; - } - - //supprimer la case avant de load - load_tree(fp,tab);//chargement de l'arbre - + dico Dico; + + init_dico(&Dico); + load_dico(fp,&Dico);//chargement de l'arbre + printf("Loading done!\n"); - wchar_t mot[50]; - int taille; + + int result = find_erreur(Dico,fp2); + printf("%d\n",result); + + /*wchar_t mot[50]; wscanf(L"%ls",mot); - wscanf(L"%d",&taille); int result; - result = find_mot(tab,mot,taille,(int)mot[0]-97); - printf("%d\n",result); + result = find_mot(Dico,mot); + printf("%d\n",result);*/ - free_dico(tab);//libérer la mémoire + free_dico(Dico);//libérer la mémoire fclose(fp); + fclose(fp2); printf("Fin du programme\n"); diff --git a/tree.c b/tree.c index b4daa6e..49cd757 100644 --- a/tree.c +++ b/tree.c @@ -10,14 +10,19 @@ void cons_tree(struct node ** ptr_tree, wchar_t val) (*ptr_tree)->fils[0]=NULL; } -void mk_empty_tree(struct node **ptr_tree) +void mk_empty_tree(dico *Dico) { - *ptr_tree = NULL; + for(int i = 0; i < Dico->taille; i++) + { + Dico->tab_ptr_tree[i] = NULL; + } } -int is_leaf(struct node *tree) +void init_dico(dico *Dico) { - return tree->fin||tree->fils[0]==NULL; + Dico->taille = 26; + Dico->tab_ptr_tree = malloc(Dico->taille*sizeof(struct node*)); + mk_empty_tree(Dico); } void add(struct node **tab_ptr_tree, wchar_t val[],int taille, int fl) @@ -60,32 +65,49 @@ void toLowerCase(wchar_t mot[]) { for(int i=0;i='A') - { - mot[i]+=32; - } + if((mot[i]<='Z' && mot[i]>='A') || (mot[i]>=192 && mot[i]<=214) || (mot[i]>=216 && mot[i]<=222))mot[i]+=32; + else if(mot[i]==138|| mot[i]==140 || mot[i]==142) mot[i]+=16; + else if(mot[i]==159) mot[i]+=96; } } -void splitcarac(struct node **tab_ptr_tree,wchar_t message[]) +void splitcarac(dico *Dico,wchar_t message[]) { - if(message[0]<'a' || message[0]>'z')return; - + int first_letter =-1; + if(message[0]>='a' && message[0]<='z') + { + first_letter = (int)message[0]-97; + } + else + { + for(int i = 26; i < Dico->taille; i++) + { + if(Dico->tab_ptr_tree[i]->val == message[0]){first_letter = i;break;} + } + if(first_letter == -1) + { + first_letter = Dico->taille; + Dico->taille++; + Dico->tab_ptr_tree = realloc(Dico->tab_ptr_tree,(Dico->taille)*sizeof(struct node*)); + Dico->tab_ptr_tree[first_letter] = NULL; + cons_tree(&(Dico->tab_ptr_tree[first_letter]),message[0]); + } + } + wchar_t *buffer; wchar_t *token = wcstok(message, L" ,?;.:/!*+\\\"()=«»", &buffer); - add(tab_ptr_tree,token,size(token),(int)message[0]-97); - if(buffer!=NULL)splitcarac(tab_ptr_tree,buffer); + add(Dico->tab_ptr_tree,token,size(token),first_letter); + if(buffer!=NULL)splitcarac(Dico,buffer); } -void load_tree(FILE *fp, struct node **tab_ptr_tree) +void load_dico(FILE *fp, dico *Dico) { - //fl (first letter) wchar_t val[50]; while(fwscanf(fp, L"%ls",val)==1) { toLowerCase(val); - splitcarac(tab_ptr_tree,val); + splitcarac(Dico,val); } //On peut tester la bonne ou mauvaise terminaison de la lecture @@ -105,30 +127,51 @@ void free_tree(struct node *ptr_tree) free(ptr_tree->fils); } -void free_dico(struct node **tab_ptr_tree) +void free_dico(dico Dico) { - for(int i=0;i<26;i++) + for(int i=0;i='0' && mot[0]<='9')return 0; + + int fl =-1; + if(mot[0]>='a' && mot[0]<='z') + { + fl = (int)mot[0]-97; + } + else { - if(tab_ptr_tree[fl]->fin==0)return 1; + for(int i = 26; i < Dico.taille; i++) + { + if(Dico.tab_ptr_tree[i]->val == mot[0]){fl = i;break;} + } + if(fl == -1)return 1; + } + + int taille = size(mot); + if(taille==1 && Dico.tab_ptr_tree[fl]!=NULL) + { + if(Dico.tab_ptr_tree[fl]->fin==0)return 1; else return 0;//vrais } - if(size==1 && tab_ptr_tree[fl]==NULL)return 1;//faux + if(taille==1 && Dico.tab_ptr_tree[fl]==NULL)return 1;//faux - struct node *ptr_node = tab_ptr_tree[fl]; - for(int i=1;inbr_fils==0)return 1; for(int k=0;k<(ptr_node->nbr_fils);k++) @@ -146,7 +189,31 @@ int find_mot(struct node **tab_ptr_tree,wchar_t mot[],int size,int fl) else return 0; } -int find() +int find_erreur(dico Dico, FILE *fp) { - return 0; + wchar_t val[5000]; + int cpt_erreur =0; + + while(fwscanf(fp, L"%ls",val)==1) + { + toLowerCase(val); + cpt_erreur += split_text(Dico,val); + } + + //On peut tester la bonne ou mauvaise terminaison de la lecture + if(feof(fp)) printf("Fin normal de lecture\n"); + if(ferror(fp)) printf("ERREUR de lecture\n"); + + return cpt_erreur; } + +int split_text(dico Dico,wchar_t message[]) +{ + if(message[0] == 0)return 0; + wchar_t *buffer; + wchar_t *token = wcstok(message, L" ,?;.:/!*+\\\"()=«»", &buffer); + int err = find_mot(Dico,token); + if(buffer!=NULL)err += split_text(Dico,buffer); + + return err; +} \ No newline at end of file diff --git a/tree.h b/tree.h index a4965b8..ad23b77 100644 --- a/tree.h +++ b/tree.h @@ -10,20 +10,33 @@ typedef struct node { struct node** fils; }Node, *PtNode, *Tree; +typedef struct dico { + struct node** tab_ptr_tree; + int taille; +}dico; + void cons_tree(struct node **, wchar_t); -void mk_empty_tree(struct node **); +void mk_empty_tree(dico*); -int is_leaf(struct node *); +void init_dico(dico*); void add(struct node **, wchar_t* ,int ,int); -void load_tree(FILE *, struct node **); +int size(wchar_t*); + +void toLowerCase(wchar_t*); + +void splitcarac(dico*,wchar_t*); + +void load_dico(FILE *, dico*); void free_tree(struct node *); -void free_dico(struct node **); +void free_dico(dico); + +int find_erreur(dico,FILE*); -int find(); +int find_mot(dico,wchar_t*); -int find_mot(struct node **,wchar_t*,int,int); \ No newline at end of file +int split_text(dico,wchar_t*); \ No newline at end of file -- libgit2 0.21.2