以下GRAPHSON格式不起作用

编程入门 行业动态 更新时间:2024-10-11 19:25:01
本文介绍了以下GRAPHSON格式不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试将以下graphSon格式转换为图形实例 使用以下命令

graph.io(IoCore.graphson()).reader().create().readGraph(stream, graph);

但是在运行时将GRaphSON转换为给定的图实例 低于

{"id":0, "label":"buyer", "outE": {"email_is": [{"id":0,"inV":1, "properties":{"weight":1} } ]} ,"properties": {"buyer": [{ "id":0,"value":"buyer0" }] ,"age": [{ "id":1,"value":10}] }} {"id":1, "label":"email", "inE": { "email_is": [{"id":1,"outV":0, "properties":{"weight":1}} ]} ,"properties": {"email": [{"id":2, "value":"email0" }] }}

我遇到以下错误

java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293) at java.lang.Thread.run(Thread.java:745)Caused by: java.lang.IllegalArgumentException: Invalid vertex provided: null at com.googlemon.base.Preconditions.checkArgument(Preconditions.java:145) at com.thinkaurelius.titan.graphdb.vertices.AbstractVertex.addEdge(AbstractVertex.java:149) at com.thinkaurelius.titan.graphdb.vertices.AbstractVertex.addEdge(AbstractVertex.java:23) at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.lambda$null$57(GraphSONReader.java:114) at java.util.Iterator.forEachRemaining(Iterator.java:116) at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.lambda$readGraph$58(GraphSONReader.java:108) at java.util.HashMap$EntrySet.forEach(HashMap.java:1035) at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.readGraph(GraphSONReader.java:108) at pluradj.titan.tinkerpop3.example.JavaExample2.main(JavaExample2.java:50) ... 6 more

谁能告诉我一种简单的制作GRAPHSON文件的方法,因为使用StringWriter和JSONWRiter类是一项非常繁琐的任务.

解决方案

看起来格式上没有任何问题,只是您有换行符,GraphSON的邻接列表每行需要一个顶点,这样: >

{"id":0,"label":"buyer","outE":{"email_is":[{"id":0,"inV":1,"properties":{"weight":1}}]},"properties":{"buyer":[{"id":0,"value":"buyer0"}],"age":[{"id":1,"value":10}]}} {"id":1,"label":"email","inE":{ "email_is":[{"id":1,"outV":0,"properties":{"weight":1}}]},"properties":{"email":[{"id":2,"value":"email0"}]}}

在这种格式下,似乎工作正常:

gremlin> graph = TitanFactory.open('conf/titan-berkeleyje.properties') ==>standardtitangraph[berkeleyje:/db/berkeley] gremlin> graph.io(graphson()).readGraph('data/sample.json') ==>null gremlin> g = graph.traversal() ==>graphtraversalsource[standardtitangraph[berkeleyje:/db/berkeley], standard] gremlin> g.V().valueMap() ==>[email:[email0]] ==>[age:[10], buyer:[buyer0]]

如果您想拥有有效的" JSON,则可以执行此操作(这仅适用于小型图):

{ "vertices": [ {"id":0,"label":"buyer","outE":{"email_is":[{"id":0,"inV":1,"properties":{"weight":1}}]},"properties":{"buyer":[{"id":0,"value":"buyer0"}],"age":[{"id":1,"value":10}]}}, {"id":1,"label":"email","inE":{ "email_is":[{"id":1,"outV":0,"properties":{"weight":1}}]},"properties":{"email":[{"id":2,"value":"email0"}]}} ] }

,然后您必须对GraphSONReader进行一些不同的初始化,并使用unwrapAdjacencyList设置:

gremlin> graph = TitanFactory.open('conf/titan-berkeleyje.properties') ==>standardtitangraph[berkeleyje:/db/berkeley] gremlin> reader = graph.io(graphson()).reader().unwrapAdjacencyList(true).create() ==>org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader@286090c gremlin> reader.readGraph(new FileInputStream('data/sample.json'), graph) ==>null gremlin> g = graph.traversal() ==>graphtraversalsource[standardtitangraph[berkeleyje:/db/berkeley], standard] gremlin> g.V().valueMap() ==>[age:[10], buyer:[buyer0]] ==>[email:[email0]]

