次のように、検証を Python コードに挿入したいと思います。
{`if (data.screen_name == node.screen_name) THEN {just create new relationship with new text} else {create new node with new relationship to text } `}
ソースコードにこのアルゴリズムを実装する必要があります
次のように、検証を Python コードに挿入したいと思います。
{`if (data.screen_name == node.screen_name) THEN {just create new relationship with new text} else {create new node with new relationship to text } `}
ソースコードにこのアルゴリズムを実装する必要があります
最初に.find()でノードを探します (ラベル付きの neo4j 2.x を使用すると仮定):
mynode = list(graph_db.find('mylabel', property_key='screen_name',
property_value='foo'))
somethink が見つかったかどうかを確認します。
your_target_node = # you didn't specify where your target node comes from
# node found
if len(mynode) > 0:
# you have at least 1 node with your property, add relationship
# iterate if it's possible that you have more than
# one node with your property
for the_node in mynode:
# create relationship
relationship = graph_db.create(
(the_node, "LABEL", your_target_node, {"key": "value"})
)
# no node found
else:
# create the node
the_node, = graph_db.create({"key", "value"})
# create relationship
relationship = graph_db.create(
(the_node, "LABEL", your_target_node, {"key": "value"})
)
または、get_or_create_path()を調べて、ノード ルックアップを回避します。ただし、ノードを知る必要があり、py2neo Node インスタンスとしてノードが必要です。これは、ターゲットノードを常に知っている/持っていて、開始ノードを作成したい場合に機能する可能性があります。
path = one_node_of_path.get_or_create_path(
"rel label", {"start node key": start node value},
)