-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
152 lines (129 loc) · 4.56 KB
/
main.cpp
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
#include <iostream>
#include <fstream>
#include <string.h>
#include <vector>
#include <map>
#include <algorithm>
#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 "TraiteurMotsVides.h"
#include "IndexeDeque.h"
#include "LecteurString.h"
#include "Moteurderecherche.h"
#include <string_view>
#include <dirent.h>
#include "AnalyseurOccurence.h"
#include <sys/types.h>
#include <fstream>
#include <chrono>
using namespace std;
void saveIndexe(MoteurRecherche* moteur){
ofstream file;
file.open("indexe.txt",ios_base::out);
for (Stat stat: moteur->getIndexe()->getAllStats()){
file << stat.mot << "|" << stat.fichier << "|" << stat.stat << endl ;
}
}
int main(int nbArguments, char *arguments[])
{
auto start = chrono::high_resolution_clock::now();
Lecteur* lect;
vector<Traiteur*> traiteurs;
Indexe* ind;
Analyseur* analy;
Ordonnanceur* ord;
LecteurFichier* lectConfig = new LecteurFichier();
vector<string> config = lectConfig->lire("config.txt");
delete lectConfig;
for (unsigned i = 0 ; i<5;i++){
if (i == 0){
if (config[i] == "fichier"){LecteurFichier* lectfich = new LecteurFichier(); lect =lectfich; }
}
if (i == 1){
vector<string> traits = split(config[i],"/");
for (string trait:traits){
if (trait == "emptywords"){TraiteurMotsVides* trait_mots_vides = new TraiteurMotsVides(); traiteurs.push_back(trait_mots_vides);}
else if (trait == "punctuations"){TraiteurPonctuations* trait_ponctuations = new TraiteurPonctuations(); traiteurs.push_back(trait_ponctuations);}
else if (trait == "lowercase"){TraiteurMiniscule* trait_miniscule = new TraiteurMiniscule(); traiteurs.push_back(trait_miniscule);}
}
}
if (i == 2){
if (config[i] == "binaire"){AnalyseurBinaire* analy_binaire = new AnalyseurBinaire(); analy = analy_binaire;}
else if (config[i] == "occurence"){AnalyseurOccurence* analy_occ = new AnalyseurOccurence(); analy = analy_occ;}
else if (config[i] == "frequentiel"){AnalyseurFrequentiel* analy_freq = new AnalyseurFrequentiel(); analy = analy_freq;}
}
if (i == 3){
if (config[i] == "vector"){IndexeVector* indvec = new IndexeVector(); ind = indvec;}
else if (config[i] == "map"){IndexeMap* indmap = new IndexeMap(); ind = indmap;}
else if (config[i] == "list"){IndexeList* indlist = new IndexeList(); ind = indlist;}
else if (config[i] == "deque"){IndexeDeque* inddeque = new IndexeDeque(); ind = inddeque;}
;
}
if (i == 4){
if (config[i] == "binaire"){OrdonnanceurBinaire* ord_binaire = new OrdonnanceurBinaire(); ord = ord_binaire;}
else if (config[i] == "occurence" || config[i] == "frequentiel"){OrdonnanceurOccurence* ord_occ = new OrdonnanceurOccurence(); ord = ord_occ;}
}
}
MoteurRecherche* moteur = new MoteurRecherche(lect,traiteurs,analy,ind,ord);
switch (nbArguments)
{
case (1):
{
cout << "Nombre d'arguments invalide!";
break;
}
case (2):
{
if ((strcmp(arguments[1], "indexer") == 0) || (strcmp(arguments[1], "add") == 0) || (strcmp(arguments[1], "delete") == 0))
{
cout << "Missing path";
break;
}
else if (strcmp(arguments[1], "rechercher") == 0)
{
cout << "Missing Request";
break;
}
else if (strcmp(arguments[1], "showIndex") == 0)
{
cout << "index :"<< endl;
for (Stat stat:moteur->getIndexe()->getAllStats()){
cout << stat.mot << endl << stat.fichier << endl << stat.stat << endl ;
}
break;
}
}
case (3):
{
if (strcmp(arguments[1], "indexer") == 0)
{
moteur->indexer(arguments[2]);
break;
}
}
default:{
if (strcmp(arguments[1], "rechercher") == 0)
{
vector<string> req ;
for (unsigned i = 2; i < nbArguments; i++)
{
req.push_back(arguments[i]);
}
moteur->rechercher(req);
break;
}
}
}
auto stop = chrono::high_resolution_clock::now();
auto duration = chrono::duration_cast<chrono::seconds>(stop - start);
cout << duration.count() << " seconds" << endl;
saveIndexe(moteur);
return 0 ;
}