#remove the comment to download all assets
#nltk.download('averaged_perceptron_tagger')
import nltk
import wikipedia as wiki
from nltk.tokenize import word_tokenize
def start():
takeCommand()
def takeCommand():
#the script for the user input
user_input = input('Ask me something ')
#the script for the NLP system
NLP_command_POS = nltk.pos_tag(word_tokenize(user_input[0:50]))
#looks if you write what, who, how or where and if you do, it calls the weikipedia function
for i in range(0, len(NLP_command_POS)):
if (NLP_command_POS[i][1] == 'WLB' or NLP_command_POS[i][1] == 'WP'):
wikipediaSearch(user_input)
def wikipediaSearch(user_input):
global result
user_input = user_input
#NLP system
NLP_sample_POS = nltk.pos_tag(word_tokenize(user_input[0:50]))
#looks if you write a name or a thing, like computer or John
#HERE IS THE CODE I NEED HELP WITH
for i in range(0, len(NLP_sample_POS)):
if NLP_sample_POS[i][1] == 'NN' or NLP_sample_POS[i][1] == 'NNP':
try:
result = NLP_sample_POS[i][0]
print(result)
except Exception:
print('I dont know anything about {}'.format(result))
#calls the start function
start()
评论
请
登录后发表观点
- 积分
0 - 话题
0 - 评论
3194 - 注册排名
2346