For an OWL class A; Getting all properties that A

2019-06-09 06:21发布

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:

  1. 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?

  1. 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.

1条回答
劳资没心,怎么记你
2楼-- · 2019-06-09 07:05

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

Why is this happening (Thing in domain and range)?

Properties in OWL can have any number of domains and ranges. When property P has D as a domain, it means that any time you see an assertion P(x,y), you can infer that x is an instance of D. That means that in OWL, owl:Thing is a domain of every property, since the subject of every assertion must be an instance of owl:Thing. Now, consider the documentation of Jena's OntProperty#getDomain() (emphasis added):

Answer a resource that represents the domain class of this property. If there is more than one such resource, an arbitrary selection is made.

Jena returns one of the domains of the property. owl:Thing is a domain of the property, so owl:Thing is a legimate response. If you want to view all the domains, then you need to use OntProperty#listDomain().

However, how can I retrieve the properties which their domain is either A or a subClassOf A in order to retrieve A intersection B?

You'd need to use a reasoner, and even with a reasoner, it might be easier to express this as a SPARQL query. Then you'd be able to write much more concisely the query:

select ?property where {
  ?property rdfs:domain/rdfs:subClassOf* ex:A
}

This query will get all properties whose domain is A or a subclass of A. You'll still need the reasoner, though, in order to infer that the intersection of A and B is a subclass of A.

Why is this happening (only explicit results)? and how to retrieve both explicit and inferred results?

There will only be inferred results if you use a reasoner. Jena's reasoners aren't logically complete, either, which means that there are some results that are legal OWL results that Jena's reasoners won't produce. You might have run into one of those cases, or there might still be issues in the code. In those cases, though, you probably should produce a complete working example and ask a question with complete code, and a complete ontology that we can use to reproduce the problem. You should also experiment with different reasoners (both the other reasoners provided by Jena as well as reasoners such as Pellet, HermiT, &c.).

查看更多
登录 后发表回答