Y05 - 008、人工智能小程序:和计算机对话

初学耗时:0.5h

注:CSDN手机端暂不支持章节内链跳转,但外链可用,更好体验还请上电脑端。

一、人工智能小程序:和计算机对话



记忆词:

  ...

Y05 - 999、Python - 风变编程


ギ 舒适区ゾ || ♂ 累觉无爱 ♀





一、人工智能小程序:和计算机对话

  • 真正地运行一个人工智能小程序,和计算机进行“对话”。
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': '名词性语素',
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值