def enter(MSG):
"""
This function takes a string (MSG) and tries to answer the query by looking through the dictionaries in the program (after some preprocessing).
It tries to mine out the correct response by performing pattern matching through the structured data
"""
msg=MSG.lower()
if msg[-1]=='?':
msg=msg[:-1]
tokens=nltk.word_tokenize(msg)
for i in words:
while (i in tokens):
tokens.remove(i)
lst=[]
flag=0
if tokens[0]=="who":
lst=data_who
elif tokens[0]=="what":
lst=data_what
elif tokens[0]=='how':
lst=data_how
#msg=str(tokens)
msg=' '.join(tokens[1:])
for i in lst:
if fuzz.token_set_ratio(i[0],msg)>=60:
print i[1]
flag=1
break
if flag==0:
print "Question Not found"
FuzzyWuzzy_1.py 文件源码
python
阅读 17
收藏 0
点赞 0
评论 0
评论列表
文章目录