gremlin - 在 gremlin 中合并地图列表
问题描述
我有这样的关系:
person --likes--> subject
这是我的查询:
g.V().
hasLabel('person').
has('name', 'Joe').
outE('likes').
range(0, 2).
union(identity(), inV().hasLabel('subject')).
valueMap('rating', 'name').
此时,我得到如下所示的结果:
[
{
"rating": 3.236155563
},
{
"rating": 3.162886797
},
{
"name": "math"
},
{
"name": "history"
}
]
我想得到这样的东西:
[
{
"rating": 3.236155563,
"name": "math"
},
{
"rating": 3.162886797,
"name": "history"
},
]
我尝试对结果进行分组——这给了我想要的结构——但由于相同的键,我只能得到一组结果。
解决方案
当您发布代码以创建图表时,它总是会有所帮助,因此我们可以为您提供经过测试的答案。像这样
g.addV('person').property('name', 'P1').as('p1').
addV('subject').property('name', 'Math').as('math').
addV('subject').property('name', 'History').as('history').
addV('subject').property('name', 'Geography').as('geography').
addE('likes').from('p1').to('math').property('rating', 1.2).
addE('likes').from('p1').to('history').property('rating', 2.3).
addE('likes').from('p1').to('geography').property('rating', 3.4)
我相信您正在尝试编写从某个人开始的遍历,沿着前两个“喜欢”边缘走,并获取他喜欢的主题的名称以及相应“喜欢”边缘的评分。
g.V().has('person', 'name', 'P1').
outE('likes').
range(0, 2).
project('SubjectName', 'Rating').
by(inV().values('name')).
by(values('rating'))
推荐阅读
- android - 视图上的 Android 卡片翻转动画,而不是片段
- python - 在python中清理打印数据的格式
- c# - C# - StringBuilder - 内存不足异常
- javascript - 如何获取html字符串中的特定元素?
- c# - NServiceBus,在将消息发送到错误队列之前如何执行操作?
- c# - 查找呈现的控件 ID
- django - NoReverseMatch at /admin/ 升级 Django 后出错
- javascript - 从数据列表中选择一个选项并将索引号与第二个数据列表中的另一个选项进行比较
- javascript - 在 JavaScript 中构建 HTML 的最佳实践
- typo3 - 选择新语言后的typo3语言选择器问题