2016-12-05 51 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() 
} 
相关问题