我必须在 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>