-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
executable file
·156 lines (149 loc) · 3.93 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
147
148
149
150
151
152
153
154
155
156
//
// test_Cmd_Interface.cpp
//
// Created by Lu Yi on 11/8/12.
// Copyright 2011 UC Davis. All rights reserved.
//
#include <iostream>
#include <ctime>
#include "basic.h"
#include "parser/grammerParser.h"
//#include "Grammer_analysis.h"
#define EXIT_SUCCESS 0
#define EXIT_FAILURE 1
using namespace std;
void bufferTest(GDataBase *);
int LinkedListTest();
int ListNodeTest();
void seperateWordTest();
void dbTest(GDataBase *);
//GDataBase dic;
int main(void) {
clock_t tik, tak;
tik = clock();
std::cout << "Trying to connect to database webster.db...";
static GDataBase dic("./webster.db");
if (!dic.is_open()) {
std::cout << "Failed.\n";
} else {
std::cout << "Succeeded.\n";
}
ListNodeTest();
LinkedListTest();
GWord apple("apple");
bufferTest(&dic);
dbTest(&dic);
apple.display();
tak = clock();
std::cout << "Time cost: " << 1000 * (double) (tak - tik) / CLOCKS_PER_SEC
<< "ms." << std::endl;
return EXIT_SUCCESS;
}
void dbTest(GDataBase * database) {
//GWord apple("apple");
database->getWordType("apple");
database->getWordType("pear");
}
void bufferTest(GDataBase * db) {
bool quit_flag = false;
//char ** ptr;
std::string inputBuffer = "";
std::cout
<< "\n\n************************************************\nWelcome to the grammer helper test interface!\nThis interface is for test only!\n************************************************\nPlease input a complete sentence or phrase for testing:\n\n";
if (db->is_open()) {
cout << "Database is open\n";
} else
cout << "Database not availble\n";
while (!quit_flag) {
std::cout << "Test_input> ";
std::getline(std::cin, inputBuffer);
if (inputBuffer == "q" || inputBuffer == "Q") {
quit_flag = true;
break;
}
if ((quit_flag == false) && db->is_open()) {
GSentence test;
//test.make_empty();
test.get_sentence(inputBuffer);
//std::cout << "Finish scanning!\n";
std::cout << "Total elements of buffer: " << test.length()
<< "\nTotal word: " << test.wordsCount()
<< "\nTotal symbols: " << test.symbolsCount() << std::endl;
/*for (int i = 0; i < test.length(); i++) {
if (test[i].GIdentifier() == id_GListNode_GWord) {
db->getWordType(test[i].content());
}
}*/
test.printList(cout);
cout << "\n";
cout << "parsing to link parser..\n";
graParser gParser;
gParser.wordCheck(test);
}
}
}
int ListNodeTest() {
std::cout << "Testing ListNode..............\n";
std::cout << "This is a test, lol!\n";
try {
GListNode thisN("This");
GListNode is("is");
GListNode a("a");
GListNode test("test");
GListNode s1(',');
GListNode lol("lol");
GListNode punc('!');
thisN.setPtr(&is);
is.setPtr(&a);
a.setPtr(&test);
test.setPtr(&s1);
s1.setPtr(&lol);
lol.setPtr(&punc);
GListNode * currentPtr = &thisN;
while (currentPtr != 0) {
std::cout << currentPtr->content();
if (currentPtr->nextPointer() != 0)
if (currentPtr->nextPointer()->GIdentifier()
== id_GListNode_GWord)
std::cout << " ";
currentPtr = currentPtr->nextPointer();
}
std::cout << std::endl;
} catch (int) {
std::cout << "error occured.\n";
return EXIT_FAILURE;
}
std::cout << "Test for list node done. All good!\n";
return EXIT_SUCCESS;
}
int LinkedListTest() {
std::cout << "Test for linked list begin.\n";
std::cout << "This is a test, lol!\n";
try {
GLinkedList test;
test.addNode("This");
test.addNode("is");
test.addNode("a");
test.addNode("test");
test.addNode(',');
test.addNode("lol");
test.addNode('!');
test.printList(cout);
test[0].setContent("That");
test.printList(cout);
test[1];
test[2];
test[3];
test[4];
test[5];
test[6];
std::cout << "Total nodes: " << test.length() << std::endl;
std::cout << "Total words: " << test.wordsCount() << std::endl;
std::cout << "Total symbols: " << test.symbolsCount() << std::endl;
} catch (int) {
std::cout << "Error occured.\n";
return EXIT_FAILURE;
}
std::cout << "Test for linked list done. All good!\n";
return EXIT_SUCCESS;
}