1

这是我在 Netbeans 中的 Groovy 脚本:

import org.apache.tinkerpop.gremlin.tinkergraph.structure.*
import org.apache.tinkerpop.gremlin.groovy.loaders.*


GremlinLoader.load()
SugarLoader.load()

def graph = TinkerFactory.createModern()
def g = graph.traversal()

def results = []

g.V(1).outE('knows').inV().values('name').fill(results) //==>[vadas, josh]  which is OK
println results

g.V(1).repeat(**out**()).times(2).fill(results)  //==>Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: Test.**out**() is applicable for argument types: () values: []
println results

//also getting "Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: ..." for all the following ones:
g.V().hasLabel('person').out().has('name',within('vadas','josh')).fill(results)
g.V().values('age').is(lte(30)).fill(results)
g.V().group().by(bothE().count()).fill(results)

我仅在“嵌套”步骤(例如,、、、等)中得到“线程“主”groovy.lang.MissingMethodException:没有方法签名:...”repeat(**out**())has('xxx',**within**(...)is(**lte**(30))异常by(**bothE**())。所有简单的步骤(outE('xxx'),is(32)等)都运行良好。Gremlin 控制台中的所有遍历都运行良好。

我在 Netbeans 中使用以下 java 库:

commons-cli-1.2.jar
commons-codec-1.9.jar
commons-configuration-1.10.jar
commons-lang-2.6.jar
commons-lang3-3.3.1.jar
commons-logging-1.2.jar
gbench-0.4.3-groovy-2.4.jar
gprof-0.3.1-groovy-2.4.jar
gremlin-console-3.2.3.jar
gremlin-core-3.2.3.jar
gremlin-driver-3.2.3.jar
gremlin-groovy-3.2.3.jar
gremlin-shaded-3.2.3.jar
groovy-2.4.7-indy.jar
groovy-2.4.7.jar
groovy-ant-2.4.7.jar
groovy-console-2.4.7.jar
groovy-groovysh-2.4.7-indy.jar
groovy-json-2.4.7-indy.jar
groovy-jsr223-2.4.7-indy.jar
groovy-sql-2.4.7-indy.jar
groovy-swing-2.4.7.jar
groovy-templates-2.4.7.jar
groovy-xml-2.4.7.jar
hppc-0.7.1.jar
httpclient-4.5.1.jar
httpcore-4.4.3.jar
ivy-2.3.0.jar
jBCrypt-jbcrypt-0.4.jar
javatuples-1.2.jar
jcabi-log-0.14.jar
jcabi-manifests-1.1.jar
jcl-over-slf4j-1.7.21.jar
jline-2.12.jar
log4j-1.2.17.jar
netty-all-4.0.40.Final.jar
slf4j-api-1.7.21.jar
slf4j-log4j12-1.7.21.jar
snakeyaml-1.15.jar
tinkergraph-gremlin-3.2.3.jar

我究竟做错了什么?

4

2 回答 2

1

来自关于图遍历的Apache TinkerPop 文档:

为了减少表达式的冗长,最好使用import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*. 这样__.inE(),就可以简单地编写inE(). 使用匿名遍历时请注意特定于语言的保留关键字。例如,in 和 as 是 Groovy 中的保留关键字,因此您必须使用详细语法__.in()__.as()避免冲突。

同样对于谓词,likelte()within()

为了减少谓词表达式的冗长,最好使用import static org.apache.tinkerpop.gremlin.process.traversal.P.*.

于 2016-12-15T18:38:13.327 回答
0

非常感谢,它与这些导入运行良好:

import org.apache.tinkerpop.gremlin.tinkergraph.structure.*
import org.apache.tinkerpop.gremlin.groovy.loaders.*
import static org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__.*
import static org.apache.tinkerpop.gremlin.process.traversal.P.*
import static org.apache.tinkerpop.gremlin.process.traversal.Order.*


GremlinLoader.load()
SugarLoader.load()

def graph = TinkerFactory.createModern()
def g = graph.traversal()

def results = []


def v4=g.V(4).next()
def v6=g.V(6).next()
v4.addEdge("knows", v6, "id" , 13, "weight", 0.4)

def subGraph = g.E().hasLabel('knows').subgraph('subGraph').cap('subGraph').next()
def sg = subGraph.traversal()
sg.E().fill(results)
println "sg.E() =>[e[7][1-knows->2], e[8][1-knows->4], e[12][4-knows->6]] ==>" + results
results = []

g.V(1).outE('knows').inV().values('name').fill(results)
println "g.V(1).outE('knows').inV().values('name') =>[vadas, josh] ==>" + results
results = []
g.V(4).outE('knows').inV().values('name').fill(results)
println "g.V(4).outE('knows').inV().values('name') =>[peter] ==>" + results
results = []
g.V(1).outE('knows').fill(results)
println "g.V(1).outE('knows') =>[e[7][1-knows->2], e[8][1-knows->4]] ==>" + results
results = []
g.V().has('name','marko').out('created').fill(results)
println "g.V(1).outE('knows') =>[v[3]] ==>" + results
results = []
g.V().has('name','marko').out('created').in('created').values('name').fill(results)
println "g.V().has('name','marko').out('created').in('created').values('name') =>[marko, josh, peter] ==>" + results
results = []
g.V().range(0, 2).fill(results)
println "g.V().range(0, 2) =>[v[1], v[2]] ==>" + results
results = []
g.V().values('name').order().fill(results)
println "g.V().values('name').order() =>[josh, lop, marko, peter, ripple, vadas] ==>" + results
results = []
g.V().values('name').order().tail().fill(results)
println "g.V().values('name').order().tail() =>[vadas] ==>" + results
results = []
g.V().hasLabel('person').fill(results)
println "g.V().hasLabel('person') =>[v[1], v[2], v[4], v[6]] ==>" + results
results = []
g.V().hasLabel('person').out().has('name','josh').fill(results)  //
println "g.V().hasLabel('person').out().has('name','josh') =>[v[4]] ==>" + results
results = []
g.V().out('knows').map{it.get().value('name') + ' is the friend name'}.fill(results)
println "g.V().out('knows').map{it.get().value('name') + ' is the friend name'} =>[vadas is the friend name, josh is the friend name, peter is the friend name] ==>" + results
results = []
g.V().values('name').order().fill(results)
println "g.V().values('name').order() =>[josh, lop, marko, peter, ripple, vadas] ==>" + results
results = []
g.V().values('age').is(32).fill(results)
println "g.V().values('age').is(32) =>[32] ==>" + results
results = []
g.V().values('age').mean().fill(results)
println "g.V().values('age').mean() =>[30.75] ==>" + results
results = []
g.V(1).property('country','usa').fill(results)
println "g.V(1).property('country','usa') =>[v[1]] ==>" + results
results = []
g.V(1).out('created').aggregate('x').fill(results)
println "g.V(1).out('created').aggregate('x') =>[v[3]] ==>" + results
results = []
g.V().as('a').out('created').as('b').select('a','b').fill(results)
println "g.V().as('a').out('created').as('b').select('a','b') =>[[a:v[1], b:v[3]], [a:v[4], b:v[5]], [a:v[4], b:v[3]], [a:v[6], b:v[3]]] ==>" + results
results = []
g.V().hasLabel('person').count().fill(results)
println "g.V().hasLabel('person').count() =>[4] ==>" + results
results = []
g.V().coin(0.5).fill(results)
println "g.V().coin(0.5) =>some random vertices ==>" + results
results = []
g.withSack(1.0f).V().sack().fill(results)
println "g.withSack(1.0f).V().sack() =>[1.0, 1.0, 1.0, 1.0, 1.0, 1.0] ==>" + results
results = []
g.V().outE().sample(1).values('weight').fill(results)
println "g.V().outE().sample(1).values('weight') =>[0.5] ==>" + results
results = []
g.V().values('age').sum().fill(results)
println "g.V().values('age').sum() =>[123] ==>" + results
results = []
g.V().as('a').both().both().as('b').count().fill(results)
println "g.V().as('a').both().both().as('b').count() =>[40] ==>" + results
results = []
g.V().as('a').both().both().as('b').where('a',neq('b')).count().fill(results)
println "g.V().as('a').both().both().as('b').where('a',neq('b')) =>[26] ==>" + results
results = []
g.V().hasLabel('person').out().has('name',within('vadas','josh')).fill(results)
println "g.V().hasLabel('person').out().has('name',within('vadas','josh')) =>[v[2], v[4]] ==>" + results
results = []
g.V().values('age').is(lte(30)).fill(results)
println "g.V().values('age').is(lte(30)) =>[29, 27] ==>" + results
results = []
g.V().group().by(bothE().count()).fill(results)
println "g.V().group().by(bothE().count()) =>[[1:[v[2], v[5]], 2:[v[6]], 3:[v[1], v[3]], 4:[v[4]]]] ==>" + results
results = []
g.V(1).repeat(out()).times(2).fill(results)
println "g.V(1).repeat(out()).times(2) =>[v[5], v[3], v[6]] ==>" + results
results = []
g.V(1).repeat(out()).times(2).path().by('name').fill(results)
println "g.V(1).repeat(out()).times(2).path().by('name') =>[[marko, josh, ripple], [marko, josh, lop], [marko, josh, peter]] ==>" + results
results = []
g.V(1).repeat(out().simplePath()).until(hasId(6)).path().limit(1).fill(results)
println "g.V(1).repeat(out().simplePath()).until(hasId(6)).path().limit(1) =>[[v[1], v[4], v[6]]] ==>" + results
results = []
g.V().until(has('name','ripple')).repeat(out()).fill(results)
println "g.V().until(has('name','ripple')).repeat(out()) =>[v[5], v[5], v[5]] ==>" + results
results = []
g.V().until(has('name','ripple')).repeat(out()).path().by('name').fill(results)
println "g.V().until(has('name','ripple')).repeat(out()).path().by('name') =>[[marko, josh, ripple], [josh, ripple], [ripple]] ==>" + results
results = []
g.V(1).until(has('name','josh')).repeat(out('knows')).path().by('name').fill(results)
println "g.V(1).until(has('name','josh')).repeat(out('knows')).path().by('name') =>[[marko, josh]] ==>" + results
results = []
g.V(1).until(outE('knows').count().is(0)).repeat(out('knows')).path().by('name').fill(results)
println "g.V(1).until(outE('knows').count().is(0)).repeat(out('knows')).path().by('name') =>[[marko, vadas], [marko, josh, peter]] ==>" + results
results = []
g.V(2).optional(out('knows')).fill(results)
println "g.V(1).optional(out('knows')) =>[v[2]] ==>" + results
results = []
g.V().where(outE('created').and().outE('knows')).values('name').fill(results)
println "g.V().where(outE('created').and().outE('knows')).values('name') =>[marko, josh] ==>" + results
results = []
g.V().values('name').order().by(decr).fill(results)
println "g.V().values('name').order().by(decr) =>[vadas, ripple, peter, marko, lop, josh] ==>" + results
results = []
g.V().hasLabel('person').order().by(shuffle).fill(results)
println "g.V().hasLabel('person').order().by(shuffle) =>some random order of v[1], v[2], v[4], v[6] ==>" + results
results = []
于 2016-12-16T14:50:35.443 回答