加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – JanusGraph将子图输出为GraphSON错误

发布时间:2020-12-15 04:38:40 所属栏目:Java 来源:网络整理
导读:我试图用JanusGraph在Gremlin shell中输出一个子图作为GraphSON. TinkerPop文档供参考: http://tinkerpop.apache.org/docs/current/reference/#graphson-reader-writer 当我编写完整的图形时,这工作正常,但是,当我想编写一个我使用这些命令查询的子图时: g
我试图用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才能干净地导出.

这是一个基于Titan previous example的示例,您可以在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')

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读