-
Notifications
You must be signed in to change notification settings - Fork 0
/
Interrogative.py
executable file
·226 lines (168 loc) · 5.19 KB
/
Interrogative.py
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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
""" CHECK IF A SENTENCE IS IN INTERROGATIVE FORM """
import os
from misc import files
def Write(folderName, fileName, text, openType):
'''Writes some text to a file on a folder'''
d = os.getcwd()
file_to_Open = os.path.join(d, folderName, fileName)
f = open(file_to_Open, openType)
f.writelines(text)
f.close()
def Open(folderName, fileName):
'''Opens a specific file from a different directory'''
d = os.getcwd()
# data_folder = os.path.join(d, folderName)
file_to_Open = os.path.join(d, folderName, fileName)
return file_to_Open
class Interrogative():
isTobeS = False
isToHaveS = False
isNoHelpVerbS = False
isWhS = False
tbVerbs = ["am", "is", 'are', 'was', 'were']
TVerbs = [line.strip() for line in open(files().open_file('wordNet','verb.exc'))]
Verbs = [words.split() for a, words in enumerate(TVerbs)]
VerbsA = list()
VerbsB = list()
Sub = ["he", "she", "you", "they", "that", "I"]
Ext = list()
for a, b in enumerate(Verbs):
VerbsA.append(b[0])
VerbsB.append(b[1])
def is_tobe_sentance(self, sentence):
"""
Verb + sub + Extention + ?\n
Example: Are you okay?
"""
s = sentence
verb = str()
sub = str()
ext = ()
a = bool()
b = bool()
c = bool()
for verbs in self.tbVerbs:
if s.startswith(verbs):
verb = verbs
sub = s.replace(verbs, "")
a = True
break
else:
a = False
for subs in self.Sub:
if subs in s:
sub = subs
b = True
break
else:
b = False
ext = s.replace(verb, "")
ext = ext.replace(sub, "")
ext = ext[ext.index(" "):]
for verbs in self.VerbsA:
if verbs in ext:
c = False
break
else:
c = True
if a and b and c:
self.isTobeS = True
else:
self.isTobeS = False
return verb, sub, ext
def is_tohave_sentance(self, sentence):
"""
Do/does/did + subject + have + Ext + ?\n
Example: Do you have a car?
"""
s = sentence
sub = str()
ext = str()
d = ["do", "did", "does"]
hV = str()
a = bool()
b = bool()
for verbs in d:
if s.startswith(verbs):
sub = s[s.index(" "): s.index(" ", s.index(" ") + 1)]
a = True
hV = verbs
if "have" in s:
ext = s[s.index(" ", s.index("have")): ]
b = True
if ext.startswith(" "):
ext.replace(" ", "")
else:
ext = ext
else:
b = False
break
else:
a = False
if a and b:
self.isToHaveS = True
else:
self.isToHaveS = False
return hV, sub, ext
def is_no_helping_verb_sentance(self, sentence):
"""
Do/Did/Does + subject + verb + Ext + ?\n
Example: Do you like to play games?
"""
s = sentence
sub = str()
ts = str()
a = bool()
b = bool()
c = bool()
d = ["do", "did", "does"]
hV = str()
for words in d:
if s.startswith(words):
hV = words
a = True
st = s[s.index(" ") + 1: s.index(" ", s.index(" ") + 1)]
for subs in self.Sub:
if subs == st:
sub = subs
b = True
break
else:
b = False
break
else:
a = False
ts = s[s.index(sub, s.index(" ")):]
if ts.startswith(sub):
ts = ts[ts.index(" ") + 1 :]
for v in self.tbVerbs:
if v not in ts:
c = True
ext = ts
else:
c = False
if a and b and c and not self.isToHaveS:
self.isNoHelpVerbS = True
else:
self.isNoHelpVerbS = False
return hV, sub, ext
def is_wh_sentance(self, sentence):
"""
who, which, whom, when, why, what, where, whoes, how + verb + sentnce\n
Example: Who did this?
"""
s = sentence
ext = str()
verb = str()
q = str()
wh_Q = ["who", "which", "whom", "why", "what", 'where', 'whoes', 'how']
for qs in wh_Q:
if s.startswith(qs):
self.isWhS = True
q = qs
verb = s[s.index(" ") + 1: s.index(" ", s.index(" ") + 1)]
ext = s[s.index(verb) + len(verb) + 1: ]
break
else:
self.isWhS = False
return q, verb, ext