简体   繁体   English

使用Orientdb 3和tinkerpop 3识别2个顶点是否与边连接

[英]Identifying if 2 Vertices are connected with edge using Orientdb 3 and tinkerpop 3

I have been trying to look through documentation. 我一直在尝试浏览文档。 I am just trying to find a simple example to identify as mentioned in the title if 2 vertices are connected to each other. 我只是想找到一个简单的示例,以便将2个顶点相互连接时进行标识(如标题中所述)。 This is for OrientDB 3 using the tinkerpop API blueprints 2.6. 这适用于使用tinkerpop API蓝图2.6的OrientDB 3。 Ex: Vertex v1; 例如:Vertex v1; Vertex v2; 顶点v2;

boolean connected = false;

connected = <somefunction returns true/false if v1 and v2 connected by an edge>;

Can someone please provide an example if they have seen something like this? 如果有人看到过这样的东西,可以请提供一个例子吗?

try this: 尝试这个:

String db_name = "dbname";
String path = "remote:localhost/" + db_name;

OrientDB orientDB = new OrientDB("remote:localhost", "username", "password", OrientDBConfig.defaultConfig());

try(ODatabaseSession db = orientDB.open(db_name,"username","password")) 
{
    ORID theEdge = new ORecordId("edge_rid");
    OEdge e = db.load(theEdge);

    ORID theVertex = new ORecordId("v1_rid");
    OVertex v1 = db.load(theVertex);

    ORID theVertex2 = new ORecordId("v2_rid");
    OVertex v2 = db.load(theVertex2);

    boolean connected = false;
    OVertex from = e.getFrom();
    OVertex to = e.getTo();

    if(from.getIdentity().equals(v1) && to.getIdentity().equals(v2))
    {
        connected = true;
    }

    if(connected)
    {
        System.out.println("Vertex v1: " + from.getIdentity());
        System.out.println("Vertex v2: " + to.getIdentity());
    }
}



Hope it helps 希望能帮助到你

Regards 问候

You need iterate one vertex(v1) edges and check if it s connecting to the other vertex(v2): 您需要迭代一个顶点(v1)的边缘,并检查它是否连接到另一顶点(v2):

OrientVertex v1,v2; 
for (Edge e : (Iterable<Edge>)() ->  v1.edges(Direction.OUT)) 
    if (e.vertices(Direction.IN).next().id().equals(v2.id())) {
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM