diff --git a/README.md b/README.md index 5fe0443..9770ece 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,20 @@ -# Programmation Avancée +# Correcteur Orthographique + +## mode d'emploi +- Compilez les fichiers (un make suffira). +- Lancez le programme (./dico.exec). +- Suivez les instructions et charger un dictionnaire. +- Choisissez ce que vous voulez faire parmi les propositions du menu. +![](img/Menu.png) + +## Description +- Lire le dictionnaire permet de faire afficher le contenu du dictionnaire. +- Lorsque que voulez tester l'orthographe vous pouvez au préalable choisir/créer un fichier de sortie en choisissant le 6), puis faire votre test en choisissant le 5). + + + +#cahier des charges > Réalisation d’un correcteur orthographique ## Objectif diff --git a/dico.c b/dico.c index 037af67..6c2deac 100644 --- a/dico.c +++ b/dico.c @@ -17,16 +17,17 @@ byte addto_dico(dico d,const string word){ byte isIn=0, endKind=0; endKind=end_kind(word); if(!is_word(endKind)){ - printf("%s is incorrect\n",word); return -1; } tree*tmp=&d[hash(word[0])],*temp=tmp; + //1st, let's go through the tree, until the word is not in tree for(i=0; word[i]!='\0' && word[i]!='\'' && !is_empty(*tmp) ;i++){ temp=tmp; if(isalpha(word[i+1])) tmp=&((*tmp)->next[hash(word[i+1])]); } + //if word is not ended at the end of the tree if(is_empty(*tmp)){ isIn=0; @@ -37,15 +38,12 @@ byte addto_dico(dico d,const string word){ tmp=&((*tmp)->next[hash(word[i+1])]); } (*temp)->isEnd = endKind; - printf("%s added\n",word); - fflush(stdout); } + //if word is ended else{ isIn=endKind & (*temp)->isEnd; (*temp)->isEnd = endKind | (*temp)->isEnd; - printf("%s %s in\n",word,(isIn!=0)?("allready"):("not yet")); - fflush(stdout); } return isIn; } @@ -62,7 +60,7 @@ void loadfrom_file(dico d,FILE*stream){ return; } char word[30]={0}; - while(fscanf(stream,"%30s",word)!=EOF){ + while(fscanf(stream,"%30s",word)==1){ addto_dico(d,word); } printf("load success\n"); @@ -161,6 +159,12 @@ void test_words(dico d,FILE*inStream,FILE*outStream){ char word[30]={0}; byte isIn=0,someWrong=0; while(fscanf(inStream,"%30s",word)!=EOF){ + /*//get rid of punctuation marks + isIn=0; + while(ischar_of_word(word[(int)isIn])) + isIn++; + word[(int)isIn]='\0'; + */ isIn=is_in(d,word); if(isIn<1){ if(someWrong==0){ @@ -176,8 +180,22 @@ void test_words(dico d,FILE*inStream,FILE*outStream){ } } } - //ajout des mots absent? - if(is_emptyLIFO(absWords))return; + //fermer outStream pour permettre à l'utilisateur de lire le compte rendu des tests + if(outStream!=stdout) + fclose(outStream); + outStream=stdout; + + //aucun mot ne peut être ajouté au dictionnaire ? + if(is_emptyLIFO(absWords)){ + if(someWrong) + printf("Parmi les mots absents du dictionnaire, aucun ne peut être ajouté au dictionnaire.\n"); + else + printf("Felicitations !!!\nAucun des mots que vous avez entre n'est absents du dictionnaire.\n"); + return; + } + + + //ajout des mots absent? printf("Voulez-vous ajouter certains de ces mots au dictionnaire?\n(1 for yes,0 for no)\n"); someWrong=saisie(0,1); diff --git a/dico.h b/dico.h index 9e60a65..bb2da37 100644 --- a/dico.h +++ b/dico.h @@ -19,6 +19,7 @@ void printto_terminal(dico); void print(tree,FILE*,string); void strupper(string str); +//uppers all letters in str byte is_in(dico,string); void test_words(dico,FILE*inStream,FILE*outStream); diff --git a/img/Menu.png b/img/Menu.png new file mode 100644 index 0000000..97616af Binary files /dev/null and b/img/Menu.png differ diff --git a/img/rapportDico.pdf b/img/rapportDico.pdf new file mode 100644 index 0000000..6f42c9f Binary files /dev/null and b/img/rapportDico.pdf differ diff --git a/main.c b/main.c index b711cfc..024cfd9 100644 --- a/main.c +++ b/main.c @@ -34,51 +34,74 @@ FILE* getFile(string mode){ - - -void menu(dico monDico){ +int main(void){ int choice=0; - char word[2]={0}; + printf("Bienvenue dans le dictonnaire !\n\n"); + dico monDico; + make_empty_dico(monDico); + //initialisation printf("Pour commencer, veuillez charger un dictionnaire.\n"); FILE*fileIn=getFile("r"),*fileOut=stdout; if(fileIn==stdin) printf("Entrez vos mots (ctrl-D pour terminer le chargement):\n"); loadfrom_file(monDico,fileIn); - fclose(fileIn); + if(fileIn!=stdin) + fclose(fileIn); + + //boucle while(1){ + clear(); //menu printf("La sortie est branchee sur %s.\n",fileOut==stdout?"le terminal":"un fichier"); printf("Que voulez-vous faire ?\n"); + //end programme printf("0) Fermer le programme.\n\n"); + //just about the dictionnary printf("1) Lire le dictionnaire.\n"); printf("2) Rajouter des mots au dictionnaire\n"); printf("3) Effacer le dictionnaire\n"); printf("4) Remplacer le dictionnaire actuel par un autre dictionnaire\n\n"); + //word correction printf("5) Tester si un mot, un ensemble de mot, une phrase ou un paragraphe appartient au dictionnaire.\n\n"); + //out stream printf("6) Définir un fichier de sortie.\n"); printf("7) Définir la sortie sur le terminal.\n"); + + + //saisie du choix - scanf("%2s",word); - choice=ctoi(*word); + choice=getchar(); + choice=ctoi(choice); + + + switch(choice){ + case 0: {//sortie du programme if(fileOut!=stdout) fclose(fileOut); - return;} + fileOut=stdout; + delete_dico(monDico); + printf("Le dictionnaire vous dit aurevoir.\n\n\n"); + return EXIT_SUCCESS; + } + + case 1: {//Lire le dictionnaire printto_file(monDico,fileOut); printf("dictionnaire imprimme\n"); break;} + //manip sur le dictionnaire case 2: {//ajout @@ -88,6 +111,7 @@ void menu(dico monDico){ loadfrom_file(monDico,fileIn); if(fileIn!=stdin) fclose(fileIn); + fileIn=stdin; break;} case 3: {//effacer delete_dico(monDico); @@ -95,11 +119,14 @@ void menu(dico monDico){ break;} case 4: {//remplacer delete_dico(monDico); + printf("Le dictionnaire est maintenant vide.\n"); fileIn=getFile("r"); loadfrom_file(monDico,fileIn); if(fileIn!=stdin) fclose(fileIn); + fileIn=stdin; break;} + case 5: {//faire des tests @@ -109,34 +136,32 @@ void menu(dico monDico){ test_words(monDico,fileIn,fileOut); if(fileIn!=stdin) fclose(fileIn); + fileIn=stdin; break;} + + //définir la sortie des tests et de "Lire" le dictionnaire case 6: { if(fileOut!=stdout) fclose(fileOut); - fileOut=getFile("w"); + fileOut=getFile("a"); break;} case 7: { if(fileOut!=stdout) fclose(fileOut); fileOut=stdout; break;} + + + //si le choix n'est pas parmi les précédents default: {break;} } - choice=0; + + + //protection, si le scanf pour le choix a un problème + choice=-1; pause(); }//end of while -} - - -int main(void){ - printf("Bienvenue dans le dictonnaire !\n\n"); - dico monDico; - make_empty_dico(monDico); - menu(monDico); - delete_dico(monDico); - printf("Le dictionnaire vous dit aurevoir.\n\n\n"); - return EXIT_SUCCESS; } diff --git a/rapportDico.odt b/rapportDico.odt index 691216d..88955ee 100644 Binary files a/rapportDico.odt and b/rapportDico.odt differ diff --git a/treeh.c b/treeh.c index f22e864..c434dbb 100644 --- a/treeh.c +++ b/treeh.c @@ -29,10 +29,6 @@ void delete_tree(tree *t){ *t=NULL; } - - - - //Casual functions bool is_empty(const tree t){ return t==NULL; @@ -57,9 +53,10 @@ bool is_acronyme_end(const tree t){return (t->isEnd & ACRONYME_END);} -//needs to check c wether isalpha -int hash(char c){return c%32-1;} -bool ischar_of_word(char c){return isalpha(c) || c=='\'';} +//functions not directly related to the structure +int hash(char c){return c%32-1;}//needs to check c wether isalpha +bool ischar_of_word(char c){return (c=='\'' || isalpha(c));} +bool is_word(const byte endKind){return endKind!=NOT_AN_END;} byte end_kind(const string s){ byte endKind=NOT_AN_END; @@ -96,6 +93,3 @@ byte end_kind(const string s){ } return NOT_AN_END; } -bool is_word(const byte endKind){ - return endKind!=0; -} diff --git a/treeh.h b/treeh.h index c07a15f..5f5de35 100644 --- a/treeh.h +++ b/treeh.h @@ -36,6 +36,8 @@ void delete_tree(tree*);//free(tree) and delete tree on all t->next bool is_empty(const tree);//==NULL bool is_followed(const tree);//if true tree has following letters + +//endKind functions bool is_end(const tree);//true when at least 1 of the following functions is true bool is_straight_end(const tree);//if true word can end here bool ends_with_apostrophe(const tree);//if true word can end here with apostrophe @@ -43,6 +45,8 @@ bool is_common_end(const tree);//if true all letters are lower bool is_proper_end(const tree);//if true 1st letter is upper bool is_acronyme_end(const tree);//if true all letters are upper + +//other int hash(char);//need to check if isalpha bool ischar_of_word(char);//tells if char can be in a word bool is_word(byte endKind);//pass end_kind() as parameter -- libgit2 0.21.2