-
Notifications
You must be signed in to change notification settings - Fork 0
/
main_wordsStat.cpp
30 lines (30 loc) · 1.14 KB
/
main_wordsStat.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
#include "wordStat.h"
int main(int argc, char* argv[]){
if (argc < 2) {
std::cerr << "Usage: " << argv[0] << " <name of analysed file in .txt format>" << std::endl;
return 1;
}
const char* bookName = argv[1];
map <string,int> dictionary;
string line;
ifstream bookFile;
vector<PairVect> sortedWords;
vector<string> my_vocabluary;
WordStat wordsWork;
my_vocabluary=wordsWork.readFileToVector();
bookFile.open(bookName);
if(bookFile.is_open()){
while(getline(bookFile,line))
{
wordsWork.countWords(bookFile,dictionary,my_vocabluary);
}
}
else cout<<"Unable to open file" <<endl;
bookFile.close();
sortedWords=wordsWork.sort_by_weight(dictionary);
wordsWork.writeStatToFile(sortedWords);
wordsWork.writeStatToFile(sortedWords,"listOfwordsForQT.txt",1);
for(StrIntMap::iterator it = dictionary.begin(); it!=dictionary.end(); ++it){
// cout<<it->first<<" occured "<<it->second<<" times. \n";
}
}