Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
BitchX
GitHub Repository: BitchX/BitchX1.3
Path: blob/master/dll/europa/cse476/p1-junk.cpp
1074 views
1
// CSE476 Bottom Up Chart Parser
2
// Ed Schlunder ([email protected])
3
4
#include <iostream.h>
5
#include <fstream.h>
6
#include <stdio.h>
7
#include <string.h>
8
9
#include "grammar.h"
10
#include "lexicon.h"
11
12
Lexicon lex("lexicon.txt");
13
Grammar gra("grammar.txt");
14
15
void procAgenda(genericNode *a) {
16
List *currLine;
17
genericNode *pred;
18
char *category;
19
20
category = a->Feature("CAT");
21
cout << " Unify searching for: " << category << endl;
22
gra.GoTop();
23
do {
24
currLine = gra.currLine();
25
currLine->GoTop();
26
currLine->GoNext();
27
pred = currLine->currItemNode();
28
29
if(unify(a, pred)) {
30
gra.Print();
31
cout << endl;
32
}
33
34
} while(gra.GoNext());
35
cout << endl;
36
}
37
38
// Jack was happy to see a dog
39
void Parse(char *sentence) {
40
List *s = MakeList(sentence);
41
42
cout << "Sentence: ";
43
s->Print();
44
cout << endl;
45
46
s->GoTop();
47
do {
48
if(s->currItem() == NULL)
49
break;
50
51
cout << "Word: " << s->currItem() << endl;
52
if(lex.Lookup(s->currItem())) {
53
cout << " CAT: " << lex.Feature("CAT") << endl;
54
procAgenda(lex.currNode());
55
}
56
else
57
cout << " No lexical entry!" << endl;
58
} while(s->GoNext());
59
}
60
61
int main(int argc, char *argv[]) {
62
char sentence[1000];
63
64
cout << "[nlp]$ Jack was happy to see a dog." << endl;
65
Parse("Jack was happy to see a dog.");
66
67
cout << "[nlp]$ " << flush;
68
cin.getline(sentence, 999);
69
while(cin) {
70
Parse(sentence);
71
72
cout << "[nlp]$ " << flush;
73
cin.getline(sentence, 999);
74
}
75
76
cout << endl;
77
78
/*
79
char tmp[100];
80
cin.getline(tmp, 99);
81
while(cin) {
82
cout << "Lexical Lookup: \"" << tmp << "\" ";
83
if(lex.Lookup(tmp)) {
84
cout << " - cat: " << lex.Feature("CAT");
85
cout << " subcat: " << lex.Feature("SUBCAT");
86
while(char *subcat = lex.Feature())
87
cout << ", " << subcat;
88
cout << endl;
89
}
90
else
91
cout << "does not exist" << endl;
92
93
cin.getline(tmp, 99);
94
}
95
*/
96
}
97
98
99