0

我必须在 java 中使用查询 gremlin,我不知道该怎么做,因为我尝试按照 https://github.com/tinkerpop/gremlin/wiki/Using-Gremlin-through中的说明进行操作-Java但我没有结果,只有例外。请有人帮助我。

这是我必须使用的查询示例:

 g.V.filter{it.AffiliatedDepartment != null}.copySplit(_().DepartmentDirector, _().inE.filter{it.label == 'Affiliated_Professor'}.outV.AffiliatedProfessor).fairMerge.

我尝试了官方文档建议的两种方式。编译 Gremlin Groovy:

    Pipe pipe = Gremlin.compile("_().filter{it.AffiliatedDepartment != null}.copySplit(_().DepartmentDirector, _().inE.filter{it.label == 'Affiliated_Professor'}.outV.AffiliatedProfessor).fairMerge");
    pipe.setStarts(g.getVertices());

我得到一个 java.lang.NoSuchFieldError: asMap

使用 JSR 223 GremlinGroovyScriptEngine:

    ScriptEngineManager manager = new ScriptEngineManager();
    ScriptEngine engine = manager.getEngineByName("gremlin-groovy");
    List results = new ArrayList();
    Bindings bindings = engine.createBindings();
    bindings.put("g", g);
    bindings.put("v", g.getVertices()); 
    engine.eval("v.filter{it.AffiliatedDepartment != null}.copySplit(_().DepartmentDirector, _().inE.filter{it.label == 'Affiliated_Professor'}.outV.AffiliatedProfessor).fairMerge", bindings);

我收到一条带有消息的 javax.script.ScriptException:

<p>groovy.lang.MissingMethodException:</p>
<p>No signature of method: com.tinkerpop.blueprints.impls.neo4j.Neo4jVertexIterable.filter() is applicable for argument types:
</div>
<div>
    (Script1$_run_closure1) values: [Script1$_run_closure1@5bcf59f5]
    </p>
    <p>Possible solutions: find(), first(), find(groovy.lang.Closure), sleep(long), with(groovy.lang.Closure) at
        com.tinkerpop.gremlin.groovy.jsr223.GremlinGroovyScriptEngine.eval(GremlinGroovyScriptEngine.java:110) at
        javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:233)</p>
</div>
4

2 回答 2

1

在 ScriptEngine 方法中,如果您更改此行,它是否有效:

engine.eval("v.filter{it.AffiliatedDepartment != null}.copySplit(_().DepartmentDirector, _().inE.filter{it.label == 'Affiliated_Professor'}.outV.AffiliatedProfessor).fairMerge", bindings);

engine.eval("g.V.filter{it.AffiliatedDepartment != null}.copySplit(_().DepartmentDirector, _().inE.filter{it.label == 'Affiliated_Professor'}.outV.AffiliatedProfessor).fairMerge", bindings);

或者

engine.eval("v._().filter{it.AffiliatedDepartment != null}.copySplit(_().DepartmentDirector, _().inE.filter{it.label == 'Affiliated_Professor'}.outV.AffiliatedProfessor).fairMerge", bindings);

v绑定设置为g.getVertices()将其设置为无法识别的 Neo4jVertexIterable filter(作为filter管道的一部分)。所以我对这两个建议的理论是评估一个正确形成的管道。

于 2013-06-18T18:01:49.203 回答
0

使用 2.2 版,例外情况是:

java.lang.NoSuchFieldError:ASMAP。

取而代之的是 2.3 版,我得到以下异常:

线程“主”java.lang.NoSuchMethodError 中的异常:com.tinkerpop.pipes.util.FluentUtility.prepareFunction(Lcom/tinkerpop/pipes/util/structures/AsMap;Lcom/tinkerpop/pipes/PipeFunction;)Lcom/tinkerpop/pipes /管道函数;

但是,查询在控制台中运行良好

于 2013-06-19T09:52:56.223 回答