2016-03-05 41 views
3

我想讀取一個GraphML文件,並使用它與Gremlin遍歷。我使用相同的代碼,因爲這頁:正確的方式來閱讀GraphML文件與Gremlin使用Groovy

http://tinkerpop.apache.org/docs/3.1.1-incubating/reference/

我寫與writeGraph的例子圖和讀回與readGraph。圖表上的toString()調用使得 顯示圖形被正確讀入(每個都有6個節點和6個頂點),但是然後應用Gremlin遍歷只產生了TinkerFactory圖形的輸出,而不是那個是讀入。

代碼
@Grab('org.apache.tinkerpop:tinkergraph-gremlin:3.1.1-incubating') 
@Grab('org.apache.tinkerpop:gremlin-core:3.1.1-incubating') 

import org.apache.tinkerpop.gremlin.structure.Graph; 
import org.apache.tinkerpop.gremlin.structure.io.IoCore; 
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerFactory; 
import org.apache.tinkerpop.gremlin.tinkergraph.structure.TinkerGraph; 

final Graph graph = TinkerFactory.createModern(); 
graph.io(IoCore.graphml()).writeGraph("test.xml"); 
final Graph newGraph = TinkerGraph.open(); 
newGraph.io(IoCore.graphml()).readGraph("test.xml"); 

def g = graph.traversal(); 
def n = newGraph.traversal(); 

println("Graph") 
println(g.toString()) 
g.V(1).out().values('name').sideEffect{println it}.iterate() 

println("newGraph") 
println(n.toString()) 
n.V(1).out().values('name').sideEffect{println it}.iterate() 

println("DONE") 

輸出
Graph 
graphtraversalsource[tinkergraph[vertices:6 edges:6], standard] 
lop 
vadas 
josh 
newGraph 
graphtraversalsource[tinkergraph[vertices:6 edges:6], standard] 
DONE 

代碼似乎與GraphSON和陀螺儀的輸出來工作。

回答

2

這是Gremlin-Users郵件列表中的related post。當您閱讀newGraph時,這些ID將被視爲String。您可以通過像這樣配置vertexIdManager來更改此行爲:

def conf = new org.apache.commons.configuration.BaseConfiguration(); 
conf.setProperty("gremlin.tinkergraph.vertexIdManager","LONG"); 
final Graph newGraph = TinkerGraph.open(conf); 
newGraph.io(IoCore.graphml()).readGraph(dest);