Commit 0f6db57b023ee867178fa140bb269ad430fe5041
1 parent
76053da1
gestion des accents en début de mot + calcul des erreurs dans un fichier
Showing
5 changed files
with
149 additions
and
71 deletions
Show diff stats
american-english
@@ -99152,20 +99152,20 @@ zwieback's | @@ -99152,20 +99152,20 @@ zwieback's | ||
99152 | zygote | 99152 | zygote |
99153 | zygote's | 99153 | zygote's |
99154 | zygotes | 99154 | zygotes |
99155 | -zÅngström | ||
99156 | -zéclair | ||
99157 | -zéclair's | ||
99158 | -zéclairs | ||
99159 | -zéclat | ||
99160 | -zéclat's | ||
99161 | -zélan | ||
99162 | -zélan's | ||
99163 | -zémigré | ||
99164 | -zémigré's | ||
99165 | -zémigrés | ||
99166 | -zépée | ||
99167 | -zépée's | ||
99168 | -zépées | ||
99169 | -zétude | ||
99170 | -zétude's | ||
99171 | -zétudes | 99155 | +Ångström |
99156 | +éclair | ||
99157 | +éclair's | ||
99158 | +éclairs | ||
99159 | +éclat | ||
99160 | +éclat's | ||
99161 | +élan | ||
99162 | +élan's | ||
99163 | +émigré | ||
99164 | +émigré's | ||
99165 | +émigrés | ||
99166 | +épée | ||
99167 | +épée's | ||
99168 | +épées | ||
99169 | +étude | ||
99170 | +étude's | ||
99171 | +études |
dico_test
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. | ||
2 | -test | ||
3 | \ No newline at end of file | 1 | \ No newline at end of file |
2 | +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 | ||
4 | \ No newline at end of file | 3 | \ No newline at end of file |
@@ -3,33 +3,32 @@ | @@ -3,33 +3,32 @@ | ||
3 | int main() | 3 | int main() |
4 | { | 4 | { |
5 | setlocale(LC_ALL, ""); | 5 | setlocale(LC_ALL, ""); |
6 | - //FILE* fp = fopen("american-english","r"); | ||
7 | - FILE* fp = fopen("dico_test","r"); | 6 | + FILE* fp = fopen("american-english","r"); |
7 | + FILE* fp2 = fopen("dico_test","r"); | ||
8 | 8 | ||
9 | if(fp == NULL) return 1 ; //File is not readable | 9 | if(fp == NULL) return 1 ; //File is not readable |
10 | 10 | ||
11 | - struct node* tab[26]; | ||
12 | - for(int i=0;i<26;i++) | ||
13 | - { | ||
14 | - tab[i]=NULL; | ||
15 | - } | ||
16 | - | ||
17 | - //supprimer la case avant de load | ||
18 | - load_tree(fp,tab);//chargement de l'arbre | ||
19 | - | 11 | + dico Dico; |
12 | + | ||
13 | + init_dico(&Dico); | ||
14 | + load_dico(fp,&Dico);//chargement de l'arbre | ||
15 | + | ||
20 | printf("Loading done!\n"); | 16 | printf("Loading done!\n"); |
21 | 17 | ||
22 | - wchar_t mot[50]; | ||
23 | - int taille; | 18 | + |
19 | + int result = find_erreur(Dico,fp2); | ||
20 | + printf("%d\n",result); | ||
21 | + | ||
22 | + /*wchar_t mot[50]; | ||
24 | wscanf(L"%ls",mot); | 23 | wscanf(L"%ls",mot); |
25 | - wscanf(L"%d",&taille); | ||
26 | int result; | 24 | int result; |
27 | - result = find_mot(tab,mot,taille,(int)mot[0]-97); | ||
28 | - printf("%d\n",result); | 25 | + result = find_mot(Dico,mot); |
26 | + printf("%d\n",result);*/ | ||
29 | 27 | ||
30 | 28 | ||
31 | - free_dico(tab);//libérer la mémoire | 29 | + free_dico(Dico);//libérer la mémoire |
32 | fclose(fp); | 30 | fclose(fp); |
31 | + fclose(fp2); | ||
33 | 32 | ||
34 | printf("Fin du programme\n"); | 33 | printf("Fin du programme\n"); |
35 | 34 |
@@ -10,14 +10,19 @@ void cons_tree(struct node ** ptr_tree, wchar_t val) | @@ -10,14 +10,19 @@ void cons_tree(struct node ** ptr_tree, wchar_t val) | ||
10 | (*ptr_tree)->fils[0]=NULL; | 10 | (*ptr_tree)->fils[0]=NULL; |
11 | } | 11 | } |
12 | 12 | ||
13 | -void mk_empty_tree(struct node **ptr_tree) | 13 | +void mk_empty_tree(dico *Dico) |
14 | { | 14 | { |
15 | - *ptr_tree = NULL; | 15 | + for(int i = 0; i < Dico->taille; i++) |
16 | + { | ||
17 | + Dico->tab_ptr_tree[i] = NULL; | ||
18 | + } | ||
16 | } | 19 | } |
17 | 20 | ||
18 | -int is_leaf(struct node *tree) | 21 | +void init_dico(dico *Dico) |
19 | { | 22 | { |
20 | - return tree->fin||tree->fils[0]==NULL; | 23 | + Dico->taille = 26; |
24 | + Dico->tab_ptr_tree = malloc(Dico->taille*sizeof(struct node*)); | ||
25 | + mk_empty_tree(Dico); | ||
21 | } | 26 | } |
22 | 27 | ||
23 | void add(struct node **tab_ptr_tree, wchar_t val[],int taille, int fl) | 28 | void add(struct node **tab_ptr_tree, wchar_t val[],int taille, int fl) |
@@ -60,32 +65,49 @@ void toLowerCase(wchar_t mot[]) | @@ -60,32 +65,49 @@ void toLowerCase(wchar_t mot[]) | ||
60 | { | 65 | { |
61 | for(int i=0;i<size(mot);i++) | 66 | for(int i=0;i<size(mot);i++) |
62 | { | 67 | { |
63 | - if(mot[i]<='Z' && mot[i]>='A') | ||
64 | - { | ||
65 | - mot[i]+=32; | ||
66 | - } | 68 | + if((mot[i]<='Z' && mot[i]>='A') || (mot[i]>=192 && mot[i]<=214) || (mot[i]>=216 && mot[i]<=222))mot[i]+=32; |
69 | + else if(mot[i]==138|| mot[i]==140 || mot[i]==142) mot[i]+=16; | ||
70 | + else if(mot[i]==159) mot[i]+=96; | ||
67 | } | 71 | } |
68 | } | 72 | } |
69 | 73 | ||
70 | -void splitcarac(struct node **tab_ptr_tree,wchar_t message[]) | 74 | +void splitcarac(dico *Dico,wchar_t message[]) |
71 | { | 75 | { |
72 | - if(message[0]<'a' || message[0]>'z')return; | ||
73 | - | 76 | + int first_letter =-1; |
77 | + if(message[0]>='a' && message[0]<='z') | ||
78 | + { | ||
79 | + first_letter = (int)message[0]-97; | ||
80 | + } | ||
81 | + else | ||
82 | + { | ||
83 | + for(int i = 26; i < Dico->taille; i++) | ||
84 | + { | ||
85 | + if(Dico->tab_ptr_tree[i]->val == message[0]){first_letter = i;break;} | ||
86 | + } | ||
87 | + if(first_letter == -1) | ||
88 | + { | ||
89 | + first_letter = Dico->taille; | ||
90 | + Dico->taille++; | ||
91 | + Dico->tab_ptr_tree = realloc(Dico->tab_ptr_tree,(Dico->taille)*sizeof(struct node*)); | ||
92 | + Dico->tab_ptr_tree[first_letter] = NULL; | ||
93 | + cons_tree(&(Dico->tab_ptr_tree[first_letter]),message[0]); | ||
94 | + } | ||
95 | + } | ||
96 | + | ||
74 | wchar_t *buffer; | 97 | wchar_t *buffer; |
75 | wchar_t *token = wcstok(message, L" ,?;.:/!*+\\\"()=«»", &buffer); | 98 | wchar_t *token = wcstok(message, L" ,?;.:/!*+\\\"()=«»", &buffer); |
76 | - add(tab_ptr_tree,token,size(token),(int)message[0]-97); | ||
77 | - if(buffer!=NULL)splitcarac(tab_ptr_tree,buffer); | 99 | + add(Dico->tab_ptr_tree,token,size(token),first_letter); |
100 | + if(buffer!=NULL)splitcarac(Dico,buffer); | ||
78 | } | 101 | } |
79 | 102 | ||
80 | -void load_tree(FILE *fp, struct node **tab_ptr_tree) | 103 | +void load_dico(FILE *fp, dico *Dico) |
81 | { | 104 | { |
82 | - //fl (first letter) | ||
83 | wchar_t val[50]; | 105 | wchar_t val[50]; |
84 | 106 | ||
85 | while(fwscanf(fp, L"%ls",val)==1) | 107 | while(fwscanf(fp, L"%ls",val)==1) |
86 | { | 108 | { |
87 | toLowerCase(val); | 109 | toLowerCase(val); |
88 | - splitcarac(tab_ptr_tree,val); | 110 | + splitcarac(Dico,val); |
89 | } | 111 | } |
90 | 112 | ||
91 | //On peut tester la bonne ou mauvaise terminaison de la lecture | 113 | //On peut tester la bonne ou mauvaise terminaison de la lecture |
@@ -105,30 +127,51 @@ void free_tree(struct node *ptr_tree) | @@ -105,30 +127,51 @@ void free_tree(struct node *ptr_tree) | ||
105 | free(ptr_tree->fils); | 127 | free(ptr_tree->fils); |
106 | } | 128 | } |
107 | 129 | ||
108 | -void free_dico(struct node **tab_ptr_tree) | 130 | +void free_dico(dico Dico) |
109 | { | 131 | { |
110 | - for(int i=0;i<26;i++) | 132 | + for(int i=0;i<Dico.taille;i++) |
111 | { | 133 | { |
112 | - if(tab_ptr_tree[i]!=NULL) | 134 | + if(Dico.tab_ptr_tree[i]!=NULL) |
113 | { | 135 | { |
114 | - free_tree(tab_ptr_tree[i]); | ||
115 | - free(tab_ptr_tree[i]); | 136 | + free_tree(Dico.tab_ptr_tree[i]); |
137 | + free(Dico.tab_ptr_tree[i]); | ||
116 | } | 138 | } |
117 | } | 139 | } |
140 | + free(Dico.tab_ptr_tree); | ||
118 | } | 141 | } |
119 | 142 | ||
120 | /*Recherche dans le dictionnaire*/ | 143 | /*Recherche dans le dictionnaire*/ |
121 | -int find_mot(struct node **tab_ptr_tree,wchar_t mot[],int size,int fl) | 144 | +int find_mot(dico Dico,wchar_t mot[]) |
122 | { | 145 | { |
123 | - if(size==1 && tab_ptr_tree[fl]!=NULL) | 146 | + if (mot==NULL) { |
147 | + return 0; | ||
148 | + } | ||
149 | + if(mot[0]>='0' && mot[0]<='9')return 0; | ||
150 | + | ||
151 | + int fl =-1; | ||
152 | + if(mot[0]>='a' && mot[0]<='z') | ||
153 | + { | ||
154 | + fl = (int)mot[0]-97; | ||
155 | + } | ||
156 | + else | ||
124 | { | 157 | { |
125 | - if(tab_ptr_tree[fl]->fin==0)return 1; | 158 | + for(int i = 26; i < Dico.taille; i++) |
159 | + { | ||
160 | + if(Dico.tab_ptr_tree[i]->val == mot[0]){fl = i;break;} | ||
161 | + } | ||
162 | + if(fl == -1)return 1; | ||
163 | + } | ||
164 | + | ||
165 | + int taille = size(mot); | ||
166 | + if(taille==1 && Dico.tab_ptr_tree[fl]!=NULL) | ||
167 | + { | ||
168 | + if(Dico.tab_ptr_tree[fl]->fin==0)return 1; | ||
126 | else return 0;//vrais | 169 | else return 0;//vrais |
127 | } | 170 | } |
128 | - if(size==1 && tab_ptr_tree[fl]==NULL)return 1;//faux | 171 | + if(taille==1 && Dico.tab_ptr_tree[fl]==NULL)return 1;//faux |
129 | 172 | ||
130 | - struct node *ptr_node = tab_ptr_tree[fl]; | ||
131 | - for(int i=1;i<size;i++) | 173 | + struct node *ptr_node = Dico.tab_ptr_tree[fl]; |
174 | + for(int i=1;i<taille;i++) | ||
132 | { | 175 | { |
133 | if(ptr_node->nbr_fils==0)return 1; | 176 | if(ptr_node->nbr_fils==0)return 1; |
134 | for(int k=0;k<(ptr_node->nbr_fils);k++) | 177 | 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) | @@ -146,7 +189,31 @@ int find_mot(struct node **tab_ptr_tree,wchar_t mot[],int size,int fl) | ||
146 | else return 0; | 189 | else return 0; |
147 | } | 190 | } |
148 | 191 | ||
149 | -int find() | 192 | +int find_erreur(dico Dico, FILE *fp) |
150 | { | 193 | { |
151 | - return 0; | 194 | + wchar_t val[5000]; |
195 | + int cpt_erreur =0; | ||
196 | + | ||
197 | + while(fwscanf(fp, L"%ls",val)==1) | ||
198 | + { | ||
199 | + toLowerCase(val); | ||
200 | + cpt_erreur += split_text(Dico,val); | ||
201 | + } | ||
202 | + | ||
203 | + //On peut tester la bonne ou mauvaise terminaison de la lecture | ||
204 | + if(feof(fp)) printf("Fin normal de lecture\n"); | ||
205 | + if(ferror(fp)) printf("ERREUR de lecture\n"); | ||
206 | + | ||
207 | + return cpt_erreur; | ||
152 | } | 208 | } |
209 | + | ||
210 | +int split_text(dico Dico,wchar_t message[]) | ||
211 | +{ | ||
212 | + if(message[0] == 0)return 0; | ||
213 | + wchar_t *buffer; | ||
214 | + wchar_t *token = wcstok(message, L" ,?;.:/!*+\\\"()=«»", &buffer); | ||
215 | + int err = find_mot(Dico,token); | ||
216 | + if(buffer!=NULL)err += split_text(Dico,buffer); | ||
217 | + | ||
218 | + return err; | ||
219 | +} | ||
153 | \ No newline at end of file | 220 | \ No newline at end of file |
@@ -10,20 +10,33 @@ typedef struct node { | @@ -10,20 +10,33 @@ typedef struct node { | ||
10 | struct node** fils; | 10 | struct node** fils; |
11 | }Node, *PtNode, *Tree; | 11 | }Node, *PtNode, *Tree; |
12 | 12 | ||
13 | +typedef struct dico { | ||
14 | + struct node** tab_ptr_tree; | ||
15 | + int taille; | ||
16 | +}dico; | ||
17 | + | ||
13 | void cons_tree(struct node **, wchar_t); | 18 | void cons_tree(struct node **, wchar_t); |
14 | 19 | ||
15 | -void mk_empty_tree(struct node **); | 20 | +void mk_empty_tree(dico*); |
16 | 21 | ||
17 | -int is_leaf(struct node *); | 22 | +void init_dico(dico*); |
18 | 23 | ||
19 | void add(struct node **, wchar_t* ,int ,int); | 24 | void add(struct node **, wchar_t* ,int ,int); |
20 | 25 | ||
21 | -void load_tree(FILE *, struct node **); | 26 | +int size(wchar_t*); |
27 | + | ||
28 | +void toLowerCase(wchar_t*); | ||
29 | + | ||
30 | +void splitcarac(dico*,wchar_t*); | ||
31 | + | ||
32 | +void load_dico(FILE *, dico*); | ||
22 | 33 | ||
23 | void free_tree(struct node *); | 34 | void free_tree(struct node *); |
24 | 35 | ||
25 | -void free_dico(struct node **); | 36 | +void free_dico(dico); |
37 | + | ||
38 | +int find_erreur(dico,FILE*); | ||
26 | 39 | ||
27 | -int find(); | 40 | +int find_mot(dico,wchar_t*); |
28 | 41 | ||
29 | -int find_mot(struct node **,wchar_t*,int,int); | ||
30 | \ No newline at end of file | 42 | \ No newline at end of file |
43 | +int split_text(dico,wchar_t*); | ||
31 | \ No newline at end of file | 44 | \ No newline at end of file |