我正在尝试使用 JanusGraph 在 Gremlin shell 中将子图输出为 GraphSON。
TinkerPop 文档供引用: http://tinkerpop.apache.org/docs/current/reference/#graphson-reader-writer
当我写完整的图时,这工作正常,但是,当我想写一个我使用这些命令查询过的子图时:
gremlin> subGraph = g.V(45240).repeat(__.bothE().subgraph('subGraph').bothV()).times(4).cap('subGraph').next()
我使用相同的写入命令:
gremlin> subGraph.io(IoCore.graphson()).writeGraph("45240_sub4.json")
我收到这个错误:
(was java.lang.IllegalStateException) (through reference chain: org.janusgraph.graphdb.relations.RelationIdentifier["inVertexId"])
四处搜索,我发现另一个线程说我需要导入一个包才能正确执行此操作(对于 TitanGraph,但我认为它也适用于 JanusGraph):Import package in gremlin
但是,每当我尝试导入时:
gremlin> import com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule
我收到这个错误:
Invalid import definition: 'com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule'; reason: startup failed: script1494618250861805544050.groovy: 1: unable to resolve class com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule @ line 1, column 1. import com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule ^
1 error
如何使用 JanusGraph 在 Gremlin shell 中将子图输出为 GraphSON?
最佳答案
当您使用 subgraph()
步骤时,结果是一个 TinkerGraph
,但是它的顶点和边 ID 是从 JanusGraph
实例。特别是,边 ID 是 RelationIdentifier
类型,需要 JanusGraph 的自定义序列化程序 JanusGraphSONModule
才能干净地导出。
这是一个基于 previous example 的示例来自 Titan,您可以在 Gremlin 控制台中运行:
graph = JanusGraphFactory.open('inmemory')
graph.io(graphson()).readGraph('data/tinkerpop-modern.json')
g = graph.traversal()
subGraph = g.E().hasLabel('knows').subgraph('sg').cap('sg').next()
graphsonIO = IoCore.graphson().graph(subGraph).registry(JanusGraphIoRegistry.getInstance()).create()
graphsonIO.writeGraph('/tmp/subgraph.json')
关于java - JanusGraph 输出子图作为 GraphSON 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43945568/