初学耗时:0.5h
注:CSDN手机端暂不支持章节内链跳转,但外链可用,更好体验还请上电脑端。
记忆词:
...
一、人工智能小程序:和计算机对话
- 真正地运行一个人工智能小程序,和计算机进行“对话”。
import requests, json, time, random
word = input('''你好,我是你的私人助理吴小枫。你可以在下方任意输入一个名词,然后敲击“Enter”键,我将会帮你自动联想它有什么相关的词汇!
注:如果你要删除自己输入的内容,要按两次删除,才可以删掉一个汉字奥!(因为在计算机世界里,中文是占两个字符的!)
下面请输入(示例:牛肉、水果、飞机、手机……),然后敲“Enter”:
>''')
word=word+'有哪些相关词汇?'
feature_text = '''
我们可以先聊点别的,我还有什么可以帮助你的吗?
输入你的问题,然后敲Enter键!
>'''
url1 = 'http://ictclas.nlpir.org/nlpir/index/getAllContentNew.do'
data1 = {
'type': 'all', 'content': word}
try:
r1 = requests.post(url1, data1, timeout=3)
dividewords = json.loads(r1.text)['dividewords']
dividewords = dividewords.split(' ')
newwords = []
cixing = []
for x in dividewords:
if x == dividewords[-1]:
continue
else:
singleword = x.split('/')
newwords.append(singleword[0])
cixing.append(singleword[1])
newlist = '/'.join(newwords)
dict = {
'n': '名词', 'nr': '人名', 'nr1': '汉语姓氏', 'nr2': '汉语名字', 'nrj': '日语人名', 'nrf': '音译人名', 'ns': '地名',
'nsf': '音译地名', 'nt': '机构团体名', 'nz': '其它专名', 'nl': '名词性惯用语', 'ng': '名词性语素',