void ac(char** mots, int nbrMots,unsigned char* text, int textLenght){ ACListe acListe = preAC(mots, nbrMots); int target = 0, nbrOcc = 0, i; for( i = 0; i < textLenght; i++){ while(findNodeByLettre(acListe->trie->transition[target], text[i]) == NULL ){ target = acListe->suppleant[target]; } target = findNodeByLettre(acListe->trie->transition[target], text[i])->targetNode; nbrOcc += acListe->trie->finite[target]; } printf("AC-LISTE - Le nombre d'occurence est : %d\n", nbrOcc); }
/** * Fonction principale d'aho Corasick * @param x l'ensemble des mots à chercher * @param k le nombre de mots à chercher * @param y le text dans lequel chercher * @param n la longueur du texte dans lequel chercher */ void ac (char ** x, int k, char * y, int n) { AcTrie acTrie = preAC (x, k); int curState = 0; for (int j = 0; j < n; j++) { //parcours du texte while (acTrie->trie->transition[curState][(int) y[j]] == -1) { curState = acTrie->sup[curState]; } curState = acTrie->trie->transition[curState][(int) y[j]]; if (acTrie->sortie[curState] == 1) { //printf("%d\n", j); Réduit les performances } } }
void ahoCorasick(unsigned char **mots, int nb_max, unsigned char *texte, long int texte_taille) { int org = 0, occ = 0, i=0; /* Création du trie */ Trie trie = preAC(mots, nb_max); /* Testerla création du trie */ if (trie == NULL) {return; /* Quitter */} /* phase de recherche */ for (i = 0; i < texte_taille; i++) { /* S'il n'existe pas de desitnation on cherche le supp */ while (chercher_vers(trie, org, texte[i]) == -1) { org = trie->mon_suppl[org]; } org = chercher_vers(trie, org, texte[i]); /* si etat final ? alors incrémenter occ */ if (trie->finite[org]) { occ = occ + 1;}} printf("\nLe nombre total de mots trouvés dans le texte est %d\n", occ); }