我想找到应该链接到给定节点的节点,其中链接由一些逻辑定义,该逻辑使用节点和现有边的属性,逻辑如下:
A)(该对具有相同的 zip(节点属性)和 name_similarity(边缘属性)> 0.3 或
B) 该对具有不同的 zip 并且 name_similarity > 0.5 或
C)该对具有边缘类型“external_info”,值为“connect”)
D)AND(该对没有带有“external info”的边缘类型,值为“disconnect”)
简而言之:(A | B | C) & (~D)
我仍然是 gremlin 的新手,所以我不确定如何在边和节点上组合多个条件。
以下是创建图表的代码,以及该图表的预期结果:
# creating nodes
(g.addV('person').property('name', 'A').property('zip', '123').
addV('person').property('name', 'B').property('zip', '123').
addV('person').property('name', 'C').property('zip', '456').
addV('person').property('name', 'D').property('zip', '456').
addV('person').property('name', 'E').property('zip', '123').
addV('person').property('name', 'F').property('zip', '999').iterate())
node1 = g.V().has('name', 'A').next()
node2 = g.V().has('name', 'B').next()
node3 = g.V().has('name', 'C').next()
node4 = g.V().has('name', 'D').next()
node5 = g.V().has('name', 'E').next()
node6 = g.V().has('name', 'F').next()
# creating name similarity edges
g.V(node1).addE('name_similarity').from_(node1).to(node2).property('score', 1).next() # over threshold
g.V(node1).addE('name_similarity').from_(node1).to(node3).property('score', 0.2).next() # under threshold
g.V(node1).addE('name_similarity').from_(node1).to(node4).property('score', 0.4).next() # over threshold
g.V(node1).addE('name_similarity').from_(node1).to(node5).property('score', 1).next() # over threshold
g.V(node1).addE('name_similarity').from_(node1).to(node6).property('score', 0).next() # under threshold
# creating external output edges
g.V(node1).addE('external_info').from_(node1).to(node5).property('decision', 'connect').next()
g.V(node1).addE('external_info').from_(node1).to(node6).property('decision', 'disconnect').next()
输入节点 A 的预期输出是节点 B(由于条件 A)、D(由于条件 B)和 F(由于条件 C)。由于条件 D,节点 E 不应链接。
我正在寻找将检索这些结果的 Gremlin 查询。