2016-12-05 79 views
1

我試圖使此腳本工作來檢索文件中存在的所有邊緣,並將用戶的評分從電影中收集。Groovy腳本無法將邊緣添加到Gremlin圖表

new File('ratings.dat').eachLine{ 
    line -> 

    components = line.split('::'); 

    userId = components[0].toInteger(); 
    movieId = components[1].toInteger(); 

    g.V().has('userId', userId).as('o').V().has('movieId', movieId).addE('rated').to('o'); 
} 

如果我添加此瓶蓋內一些調試版畫,我可以看到所有的信息被正確地加載到我的變量,但在執行結束時,我算在我的圖和它的邊數當它應該是多個時,僅增加1。一些調查顯示,邊緣被有效地添加到圖形中是最後被讀取的。可能會出現什麼問題?

回答

2

你永遠不會執行你的遍歷。您的代碼應該如下所示:

new File('ratings.dat').eachLine { def line -> 
    def (userId, movieId) = line.split('::')*.toInteger() 
    g.V().has('userId', userId).as('o'). 
     V().has('movieId', movieId). 
     addE('rated').to('o').iterate() 
}