-
Notifications
You must be signed in to change notification settings - Fork 2
/
execute.py
49 lines (38 loc) · 1.22 KB
/
execute.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
from py2neo import Graph
import pandas as pd
e = ""
graph = Graph("http://18.215.249.105:7474", username="neo4j", password="i-0264fccb248189ea5")
def getQueryForIntent(intent, entity):
d = pd.read_excel("QA.xlsx", sheetname='Intent-Query')
query = list(d[d["Intent"] == intent]["Query"])[0].replace("entity_name", entity)
return query
def runQueryAndGetResult(query):
results= graph.run(query).to_data_frame()
# print(len(results))
# print(results)
answer=[]
for i in range(0 , min(5, len(results))):
answer.append(results["x"][i]["name"])
return answer
def printAnswer(results , intent):
a = intent.split("_")[0]
q = intent.split("_")[1] + "s"
ans = (", ").join(results)
print("Some " , q , " for " , a , e, " are " , ans )
def executeQuery(intent , entity):
done = False
for x in entity:
query = getQueryForIntent(intent , x)
# print(query)
results=runQueryAndGetResult(query)
# print(x ,results)
if(len(results)!=0):
global e
e = x
done = True
printAnswer(results , intent)
break
if(not done):
print("Sorry i dont really have the answer to that!" )
if __name__ == '__main__':
executeQuery("disease_symptom" , ["cardiac arrest" , "thyroid"])