简体   繁体   English

Groovy脚本无法将边添加到Gremlin图

[英]Groovy script fails to add edges to a Gremlin graph

I'm trying to make this script work to retrieve all edges that are present in a file, with ratings from users to movies. 我正在尝试使此脚本起作用,以检索文件中存在的所有边缘,以及从用户到电影的分级。

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');
}

If I add some debug-prints inside this closure I can see that all the information is being loaded correctly to my variables, but at the end of the execution I count the number of edges in my graph and it is increased by only 1, when it should be multiple. 如果在此闭包中添加一些调试打印,我可以看到所有信息都已正确加载到我的变量中,但是在执行结束时,我对图形中的边数进行了计数,并且仅将其增加1,它应该是多个。 A bit of investigation showed that the edge being effectively added to the graph is the last to be read. 一点调查表明,有效地添加到图形的边是最后要读取的边。 What could have possibly gone wrong? 可能出了什么问题?

You never execute your traversal. 您永远不会执行遍历。 Your code should look like this: 您的代码应如下所示:

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()
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM