问题描述
这对我来说可能是个问题,因为我工作的时间超过了需要的时间.你能告诉我我可以在两个顶点之间添加一条边吗,在这里我有50个顶点,我找不到找到在其顶点ID为0到49的边上添加边的方法.到目前为止,我已经使用
This can be a bit problem occuring for me as i am working for more time than needed . Can you tell me can i add an edge between two vertices and here i have 50 vertices and i cant find a way to add edge on it having vertex id 0 to 49 . Till now I have use
gremlin> (0..<50)each{g.addEdge(V[it],V[it+1]).next()}
No such property: V for class: groovysh_evaluate
gremlin> (0..<=49)each{g.addEdge(g.getVertex([NodeID]),g.getVertex([NodeID+1]),'abc')}
groovysh_parse: 2: unexpected token: = @ line 2, column 6.
(0..<=49)each{g.addEdge(g.getVertex([NodeID]),g.getVertex([NodeID+1]),'abc')}
^
1 error
推荐答案
看起来您只想遍历各个顶点,并从一个顶点到另一个顶点添加一条边,直到它们被连接为止.首先,我将创建50个顶点:
It looks like you just want to iterate through the vertices and add an edge from one vertex to the next until they are all connected. First, I'll create the 50 vertices:
gremlin> g.inject((0..<50).toArray()).as('i').addV('myid',select('i')).iterate()
然后我添加边缘:
gremlin> (0..<49).each { def v = g.V().has('myid',(long) it).next(); v.addEdge('knows',g.V().has('myid',(long)it+1).next()) }
在上面的示例中,我使用TinkerGraph时强制转换为"long".发电机可能不需要演员表.请注意,您可以使用以下命令将所有这些内容合并为一行:
I cast to "long" in my example above as I was using a TinkerGraph. That cast may not be necessary for dynamo. Note that you can combine all of this into a single line with:
gremlin> g.addV().repeat(__.as('a').addV().as('b').
select(last,'a','b').
addE('.').from('a').to('b').
inV().as('a')).
times(49)
上面将以迭代方式同时创建顶点和边.请注意,"49"代表您想要的边数.
The above will create both the vertices and the edges at the same time in an iterative fashion. Note that "49" represents the number of edges you'd like to have.
您已经在StackOverflow中的多个标签中分散了相同的问题,包括: 和此处.在所有情况下,您都有许多基本的语法错误,并且正在调用不存在的方法并引用不存在的对象.我建议您在深入研究dynamodb和TinkerPop之前,先关注Java和Groovy的更多基础知识.至少要从TinkerPop教程开始(就像您的问题的注释中提到的那样),以更好地了解API以及编程语法.
You have spread this same question across multiple tags in StackOverflow including: here and here. In all cases you have lots of basic syntax errors and are calling methods that don't exist and referencing objects that don't exist. I suggest you focus on more of the basics of Java and Groovy before digging too deeply into dynamodb and TinkerPop. At a mimimum, start with the TinkerPop tutorials (like the one mentioned in the comment to your question) to get a better feel for the APIs and how the programmign syntax.
这篇关于创建顶点ID号为0到49的多个边的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!