Ejemplo n.º 1
0
void insert_word_in_list(Sugestion** No,char* str,int len){
	Sugestion* aux;
	aux = (*No);
	gi_custo = C_MAX_INT;
	gs_sugestion_word = NULL;
	if(aux==NULL){
		(*No) = (Sugestion *)malloc(sizeof(Sugestion));
		(*No)->word_text = gs_palavra;
		(*No)->length = len;
		gs_palavra = str;
		correct_word(gno_root_dictionary,NULL);
		(*No)->word_sugestion = gs_sugestion_word;

	}else{
		bool finded = false;
		Sugestion* novo_no =(Sugestion *)malloc(sizeof(Sugestion));
		if(aux->length == len)
			if(strcmp(aux->word_text , gs_palavra)==0){
				gs_sugestion_word = aux->word_sugestion;
				finded = true;
			}


		while (aux->prox != NULL){
			aux = aux->prox;
			if(aux->length == len && !finded)
				if(strcmp(aux->word_text , gs_palavra)==0){
					gs_sugestion_word = aux->word_sugestion;
					finded = true;
				}

		}

		novo_no->word_text = gs_palavra;
		novo_no->length = len;

		gs_palavra = str;
		if(!finded)
			correct_word(gno_root_dictionary,NULL);

		novo_no->word_sugestion = gs_sugestion_word;
		novo_no->prox = NULL;

		aux->prox = novo_no;


	}
	//printf("%s %s\n",gs_palavra,gs_sugestion_word);
}
Ejemplo n.º 2
0
char* correct_word(No* a_root, char* a_word){


	if(a_root == NULL)//Caso a arvore esteja nula, só ocorre na inicialização
		return NULL;
	else {

		int i;
		if(a_root->exists!=NULL){
			gi_custo_aux = LevenshteinDistance(a_word,gs_palavra);
			if(gi_custo_aux<gi_custo){
				gi_custo = gi_custo_aux;
				gs_sugestion_word = a_root->exists;
			}
			if(gi_custo==1)
				return gs_sugestion_word;
		}

		for(i = 0 ; i<c_alphabet_length; i++)//Continue procurando em cada filho
			if(a_root->sheet[i]!= NULL)
				if(correct_word(a_root->sheet[i],append(a_word,'a'+i))!=NULL)
					return gs_sugestion_word;
	}

	return NULL;

}
Ejemplo n.º 3
0
int main(int argc, char* argv[])
{
   if (argc != 2) {
     fprintf(stderr, "Usage: %s mot-a-corriger\n", *argv);
     exit(EXIT_FAILURE);
   }

   /* Créer la table de hash */
   hash_table_create();

   /* Initialiser le corpus */
   if (! init_corpus_from_file("Data/Iliad.txt"))
     return EXIT_FAILURE;

   /* proposer une correction éventuelle */
   printf("%s ==> %s\n", argv[1], correct_word(argv[1]));

   /* Terminer */
   hash_table_destroy();
   return EXIT_SUCCESS;
}