-
Notifications
You must be signed in to change notification settings - Fork 1
/
Explainer.py
440 lines (397 loc) · 29.6 KB
/
Explainer.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
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
import random
import GeomTool
# auto perturbation
PERT_NUM = 1e-6
def is_float(s):
try:
float(s)
return True
except ValueError:
pass
def calculate(in_text, geom_list):
for obj in geom_list:
if obj.name + '.' in in_text or obj.name + '[' in in_text:
if obj.hasc:
if obj.type == "Point":
in_text = in_text.replace(obj.name + '.x', str(obj.c[0]))
in_text = in_text.replace(obj.name + '.y', str(obj.c[1]))
in_text = in_text.replace(obj.name + '[0]', str(obj.c[0]))
in_text = in_text.replace(obj.name + '[1]', str(obj.c[1]))
if obj.type == "Line":
in_text = in_text.replace(obj.name + '.a', str(obj.c[0]))
in_text = in_text.replace(obj.name + '.b', str(obj.c[1]))
in_text = in_text.replace(obj.name + '.c', str(obj.c[2]))
in_text = in_text.replace(obj.name + '[0]', str(obj.c[0]))
in_text = in_text.replace(obj.name + '[1]', str(obj.c[1]))
in_text = in_text.replace(obj.name + '[2]', str(obj.c[2]))
if obj.type == "Circle":
in_text = in_text.replace(obj.name + '.x', str(obj.c[0]))
in_text = in_text.replace(obj.name + '.y', str(obj.c[1]))
in_text = in_text.replace(obj.name + '.r', str(obj.c[2]))
in_text = in_text.replace(obj.name + '[0]', str(obj.c[0]))
in_text = in_text.replace(obj.name + '[1]', str(obj.c[1]))
in_text = in_text.replace(obj.name + '[2]', str(obj.c[2]))
else:
return None
try:
return eval(in_text)
except Exception:
return None
class ExplainLine:
def __init__(self, in_text, geom_list):
mode_list=["mdpt", "pt", "line", "para", "perp", "pbis", "abis", "circ"]
inword = False
informula = False
word = ''
self.wordlist = []
self.geom_list = geom_list
self.mode_list = mode_list
while len(in_text) > 0:
read_char = in_text[0]
if informula:
if read_char == '$':
informula = False
self.wordlist.append(word)
word = ''
else:
word += read_char
else:
if read_char == '$':
informula = True
else:
if read_char != ' ':
inword = True
word += read_char
if (inword and read_char == ' '):
inword = False
self.wordlist.append(word)
word = ''
in_text = in_text[1:]
self.geom_appear = []
self.mode_appear = ""
for word in self.wordlist:
for geom_num in range(len(geom_list)):
if geom_list[geom_num].name == word:
self.geom_appear.append(geom_num)
if word in mode_list:
self.mode_appear = word
def isname(self, instr):
for geom_num in range(len(self.geom_list)):
if self.geom_list[geom_num].name == instr:
return geom_num
return -1
def isnameobj(self, instr):
for geom_num in range(len(self.geom_list)):
if self.geom_list[geom_num].name == instr:
return self.geom_list[geom_num]
return None
def wordtype(self, instr):
isn = self.isname(instr)
if isn >= 0:
return self.geom_list[isn].type
if is_float(instr):
return "Number"
if is_float(str(calculate(instr, self.geom_list))):
return "Formula"
return None
def newname(self):
for word_num in range(len(self.wordlist)):
if self.wordlist[word_num] == "=" and word_num > 0:
return self.wordlist[word_num - 1]
return None
def kerneluse(self):
MethodList = list(GeomTool.MethodDict.values())
NewMethodDict = dict()
for term in MethodList:
if term[0] in NewMethodDict:
NewMethodDict[term[0]].append([term[1], term[2], term[3]])
else:
NewMethodDict[term[0]] = [[term[1], term[2], term[3]]]
mode_name = ""
word_num = -1
for word_num in range(len(self.wordlist)):
if self.wordlist[word_num] in self.mode_list:
mode_name = self.wordlist[word_num]
break
if self.wordlist[word_num] in NewMethodDict:
mode_name = self.wordlist[word_num]
break
"""
The Built in Methods!
"""
if mode_name == "line":
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Point" and self.wordtype(self.wordlist[word_num + 2]) == "Point":
return [GeomTool.MethodDict['line'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
if mode_name == "circ":
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Point" and self.wordtype(self.wordlist[word_num + 2]) == "Point":
return [GeomTool.MethodDict['circle'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
if mode_name == "pbis":
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Point" and self.wordtype(self.wordlist[word_num + 2]) == "Point":
return [GeomTool.MethodDict['perp_bis'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
if mode_name == "mdpt":
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Point" and self.wordtype(self.wordlist[word_num + 2]) == "Point":
return [GeomTool.MethodDict['mid_pt'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
if word_num == len(self.wordlist) - 2 and self.wordtype(self.wordlist[word_num + 1]) == "Circle":
return [GeomTool.MethodDict['circle_center'][1], [self.isnameobj(self.wordlist[word_num + 1])]]
if mode_name == "abis":
if word_num == len(self.wordlist) - 4 and self.wordtype(self.wordlist[word_num + 1]) == "Point" and self.wordtype(self.wordlist[word_num + 2]) == "Point" and self.wordtype(self.wordlist[word_num + 3]) == "Point":
return [GeomTool.MethodDict['angle_bis'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 3])]]
if mode_name == "pt":
if word_num == len(self.wordlist) - 1:
return [GeomTool.MethodDict['free_pt'][1], []]
if word_num == len(self.wordlist) - 2 and self.wordtype(self.wordlist[word_num + 1]) == "Line":
return [GeomTool.MethodDict['pt_on_line'][1], [self.isnameobj(self.wordlist[word_num + 1])]]
if word_num == len(self.wordlist) - 2 and self.wordtype(self.wordlist[word_num + 1]) == "Circle":
return [GeomTool.MethodDict['pt_on_circle'][1], [self.isnameobj(self.wordlist[word_num + 1])]]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Number" and self.wordtype(self.wordlist[word_num + 2]) == "Number":
return [GeomTool.MethodDict['free_pt'][1], [], float(self.wordlist[word_num + 1]) * random.gauss(1, PERT_NUM) + random.gauss(0, PERT_NUM), float(self.wordlist[word_num + 2]) * random.gauss(1, PERT_NUM) + random.gauss(0, PERT_NUM)]
if word_num == len(self.wordlist) - 4 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Number" and self.wordtype(self.wordlist[word_num + 3]) == "Number":
return [GeomTool.MethodDict['pt_on_line'][1], [self.isnameobj(self.wordlist[word_num + 1])], float(self.wordlist[word_num + 2]) * random.gauss(1, PERT_NUM) + random.gauss(0, PERT_NUM), float(self.wordlist[word_num + 3]) * random.gauss(1, PERT_NUM) + random.gauss(0, PERT_NUM)]
if word_num == len(self.wordlist) - 4 and self.wordtype(self.wordlist[word_num + 1]) == "Circle" and self.wordtype(self.wordlist[word_num + 2]) == "Number" and self.wordtype(self.wordlist[word_num + 3]) == "Number":
return [GeomTool.MethodDict['pt_on_circle'][1], [self.isnameobj(self.wordlist[word_num + 1])], float(self.wordlist[word_num + 2]) * random.gauss(1, PERT_NUM) + random.gauss(0, PERT_NUM), float(self.wordlist[word_num + 3]) * random.gauss(1, PERT_NUM) + random.gauss(0, PERT_NUM)]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Line":
return [GeomTool.MethodDict['inx_line_line'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
if word_num == len(self.wordlist) - 4 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Line" and self.wordtype(self.wordlist[word_num + 3]) == "Number":
return [GeomTool.MethodDict['inx_line_line'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
if word_num == len(self.wordlist) - 5 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Line" and self.wordtype(self.wordlist[word_num + 3]) == "Number" and self.wordtype(self.wordlist[word_num + 4]) == "Number":
return [GeomTool.MethodDict['inx_line_line'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
if word_num == len(self.wordlist) - 5 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Circle" and self.wordtype(self.wordlist[word_num + 3]) == "Number" and self.wordtype(self.wordlist[word_num + 4]) == "Number":
lineobj = self.isnameobj(self.wordlist[word_num + 1])
circobj = self.isnameobj(self.wordlist[word_num + 2])
testx = float(self.wordlist[word_num + 3])
testy = float(self.wordlist[word_num + 4])
isclose = ((testx * -lineobj.c[1] + testy * lineobj.c[0]) > (circobj.c[0] * -lineobj.c[1] + circobj.c[1] * lineobj.c[0])) ^ ((lineobj.item[0].c[0] * -lineobj.c[1] + lineobj.item[0].c[1] * lineobj.c[0]) > (lineobj.item[1].c[0] * -lineobj.c[1] + lineobj.item[1].c[1] * lineobj.c[0]))
if isclose:
return [GeomTool.MethodDict['inx_line_circle_far'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
else:
return [GeomTool.MethodDict['inx_line_circle_close'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
if word_num == len(self.wordlist) - 5 and self.wordtype(self.wordlist[word_num + 1]) == "Circle" and self.wordtype(self.wordlist[word_num + 2]) == "Line" and self.wordtype(self.wordlist[word_num + 3]) == "Number" and self.wordtype(self.wordlist[word_num + 4]) == "Number":
lineobj = self.isnameobj(self.wordlist[word_num + 2])
circobj = self.isnameobj(self.wordlist[word_num + 1])
testx = float(self.wordlist[word_num + 3])
testy = float(self.wordlist[word_num + 4])
isclose = ((testx * -lineobj.c[1] + testy * lineobj.c[0]) > (circobj.c[0] * -lineobj.c[1] + circobj.c[1] * lineobj.c[0])) ^ ((lineobj.item[0].c[0] * -lineobj.c[1] + lineobj.item[0].c[1] * lineobj.c[0]) > (lineobj.item[1].c[0] * -lineobj.c[1] + lineobj.item[1].c[1] * lineobj.c[0]))
if isclose:
return [GeomTool.MethodDict['inx_line_circle_far'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
else:
return [GeomTool.MethodDict['inx_line_circle_close'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
if word_num == len(self.wordlist) - 5 and self.wordtype(self.wordlist[word_num + 1]) == "Circle" and self.wordtype(self.wordlist[word_num + 2]) == "Circle" and self.wordtype(self.wordlist[word_num + 3]) == "Number" and self.wordtype(self.wordlist[word_num + 4]) == "Number":
circ1obj = self.isnameobj(self.wordlist[word_num + 1])
circ2obj = self.isnameobj(self.wordlist[word_num + 2])
testx = float(self.wordlist[word_num + 3])
testy = float(self.wordlist[word_num + 4])
if -testy * circ1obj.c[0] + testx * circ1obj.c[1] + testy * circ2obj.c[0] - circ1obj.c[1] * circ2obj.c[0] - testx * circ2obj.c[1] + circ1obj.c[0] * circ2obj.c[1] >= 0:
return [GeomTool.MethodDict['inx_circle_circle_pos'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
else:
return [GeomTool.MethodDict['inx_circle_circle_pos'][1], [self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 1])]]
if mode_name == "para":
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Point" and self.wordtype(self.wordlist[word_num + 2]) == "Line":
return [GeomTool.MethodDict['para_line'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Point":
return [GeomTool.MethodDict['para_line'][1], [self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 1])]]
if mode_name == "perp":
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Point" and self.wordtype(self.wordlist[word_num + 2]) == "Line":
return [GeomTool.MethodDict['perp_line'][1], [self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])]]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Point":
return [GeomTool.MethodDict['perp_line'][1], [self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 1])]]
if mode_name != "":
for usage in NewMethodDict[mode_name]:
method = usage[0]
in_item_list = usage[1]
FINISHED = True
if word_num == len(self.wordlist) - 1 - len(in_item_list):
item_list = []
for item_num in range(1, len(in_item_list) + 1):
if self.wordtype(self.wordlist[word_num + item_num]) != in_item_list[item_num - 1]:
FINISHED = False
break
item_list.append(self.isnameobj(self.wordlist[word_num + item_num]))
if FINISHED:
return [method, item_list]
return None
def descent_conditions(self):
word_num = 0
conditions = []
while word_num < len(self.wordlist):
if self.wordlist[word_num] == "eq":
conditions.append(["eq", self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])])
word_num += 3
continue
if self.wordlist[word_num] == "eqdist":
conditions.append(["eqdist", self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 3]), self.isnameobj(self.wordlist[word_num + 4])])
word_num += 5
continue
if self.wordlist[word_num] == "eqangle":
if word_num <= len(self.wordlist) - 9 and (self.wordtype(self.wordlist[word_num + 7]) == self.wordtype(self.wordlist[word_num + 8]) == "Point"):
conditions.append(["eqangle", self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 3]), self.isnameobj(self.wordlist[word_num + 4]), self.isnameobj(self.wordlist[word_num + 5]), self.isnameobj(self.wordlist[word_num + 6]), self.isnameobj(self.wordlist[word_num + 7]), self.isnameobj(self.wordlist[word_num + 8])])
word_num += 9
else:
conditions.append(["eqangle", self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 3]), self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 4]), self.isnameobj(self.wordlist[word_num + 5]), self.isnameobj(self.wordlist[word_num + 6]), self.isnameobj(self.wordlist[word_num + 5])])
word_num += 7
continue
if self.wordlist[word_num] == "simtri":
conditions.append(["simtri", self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 3]), self.isnameobj(self.wordlist[word_num + 4]), self.isnameobj(self.wordlist[word_num + 5]), self.isnameobj(self.wordlist[word_num + 6])])
word_num += 7
continue
if self.wordlist[word_num] == "col":
conditions.append(["col", self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 3])])
word_num += 4
continue
if self.wordlist[word_num] == "cyc":
conditions.append(["cyc", self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 3]), self.isnameobj(self.wordlist[word_num + 4])])
word_num += 5
continue
if self.wordlist[word_num] == "para":
conditions.append(["para", self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 3]), self.isnameobj(self.wordlist[word_num + 4])])
word_num += 5
continue
if self.wordlist[word_num] == "perp":
conditions.append(["perp", self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 3]), self.isnameobj(self.wordlist[word_num + 4])])
word_num += 5
continue
if self.wordlist[word_num] == "online":
if self.wordtype(self.wordlist[word_num + 1]) == "Point":
conditions.append(["online", self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])])
if self.wordtype(self.wordlist[word_num + 1]) == "Line":
conditions.append(["online", self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 1])])
word_num += 3
continue
if self.wordlist[word_num] == "oncirc":
if self.wordtype(self.wordlist[word_num + 1]) == "Point":
conditions.append(["oncirc", self.isnameobj(self.wordlist[word_num + 1]), self.isnameobj(self.wordlist[word_num + 2])])
if self.wordtype(self.wordlist[word_num + 1]) == "Circle":
conditions.append(["oncirc", self.isnameobj(self.wordlist[word_num + 2]), self.isnameobj(self.wordlist[word_num + 1])])
word_num += 3
continue
if self.wordtype(self.wordlist[word_num]) == "Formula":
conditions.append(["Formula", self.wordlist[word_num]])
word_num += 1
continue
word_num += 1
return conditions
def waitfor(self):
# print("Hi")
if len(self.wordlist) > 0 and self.wordlist[0] == "descent":
return ["Point", "Line", "Circle", "Done"]
MethodList = list(GeomTool.MethodDict.values())
NewMethodDict = dict()
for term in MethodList:
if term[0] in NewMethodDict:
NewMethodDict[term[0]].append([term[1], term[2], term[3]])
else:
NewMethodDict[term[0]] = [[term[1], term[2], term[3]]]
mode_name = ""
word_num = -1
for word_num in range(len(self.wordlist)):
if self.wordlist[word_num] in self.mode_list:
mode_name = self.wordlist[word_num]
break
if self.wordlist[word_num] in NewMethodDict:
mode_name = self.wordlist[word_num]
break
"""
The Built in Methods!
"""
if mode_name in ("line", "circ", "pbis"):
if word_num == len(self.wordlist) - 1:
return ["Point"]
if word_num == len(self.wordlist) - 2 and self.wordtype(self.wordlist[word_num + 1]) == "Point":
return ["Point"]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Point" and self.wordtype(self.wordlist[word_num + 2]) == "Point":
return ["Done"]
if mode_name == "mdpt":
if word_num == len(self.wordlist) - 1:
return ["Point", "Circle"]
if word_num == len(self.wordlist) - 2 and self.wordtype(self.wordlist[word_num + 1]) == "Point":
return ["Point"]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Point" and self.wordtype(self.wordlist[word_num + 2]) == "Point":
return ["Done"]
if word_num == len(self.wordlist) - 2 and self.wordtype(self.wordlist[word_num + 1]) == "Circle":
return ["Done"]
if mode_name == "abis":
if word_num == len(self.wordlist) - 1:
return ["Point"]
if word_num == len(self.wordlist) - 2 and self.wordtype(self.wordlist[word_num + 1]) == "Point":
return ["Point"]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Point" and self.wordtype(self.wordlist[word_num + 2]) == "Point":
return ["Point"]
if word_num == len(self.wordlist) - 4 and self.wordtype(self.wordlist[word_num + 1]) == "Point" and self.wordtype(self.wordlist[word_num + 2]) == "Point" and self.wordtype(self.wordlist[word_num + 3]) == "Point":
return ["Done"]
if mode_name == "pt":
if word_num == len(self.wordlist) - 1:
return ["Pt"]
if word_num == len(self.wordlist) - 2 and self.wordtype(self.wordlist[word_num + 1]) == "Number":
return ["Number"]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Number" and self.wordtype(self.wordlist[word_num + 2]) == "Number":
return ["Done"]
if word_num == len(self.wordlist) - 2 and self.wordtype(self.wordlist[word_num + 1]) == "Line":
return ["Done", "Line", "Circle", "Number"]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Number":
return ["Number"]
if word_num == len(self.wordlist) - 4 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Number" and self.wordtype(self.wordlist[word_num + 3]) == "Number":
return ["Done"]
if word_num == len(self.wordlist) - 2 and self.wordtype(self.wordlist[word_num + 1]) == "Circle":
return ["Done", "Line", "Circle", "Number"]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Circle" and self.wordtype(self.wordlist[word_num + 2]) == "Number":
return ["Number"]
if word_num == len(self.wordlist) - 4 and self.wordtype(self.wordlist[word_num + 1]) == "Circle" and self.wordtype(self.wordlist[word_num + 2]) == "Number" and self.wordtype(self.wordlist[word_num + 3]) == "Number":
return ["Done"]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Line":
return ["Done"]
if word_num == len(self.wordlist) - 4 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Line" and self.wordtype(self.wordlist[word_num + 3]) == "Number":
return ["Done"]
if word_num == len(self.wordlist) - 5 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Line" and self.wordtype(self.wordlist[word_num + 3]) == "Number" and self.wordtype(self.wordlist[word_num + 4]) == "Number":
return ["Done"]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Circle":
return ["Number"]
if word_num == len(self.wordlist) - 4 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Circle" and self.wordtype(self.wordlist[word_num + 3]) == "Number":
return ["Number"]
if word_num == len(self.wordlist) - 5 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Circle" and self.wordtype(self.wordlist[word_num + 3]) == "Number" and self.wordtype(self.wordlist[word_num + 4]) == "Number":
return ["Done"]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Circle" and self.wordtype(self.wordlist[word_num + 2]) == "Circle":
return ["Number"]
if word_num == len(self.wordlist) - 4 and self.wordtype(self.wordlist[word_num + 1]) == "Circle" and self.wordtype(self.wordlist[word_num + 2]) == "Circle" and self.wordtype(self.wordlist[word_num + 3]) == "Number":
return ["Number"]
if word_num == len(self.wordlist) - 5 and self.wordtype(self.wordlist[word_num + 1]) == "Circle" and self.wordtype(self.wordlist[word_num + 2]) == "Circle" and self.wordtype(self.wordlist[word_num + 3]) == "Number" and self.wordtype(self.wordlist[word_num + 4]) == "Number":
return ["Done"]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Circle" and self.wordtype(self.wordlist[word_num + 2]) == "Line":
return ["Number"]
if word_num == len(self.wordlist) - 4 and self.wordtype(self.wordlist[word_num + 1]) == "Circle" and self.wordtype(self.wordlist[word_num + 2]) == "Line" and self.wordtype(self.wordlist[word_num + 3]) == "Number":
return ["Number"]
if word_num == len(self.wordlist) - 5 and self.wordtype(self.wordlist[word_num + 1]) == "Circle" and self.wordtype(self.wordlist[word_num + 2]) == "Line" and self.wordtype(self.wordlist[word_num + 3]) == "Number" and self.wordtype(self.wordlist[word_num + 4]) == "Number":
return ["Done"]
if mode_name in ("para", "perp"):
if word_num == len(self.wordlist) - 1:
return ["Point", "Line"]
if word_num == len(self.wordlist) - 2 and self.wordtype(self.wordlist[word_num + 1]) == "Point":
return ["Line"]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Point" and self.wordtype(self.wordlist[word_num + 2]) == "Line":
return ["Done"]
if word_num == len(self.wordlist) - 2 and self.wordtype(self.wordlist[word_num + 1]) == "Line":
return ["Point"]
if word_num == len(self.wordlist) - 3 and self.wordtype(self.wordlist[word_num + 1]) == "Line" and self.wordtype(self.wordlist[word_num + 2]) == "Point":
return ["Done"]
if mode_name != "":
outlst = []
for usage in NewMethodDict[mode_name]:
in_item_list = usage[1]
if word_num >= len(self.wordlist) - 1 - len(in_item_list):
SUCCESS = True
for item_num in range(word_num + 1, len(self.wordlist)):
if self.wordtype(self.wordlist[item_num]) != in_item_list[item_num - word_num - 1]:
SUCCESS = False
if not SUCCESS:
continue
elif word_num == len(self.wordlist) - 1 - len(in_item_list):
outlst.append("Done")
else:
outlst.append(in_item_list[len(self.wordlist) - 1 - word_num])
else:
continue
if len(outlst) > 0:
return outlst
return ["Point", "Line", "Circle"]
if __name__ == '__main__':
a = ExplainLine('descent col p a b ', [])
print(a.wordlist)
print(a.geom_appear)