Assuming you are using the Jena ontology API, it's pretty simple. Note that in RDF this instance can have many types, so your question is really βhow can I check if two instances have one or more types?β.
I would do it as follows. Suppose the two instances you want to test are Individual
objects (note that you can do this with OntResource
or even Resource
with a little code change):
Individual i0 = ....; Individual i1 = ....;
List the rdf:type
values ββfor each and convert them to settings
Set<Resource> types0 = i0.listRDFTypes( false ).toSet(); Set<Resource> types1 = i1.listRDFTypes( false ).toSet();
They have common types if the intersection is nonempty:
types0.retainAll( types1 ); if (!types0.isEmpty()) { // at least one type in common // types0 contains the common type resources }
Ian dickinson
source share