-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnlpchecker.py
More file actions
executable file
·61 lines (48 loc) · 1.32 KB
/
nlpchecker.py
File metadata and controls
executable file
·61 lines (48 loc) · 1.32 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
#! /usr/bin/python3
from nlp import NLP
from queryconstruction import QueryConstruction
class NLPChecker():
#for string in queries:
#string ="Biggest and smallest project in terms of workforce"
def execute(self, string):
#print(queries.index(string))
a = NLP(string)
a.namedEntityRecognition()
a.replaceContractions()
a.lemmatize()
print("Lemmatized query:", a.lowercase_query)
a.tokenize()
a.removePunctAndStop()
a.replaceRelations()
a.replaceAttr()
a.reconstruct()
a.replaceOperators()
a.replaceSynAttr()
a.replaceSynCommon()
#print (a.lowercase_query)
a.andOr()
a.unknownAttr()
a.relationSearch()
a.negationCheck()
a.removeDuplicates()
a.cleaningSelectList()
#print(a.SELECT)
#print(a.WHERE)
#print("Unique relation ",a.unique_attribute_relation)
#print("Common relation ",a.common_attribute_relation)
b = QueryConstruction(a.SELECT, a.WHERE, a.unique_attribute_relation, a.common_attribute_relation)
b.checkJoin()
b.constructSelectPart()
check = b.constructFromPart()
if check is True:
b.constructWherePart()
#print(b.final_query)
return b.final_query
if __name__ == "__main__":
l = NLPChecker()
queries = open("testing.txt").readlines()
output = open('output.txt', 'w')
for string in queries:
q = l.execute(string)
output.write(q + '\n')
output.close()