| 1 |
#include "Meanings.h" |
| 2 |
#include <iostream> |
| 3 |
#include <fstream> |
| 4 |
#include <string> |
| 5 |
#include <map> |
| 6 |
using namespace std; |
| 7 |
|
| 8 |
const char* message = |
| 9 |
"This program converts a meanings (words) file into a meanings \n" |
| 10 |
"implementation file. It requires a meanings file (m.#) and an \n" |
| 11 |
"associated words file (w.#). \n"; |
| 12 |
|
| 13 |
const char NEWLINE[3] = { 0xFF, 0xFF, 0 }; |
| 14 |
|
| 15 |
int main() |
| 16 |
{ |
| 17 |
cout << message << endl; |
| 18 |
|
| 19 |
|
| 20 |
cout << "Name of Meanings file (m.#): " << flush; |
| 21 |
string mfile; cin >> mfile; |
| 22 |
|
| 23 |
cout << "Name of Words file (w.#): " << flush; |
| 24 |
string wfile; cin >> wfile; |
| 25 |
|
| 26 |
cout << "Name of Output file: (m-itxt.#): " << flush; |
| 27 |
string ofile; cin >> ofile; |
| 28 |
|
| 29 |
|
| 30 |
cout << "Reading words file..." << flush; |
| 31 |
map<string, int> words; |
| 32 |
ifstream win(wfile.c_str()); |
| 33 |
string s; |
| 34 |
int line = 0; |
| 35 |
while(win >> s) |
| 36 |
words.insert(make_pair(s, line++)); |
| 37 |
cout << " done. (" << words.size() << " words)" << endl; |
| 38 |
|
| 39 |
|
| 40 |
cout << "Reading meanings file..." << flush; |
| 41 |
ifstream min(mfile.c_str()); |
| 42 |
MeaningFamily meanings; |
| 43 |
extractMeaningFamily(min, meanings); |
| 44 |
cout << "done. (" << meanings.size() << " meanings)" << endl; |
| 45 |
|
| 46 |
|
| 47 |
cout << "Creating output file...\n" << flush; |
| 48 |
ofstream out(ofile.c_str()); |
| 49 |
|
| 50 |
cout << "["; |
| 51 |
for(unsigned int i = 0;i <= meanings.size() / 100;++i) |
| 52 |
cout << '-'; |
| 53 |
cout << "]" << endl; |
| 54 |
|
| 55 |
cout << '['; |
| 56 |
for(unsigned int x = 0;x < meanings.size();++x) |
| 57 |
{ |
| 58 |
if ((x % 100) == 0) |
| 59 |
cout << "*" << flush; |
| 60 |
|
| 61 |
const MeaningSet& ms = meanings[x]; |
| 62 |
|
| 63 |
for(unsigned int i = 0;i < ms.size();++i) |
| 64 |
{ |
| 65 |
map<string, int>::iterator word = words.find(ms[i]); |
| 66 |
assert(word != words.end()); |
| 67 |
|
| 68 |
int x = word->second; |
| 69 |
out << x << ' '; |
| 70 |
} |
| 71 |
|
| 72 |
out << endl; |
| 73 |
} |
| 74 |
cout << ']'; |
| 75 |
|
| 76 |
cout << endl; |
| 77 |
return 0; |
| 78 |
} |