Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/neo4j/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用返回的数据来操作字符串,而不是在Neo4j中返回_Neo4j_Cypher - Fatal编程技术网

使用返回的数据来操作字符串,而不是在Neo4j中返回

使用返回的数据来操作字符串,而不是在Neo4j中返回,neo4j,cypher,Neo4j,Cypher,数据采用以下格式 {"domain":"sdcastroverde.com","cat_labels_in":"Top/World/Galego/regional/Galicia/Lugo/municipalities/Castroverde"} 当我运行密码查询时 MATCH (n:Dmoz) return split(n.cat_labels_in,'/') as data limit 10 我得到了答案 ["Top","World","Galego","regional","Gali

数据采用以下格式

{"domain":"sdcastroverde.com","cat_labels_in":"Top/World/Galego/regional/Galicia/Lugo/municipalities/Castroverde"} 
当我运行密码查询时

MATCH (n:Dmoz)
return split(n.cat_labels_in,'/') as data limit 10
我得到了答案

["Top","World","Galego","regional","Galicia","Lugo","municipalities","Castroverde"]
我不想返回数据,我想对其使用UNWIND,这样我就可以将“Tags”作为(:Tags{name:“Tag”})写入数据库,并以以下方式添加关系

(:Domain{name:"somedomain.com"})-[LINKS_TO]->((:Tags{name:"Tag"})) #first tag
(:Tags{name:"Tag"})-[LINKS_TO]->((:Tags{name:"Tag"})) #first tag to second tag and so on
(:Tags{name:"Tag"})-[LINKS_TO]->((:Domain{name:"anotherdomain.com"}))

类似于此但不是来自CSV文件的内容。

您正在寻找类似于此的内容吗

// start with the sample data
WITH {domain:"sdcastroverde.com",cat_labels_in:"Top/World/Galego/regional/Galicia/Lugo/municipalities/Castroverde"} as node

// split the labels into tags
WITH node, split(node.cat_labels_in,'/') as tags 

// unwind the tags and make the chain of tags
UNWIND range(0, size(tags)-2) as i
  MERGE (a:Tags {name: tags[i] })
  MERGE (b:Tags {name: tags[i+1] })
  MERGE (a)-[:LINKS_TO]->(b)

// prepend the tag chain with the starting domain 
WITH node, tags
MATCH (a:Tags {name: tags[0]})
MERGE (:Domain{name:"somedomain.com"})-[:LINKS_TO]->(a)

// append the tag chain with the next domain
WITH node, tags
MATCH (a:Tags {name: tags[size(tags)-1]} )
MERGE (a)-[:LINKS_TO]->(:Domain {name:"anotherdomain.com"} )
每个后续问题的第二个解决方案。这里使用混合分隔符的关键是首先使用混合分隔符从字符串中生成单个集合,然后像以前一样继续

//Start with some test data
WITH {domain:"sdcastroverde.com",cat_labels_in:"Top/World/Galego|Test/regional/Galicia|Test/Lugo/municipalities/Castroverde"} as node

// split up the list on forward slash
UNWIND split(node.cat_labels_in,'/') as tags

    // for each item in the first collection attempt to split on |
    UNWIND split(tags,'|') as tag

// recombine the split nodes into a single collection
WITH node, collect(tag) as tags

// then carry on as before in the above solution
UNWIND range(0, size(tags)-2) as i
    MERGE (a:Tags {name: tags[i] })
    MERGE (b:Tags {name: tags[i+1] })
    MERGE (a)-[:LINKS_TO]->(b)
WITH node, tags
MATCH (a:Tags {name: tags[0]})
MERGE (:Domain{name:"somedomain.com"})-[:LINKS_TO]->(a)
WITH node, tags
MATCH (a:Tags {name: tags[size(tags)-1]} )
MERGE (a)-[:LINKS_TO]->(:Domain {name:"anotherdomain.com"} )

排序!!谢谢你,戴夫。我想对此做一个补充,使用MATCH获取初始数据,因此我现在就开始使用CYPHER查询。匹配(n:Dmoz)和n,拆分(n.cat_labels_in,“/”)作为标记返回标记限制10该查询像一个符咒一样工作,但是我有另一个问题。一些数据有多个标记链,用竖条(|)分隔,例如{domain:“sdcastroverde.com”,cat_labels_in:“Top/World/Galego | Top/World/Somethingelse |”}我如何可能展开两次,以及如何检查行是否有多个标签?@chandan-添加了第二个解决方案,该解决方案首先从混合分隔符字符串中构建单个集合感谢您的回答,然而,第二个解决方案有一个问题,我实际上在寻找的是单独的标记路径Top/World/Galego | Test/regional/Galicia | Test/Lugo/circipes/Castroverde应该变成somedomain.com->Top->World->Galego->anotherdomain.com somedomain.com->Test->regional->Galicia->anotherdomain.comsomedomain.com->Test->Lugo->Communications->Castroverde->anotherdomain.com在解决方案中路径被保存为somedomain->Top->World->Galego->Test Test->Regional->Galcia->Test->Lugo->Communications->Castroverde->anotherdomain.com我现在明白你想要什么了。今天早上晚些时候我或许可以做点什么。