随着标签的引入,neo4j 获得了管理实体的简洁机制。现在,让我们假设我们有一个包含许多不同实体的通用图,并且想要找出哪些实体(标签)相互关联。这是一个起点: http ://console-test.neo4j.org/?id=wdnbuj
Graph Setup:
CYPHER 2.0
create
(_1:Crew {name:"Neo"}),
(_2:Crew {name:"Morpheus"}),
(_3:Crew {name:"Trinity"}),
(_4:Language {name:"Cypher"}),
(_5:Machines {name:"Agent Smith"}),
(_6:Machines {name:"The Architect"}),
_1-[:KNOWS]->_2,
_1-[:LOVES]->_3,
_2-[:KNOWS]->_3,
_2-[:KNOWS]->_4,
_4-[:KNOWS]->_5,
_5-[:CODED_BY]->_6
Query:
CYPHER 2.0
match x-[r]->y
return head(labels(x)) as head, type(r), head(labels(y)) as tail
这将使我们对彼此相关的实体有一个概述:
+--------------------------------------+
| head | type(r) | tail |
+--------------------------------------+
| "Machines" | "CODED_BY" | "Machines" |
| "Language" | "KNOWS" | "Machines" |
| "Crew" | "KNOWS" | "Crew" |
| "Crew" | "KNOWS" | "Language" |
| "Crew" | "KNOWS" | "Crew" |
| "Crew" | "LOVES" | "Crew" |
+--------------------------------------+
现在。是否有任何 Cypher 查询可以为这些三元组返回不同的值?
额外的问题:我们可以得到它们的计数/频率吗?