csv文件数据直接导入neo4j构建知识图谱

from py2neo import Node, Relationship, PropertyDict, Graph
import csv

g = Graph("", username="neo4j", password="neo4j123")
with open(r'', 'r', encoding='gbk') as r:
    reader = csv.reader(r)
    for item in reader:
        if reader.line_num == 1:
            continue
        node = Node("jd", name=item[0], lat_lng=item[1], desc=item[2])
        g.merge(node, "jd", "name")
from py2neo import Node, Relationship, Graph
import csv

g = Graph("xxx", username="neo4j", password="neo4j123")
with open(r'xxx', 'r', encoding='utf-8') as r:
    reader = csv.reader(r)
    for item in reader:
        # print(item)
        start_node = Node("Person", name=item[0])
        end_node = Node("Person", name=item[1])
        Relation = Relationship(start_node, item[2], end_node)
        g.merge(start_node, "Person", "name")
        g.merge(end_node, "Person", "name")
        g.merge(Relation, "Person", "name")

你可能感兴趣的:(知识图谱,人工智能)