I Am trying to convert the following graphSon Format into a graph instance using the follwing command

graph.io(IoCore.graphson()).reader().create().readGraph(stream, graph);

But while running converting the GRaphSON into graph instance given below

{"id":0, "label":"buyer", "outE": {"email_is": [{"id":0,"inV":1, "properties":{"weight":1} } ]} ,"properties": {"buyer": [{ "id":0,"value":"buyer0" }] ,"age": [{ "id":1,"value":10}] }} {"id":1, "label":"email", "inE": { "email_is": [{"id":1,"outV":0, "properties":{"weight":1}} ]} ,"properties": {"email": [{"id":2, "value":"email0" }] }}

I am getting the following error

java.lang.reflect.InvocationTargetException at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:497) at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:293) at java.lang.Thread.run(Thread.java:745)Caused by: java.lang.IllegalArgumentException: Invalid vertex provided: null at com.googlemon.base.Preconditions.checkArgument(Preconditions.java:145) at com.thinkaurelius.titan.graphdb.vertices.AbstractVertex.addEdge(AbstractVertex.java:149) at com.thinkaurelius.titan.graphdb.vertices.AbstractVertex.addEdge(AbstractVertex.java:23) at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.lambda$null$57(GraphSONReader.java:114) at java.util.Iterator.forEachRemaining(Iterator.java:116) at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.lambda$readGraph$58(GraphSONReader.java:108) at java.util.HashMap$EntrySet.forEach(HashMap.java:1035) at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.readGraph(GraphSONReader.java:108) at pluradj.titan.tinkerpop3.example.JavaExample2.main(JavaExample2.java:50) ... 6 more

Can anyone tell me an easier way to make GRAPHSON file , as it is a very tedious task using StringWriter and JSONWRiter classes.

解决方案

It doesn't look like there is anything wrong with your format except that you have line breaks where GraphSON's adjacency list requires one vertex per line as so:

{"id":0,"label":"buyer","outE":{"email_is":[{"id":0,"inV":1,"properties":{"weight":1}}]},"properties":{"buyer":[{"id":0,"value":"buyer0"}],"age":[{"id":1,"value":10}]}} {"id":1,"label":"email","inE":{ "email_is":[{"id":1,"outV":0,"properties":{"weight":1}}]},"properties":{"email":[{"id":2,"value":"email0"}]}}

In this format it seems to work just fine:

gremlin> graph = TitanFactory.open('conf/titan-berkeleyje.properties') ==>standardtitangraph[berkeleyje:/db/berkeley] gremlin> graph.io(graphson()).readGraph('data/sample.json') ==>null gremlin> g = graph.traversal() ==>graphtraversalsource[standardtitangraph[berkeleyje:/db/berkeley], standard] gremlin> g.V().valueMap() ==>[email:[email0]] ==>[age:[10], buyer:[buyer0]]

If you want to have "valid" JSON, then you can do this (which is only practical for small graphs):

{ "vertices": [ {"id":0,"label":"buyer","outE":{"email_is":[{"id":0,"inV":1,"properties":{"weight":1}}]},"properties":{"buyer":[{"id":0,"value":"buyer0"}],"age":[{"id":1,"value":10}]}}, {"id":1,"label":"email","inE":{ "email_is":[{"id":1,"outV":0,"properties":{"weight":1}}]},"properties":{"email":[{"id":2,"value":"email0"}]}} ] }

and then you have to initialize the GraphSONReader a little differently and use the unwrapAdjacencyList setting:

gremlin> graph = TitanFactory.open('conf/titan-berkeleyje.properties') ==>standardtitangraph[berkeleyje:/db/berkeley] gremlin> reader = graph.io(graphson()).reader().unwrapAdjacencyList(true).create() ==>org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader@286090c gremlin> reader.readGraph(new FileInputStream('data/sample.json'), graph) ==>null gremlin> g = graph.traversal() ==>graphtraversalsource[standardtitangraph[berkeleyje:/db/berkeley], standard] gremlin> g.V().valueMap() ==>[age:[10], buyer:[buyer0]] ==>[email:[email0]]

更多推荐

以下GRAPHSON格式不起作用

本文发布于:2023-11-26 20:28:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1635079.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不起作用   格式   GRAPHSON

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!