Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to find out whether two instances are of the same RDF class, programmatically?

Is it possible to find out whether two instances are of the same class, programmatically (Using api such as JENA)

like image 682
PCoder Avatar asked Jan 29 '12 18:01

PCoder


People also ask

How can you tell if two instances of a class have the same field values?

If the two objects have the same values, equals() will return true . In the second comparison, equals() checks to see whether the passed object is null, or if it's typed as a different class. If it's a different class then the objects are not equal.

How can you tell if an object is in the same instance?

The referential equality (using === , == or Object.is() ) determines whether the operands are the same object instance.

What is rdf bag?

An rdf:Bag is used to indicate that the container is intended to be unordered. An rdf:Seq is used to indicate that the order indicated by the numerical order of the container membership properties of the container is intended to be significant.


1 Answers

Easy in SPARQL:

ASK { <instance1> a ?class . <instance2> a ?class . }

In Jena API:

boolean shareClass = false;
for (Statement s: instance1.listProperties(RDF.type)) {
    if (instance2.hasProperty(RDF.type, s.getObject()) {
        shareClass = true;
        break;
    }
}

Not very elegant.

like image 71
user205512 Avatar answered Sep 19 '22 20:09

user205512