首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >以下GRAPHSON格式不起作用

以下GRAPHSON格式不起作用
EN

Stack Overflow用户
提问于 2015-10-02 09:01:10
回答 1查看 930关注 0票数 1

我试图使用follwing命令将以下graphSon格式转换为一个图形实例

代码语言:javascript
复制
    graph.io(IoCore.graphson()).reader().create().readGraph(stream, graph);

但是,在运行时,将GRaphSON转换为下面给出的图形实例

代码语言:javascript
复制
{"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"
    }]
    }}

我收到以下错误

代码语言:javascript
复制
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.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$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类是一项非常繁琐的任务。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-02 13:12:34

看起来,您的格式没有什么问题,只是在GraphSON的邻接列表中,每行需要一个顶点,只有一个换行符:

代码语言:javascript
复制
{"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"}]}}

在这种格式中,它似乎工作得很好:

代码语言:javascript
复制
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,那么您可以这样做(这仅适用于小型图):

代码语言:javascript
复制
{
  "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设置:

代码语言:javascript
复制
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]]
票数 5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32903802

复制
相关文章

相似问题

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