简体   繁体   English

图形算法能否在Neo4J中采用节点和关系的属性?

[英]Can graph algorithms take nodes' and relationships' properties in Neo4J?

I'm starting to use Graph Algorithms plugin of Neo4J (3.3.x) and wanted to ask if the plugin can take in the properties of the nodes/relationships, so that I could add in a request like this: 我开始使用Neo4J(3.3.x)的Graph Algorithms插件,并想问一下该插件是否可以接受节点/关系的属性,以便可以添加如下请求:

CALL algo.pageRank.stream('Page', 'LINKS', {iterations:20, dampingFactor:0.85})
YIELD node, score
RETURN node,score order by score desc limit 20

Some properties of the Nodes labeled Page (eg only the ones with timestamp > certain_date) or only the LINKS which have a specific property x. 标记为Page的节点的某些属性(例如,只有时间戳> sure_date_date的那些节点)或具有特定属性x的LINKS的某些属性。

Or then if it's not possible, shall I use Cypher projection and simply make a Cypher query inside the pageRank algorithm? 还是如果不可能,我是否应该使用Cypher投影并在pageRank算法内简单地进行Cypher查询?

You can use Cypher projection to be more selective about which nodes and relationships to process with an graph algorithm. 您可以使用Cypher投影来更灵活地选择要使用图算法处理的节点和关系。

For example, to execute the algo.pageRank algorithm only on Page nodes whose timestamp > 1000 , and LINKS relationships that have a specific property x , this should work: 例如,要仅在timestamp > 1000 Page节点以及具有特定属性x LINKS关系上执行algo.pageRank算法,这应该可以工作:

MERGE (dummy:Dummy)
WITH dummy, ID(dummy) AS dummy_id
CALL algo.pageRank.stream(
  'OPTIONAL MATCH (p:Page) WHERE p.timestamp > 1000 RETURN CASE WHEN p IS NOT NULL THEN ID(p) ELSE ' + dummy_id + ' END AS id',
  'OPTIONAL MATCH (p1:Page)-[link:LINKS]->(p2:Page) WHERE EXISTS(link.x) WITH CASE WHEN link IS NOT NULL THEN [ID(p1), ID(p2)] ELSE [' + dummy_id + ',' + dummy_id + '] END AS res RETURN res[0] AS source, res[1] as target',
  {graph:'cypher', iterations:20, dampingFactor:0.85})
YIELD node, score
WITH dummy, node, score
WHERE node <> dummy
RETURN node, score ORDER BY score DESC LIMIT 20;

NOTE: The graph algorithms are currently badly behaved (ie, they throw exceptions) when either of the Cypher statements used in a Cypher projection return no results. 注意:当在Cypher投影中使用的任何Cypher语句均未返回结果时,图形算法当前表现不佳(即,它们引发异常)。 The above query works around that by making sure that both statements return a dummy node instead of returning nothing. 上面的查询通过确保两个语句都返回一个虚拟节点而不是不返回任何内容来解决此问题。 The Cypher statement that "wraps" the algorithm call will then filter out the dummy node if it is returned by the algorithm. 如果算法返回了“环绕”算法调用的Cypher语句,则将过滤掉该哑节点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM