jlanza
jlanza

Reputation: 1258

Jena API differenciate between class and instance of a class

When using Jena API to list all the statements conforming a resource, I don't find a way to differentiate if either subject or object are instances of a class or a class itself.

<http://jlanza.net/node1>  <http://www.w3.org/1999/02/22-rdf-syntax-ns#type>  <http://purl.oclc.org/NET/ssnx/ssn#Device>
<http://jlanza.net/node1>  <http://purl.oclc.org/NET/ssnx/ssn#onPlatform>  <<http://jlanza.net/node2>

node1 and node2 is what I call an instance or individual, while the http://purl.oclc.org/NET/ssnx/ssn#Device is the class it instantiate.

Do you know of any way of differentiating it? By using isUriResource(), isResource(), etc. I get the same result. Let's also say that it is not just valid to get the rdf:type property as there might be other properties that link to a class.

Any help is more than welcome.

Upvotes: 0

Views: 137

Answers (1)

Joshua Taylor
Joshua Taylor

Reputation: 85883

In general, there's not much difference

RDF, by itself, doesn't make this distinction. Rdf:type is just another IRI that is commonly used as a property. In practice, of course, we assign some special meanings to rdf:type whereby we indicate class membership. That is, when we have a triple of the form

x rdf:type y

we say that (the individual) x is an instance of (the class) y. But in RDF(S) inference, this also lets us infer that

y rdf:type rdfs:Class

which means that (the individual, but also a class) y is an instance of (the class) rdfs:Class. So there's no real clear distinction between individuals and classes. In fact, for a property p, we also have that

p rdf:type rdfs:Property

so (the property) p is also an individual! In pure RDF, the only way to determine "the type" of an individual is to look for the its rdf:type values. And the only way to determine whether something is a class is to look for either:

  • it being used as a class, i.e., as the object in a triple of the form x rdf:type C; or
  • is being declared as a class with a triple like C rdf:type rdfs:Class (or, if you're using OWL, C rdf:type owl:Class).

In Jena, OntResource can check with isClass and isIndividual

In Jena, though, if you use an OntModel and get resource as an instance of OntResouce, you can use the methods isClass() and isIndividual() to check whether a resource can be viewed as a class or an individual. Note that those method descriptions include (emphasis added):

Answer true if this resource can be viewed as a class

Answer true if this resource can be viewed as an individual

That phrase, "can be viewed" is important, because as I described above, resources can be classes, individuals, and properties, all at the same time. It might be possible for a resource to be viewed as more than one thing. But these methods will probably work for most use cases.

Upvotes: 1

Related Questions