格式化Neo4J-Shell cypher查询结果?

时间:2013-06-07 12:11:19

标签: shell neo4j cypher export-to-csv

是否可以选择以逗号分隔值格式导出Neo4J-Shell cypher查询的结果,即代替

echo "START n=node(*)  MATCH n-[r]->m  RETURN n.value, type(r), m.value  ORDER BY n.value, type(r), m.value;"  |  neo4j-shell -v  -path neo4j-database/   >  /tmp/output.csv

less  /tmp/output.csv
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| n.value                                                 | type(r)                                           | m.value                                                       |
+-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| "http://www.co-ode.org/ontologies/pizza/pizza.owl#Rosa" | "http://www.w3.org/1999/02/22-rdf-syntax-ns#type" | "http://www.w3.org/2002/07/owl#Class"                         |
| "http://www.co-ode.org/ontologies/pizza/pizza.owl#Rosa" | "http://www.w3.org/2000/01/rdf-schema#label"      | "Rosa"                                                        |
| "http://www.co-ode.org/ontologies/pizza/pizza.owl#Rosa" | "http://www.w3.org/2000/01/rdf-schema#subClassOf" | "http://www.co-ode.org/ontologies/pizza/pizza.owl#NamedPizza" |
...

我想获得以下输出

less  /tmp/output.csv

"http://www.co-ode.org/ontologies/pizza/pizza.owl#Rosa", "http://www.w3.org/1999/02/22-rdf-syntax-ns#type", "http://www.w3.org/2002/07/owl#Class"                        
"http://www.co-ode.org/ontologies/pizza/pizza.owl#Rosa", "http://www.w3.org/2000/01/rdf-schema#label", "Rosa"                                                        
"http://www.co-ode.org/ontologies/pizza/pizza.owl#Rosa", "http://www.w3.org/2000/01/rdf-schema#subClassOf", "http://www.co-ode.org/ontologies/pizza/pizza.owl#NamedPizza" 
...

就像MySQL一样,当shell的echo命令使用客户端时,ascii表被省略。

1 个答案:

答案 0 :(得分:2)

  1. 您可以使用neo4j-JDBC通过JDBC运行您的密码查询。有了它,您可以使用任何允许您创建csv的JBCD工具。
  2. 使用https://gist.github.com/5736410
  3. 中的groovy脚本