B.1 GraphSONデータ形式
GraphSONファイル形式では、JavaScript Object Notation (JSON)に基づいてグラフを記述します。
-
このトピックの最初の例は、プロパティ・グラフとはに示すプロパティ・グラフのGraphSONの説明を示しています。
-
このトピックの2番目の例では、Tinkerpop 3に対する同じグラフのGraphSONの説明を示しています。
例B-1 単純なプロパティ・グラフのGraphSONの記述
{ "graph": { "mode":"NORMAL", "vertices": [ { "name": "Alice", "age": 31, "_id": "1", "_type": "vertex" }, { "name": "Bob", "age": 27, "_id": "2", "_type": "vertex" } ], "edges": [ { "type": "friends", "_id": "3", "_type": "edge", "_outV": "1", "_inV": "2", "_label": "knows" } ] } }
例B-2 単純なプロパティ・グラフのGraphSON 3.0の記述
{"id":{"@type":"g:Int64","@value":1},"label":"person","outE":{"knows":[{"id":{"@type":"g:Int64","@value":3},"inV":{"@type":"g:Int64","@value":2},"properties":{"type":"friends"}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":66724076},"value":"Alice"}],"age":[{"id":{"@type":"g:Int64","@value":96543},"value":{"@type":"g:Int32","@value":31}}]}} {"id":{"@type":"g:Int64","@value":2},"label":"person","inE":{"knows":[{"id":{"@type":"g:Int64","@value":3},"outV":{"@type":"g:Int64","@value":1},"properties":{"type":"friends"}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":3440674},"value":"Bob"}],"age":[{"id":{"@type":"g:Int64","@value":96540},"value":{"@type":"g:Int32","@value":27}}]}}
GraphSON形式でグラフをインポートおよびエクスポートするメソッドが用意されています。
次のコードのフラグメントは、Tinkerpop 2およびTinkerpop 3バージョンでGraphSONデータをインポートおよびエクスポートする方法を示しています。Tinkerpop 3バージョンには、「Tinkerpop 3」という接尾辞が付いています。これは後方互換性の維持を目的として提供されています。
// Get graph instance OraclePropertyGraph opg = OraclePropertyGraph.getInstance(args, szGraphName); // Import graph in GraphSON format String fileName = "./mygraph.graphson"; PrintStream ps = new PrintStream("./output"); OraclePropertyGraphUtils.importGraphSON(opg,fileName,ps); // Export graph into GraphSON format String fileName = "./mygraph.graphson"; PrintStream ps = new PrintStream("./output"); OraclePropertyGraphUtils.exportGraphSON(opg,fileName,ps); // Import graph into Tinkerpop 3 GraphSON format String fileName = "./mygraphT3.graphson"; PrintStream ps = new PrintStream("./output"); OraclePropertyGraphUtils.importGraphSONTinkerpop3(opg,fileName,ps); // Export graph into Tinkerpop 3 GraphSON format String fileName = "./mygraphT3.graphson"; PrintStream ps = new PrintStream("./output"); OraclePropertyGraphUtils.exportGraphSONTinkerpop3(opg,fileName,ps);
関連トピック
親トピック: プロパティ・グラフのデータ形式について