| 1 |
#include <fstream> |
| 2 |
#include <iostream> |
| 3 |
#include <vector> |
| 4 |
#include <string> |
| 5 |
#include <set> |
| 6 |
#include <algorithm> |
| 7 |
#include "fast.h" |
| 8 |
#include "cleanup.h" |
| 9 |
|
| 10 |
static AikSaurusFAST Thesaurus; |
| 11 |
|
| 12 |
|
| 13 |
void maximizeClass(vector<string>& meaning, int place) |
| 14 |
{ |
| 15 |
const vector<string>& synonyms = Thesaurus.getSynonyms( |
| 16 |
meaning[place] |
| 17 |
); |
| 18 |
|
| 19 |
for(int i = 0;i < synonyms.size();++i) |
| 20 |
{ |
| 21 |
const vector<string>& subsyns = Thesaurus.getSynonyms( |
| 22 |
synonyms[i] |
| 23 |
); |
| 24 |
|
| 25 |
sort( meaning.begin(), meaning.end() ); |
| 26 |
|
| 27 |
if (includes(subsyns.begin(), subsyns.end(), |
| 28 |
meaning.begin(), meaning.end())) |
| 29 |
{ |
| 30 |
meaning.push_back(synonyms[i]); |
| 31 |
} |
| 32 |
} |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
bool wordAlreadyInClass( |
| 37 |
const vector<vector<string> >& classes, |
| 38 |
const string& word) |
| 39 |
{ |
| 40 |
for(int i = 0;i < classes.size();++i) |
| 41 |
{ |
| 42 |
for(vector<string>::const_iterator x = classes[i].begin(); x != classes[i].end(); ++x) |
| 43 |
{ |
| 44 |
if ((*x) == word) |
| 45 |
return true; |
| 46 |
} |
| 47 |
} |
| 48 |
|
| 49 |
return false; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
int equivs(const string& word) |
| 54 |
{ |
| 55 |
const vector<string>& topsyns = Thesaurus.getSynonyms(word); |
| 56 |
|
| 57 |
vector< vector<string> > classes; |
| 58 |
|
| 59 |
for(int i = 0;i < topsyns.size();++i) |
| 60 |
{ |
| 61 |
if (!wordAlreadyInClass(classes, topsyns[i])) |
| 62 |
{ |
| 63 |
classes.push_back(vector<string>()); |
| 64 |
int index = classes.size() - 1; |
| 65 |
classes[index].reserve(10); |
| 66 |
classes[index].push_back(word); |
| 67 |
classes[index].push_back(topsyns[i]); |
| 68 |
maximizeClass(classes[index], 1); |
| 69 |
|
| 70 |
sort(classes[index].begin(), classes[index].end()); |
| 71 |
|
| 72 |
// copy(classes[index].begin(), classes[index].end(), |
| 73 |
// ostream_iterator<string>(cout, " ")); |
| 74 |
|
| 75 |
// cout << endl; |
| 76 |
} |
| 77 |
} |
| 78 |
|
| 79 |
vector< vector<string> > output; |
| 80 |
cleanup(classes, output); |
| 81 |
|
| 82 |
for(int i = 0;i < output.size();++i) |
| 83 |
{ |
| 84 |
copy(output[i].begin(), output[i].end(), |
| 85 |
ostream_iterator<string>(cout, " ")); |
| 86 |
|
| 87 |
cout << endl; |
| 88 |
} |
| 89 |
|
| 90 |
return 0; |
| 91 |
} |
| 92 |
|
| 93 |
|
| 94 |
#include <ctime> |
| 95 |
|
| 96 |
int main() |
| 97 |
{ |
| 98 |
ifstream fin("thesaurus.in"); |
| 99 |
|
| 100 |
time_t start = time(NULL); |
| 101 |
while(start == time(NULL)); |
| 102 |
start = time(NULL); |
| 103 |
|
| 104 |
string index, shit; |
| 105 |
while(fin >> index >> shit) |
| 106 |
{ |
| 107 |
cout << "# " << index << endl; |
| 108 |
equivs(index); |
| 109 |
} |
| 110 |
|
| 111 |
time_t end = time(NULL); |
| 112 |
|
| 113 |
cout << "start = " << start << ", end = " << end << endl; |
| 114 |
cout << "elapsed = " << end - start << endl; |
| 115 |
|
| 116 |
return 0; |
| 117 |
} |
| 118 |
|