2017-12-18 110 views

回答

0

我這樣的代碼:

graph = TinkerGraph.open() 

    //g = graph.traversal() 

    println "nodes.csv:" 
    /*add nodes.csv to db, each node as int*/ 
    new File('nodes.csv').eachLine {line -> 
     (fromVertex) = line.split(",") 
     //println fromVertex 
     v1 = graph.addVertex("nodeid", fromVertex.toInteger()) 
    } 


    println "edges.csv:" 
    graph.createIndex("edges", Vertex.class) 
    g = graph.traversal() 

    getOrCreate = {id -> 
     g.V().has("nodeid", id.toInteger()).tryNext().orElseGet{g.addV().property("nodeid", id.toInteger()).next() } 
    } 

/*traver edges.csv each line, add edge to db*/ 
new File("edges.csv").eachLine { 
    if(!it.startsWith("#")){ 
    (fromVertex, toVertex) = it.split(",").collect(getOrCreate) 
    fromVertex.addEdge("friend", toVertex) 
    } 
} 


println "group-edges.csv:" 
new File("group-edges.csv").eachLine { line -> 
    (fromVertex, toVertex) = line.split(",") 
    v = g.V().has("nodeid", fromVertex.toInteger()) 
    //println v 
    v.property("grpid",toVertex.toInteger()) 
} 

//g.tx().commit() 

edges.csv:

1,2 
1,3 
4,5 

組edges.csv:

1,1 
2,1 
3,1 
4,2 
5,2 

nodes.csv:

1 
2 
3 
4 
5 

現在的問題是:當我關閉這個gremlin時,我無法查詢保存到titan db的數據。