Debian Codegraph @

data/0.12-dev/gen_pms/stage1.cpp

raw
1 //
2 // stage1
3 // input: single word
4 // output: preliminary meaning classes on lines separated by spaces.
5 //
6
7 #include <iostream>
8 #include <vector>
9 #include <string>
10 #include <set>
11 #include <algorithm>
12 #include "fast.h"
13
14 static AikSaurusFAST Thesaurus;
15
16
17 void maximizeClass(vector<string>& meaning, int place)
18 {
19 const vector<string>& synonyms = Thesaurus.getSynonyms(
20 meaning[place]
21 );
22
23 for(int i = 0;i < synonyms.size();++i)
24 {
25 const vector<string>& subsyns = Thesaurus.getSynonyms(
26 synonyms[i]
27 );
28
29 sort( meaning.begin(), meaning.end() );
30
31 if (includes(subsyns.begin(), subsyns.end(),
32 meaning.begin(), meaning.end()))
33 {
34 meaning.push_back(synonyms[i]);
35 }
36 }
37 }
38
39
40 bool wordAlreadyInClass(
41 const vector<vector<string> >& classes,
42 const string& word)
43 {
44 for(int i = 0;i < classes.size();++i)
45 {
46 for(vector<string>::const_iterator x = classes[i].begin(); x != classes[i].end(); ++x)
47 {
48 if ((*x) == word)
49 return true;
50 }
51 }
52
53 return false;
54 }
55
56
57 int main(int argc, const char** argv)
58 {
59 string word;
60 if (argc < 2)
61 {
62 cout << "Enter word to build meanings for: " << flush;
63 cin >> word;
64 }
65 else
66 {
67 word = argv[1];
68 }
69
70 const vector<string>& topsyns = Thesaurus.getSynonyms(word);
71
72 vector< vector<string> > classes;
73
74 for(int i = 0;i < topsyns.size();++i)
75 {
76 if (!wordAlreadyInClass(classes, topsyns[i]))
77 {
78 classes.push_back(vector<string>());
79 int index = classes.size() - 1;
80 classes[index].reserve(10);
81 classes[index].push_back(word);
82 classes[index].push_back(topsyns[i]);
83 maximizeClass(classes[index], 1);
84
85 sort(classes[index].begin(), classes[index].end());
86
87 copy(classes[index].begin(), classes[index].end(),
88 ostream_iterator<string>(cout, " "));
89
90 cout << endl;
91 }
92 }
93
94 return 0;
95 }
96
97
98
99