Debian Codegraph @

data/0.12-dev/src/ImplMeanings.cpp

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