On Thu, 2011-06-09 at 16:35 +0200, Lars Wißler wrote:
> Hi all,
> 
> im writing an Ontology based application for mapping information. In simple
> terms this is done by defining keywords for classes and instances and
> matching the keywords to words in documents.
> 
> Now while the mapping of instance - keyword relations is working fine i am
> having trouble with class - keyword relations.
> 
> With the following code snippet i can retrieve all keywords of instances:
> public HashMap<String,Resource> readKeywords(){
>         StmtIterator iter = model.listStatements(null , keywordProp,
> (RDFNode)null);
> 
>         while (iter.hasNext()){
>             Statement stmt= iter.next();
>             Resource subject = stmt.getSubject();
> 
>             if (readKeywordsOf(subject)!=null){
>                 keywords.putAll(readKeywordsOf(subject));
>             }
>       }
> }
> 
> I modeled keywords of classe by using has-restrictions on the class with the
> appropiate keyword. I assume the class keywords dont show in the iterator
> defined above, because i need to iterate over restrictions and not the
> keywordProp. 

I'm not clear on whether you want to find instances with values
inferrable as a result of hasValue restrictions or to find the classes
which are subject to those restrictions.

If you just want individuals then you could switch on a reasoner (e.g.
OWLMicro or Pellet) and your instance level query will work.

If you want the classes (either because that's your aim or because you
want to avoid full inference and use the classes as a stepping stone to
the instances) then you need a couple of steps.

To find the restrictions then you can use SPARQL or the RDF API.
Remember that hasValue restrictions look like:

   [] a owl:Restriction;
        owl:onProperty p;
        owl:hasValue   v.

So you can find all subjects which have (owl:onProperty p) or
(owl:hasValue v) or both depending on which of p and v you are looking
up.

>From there to find the classes which are subject to that restriction you
can traverse the rdfs:subClassOf links. You can do this at the RDF level
or you can coerce your restriction into a Restriction object and use the
OntAPI to search the subclass links.

You can put the two steps together in one SPARQL query using SPARQL
1.1's property patterns.

Dave


Reply via email to