【发布时间】:2015-01-20 17:30:00
【问题描述】:
我有以下 python 代码在 neo4j 中制作图表。我使用的是 py2neo 2.0.3 版。
import json
from py2neo import neo4j, Node, Relationship, Graph
graph = neo4j.Graph("http://localhost:7474/db/data/")
with open("example.json") as f:
for line in f:
while True:
try:
file = json.loads(line)
break
except ValueError:
# Not yet a complete JSON value
line += next(f)
# Now creating the node and relationships
news, = graph.create(Node("Mainstream_News", id=unicode(file["_id"]), entry_url=unicode(file["entry_url"]),
title=unicode(file["title"]))) # Comma unpacks length-1 tuple.
authors, = graph.create(
Node("Authors", auth_name=unicode(file["auth_name"]), auth_url=unicode(file["auth_url"]),
auth_eml=unicode(file["auth_eml"])))
graph.create(Relationship(news, "hasAuthor", authors ))
我可以创建一个图表,其中包含节点 Mainstream_News 和 Authors 以及关系“hasAuthor”。我的问题是,当我这样做时,我有一个 Mainstream_News 节点和一个作者,但实际上一个作者节点有多个 Mainstream_News。我想将 Author 节点的 auth_name 属性作为连接 Mainstream_news 节点的索引。任何建议都会很棒。
【问题讨论】: