简体   繁体   English

neo4j密文作为图形重构

[英]neo4j cypher text as a graph refactoring

We have a graph-db with text as a graph. 我们有一个图数据库,其中文本作为图。 In the system the pagebreaks are expressed with (pb)-nodes. 在系统中,分页符用(pb)-节点表示。 Now i want to modell the pages with (page) nodes which point to the begin and the end of the page. 现在,我想用(页面)节点指向页面的开头和结尾来对页面进行建模。

Example of text in a graph with w-nodes for the words (the n-property is incremental): 带有单词的w节点的图形中的文本示例(n属性为增量式):

(pb {n:1})-[:NEXT]->(w)-[:NEXT]->(w)-[:NEXT]->(w)-[:NEXT]->
(w)-[:NEXT]->(pb {n:2})-[:NEXT]->(w)-[:NEXT]->(w)-[:NEXT]->
(w)-[:NEXT]->(w)-[:NEXT]->(pb {n:3})-[:NEXT]->(w)-[:NEXT]->
(w)-[:NEXT]->(pb {n:4})

The result should add these nodes an edges: 结果应为这些节点添加一条边:

(pb {n:1})-[:FIRST_CHILD-OF]->(Page)<-[:FIRST_CHILD-OF]->(pb {n:2})
(pb {n:2})-[:FIRST_CHILD-OF]->(Page)<-[:FIRST_CHILD-OF]->(pb {n:3})
(pb {n:3})-[:FIRST_CHILD-OF]->(Page)<-[:FIRST_CHILD-OF]->(pb {n:4})

Any help would be great. 任何帮助都会很棒。

Here is the answer i have found (using informations from here: How to find a path in cypher the ungreedy way ) 这是我找到的答案(使用来自这里的信息: 如何以不友好的方式在cypher中找到路径

// Find pb tags
MATCH (t1:pb})
WITH collect(t1) AS tags

// create unique pairs
UNWIND tags AS x UNWIND tags AS y    
WITH x, y WHERE ID(x) < ID(y)
AND y.n = x.n+1

// create nodes and edges
CREATE (p:Page)
MERGE (y)<-[:FIRST_CHILD_OF]-(p)-[:LAST_CHILD_OF]->(x)
RETURN *;

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

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