forked from reidaruss/cs3342_09
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
150 lines (128 loc) · 3.36 KB
/
main.cpp
File metadata and controls
150 lines (128 loc) · 3.36 KB
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
/*
Please include a text file that has one sentence per line.
Input the number of lines you want to test and this program will return whether or not those lines are valid within the grammar
*/
#include <iostream>
#include <string>
#include <fstream>
#include <istream>
#include <map>
using namespace std;
bool article(string theArticle) {
map < string, bool > article;
article.insert(std::pair < string, bool > ("The", true));
if (article[theArticle]) {
return true;
} else {
return false;
}
}
string nextWord(string temp) {
string word = "";
int i = 0;
while (i < temp.length() && (temp[i] != ' ')) {
word += temp[i];
i++;
}
return word;
}
string checker(string temp) {
map < string, bool > article;
article.insert(std::pair < string, bool > ("The", true));
map < string, bool > adjs;
adjs.insert(std::pair < string, bool > ("lazy", true));
adjs.insert(std::pair < string, bool > ("smelly", true));
map < string, bool > nouns;
nouns.insert(std::pair < string, bool > ("dog", true));
nouns.insert(std::pair < string, bool > ("cat", true));
map < string, bool > verbs;
verbs.insert(std::pair < string, bool > ("ate", true));
verbs.insert(std::pair < string, bool > ("ran", true));
map < string, bool > adverbs;
adverbs.insert(std::pair < string, bool > ("slowly", true));
adverbs.insert(std::pair < string, bool > ("noisily", true));
map < string, bool > period;
period.insert(std::pair < string, bool > (".", true));
map < string, bool > eoi;
eoi.insert(std::pair < string, bool > ("EOI", true));
bool keepGoing = true;
string word = "";
word = nextWord(temp);
temp = temp.substr(word.length());
if(temp[0] == ' ')
{
temp = temp.substr(1);
}
if(!(article[word]))
{
return "Article Invalid Sentence";
}
word = nextWord(temp);
temp = temp.substr(word.length());
if(temp[0] == ' ')
{
temp = temp.substr(1);
}
while(adjs[word])
{
word = nextWord(temp);
temp = temp.substr(word.length());
if(temp[0] == ' ')
{
temp = temp.substr(1);
}
}
if(!(nouns[word]))
{
return "Noun Invalid Sentence";
}
word = nextWord(temp);
temp = temp.substr(word.length());
if(temp[0] == ' ')
{
temp = temp.substr(1);
}
if(!(verbs[word]))
{
return "Verbs Invalid Sentence";
}
word = nextWord(temp);
temp = temp.substr(word.length());
if(temp[0] == ' ')
{
temp = temp.substr(1);
}
if((adverbs[word]))
{
word = nextWord(temp);
temp = temp.substr(word.length());
}
if(temp[0] == ' ')
{
temp = temp.substr(1);
}
if(!(period[word]))
{
return "Period Invalid Sentence";
}
word = nextWord(temp);
temp = temp.substr(word.length());
if(!(eoi[word]))
{
return "EOI Invalid Sentence";
}
return "Valid Sentence";
}
int main() {
ifstream inFile("examples.txt");
string sentence = "";
string temp = "1";
cout << "Please enter how many lines you are testing: ";
int testing;
cin >> testing;
for(int i = 0; i < testing; i++)
{
getline(inFile, temp);
cout << checker(temp) << endl;
}
}