我有一个编程语言图,其中包是按Eclipse表示的结构,所以每个包都是一个顶点。我想从一个类开始遍历边缘belongsTo,其中顶点的类是code_Package。最后,我想打印完整的包名。这可能吗?
结构与此类似:
答案 0 :(得分:4)
如果我理解正确,你的情况是这样的:
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
通过定义函数(例如加入)可以实现您的要求:
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))
输出: