-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
166 lines (143 loc) · 4.36 KB
/
Copy pathmain.cpp
File metadata and controls
166 lines (143 loc) · 4.36 KB
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/*
SHV181
Copyright (C) 2019 ghaith sassi & ahmed yassine hammami
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include<bits/stdc++.h>
#include <time.h>
#include "file.h"
#include "engine.h"
#include "stream.h"
#include "ranking.h"
#include "index.h"
using namespace std;
int n;// this variable is not used
//#define inputStream cin
//#define outputStream cout
/* global varibales */
//notVerySmartRankingAlgorithm *algorithm = new notVerySmartRankingAlgorithm;
//aLitleBitSmarterAlgorithm *algorithm = new aLitleBitSmarterAlgorithm;
//smarterAlgorithm * algorithm = new smarterAlgorithm;
//evenMoreSmarterAlgorithm *algorithm = new evenMoreSmarterAlgorithm;
intelligenceAlgorithm * algorithm = new intelligenceAlgorithm;
//map_vec_index *myindex = new map_vec_index;
map_map_index *myindex = new map_map_index;
//unorderedmap_vec_index *myindex = new unorderedmap_vec_index;
engine searchEngine(myindex,algorithm);
input<istream> inputStream(cin);
output<ostream> outputStream(cout);
void duree(time_t,time_t);
void search();
void index();
void indexafile();
void indexapath();
//main
int main(){
//text test_text("dataset/test.txt"); // used for debug
int q;
//searchEngine.loadIndex(); // auto load
outputStream<<"------------------------------------------------------"<<endl;
outputStream<<" Welcome to SVH181 search engine "<<endl;
start:
outputStream<<""<<endl<<endl;
outputStream<<"[1] :search\t[2] :index\t[3] :index a file\t[4] :index a path\t\t[0] :exit"<<endl;
outputStream<<"[5] :load index\t[6] :save index"<<endl<<endl;
outputStream<<">>";
inputStream>>q;
switch (q)
{
case 0:
return 0;
case 1:
search();
goto start;
break; // just to remove compiler warnning
case 2:
{
outputStream<<"indexing dataset %%%%"<<endl;
time_t begin=time(NULL);
searchEngine.indexPath("./dataset");
cout<<"--Indexation time : ";
time_t end=time(NULL);
duree(begin,end);
searchEngine.saveIndex();
}
goto start;
break;
case 3:
indexafile();
goto start;
break;
case 4 :
indexapath();
goto start;
break;
case 5:
outputStream<<"loading index %%%?"<<endl;
searchEngine.loadIndex();
goto start;
break;
case 6:
outputStream<<"saving index %%%?"<<endl;
searchEngine.saveIndex();
goto start;
break;
default:
goto start;
break;
}
return 0;
}
void duree(time_t _begin, time_t _end)
{
double temp;
double hours=0, min=0, sec=0;
double dureeCalc = difftime(_end, _begin);
temp = modf(dureeCalc/3600., &hours);
temp = modf(temp*60., &min);
temp = modf(temp*60., &sec);
cout<<hours<<" h "<<min<<" min "<<sec<<" sec"<<endl;
}
inline void search(){
string s;
outputStream<<"-------search----------"<<endl;
getline(inputStream,s);
time_t begin1=time(NULL);
searchEngine.search(s);
outputStream<<"--Search time : ";
time_t end1=time(NULL);
duree(begin1,end1);
}
inline void index(){
outputStream<<"indexing dataset %%%%"<<endl;
time_t begin=time(NULL);
searchEngine.indexPath("./dataset");
cout<<"--Indexation time : ";
time_t end=time(NULL);
duree(begin,end);
searchEngine.saveIndex();
}
inline void indexafile(){
string s="";
outputStream<<"-------index a file----------"<<endl;
outputStream<<"enter file path/name.txt: ";
inputStream>>s;
text myfile(s);
searchEngine.indexFile(myfile);
}
inline void indexapath(){
string s="";
outputStream<<"-------index a path----------"<<endl;
outputStream<<"enter path: ";
inputStream>>s;
searchEngine.indexPath(s);
}