4

随着标签的引入,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 查询可以为这些三元组返回不同的值?

额外的问题:我们可以得到它们的计数/频率吗?

4

1 回答 1

2

我刚刚使用了您的起始查询,添加了 distinct 和 count。那是你要找的吗?或者您是否希望我从标签集合中拆分标签(如果没有某种展开功能,这并不容易)。

match x-[r]->y 
return distinct head(labels(x)) as head, type(r), head(labels(y)) as tail

match x-[r]->y 
return head(labels(x)) as head, type(r), head(labels(y)) as tail, count(*)
于 2013-05-17T11:33:57.787 回答