1

次のコマンドを使用して、次の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$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

StringWriter および JSONWRiter クラスを使用するのは非常に面倒な作業であるため、誰でも簡単に GRAPHSON ファイルを作成する方法を教えてもらえますか?

4

1 に答える 1

5

GraphSON の隣接リストが行ごとに 1 つの頂点を必要とする改行があることを除いて、フォーマットに問題があるようには見えません。

{"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]]

「有効な」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]]
于 2015-10-02T13:12:34.090 に答える