First I know this topic maybe repeated, but actually I have further questions.
I'm using Jena to manipulate OWL ontology. Given a class A
, I want to find all properties that A
is their domain whether this is explicit or inferred.
Let's consider the following ontology: A1 subClassOf A; P domain A; P range B;
I create an ontology moel with DL rule inference, this is supposed to turn reasoner on.
ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM_RULE_INF)
A work around introduced two methods for doing this task:
- Using
listDeclaredProperties()
: this is the code where cls is my OntClass
ExtendedIterator<OntProperty> exItr;
exItr = cls.listDeclaredProperties(false);
while (exItr.hasNext()) {
OntProperty prop = exItr.next();
System.out.println("Object Property Name: "+ prop.getLocalName());
System.out.println("Domain: "+ prop.getDomain());
System.out.println("Range: "+ prop.getRange());
}
This retrieves correct answer: properties that its domain is A
both explicit and inferred, but the printed domains and ranges are set to Thing. This is the output for both A
and A1
:
Object Property Name: P
Domain: http://www.w3.org/2002/07/owl#Thing
Range: http://www.w3.org/2002/07/owl#Thing
Question 1
Why is this happening (Thing
in domain and range)?
Besides, if the domain of some property is intersection, it's ignored i.e. if P domain A intersection B
, and I call this for A
, P
will not be retrieved, this is typical because A intersection B
is a subClassOf A
.
Question 2
However, how can I retrieve the properties which their domain is either A
or a subClassOf A
in order to retrieve A intersection B
?
- Using
listStatements
This only retrieves the explicitly stated answer i.e:
StmtIterator it = model.listStatements(null, RDFS.domain, cls);
while (it.hasNext()) {
Statement stmt = it.next();
System.out.println("Object Property Name: "+ prop.getLocalName());
System.out.println("Domain: "+ stmt.getSubject());
}
This gives no results nothing for A1
. and this is the result for A
Object Property Name: P
Domain: http://www.w3.org/2002/07/owl#A
Range: http://www.w3.org/2002/07/owl#B
Question 3
Why is this happening (only explicit results)? and how to retrieve both explicit and inferred results?
Besides, this way also retrieves properties that A
or A intersection B
is its domain (an answer for question.2), why is this happening? I'm getting a bit lost.