1

I am new to a graph database. I am very sure that the answer should be simple as one or two command lines.

I have very simple schema. Person and Email class. There are edges between Person and Email, SendFrom and SendTo. I want to create edges between Person vertices which is joined by the same email.

For instance, if person A sends an email to person B. I want to create an edge between A and B, and increment count property of the edge.

I tried something like, CREATE EDGE FROM (SELECT in() from Email) TO (SELECT out() from Email). Since I am using pyorient, a python driver for OrientDB, this could be done in Python script, or just SQL like language.

I will edit my post, if you need more information. Just let me know.

4

2 回答 2

1

这只是 Alessandro 使用 pyorient 的答案的 Python 版本。

cluster_id = client.command("create class Email_ex extends E")                   
rst = client.query("select in('SendFrom') as SF, out('SendTo') as ST " +         
                   "from Email limit -1")                                                                                                    
for email in rst:                                                                
    for sf in email.SF:                                                          
        for st in email.ST:                                                      
            edge_ex = client.command("create edge Email_ex from " +  
                                     str(sf) + " to " + str(st)); 
于 2016-04-12T19:18:06.307 回答
1

我试过这个结构

在此处输入图像描述

这是图表。

在此处输入图像描述

我使用了这个javascript函数。

var g=orient.getGraph();
var c=g.command("sql","select in('SendFrom')[0].@rid as SF, out('SendTo')[0].@rid as ST from email");
for(i=0;i<c.length;i++){
    var p1=c[i].getProperty("SF");
    var id1=p1.toString();
    id1=id1.substring(id1.lastIndexOf("[")+1,id1.lastIndexOf("]"));
    var p2=c[i].getProperty("ST");
    var id2=p2.toString();
    id2=id2.substring(id2.lastIndexOf("[")+1,id2.lastIndexOf("]"));
    g.command("sql","create edge e from " + id1 + " to " + id2 );
}

这是新结构

在此处输入图像描述

这是新图

在此处输入图像描述

希望能帮助到你。

于 2016-04-12T16:34:04.987 回答