在OrientDb中查找并删除重复的边

时间:2016-01-18 14:50:26

标签: orientdb orientdb-2.1

考虑我们有Vertex用户和Edge FriendsWith。 FriendsWith可以在两个方向上进出(通常是在两个用户之外或之间)。

重复是指从一个用户到另一个用户的一个或多个被发现超过一次(out and in together不被视为重复)

有没有办法找到重复的边并删除它们?

更新添加说明问题的图片

enter image description here

谢谢。

3 个答案:

答案 0 :(得分:5)

这是我的javascript函数:

var g=orient.getGraph();
var C=g.command('sql','select from FriendsWith');
var arr = new Array(C.length);
var toRemove = new Array();

for(i=0;i<C.length;i++){
  var found = false;
  for (x = 0; x < i+1 && !found; x++) {
  if (arr[x] === C[i].getProperty("out").getId()+" "+C[i].getProperty("in").getId()) {
    found = true;
    toRemove.push(C[i].getId());
    }
  }
  arr[i] = C[i].getProperty("out").getId()+" "+C[i].getProperty("in").getId();
}

for(a=0;a<toRemove.length;a++){
  var C=g.command('sql','delete edge '+toRemove[a]);
}

希望它有所帮助。 再见

答案 1 :(得分:3)

您可以尝试此功能

#include "ntddk.h"

void Unload(PDRIVER_OBJECT pDriverObject) {
DbgPrint("Driver unloading...\n");
return;
}

NTSTATUS DriverEntry(PDRIVER_OBJECT pDriverObject, PUNICODE_STRING RegPath) {

pDriverObject->DriverUnload=Unload;
DbgPrint("Driver has been loaded..");

return (STATUS_SUCCESS);

}

enter image description hereenter image description here

答案 2 :(得分:2)

我创建了一个小型数据库来试试你的情况。这是我的代码:

create class User extends V
create class follows extends E

create property User.id integer
create property User.name String

create vertex User set id=1, name="Paul"
create vertex User set id=2, name="John"
create vertex User set id=3, name="Mark"
create vertex User set id=4, name="Robert"

create edge follows from (select from User where id=1) to (select from User where id=2)
create edge follows from (select from User where id=2) to (select from User where id=1)
create edge follows from (select from User where id=1) to (select from User where id=3)
create edge follows from (select from User where id=2) to (select from User where id=3)
create edge follows from (select from User where id=3) to (select from User where id=2)
create edge follows from (select from User where id=3) to (select from User where id=4)

图表:

enter image description here

然后我创建了一个简单的Javascript函数,一旦找到重复边缘,就会删除方向边缘。

输入:ridA(你开始@rid)

代码:

var g=orient.getGraph();
var outF=g.command('sql','select expand(out("follows")) from '+ridA);
var inF=g.command('sql','select expand(in("follows")) from '+ridA);
for(x=0;x<outF.length;x++){
  var ridOut=outF[x].getId();
  for(y=0;y<inF.length;y++){
    var ridIn=inF[y].getId();
    if(ridOut==ridIn){
      g.command('sql','delete edge follows from '+ridIn+' to '+ridA);
    }
  }
}

编辑:

例如,如果您尝试从顶点#12:1删除重复边缘,则在启动该功能后,两个方向边缘会跟随&#39;将被删除。