美文网首页
KG知识图谱 学习 Part4 - 知识图谱应用

KG知识图谱 学习 Part4 - 知识图谱应用

作者: 遇见Miu | 来源:发表于2020-05-14 22:05 被阅读0次

四、知识图谱应用

📜主要是如何使用知识图谱和Python结合
😅由于和同事学习完毕初步评估各个方面,知识图谱在我们的业务场景可能是大材小用,而且实际场景很少,所以这次学习就当是一次知识的扩展和积累吧~


1.第一个智能聊天机器人

如何将智能问答机器人与知识图谱结合起来

构建一个英文聊天机器人

使用python-aiml来进行

# -* coding: utf-8 -*-

import aiml
import sys
import os

def get_module_dir(name):
    path = getattr(sys.modules[name], '__file__', None)
    if not path:
        raise AttributeError('module %s has not attribute __file__' %name)
    return os.path.dirname(os.path.abspath(path))

alice_path = get_module_dir('aiml') + '/botdata/alice'

# 切换到语料库所在工作目录
os.chdir(alice_path)
alice = aiml.Kernel()
alice.learn("startup.xml")
alice.respond('load alice')

while True:
    print(alice.respond(input("Enter your message >>")))

可以进行简单的对话

2.Python与Neo4j的集成

1.pip直接安装Neo4j

pip3 install py2neo

2.连接并操作Neo4j

# -*- coding: utf-8 -*-

from py2neo import Graph, Node, Relationship

test_graph = Graph(
    "http://localhost:7474",
    # 默认用户是neo4j
    username="neo4j",
    # 自己修改的后的密码111
    password="111"
)

test_graph.delete_all()

# 创建节点
zgr = Node("歌手", label="singer", name="张国荣")
zhm = Node("歌手", label="singer", name="张惠妹")
test_graph.create(zgr)
test_graph.create(zhm)
  • 执行代码前

  • 执行代码后

相关文章

网友评论

      本文标题:KG知识图谱 学习 Part4 - 知识图谱应用

      本文链接:https://www.haomeiwen.com/subject/lhlxohtx.html