2

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.

NeoJi
  • 245
  • 2
  • 14

2 Answers2

1

I tried with this structure

enter image description here

This is the graph.

enter image description here

I used this javascript function.

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 );
}

This is the new structure

enter image description here

and this is the new graph

enter image description here

Hope it helps.

Alessandro Rota
  • 3,560
  • 1
  • 8
  • 10
  • This works great. I thought I could make one 'create edge' command with some sort of 'join' operation. Maybe iterating over the result is the simplest. I will post my python version of it. thanks. – NeoJi Apr 12 '16 at 19:14
1

This is just a Python version of Alessandro's answer using pyorient.

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)); 
NeoJi
  • 245
  • 2
  • 14