-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoteurderecherche.h
127 lines (115 loc) · 4.15 KB
/
Moteurderecherche.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef MOTEURDERECHERCHE_H_INCLUDED
#define MOTEURDERECHERCHE_H_INCLUDED
#include "Indexe.h"
#include "Stat.h"
#include <vector>
#include "Analyseur.h"
#include "Ordonnanceur.h"
#include "Lecteur.h"
#include "LecteurFichier.h"
#include "OrdonnanceurOccurence.h"
#include "TraiteurPonctuations.h"
#include "LecteurRepertoire.h"
#include "AnalyseurBinaire.h"
#include "AnalyseurFrequentiel.h"
#include "IndexeVector.h"
#include "IndexeMap.h"
#include "IndexeList.h"
#include "IndexeDeque.h"
#include "LecteurString.h"
#include "Moteurderecherche.h"
#include <string_view>
#include <dirent.h>
#include "AnalyseurOccurence.h"
#include "OrdonnanceurBinaire.h"
class MoteurRecherche{
Lecteur* lecteur;
vector<Traiteur*> traiteurs;
Analyseur* analyseur;
Indexe* indexe;
Ordonnanceur* ordonnanceur;
public:
Indexe* getIndexe(){return indexe;};
MoteurRecherche(Lecteur* lect, vector<Traiteur*> traits, Analyseur* analy, Indexe* ind, Ordonnanceur* ord);
void rechercher(vector<string> wordsReq);
void indexer(string chemin);
};
vector<string> split(string str, string token){
vector<string>result;
while(str.size()){
int index = str.find(token);
if(index!=string::npos){
result.push_back(str.substr(0,index));
str = str.substr(index+token.size());
if(str.size()==0)result.push_back(str);
}else{
result.push_back(str);
str = "";
}
}
return result;
}
MoteurRecherche::MoteurRecherche(Lecteur* lect, vector<Traiteur*> traits, Analyseur* analy, Indexe* ind, Ordonnanceur* ord):lecteur(lect),traiteurs(traits),analyseur(analy),
indexe(ind),ordonnanceur(ord){
LecteurFichier lecteur_fichier;
vector<Stat> vectStat;
vector<string> stats = lecteur_fichier.lire("indexe.txt");
for (string stat:stats){
vector<string> prov = split(stat,"|");
Stat s;
s.mot = prov[0];
s.fichier = prov[1];
s.stat = stof(prov[2]);
vectStat.push_back(s);
}
indexe->addStats(vectStat);
}
void MoteurRecherche::rechercher(vector<string> wordsReq){
for (Traiteur* trait:traiteurs){
wordsReq = trait->traiter(wordsReq);
}
ordonnanceur->ordonnancer(indexe,wordsReq);
}
void MoteurRecherche::indexer(string chemin){
if (chemin[chemin.size()-1]=='/')
{
vector<string> mots;
string fileName="";
DIR *dr;
struct dirent *en;
dr = opendir(chemin.c_str());
if (dr) {
while ((en = readdir(dr)) != NULL) {
int i = 0;
while(true){
if(en->d_name[i]=='.'){
if((en->d_name[i+1]=='t')&&(en->d_name[i+2]=='x')&&(en->d_name[i+3]=='t')){
fileName=chemin;
fileName.append(en->d_name);
mots = lecteur->lire(fileName);
for (Traiteur* trait:traiteurs){
mots = trait->traiter(mots);
}
vector<Stat> stats = analyseur->analyser(mots,fileName);
indexe->addStats(stats);
break;
}
}
i++;
if (i>260){break;}
}
}
closedir(dr);
}
}
else
{
vector<string> mots = lecteur->lire(chemin);
for (Traiteur* trait:traiteurs){
mots = trait->traiter(mots);
}
vector<Stat> stats = analyseur->analyser(mots,chemin);
indexe->addStats(stats);
}
}
#endif // MOTEURDERECHERCHE_H_INCLUDED