/
main.extract_grammar.cpp
165 lines (140 loc) · 4.78 KB
/
main.extract_grammar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
/*
* main.extract_grammar.cpp
* TreeTester
*
* Created by Венцислав Жечев on 02.06.07.
* Copyright 2007 Венцислав Жечев.
* Released under the GPL. See COPYING for information.
*
*/
#include <ctime>
#include "DOPTree.h"
namespace bg_zhechev_ventsislav {
extern void buildLowercasingTable(const string& fileName);
}
int main (int argc, char * const argv[]) {
time_t startTime = time(0);
time_t currentTime;
unsigned long long sec;
#ifndef MACOSX
locale::global(locale("en_US.UTF-8"));
#else
//This points to the file, where lowercase versions for diacritisised characters can be found. The version of GCC that Xcode uses has broken locale system.
#ifdef DATA_DIR
string uml = DATA_DIR;
#else
string uml = "/Users/ventzi/Desktop/курсове - университет/ATTEMPT/software/TreeTester all";
#endif
uml += "/umlauts.txt";
buildLowercasingTable(uml);
#endif //#ifdef MACOSX
/* chudInitialize();
chudMarkPID(getpid(),1);
chudAcquireRemoteAccess();
chudStartRemotePerfMonitor("testthetester");*/
wcout << "DATA_SET: " << DATA_SET << endl;
wifstream input;
wifstream internal;
wofstream output;
bool files_loaded = false;
if (argc > 1 && argc != 4 && argc != 3) {
wcout << "Incorrect number of arguments: " << (argc - 1) << "! Usage:\n " << argv[0] << " [input [internal] output]\n";
exit(1);
} else if (argc == 4 || argc == 3) {
files_loaded = true;
input.open(argv[1]);
if (argc == 4)
internal.open(argv[2]);
output.open(argv[argc - 1]);
}
if (!files_loaded) {
if (1) {
//HomeCenter data
// } else if (DATA_SET == "HomeCentre") {
// NonTerminal::idBase.reset(500);
// input.open("/Users/ventzi/Desktop/курсове - университет/ATTEMPT/data/HomeCentre/new_manual.txt");
//English-Spanish data
// } else if (DATA_SET == "en-sp") {
// input.open("/Users/ventzi/Desktop/курсове - университет/ATTEMPT/data/en-sp/pairs.txt");
//English-German data
// } else if (DATA_SET == "en-de") {
// input.open("/Users/ventzi/Desktop/курсове - университет/ATTEMPT/data/en-de/10k/pairs.txt");
//German News data
} else if (DATA_SET == "de-news") {
input.open("/Users/ventzi/Desktop/курсове - университет/ATTEMPT/data/de-news/weaver/de-news.de.bitpar.clean");
internal.open("/Users/ventzi/Desktop/курсове - университет/ATTEMPT/data/de-news/de-news.de.DOP.internal.only.txt");
output.open("/Users/ventzi/Desktop/курсове - университет/ATTEMPT/data/de-news/de-news.de.DOP.grammar.txt");
} else {
exit(15);
}
}
// exit(66);
if (input.fail()) {
wcout << "!!!Cannot open the pairs file!!!" << endl;
exit(1);
}
if (internal.fail()) {
wcout << "!!!Cannot open the internals file!!!" << endl;
exit(1);
}
DOPTree tree;
int counter = 1;
// PCFGRulesMap PCFGRules;
output.unsetf(ios::fixed);
output.precision(16);
// currentTime = time(0);
// DOPTree::internalOnlyLabels = wstringSet();
if (internal.is_open())
while (!internal.eof()) {
wstring label;
internal >> label;
DOPTree::internalOnlyLabels.insert(label);
wcout << "Got internalOnlyLabel " << label << endl;
}
// internalOnlyLabels.insert(L"#EOS#");
tree = L"(NP (D the)(NPadj (Adj green)(N house)))";
tree.collectPCFGRules(wcout);
tree = L"(NP (D the)(NPadj (Adj small)(N house)))";
tree.collectPCFGRules(wcout);
int treeNo = 10;
while (0 && !input.eof()) {
input >> tree;
if (tree.sentLength() > 0) {
++counter;
// if (counter <= treeNo) continue;
// wcout << "Tree №" << counter - 1 << ":" << endl;
// treePair.printXML();
// wcout << tree;
wcout << ".";
tree.collectPCFGRules(output);
// wcout << endl;
// treePair.removeExtraNodes();
// treePair.printTaggedSentences();
// treePair.printSentences();
// treePair.freezeLinks();
// treePair.printBracketed();
// wcout << endl;
if (counter > treeNo) break;
} else {
wcout << "Tree №" << counter << ": !!!ERROR!!!" << endl;
}
}
wcout << endl;
input.close();
DOPTree::outputPCFGRules(wcout);
/* for (PCFGRulesMap::const_iterator it = PCFGRules.begin(); it != PCFGRules.end(); ++it) {
for (PCFGRulesMap::value_type::second_type::second_type::const_iterator rit = it->second.second.begin(); rit != it->second.second.end(); ++rit) {
wcout << it->first << "\t" << rit->first << "\t" << ((1.0*rit->second)/it->second.first) << endl;
// output << it->first << "\t" << rit->first << "\t" << ((1.0*rit->second)/it->second.first) << endl;
}
}*/
output.close();
/* chudStopRemotePerfMonitor();
chudReleaseRemoteAccess();*/
currentTime = time(0);
tm* local = localtime(¤tTime);
sec = difftime(currentTime, startTime);
wcout << endl << "Elapsed: " << sec << "sec" << endl;
wcout << "Finished at " << asctime(local);
return 0;
}