| 1 |
#include "AikSaurus.h" |
| 2 |
#include <iostream> |
| 3 |
#include <cstdlib> |
| 4 |
#include <string> |
| 5 |
#include <algorithm> |
| 6 |
#include <vector> |
| 7 |
|
| 8 |
using namespace std; |
| 9 |
|
| 10 |
void checkError(const AikSaurus& T) |
| 11 |
{ |
| 12 |
const char* err = T.error(); |
| 13 |
|
| 14 |
if (err[0] != '\0') |
| 15 |
{ |
| 16 |
cout << "Error: " << err << endl; |
| 17 |
exit(1); |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
// |
| 22 |
// fillSet |
| 23 |
// ------- |
| 24 |
// 'word' is looked up in AikSaurus, and the vector v is filled with it's synonyms |
| 25 |
// |
| 26 |
void fillSet( const char *word, vector<string> &v ) |
| 27 |
{ |
| 28 |
AikSaurus T; |
| 29 |
char code; |
| 30 |
|
| 31 |
v.clear(); |
| 32 |
|
| 33 |
if ( T.find( word ) ) |
| 34 |
{ |
| 35 |
for(const char* result = T.next(code); result[0] != '\0'; result = T.next(code)) |
| 36 |
{ |
| 37 |
v.push_back( result ); |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
// sort( v.begin(), v.end() ); |
| 42 |
} |
| 43 |
|
| 44 |
// |
| 45 |
// setInt |
| 46 |
// ------ |
| 47 |
// This function makes 'a' the set intersection of vectors 'a' and 'b' |
| 48 |
// It is the mathematical equivalent of a = a^b |
| 49 |
// |
| 50 |
void setInt( vector<string> &a, vector<string> &b ) |
| 51 |
{ |
| 52 |
vector< string > result; |
| 53 |
|
| 54 |
set_intersection( a.begin(), a.end(), b.begin(), b.end(), |
| 55 |
inserter( result, result.end() ) ); |
| 56 |
|
| 57 |
a.swap( result ); |
| 58 |
} |
| 59 |
|
| 60 |
// |
| 61 |
// equivClass |
| 62 |
// ---------- |
| 63 |
// This function takes two words and propogates their appropriate class into rval |
| 64 |
// |
| 65 |
void equivClass( const char *first, const char *second, vector<string> &rval ) |
| 66 |
{ |
| 67 |
rval.clear(); |
| 68 |
|
| 69 |
vector< string > candidates; |
| 70 |
vector< string > tmp; |
| 71 |
|
| 72 |
fillSet( first, candidates ); |
| 73 |
rval.push_back( first ); |
| 74 |
|
| 75 |
fillSet( second, tmp ); |
| 76 |
rval.push_back( second ); |
| 77 |
|
| 78 |
sort( rval.begin(), rval.end() ); |
| 79 |
|
| 80 |
setInt( candidates, tmp ); |
| 81 |
|
| 82 |
while ( ! candidates.empty() ) |
| 83 |
{ |
| 84 |
fillSet( candidates.back().c_str(), tmp ); |
| 85 |
if ( includes( tmp.begin(), tmp.end(), rval.begin(), rval.end() ) ) |
| 86 |
{ |
| 87 |
rval.push_back( candidates.back() ); |
| 88 |
sort( rval.begin(), rval.end() ); |
| 89 |
setInt( candidates, tmp ); |
| 90 |
} |
| 91 |
else |
| 92 |
{ |
| 93 |
candidates.pop_back(); |
| 94 |
} |
| 95 |
} |
| 96 |
} |
| 97 |
|
| 98 |
|