The approximate string matching is a fundamental and recurrent problem that arises in most computer science fields. This problem can be defined as follows:
\begin{quote}
\textit{Let $D=\{x_1,x_2,\ldots x_d\}$ be a set of $d$ words defined on an alphabet $\Sigma$, let $q$ be a query defined also on $\Sigma$, and let $k$ be a positive integer.\\
We want to build a data structure on $D$ capable of answering the following query: find all words in $D$ that are at most different from the query word $q$ with $k$ errors.}
\end{quote}
In this thesis, we study the approximate string matching methods in dictionaries, texts, and indexes, to propose practical methods that solve this problem efficiently. We explore this problem in three complementary directions:
1) The approximate string matching in the dictionary. We propose two solutions to this problem, the first one uses hash tables for $k \geq 2$, the second uses the Trie and reverse Trie, and it is restricted to (k = 1). The two solutions are adaptable, without loss of performance, to the approximate string matching in a text.
2) The approximate string matching for \textit{autocompletion}, which is, find all suffixes of a given prefix that may contain errors. We give a new solution better in practice than all the previous proposed solutions.
3) The problem of the alignment of biological sequences can be interpreted as an approximate string matching problem. We propose a solution for peers and multiple sequences alignment.
\medskip
All the results obtained showed that our algorithms, give the best performance on sets of practical data (benchmark from the real world). All our methods are proposed as libraries, and they are published online.
La recherche approchée de motifs : théorie et applications
1. La recherche approchée de motifs :
théorie et applications
République Algérienne Démocratique et Populaire
Ministère de L'Enseignement Supérieur et de la Recherche Scientifique
Université des Sciences et de la Technologie Houari Boumediene
Présentée pour l’obtention du diplôme de DOCTORAT
En : INFORMATIQUE
Par : Chegrane Ibrahim
Mme. Aicha Aissani-Mokhtari Prof USTHB/FEI Président
Mme. Nacéra Bensaou MCA USTHB/FEI Directrice de thèse
M. Thierry Lecroq Prof U. Rouen-Normandie Examinateur
M. Riadh BabaAli Prof USTHB/FEI Examinateur
M. Abdelmajid Boukra Prof USTHB/FEI Examinateur
M. Djamal Belazzougui M.R CERIST Invité
Soutenue publiquement, le 07 /12/ 2016 , devant le jury composé de :
1
Ibra_chegrane@hotmail.com , ibra.chegrane@gmail.com
2. Plan
Background : la recherche de motifs
• La recherche approchée avec hachage
• La recherche approchée avec Trie et Trie inversé
La recherche approchée
L’auto-complétion approchée
L’alignement multiple
2
3. La recherche de motifs
3
Exacte ibrahim
ibrahim
Approchée ibrahim
ibrahim
brahim
abraham
ibrahimovich
blahim
Hors-ligne : indexationEn-ligne
5. Les fonctions de distance
D. Hamming
D. Levenshtein
D. Levenshtein-
Damerau
Ibrahim
Ibraham
Substitution
Ibrahim
Ibrahimo
Insertion
Ibrahim
brahim
Suppression
Ibrahim
birahim
Transposition
5
7. Problématique de la recherche approchée
1. Dans quelle position l'erreur se trouve ?
xbrahim, ixrahim, ibxahim, …., ibrahix,…..,pos insertion, …….
2. Quels sont les caractères qui mènent à des solutions possibles
dans une position donnée.
3. Les types des erreurs à considérer ? (sub, insert, sup)
4. K>= 2 , combinaison entre les positions et les types.
-xyrahim, xbyahim, xbryhim, xbrayim, ….
5. L’espace mémoire de SDD.
6. Combiner 1+2+3+4+5. 7
…. ibrxhim ……..
a
b
.
.
.
z
7 + 8 +7 = 22 Cas
K=2 erreurs
20+36+20+….= 228 Cas
Trouver des mots contenants des erreurs
8. Méthodes de la recherche approchée
Programmation
dynamique
Méthodes de
filtrage
Génération
de voisinage
Indexation
HachageBit-parallélisme
Parallélisme
Méthodes hybrides
8
10. La recherche approchée pour k >=2 en
utilisant les tables de hachage**
10
** Belazzougui, D. : Faster and space-optimal edit distance "1" dictionary. In : Combinatorial
Pattern Matching, 20th Annual Symposium, CPM 2009, Lille, France, June 22-24, 2009, Proceedings. (2009) 154 167.
1ère Contribution
11. La structure de données :
Le dictionnaire exact
L’index[i] stocke les
mots de longueur i+2
Si |mot|< 𝛽.
11
𝒉 𝒙 =
𝒊=𝟏
𝒎
𝒙𝒊 × 𝒕𝒊
𝒎𝒐𝒅 𝑷
L’espace mémoire : 𝑶 𝒏
Donc 𝑶 𝒏 𝐥𝐨𝐠 𝝈 𝒃𝒊𝒕𝒔
Temps de Constr: 𝑶 𝒏
L’ index[𝛽 -2], stocke les
mots >= 𝛽.
𝑃 = 232
− 5, 𝑡 ∈ [1, 𝑃 − 1]
𝐿𝐹 < 1 , 𝛽 = 16
12. La structure de données :
Dictionnaire des listes de substitution
• D={…,ABCDE,…, ABXDE,….}
– ℎ(𝜙𝐵𝐶𝐷𝐸) stocke 𝐴 .
– ℎ(𝐴𝜙𝐶𝐷𝐸) stocke 𝐵 .
– ℎ(𝐴𝐵𝜙𝐷𝐸) stocke 𝐶 ≡ ℎ(𝐴𝐵𝜙𝐷𝐸) stocke 𝑋
– ℎ(𝐴𝐵𝐶𝜙𝐸) stocke 𝐷 .
– ℎ(𝐴𝐵𝐶𝐷𝜙) stocke 𝐸 .
• C, X sont stockés dans la même position.
D E A C X B
12
L’espace mémoire : 𝑶 𝒏 𝐥𝐨𝐠 𝝈 𝒃𝒊𝒕𝒔
Temps de Constr : 𝑶 𝒏
13. La vérification des occurrences
• D={…,ABCDE,…, ABXDE,….}
• 𝑞 = 𝐴𝐵𝑦𝐷𝐸
• ℎ(𝐴𝐵𝜙𝐷𝐸)
• 𝐿 = {𝐶, 𝑋}
– ABCDE ℎ(𝐴𝐵𝐶𝐷𝐸)
– ABXDE ℎ(𝐴𝐵X𝐷𝐸)
D E A C X B
vérification
13
Temps de Vérification : 𝑶 𝒎 ×
𝒎 𝒍𝒐𝒈 𝝈
𝒘
14. Extension à deux erreurs ou plus
D E A C X B
. . . . . . . . . . . .
. . . . . . . . . . . .
𝑘 = 1 ≡ 𝑢1 𝜙 𝑢2
𝑘 = 2 ≡ 𝑢1 𝜙 𝑢2 𝜙 𝑢3
𝑘 = 𝑃 ≡ 𝑢1 𝜙 … 𝜙 𝑢 𝑝+1
.
.
.
Génération Vérification
14
Pour K=2 erreurs
L’espace mémoire : 𝐎 𝐍 𝐥𝐨𝐠 𝝈 𝒃𝒊𝒕𝒔
𝑵 =
𝒊=𝟏
𝒅
𝒏𝒊 𝒏𝒊 − 𝟏
𝟐
Temps de Constr: 𝑶 𝑵
Temps de Vérif : 𝑶 𝒎 𝟐
×
𝒎 𝒍𝒐𝒈 𝝈
𝒘
18. L’idée de base de cette approche TRT_CI
• Soit 𝑃 = 𝑃1 𝜙 𝑃2 mot requête
• Soit 𝑃′ = 𝑃1 𝑎 𝑃2 mot solution
𝑃1
𝑎
𝑒1
𝑒2
𝑃2
𝑐1 𝑎
𝑐2𝑎, 𝑒1, 𝑒2 ∩ 𝑐1, 𝑎, 𝑐2 = {𝑎}
𝑃1 𝑎 𝑃2
Trie Trie inversé
18
Temps de Vérif pire cas : 𝑶 𝝈𝒎 𝟐
T de Vérif cas moy : 𝑶(𝒎 𝟐
) si 𝒎 ≥
𝒍𝒐𝒈 𝒅
𝒍𝒐𝒈 𝝈
𝑶(𝒎 + 𝒎. 𝒐𝒄𝒄𝒓𝒔) si 𝒎 ≥
𝒍𝒐𝒈 𝒅
𝒍𝒐𝒈 𝝈
+
𝒍𝒐𝒈 𝒎
𝒍𝒐𝒈 𝝈
19. La Méthode TRT_CI avec exemple
D={
….
ABCDE
ABDDE
XYADA
XYCDE
XYDAA
XYDDE
XYZDZ
….
}
A
B
C
D
E
D
D
E
X
Y
C
D
E
D
A
A
D
E
A
D
A
Z
D
Z
Trie
𝐷={
….
EDCBA
EDDBC
ADAYX
EDCYX
AADYX
EDDYX
ZDZYX
….
}
A
A
D
Y
D
A
Y
E
D
B
A
D
B
C
Y
X
C
Y
X
Trie
inversé
X X
X
3) {A,C,D,Z} ∩ {CD} = {𝑪𝑫}
Mot requête : XYqDE
1) Chercher « XY » dans le Trie {A,C,D,Z}
2) Chercher « ED » dans le Trie inversé {CD}
Solutions : XYCDE
XYDDE
4) Continuer la recherche
dans les branches {𝑪𝑫}
19
21. L'application de TRT_CI pour
l'indexation de texte
• La recherche des occurrences des mots :
– Ajouter un champ dans chaque feuille du Trie qui
pointe vers une liste de toutes les positions des
mots dans le texte.
• La recherche des facteurs dans un texte :
– Utiliser un arbre des suffixes.
21
24. Auto complétion approchée
Xaut
No Results
Xaut
Autocomplete
Autocomplete jquery
Automobile
Autour
Autolib
Autisme
Tolérer un certain
nombre d'erreurs dans
le préfixe tapé.
Erreur
24
25. Top-k auto complétion
Rapporter les k suggestions les plus hautement classées.
Aut
……
……
……
……
……
……
……
…….
…….
K éléments.
25
26. La structure de données
Root
B
A
C
D
C
A
D
B
C
B
C
D
D
E
5
0
5
0
4
0
5
0
5
0 8
1
0
1
1
1
3
ABCD #50
ADBC #40
AC #10
ABDE #8
BA #11
CD #131) Trie compact avec
un système de classement
2) La file de priorité
3) Tableau de hachage
26
27. La méthode de recherche
• Étape 1: Trouver les nœuds
– Nœud : une solution exacte
– Nœuds : des solutions approchées (avec une recherche naïve)
• Étape 2: la liste du top-k complétion.
Temps Rech approchée (Algo naïf) : 𝑶 𝒏 27
28. Réduire le nombre de branches
sortantes testées.
Choisir la bonne branche dans l'arbre.
28
29. Réduire le nombre de branches
sortantes testées.
ABxCDZZZ
H(AB?CD)%n =3
x y ………..
AByXY
0 1 2 3 4 5 .........
n
Mot requête = ABzCD
H(AB?CD)%n=3 , tab[3]=x
AB
x
CD
D={…
…}
Long des préfixes limitée (exemple: 5)
29Temps de Vérification , cas moyenne : 𝑶(𝒎 𝟐)
30. Méthode hybride :
Liste de substitutions + méthode naïve
30
Trie
Liste de substitutions
Naïve
32. Introduction
• Alignement : consiste à trouver des similitudes
entre deux ou plusieurs séquences et
déterminer leurs homologies possibles.
- G C T G A T A T A G C T
| | | | | | | | | |
G G G T G A T - T A G C T
32
33. - G C T G A T A T A G C T
| | | | | | | | | |
G G G T G A T - T A G C T
| | | | | |
- G C T - A T - - C G C -
| | | |
A G C G G A - A C A C C T
L’alignement multiple
33
34. L’approche DiaWay
Basé sur l’algorithme DiAlign**
** Morgenstren, B., Dress, A., Werner, T. : Multiple DNA and protein sequence alignment
based on segment-to-segment comparison. 93(October) (1996) 1209812103 34
35. DiaWay: l'extraction des diagonales
• La Matrice Dot plot:
• S1 : ATTCCGACT
• S2 : AATTCGCGT
M [i]
[M[i][j]= =
1: Si Match
0: Sinon
A T T C C G A C T
A 1 0 0 0 0 0 1 0 0
A 1 0 0 0 0 0 1 0 0
T 0 1 1 0 0 0 0 0 1
T 0 1 1 0 0 0 0 0 1
C 0 0 0 1 1 0 0 1 0
G 0 0 0 0 0 1 0 0 0
C 0 0 0 1 1 0 0 1 0
G 0 0 0 0 0 1 0 0 0
T 0 1 1 0 0 0 0 0 1
d1 : TT
AA
d2 : ATTCCG
ATTCGC
d3 : CCGA
GCGT
>Tri des diagonales
D={d2, d3, d1}
>>Indexation de D.
35
36. DiaWay: l'inconsistance
• Inconsistance simple:
S1:
s2:
• Inconsistance complexe:
S1:
S2:
S3:
chevauchement
NP-complet **
** Subramanian, A.R., Kaufmann, M., Morgenstern, B. : DIALIGN-TX : greedy and
progressive approaches for segment-based multiple sequence alignment. Algorithms
for molecular biology : AMB 3 (January 2008) 36
37. DiaWay: la résolution de l’inconsistance
1) Inconsistance
chemin
2) Inconsistance
Avec chemin
Trouvé dans (1)
3) Inconsistance
simple
37
38. DiaWay : l'étape finale de l'alignement
1) Mettre
les fragments
ensemble
2) insérer
les gaps (-).
Un ensemble consistant de diagonales D'= {}
Un ensemble trié D’’={d0, d1, d2, d4, d3, d6, d5}
38
40. Les Dictionnaires
Mobydick 37 milles mots
Town 47 milles mots
Anglais 213 milles mots
WikiTitle 1,8 millions mots
40
41. R.A. avec Hachage
Dictionnaire WikiTitle (Wi) pour une erreurDictionnaire Anglais (En) pour une erreur
Dictionnaire WikiTitle (Wi) pour 2 erreursDictionnaire Anglais (En) pour 2 erreurs
Le temps d'insertion dans l'index
41
43. TRT_CI
Aleksander Cislak et Szymon Grabowski
Avec la distance de Hamming.
TRT_CI : 3 fois plus rapide , et stable
Aleksander Cislak et Szymon
Grabowski
TRT_CI
Distance Hamming = 1 Type d’erreur Edit Distance = 3 Types d’erreurs
Temps 0< t <1 Temps : 0< t <1
Changement de temps / la taille de
Dic
Augmente Stable
43
La 2ème méthode
TRT_CI
La 1ère Méthode
RA hachage
44. TRT_CI
𝑇𝑅𝑇_𝐶𝐼 ≈ 167 𝑙𝑎 𝑟𝑒𝑐ℎ𝑒𝑟𝑐ℎ𝑒 𝑒𝑥𝑎𝑐𝑡𝑒
La recherche exacte est l’opération de référence qui
donne le temps d'exécution optimal.
44
45. Auto-complétion : Coté serveur, C/C++
Requête + top-k (en millisecondes) sur l'anglais (En) et sur les titres Wiki
(Wi).
Construction du Trie En : 177 ms , Wi : 980 ms.
45
46. Auto-complétion : Coté serveur, liste
de substitutions
Les listes de substitutions (SL) augmentent la taille de l’index de 0,7 Mo pour
Anglais (En), et de 5 Mo pour Wiki (Wi).
Temps de requête avec et sans l'utilisation des listes de
substitutions.
46
48. Auto-complétion : Coté Client,
JavaScript
Navigateur Chrome.
Construction du Trie
En : 2.7 seconds
Wi : 13 seconds.
Navigateur Internet Explorer.
Construction du Trie
En : 30 s.
Wi : 150 s.
48
49. Les diagonales
initiales
Le nombre des diagonales consistantes est inférieur à 1%
de l'ensemble des diagonales initiales.
DiaWay
49
Les diagonales
consistantes.
52. Conclusion
• Chegrane, I., Belazzougui, D.
Simple, compact and robust approximate string dictionary.
Journal of Discrete Algorithms 28(0) (2014) 49 60 StringMasters 2012 & 2013 Special Issue (Volume 1).
• Chegrane, I., Belazzougui, D., Raffinot, M.
Jquery ui like approximate autocomplete.
International Symposium on Web Algorithms. (2015).
• Chegrane, I, c., Athmane, s., Chahrazed, i., Aicha, b.
Diagonal consistency problem resolution in dialign algorithm.
Bioinformatics (2015) 225 231, Lisbon, Portugal.
• Athmane, S., Chegrane, I., Chahrazed, I.
DNA multiple alignment problem with the new diaway algorithm.
ISPS 2015 (2015).
• Beloucif, M , Chegrane, I .
State of the art about Approximate Pattern Matching.
META’12 Tunis 27-31.
• Chegrane, I. Hadj Ameur, M.S. , Bensaou, N.
Fast approximate string matching in dictionary using Trie and reverse Trie.
in progress.
52
1) Les publications
53. Conclusion
• https://github.com/chegrane/compact-approximate-string-
dictionary
– Langage C Nb ligne code : 5766
• https://github.com/chegrane/TrieRTrie
– Langage C Nb ligne code : 4444
• https://github.com/AppacoLib/api.appacoLib
– Langage C Nb ligne code : 7593
– JavaScript Nb ligne code : 3884
• https://github.com/chegrane/DiaWay_2.0
– C/C++ (Qt) Nb ligne code : 5453
53
2) Les librairies
54. Perspectives
1. Des solutions efficaces en pratique pour 𝑘 ≥ 2.
2. Utiliser les caractéristiques de chaque langue
afin de proposer des solutions spécifiques.
3. Utiliser le parallélisme.
4. Utiliser les techniques de intelligence artificiel.
54