我必须在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>
答案 0 :(得分: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()
会将其设置为无法识别filter
的Neo4jVertexIterable(因为filter
将被视为管道的一部分)。因此,我对这两个建议的理论是评估一个正确形成的管道。
答案 1 :(得分:0)
使用2.2版,例外是:
java.lang.NoSuchFieldError:ASMAP。
与版本2.3相反,我得到以下异常:
线程“main”中的异常java.lang.NoSuchMethodError:com.tinkerpop.pipes.util.FluentUtility.prepareFunction(Lcom / tinkerpop / pipes / util / structures / AsMap; Lcom / tinkerpop / pipes / PipeFunction;)Lcom / TinkerPop有关/管/ PipeFunction;
但是,查询在控制台
中工作正常