首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Python中添加g:顶点GraphSON?

如何在Python中添加g:顶点GraphSON?
EN

Stack Overflow用户
提问于 2020-04-10 04:29:41
回答 1查看 853关注 0票数 3

我将示例顶点GraphSONg:Vertex放在一个文件中:

代码语言:javascript
复制
$ cat vertex.json 
{ "@type" : "g:Vertex", "@value" : { "id" : { "@type" : "g:Int32", "@value" : 1 }, "label" : "person", "properties" : { "name" : [ { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 0 }, "value" : "marko", "label" : "name" } } ], "location" : [ { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 6 }, "value" : "san diego", "label" : "location", "properties" : { "startTime" : { "@type" : "g:Int32", "@value" : 1997 }, "endTime" : { "@type" : "g:Int32", "@value" : 2001 } } } }, { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 7 }, "value" : "santa cruz", "label" : "location", "properties" : { "startTime" : { "@type" : "g:Int32", "@value" : 2001 }, "endTime" : { "@type" : "g:Int32", "@value" : 2004 } } } }, { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 8 }, "value" : "brussels", "label" : "location", "properties" : { "startTime" : { "@type" : "g:Int32", "@value" : 2004 }, "endTime" : { "@type" : "g:Int32", "@value" : 2005 } } } }, { "@type" : "g:VertexProperty", "@value" : { "id" : { "@type" : "g:Int64", "@value" : 9 }, "value" : "santa fe", "label" : "location", "properties" : { "startTime" : { "@type" : "g:Int32", "@value" : 2005 } } } } ] } } }

试图将其读入:

代码语言:javascript
复制
from gremlin_python.process.anonymous_traversal import traversal 
from gremlin_python.driver.driver_remote_connection import DriverRemoteConnection 

g = traversal().withRemote(DriverRemoteConnection('ws://localhost:8182/gremlin','g')) 
g.io("/home/ubuntu/vertex.json").read().iterate()                                                                                                                                                                       

产生一个错误:

org.apache.tinkerpop.shaded.jackson.databind.JsonMappingException:无法按需要反序列化JSON值。嵌套异常: java.lang.InstantiationException:无法将包含在JSON (‘g:顶点’)中的检测类型的值反序列化为对象映射程序参数中指定的类型(接口java.util.Map)。这些类型是不相容的。资料来源:(ByteArrayInputStream);一行: 1,列: 36

我尝试使用graphson_readerDriverRemoteConnectionmessage_serializer参数来指定GraphSONSerializersV3d0,但是我无法克服这个错误。

上面的示例顶点GraphSON如何从读取到图中?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-04-10 13:35:50

您是如何创建GraphSON的?可能值得使用TinkerGraph创建一个简单的GraphSON文件,并将您的文件与之进行比较,以确保语法正确。我使用下面的步骤创建JSON,如下所示。您的示例中的GraphSON看起来更像是查询结果,而不是描述图形的文件。总之,这里有一个例子:

代码语言:javascript
复制
gremlin> g.addV('test').property('name','some-name').property('age','some-age')
==>v[61015]
gremlin> g.io('test.json').write()   

{"id":{"@type":"g:Int64","@value":61015},"label":"test","properties":{"name":[{"id":{"@type":"g:Int64","@value":61016},"value":"some-name"}],"age":[{"id":{"@type":"g:Int64","@value":61017},"value":"some-age"}]}}

这里有一个指向Apache TinkerPop GraphSON参考文档的链接。

http://tinkerpop.apache.org/docs/3.4.6/dev/io/#graphson

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61134072

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档