groovy - Gremlin/Groovy 组计数结果

标签 groovy neo4j gremlin

我对groupCount有点困惑,并使用结果节点来执行更多查询。我一直在 Neo4j 控制台中执行此操作。例如,使用 TinkerGraph 数据集:

gremlin> g = TinkerGraphFactory.createTinkerGraph()
==> tinkergraph[vertices:6 edges:6]

gremlin> g.V.getClass()
==> class com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline

gremlin> m = [:]

gremlin> g.V.out.groupCount(m)
==> v[2]
==> v[4]
==> v[3]
==> v[3]
==> v[5]
==> v[3]

gremlin> m
==> v[2]=1
==> v[4]=1
==> v[3]=3
==> v[5]=1

gremlin> m.getClass()
==> class java.util.LinkedHashMap

gremlin> m = m.keySet()
==> v[2]
==> v[4]
==> v[3]
==> v[5]

gremlin> m.getClass()
==> class java.util.HashMap$KeySet

gremlin> m.outE
==> [StartPipe, OutEdgesPipe]
==> [StartPipe, OutEdgesPipe]
==> [StartPipe, OutEdgesPipe]
==> [StartPipe, OutEdgesPipe]

gremlin> m.outE.map
==> [StartPipe, OutEdgesPipe, PropertyMapPipe]
==> [StartPipe, OutEdgesPipe, PropertyMapPipe]
==> [StartPipe, OutEdgesPipe, PropertyMapPipe]
==> [StartPipe, OutEdgesPipe, PropertyMapPipe]

如何使用 m 作为 GremlinGroovyPipeline 对象?我期待类似的结果:

gremlin> m.outE
==> e[7][1-knows->2]
==> e[8][1-knows->4]
==> e[9][1-created->3]
==> e[12][6-created->3]
==> e[10][4-created->5]
==> e[11][4-created->3]

最佳答案

我在论坛帖子上随机找到了与问题完全无关的答案。

尽管如此,答案如下:

gremlin> m.keySet()_().outE.map
==> {weight=1.0}
==> {weight=0.4}

只需在 keySet() 方法调用后添加文本 _() 似乎就能将其直接转回 GremlinGrrovyPipeline 对象:

gremlin> m.keySet()_().getClass()
==> class com.tinkerpop.gremlin.groovy.GremlinGroovyPipeline

关于groovy - Gremlin/Groovy 组计数结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11200124/

相关文章:

intellij-idea - Geb/Spock错误-未配置报告目录,您需要在配置文件中或通过构建适配器进行设置

java - Intellij 无法正确识别 Groovy 测试

graph-databases - 如何在 gremlin python 中使用 'as' 关键字?

orientdb - gremlin 服务器未随 orientDB 启动

grails - 如何在已部署的 Grails 2.1.0 应用程序中包含 Groovy 2.0?

java - Groovy/Java 生成长值(最小、最大范围)

Neo4j 2.0.0RC1 启动服务失败 87

neo4j - Neo4 层级遍历

Neo4j,密码 : Conditional Create

gremlin - 在 gremlin 查询中进行类型转换