-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
146 lines (130 loc) · 2.99 KB
/
main.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
#include "SAP.h"
#include "WordNet.h"
#include "Outcast.h"
#include <fstream>
#include <iostream>
#include <cstdio>
#include <string>
#include "vld.h"
using namespace std;
// SAP test
void SAP_test() {
cout << "-- SAP test --" << endl;
cout << "Enter digraph filename: ";
string file;
cin >> file;
ifstream inFile;
inFile.open(file);
// inFile.open("files/digraph1.txt");
if (!inFile.is_open()) {
cerr << "File not opened!" << endl;
return;
}
Digraph G(inFile);
cout << G << endl;
SAP sap(G);
int v, w;
cout << "v: (-1 to exit)";
while (cin >> v) {
if (v == -1) break;
cout << "w: ";
cin >> w;
int length = sap.length(v, w);
int ancestor = sap.ancestor(v, w);
printf("length = %d, ancestor = %d\n", length, ancestor);
cout << "v: ";
}
}
// WordNet test
void WordNet_test(WordNet& word) {
cout << "-- WordNet test --" << endl;
string a, b;
cout << "Enter words (-1 to quit)" << endl;
cout << "First word: ";
while (cin >> a) {
if (a == "-1") break;
cout << "Second word: ";
cin >> b;
if (!word.isNoun(a) || !word.isNoun(b)) {
cerr << "Word(s) not found" << endl;
return;
}
//a = "Black_Plague";
//b = "black_marlin";
int d = word.distance(a, b);
string anc = word.sap(a, b);
cout << d << " = distance between " << a << " and " << b << endl;
cout << anc << " = common ancestor between " << a << " and " << b << endl;
cout << "First word: ";
}
}
// Outcast test
void Outcast_test(WordNet& wordnet) {
cout << "-- Outcast test --" << endl;
Outcast outcast(wordnet);
string file;
cout << "Filename: (exit to quit)";
while (cin >> file) {
if (file == "exit") break;
ifstream inFile;
// string file = "files/outcast17.txt";
inFile.open(file);
// inFile.open(argv[1]);
if (!inFile.is_open()) {
cerr << file << " not opened!" << endl;
return;
}
string buffer;
int N = 0;
Bag<std::string> bag;
while (getline(inFile, buffer)) {
if (buffer == "") break;
bag.add(buffer);
N++;
}
inFile.close();
std::string* words = new std::string[N];
int i = 0;
for (string s : bag) {
words[i] = s;
i++;
}
//int N;
//cout << "Number of words: ";
//cin >> N;
//for (int i = 0; i < N; i++) {
// cout << "Word " << i + 1 << ": ";
// cin >> words[i];
//}
//cout << endl;
cout << "Outcast: " << outcast.outcast(words, N) << endl;
delete[] words;
cout << "Filename: ";
}
}
int main(int argc, char* argv[]) {
// Loads in the synsets and hypernyms file
string synsetsFile = "files/synsets.txt";
string hypernymsFile = "files/hypernyms.txt";
WordNet wordnet(synsetsFile, hypernymsFile);
cout << "** WordNet **" << endl;
cout << "Please choose one of the following: " << endl;
cout << "1. SAP test" << endl << "2. WordNet test" << endl << "3. Outcast test" << endl;
int choice;
cin >> choice;
switch (choice) {
case 1:
SAP_test();
break;
case 2:
WordNet_test(wordnet);
break;
case 3:
Outcast_test(wordnet);
break;
default:
cout << "Invalid input" << endl;
}
cout << "Done!" << endl;
return 0;
}