0

我有一个像下面这样的场景,需要获取“应用程序”标签顶点属性以及连接到它的“工作”顶点的 id 或属性

在此处输入图像描述

我已经编写了 gremlin glv 查询来获取路径和应用程序属性,但是努力获取连接到它的顶点的属性,(使用 pyton)

查询是,

g.V().hasLabel('Company').outE().inV().hasLabel('Person').outE().inV().hasLabel('Work').outE().inV().hasLabel('Applications').path().unfold().dedup().filter('Applications').elementMap().toList()

这将返回我的应用程序顶点值,例如

[{
  id:'12159',label:'Applications', 'applicationname':'application1'
},
{
 id:'12157',label:'Applications', 'applicationname':'application2'
},
{
 id:'12155',label:'Applications', 'applicationname':'application3'
}

]

但我们还需要获取“工作”顶点详细信息以及应用程序详细信息(应用程序可以连接到多个工作),例如,

{
  id:'12159',label:'Applications', 'applicationname':'application1', 'workcode':['workcode1', 'workcode2']
},
{
  id:'12157',label:'Applications', 'applicationname':'application2', 'workcode':['workcode2']
}.
{
  id:'12157',label:'Applications', 'applicationname':'application3', 'workcode':['workcode2']
}

是否有可能在 gremlin 本身中获取此信息,或者我们是否需要在获取路径后使用 python,

要添加的查询是,

g.addV('Company').as('1').
addV('Company').as('2').
addV('Person').as('3').
addV('Work').as('4').
property(single, 'workcode', 'workcode2').
addV('Work').as('5').
property(single, 'workcode', 'workcode1').
addV('Application').as('6').
property(single, 'applicationname', 'application3').
addV('Application').as('7').
property(single, 'applicationname', 'application2').
addV('Application').as('8').
property(single, 'applicationname', 'application1').
addE('Contractor').from('2').to('3').
addE('Contractor').from('1').to('3').
addE('work').from('3').to('5').addE('work').
from('3').to('4').addE('workingon').from('4').
to('7').addE('workingon').from('4').to('6').
addE('workingon').from('5').to('8').
addE('workingon').from('4').to('8')

谢谢你

4

1 回答 1

2

我不认为你应该使用pathstep 因为你只使用最后一个顶点。如果要将元素映射与另一个顶点的属性合并,可以使用project

g.V().hasLabel('Company').outE().inV().
  hasLabel('Person').outE().inV().
  hasLabel('Work').outE().inV().
  hasLabel('Application').dedup().local(union(
      elementMap().unfold(),
      project('workcose').
        by(in().hasLabel('Work').
          values('workcode').fold())
    ).
    fold())

示例:https ://gremlify.com/d5wsk80nm2t/1

于 2020-11-30T15:24:24.230 回答