gremlin - 如何从遍历中使用的顶点收集值?

标签 gremlin

我想要顶点的详细信息以及连接到该顶点的顶点的详细信息。

我有一个组顶点,传入“成员”边到用户顶点。我想要顶点的详细信息。

g.V(1).as('a').in('member').valueMap().as('b').select('a','b').unfold() .dedup()

==>a=v[1]
==>b={image=[images/profile/friend9.jpg], name=[Thomas Thompson], email=[<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="afc2caefdbc7c0c2cedcdbc7c0c2dfdcc0c181ccc081dac4" rel="noreferrer noopener nofollow">[email protected]</a>]}
==>b={image=[images/profile/friend13.jpg], name=[Laura Tostevin], email=[<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="82efe7c2eee3f7f0e3f6edf1f6e7f4ebecace1edacf7e9" rel="noreferrer noopener nofollow">[email protected]</a>]}
==>b={image=[images/profile/friend5.jpg], name=[Alan Thompson], email=[<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="432e2603222f222d372b2c2e33302c2d6d202c6d3628" rel="noreferrer noopener nofollow">[email protected]</a>]}
==>b={image=[images/profile/friend10.jpg], name=[Laura Bourne], email=[<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ed8088ad818c989f8c8f82989f8388c38e82c39886" rel="noreferrer noopener nofollow">[email protected]</a>]}

理想情况下我想要的是:

{label: 'group', id=1, name='A Group', users=[{id=2, label="user",name=".."}, ... } ]}

当我尝试一个项目时,它不喜欢我使用“in”

gremlin> g.V('1').project('name','users').by('name').by(in('member').select()) groovysh_parse: 1: 意外标记:位于 @ 第 1 行第 83 列。 'name','users').by('name').by(in('member

最佳答案

要获得您首选的输出格式,您必须将组的 valueMap() 与用户列表结合起来。在 TinkerPop 的现代玩具图上,您可以执行以下操作:

gremlin> g.V(3).union(valueMap(true).
                        by(unfold()), 
                      project('users').
                        by(__.in('created').
                           valueMap(true).
                             by(unfold()).
                           fold())).
                unfold().
                group().
                  by(keys).
                  by(select(values))
==>[name:lop,id:3,lang:java,label:software,users:[[id:1,label:person,name:marko,...],...]]

将其映射到您的图表应该非常简单,基本上只是更改标签。

关于gremlin - 如何从遍历中使用的顶点收集值?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56935152/

相关文章:

groovy - Gremlin 中对语句进行排序的语法是什么?

graph - Tinkerpop - 我如何在图中找到一个节点?

java - TinkerPop - 从多个顶点检索值会产生奇怪的输出

javascript - gremlin-javascript 示例仅返回 Pending Promises

Neo4j Facet 字段,如 Solr

Gremlin 顶点 id 与标签 : advantages?

sql - 图灵完备的图查询语言

hadoop - 在 Windows 上安装 Titan DB 时出错

java - 如何使用 gremlin (Apache TinkerPop) 在图数据库中搜索顶点?

Gremlin - 从属性值的压缩列表中过滤边缘