-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDictWordCounter.cpp
More file actions
85 lines (71 loc) · 2.45 KB
/
DictWordCounter.cpp
File metadata and controls
85 lines (71 loc) · 2.45 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
#include <iostream>
#include <cstdio>
#include <string>
#include <fstream>
#include <vector>
using namespace std;
// Simply opens the plaintext word-list dictionary and tallies the number of words vs. word length
// Used to gather stats on various candidate dictionaries for the New Sator Square project
int main(int argc, char** argv)
{
char filename[]="la-novs-nodups.txt"; //Comment out to use a filename supplied on the command line
argv[1]=filename;
if (argv[1]) {
cout<<"Opening dictionary...";
} else {
fprintf(stderr,"correct syntax is:\n");
fprintf(stderr,"WordCounter textfile.txt\n");
exit(1);
}
ifstream dictionary;
dictionary.open(argv[1],ifstream::in);
if (!dictionary.is_open()) {
cerr<<"Error opening dictionary file!"<<endl;
exit(-1);
}
cout<<" success."<<endl;
vector<unsigned int> stats(32,0);
string load_a_word;
unsigned int counter=0;
unsigned int wordlength=0;
vector<string> interesting;
vector<vector<string> > AllWordsByLength;
AllWordsByLength.reserve(32);
while (!dictionary.eof()) {
getline(dictionary,load_a_word);
counter++;
if (counter%100000==0) cout<<"Processed "<<counter<<endl;
wordlength=load_a_word.length();
//if (wordlength==2) interesting.push_back(load_a_word);
//if (wordlength>30) stats[31]++; else stats[wordlength]++;
if (wordlength>30) {
stats[31]++;
AllWordsByLength[31].push_back(load_a_word);
}
else {
stats[wordlength]++;
AllWordsByLength[wordlength].push_back(load_a_word);
}
}
cout<<"Analysis completed. Total words processed="<<counter<<endl;
dictionary.close();
ofstream res;
res.open("results-lat-noVs.txt",ofstream::out);
if (!res.is_open()) {cerr<<"Can't open results file for writing"<<endl; exit(-1);}
res<<"Analysis completed. Total words processed="<<counter<<endl;
for (unsigned int i=1;i<stats.size();i++) {
cout<<"Word size: "<<i<<" Words: "<<stats[i]<<endl;
res<<"Word size: "<<i<<" Words: "<<stats[i]<<endl;
}
unsigned int selector=1;
do {
cin>>selector;
cout<<"Words of size "<<selector<<" are: "<<endl;
for (unsigned int i=0;i<AllWordsByLength[selector].size();i++) {
cout<<AllWordsByLength[selector].at(i)<<" ";
}
cout<<endl;
} while (selector!=0);
res.close();
return 0;
}