OrientDB:如何遍历图并获取给定类型的完整路径

OrientDB: How to traverse a graph and get the full path of a given type

我有一个编程语言图,其中包的结构如 Eclipse 所示,因此每个包都是一个顶点。我想从 class 开始,遍历顶点 class 为 code_Package 的边 belongsTo。最后,我想打印完整的包名。这可能吗?

结构与此类似:

如果我没理解错的话,你的情况是这样的:

create class code_Package extends V
create property code_Package.name string

create class code_ClassUnit extends V
create property code_ClassUnit.name string

create class belongsTo extends E


# class sdc.spd.ssi.Main
create vertex code_Package set name = 'sdc'      #12:0
create vertex code_Package set name = 'spd'      #12:1
create vertex code_Package set name = 'ssi'      #12:2

create vertex code_ClassUnit set name = 'Main'   #13:0


create edge belongsTo from #13:0 to #12:2
create edge belongsTo from #12:2 to #12:1
create edge belongsTo from #12:1 to #12:0

你所问的可以通过定义一个函数来实现(例如join):

var result = "";
for(var i = input.length - 1; i >= 0; i--){
  result += input[i] + ".";
}

return result.substring(0, result.length - 1);

像这样:

然后:

select join($all.fullPath[0])
let $all = (select unionall(name) as fullPath from (traverse out('belongsTo') from #13:0))

输出: