以下 GRAPHSON 格式不起作用
Following GRAPHSON format not working
我正在尝试将以下 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.run(ExecJavaMojo.java:293)
at java.lang.Thread.run(Thread.java:745)Caused by: java.lang.IllegalArgumentException: Invalid vertex provided: null
at com.google.common.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(GraphSONReader.java:114)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.lambda$readGraph(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]]
如果你想要"valid"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]]
我正在尝试将以下 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.run(ExecJavaMojo.java:293)
at java.lang.Thread.run(Thread.java:745)Caused by: java.lang.IllegalArgumentException: Invalid vertex provided: null
at com.google.common.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(GraphSONReader.java:114)
at java.util.Iterator.forEachRemaining(Iterator.java:116)
at org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONReader.lambda$readGraph(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]]
如果你想要"valid"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]]