赞
踩
目录
我只是一个小垃圾,毕业之后的工作范围就变成这样子,图像算法-->语音识别-->NLP,啥都要看一点,啥都不精通,啥都不会,emo了,23岁为什么要承受这么多,呜呜呜。
NLTK
,全称Natural Language Toolkit
,自然语言处理工具包,是NLP研究领域常用的一个Python
库。
不整理了,看这个博主姐姐的,详细的嘞。自然语言处理库——NLTK_满腹的小不甘_静静的博客-CSDN博客
运行地址:jupyter notebook
- import random
- import nltk
- nltk.download('punkt')
- from nltk import word_tokenize
-
- # 打招呼用词
- greetings = ['hola', 'hello', 'hi', 'Hi', 'hey!','hey']
- # 回复打招呼
- random_greeting = random.choice(greetings)
-
- #对于假期的话题关键词
- question = ['break','holiday','vacation','weekend']
- #针对假期话题的回答
- responses = ['It was nice',"I went to Paris","Sadly,I just stay at home"]
- # 回复假期话题
- random_responses = random.choice(responses)
-
- # 机器人跑起来
- while True:
- userInput = input(">>> ")
- #清理一下输入
- cleaned_input = word_tokenize(userInput)
- #对比一下关键词,看看具体属于哪个问题
- if not set (cleaned_input).isdisjoint(greetings):
- print(random_greeting)
- elif not set (cleaned_input).isdisjoint(question):
- print(random_responses)
- # 除非你说“拜拜”
- elif userInput == 'bye':
- break
- else:
- print("I did not understand what you said")
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。