Re: [newbie] Question about linking to an ontology

On 26 Nov 2008, at 6:17 AM, Barry Nauta wrote:

> Hello all,
>
> For the university, we need to calculate the compatibility of two  
> persons,
> based on their FOAF-profiles. My idea was (amongst others) to  take  
> a look
> at the interests of people and resolve whether they are similar.  
> Here is
> what I am trying to do
>
> Person A has the following in his profile:
>
>    <foaf:interest
>        rdf:resource="http://en.wikipedia.org/wiki/Taekwondo" />
>
> Person B has the following:
>
>    <foaf:interest
>        rdf:resource="http://en.wikipedia.org/wiki/Soccer"  />

:personA rdf:type foaf:Person ;
          foaf:interest <http://en.wikipedia.org/wiki/Taekwondo> .

:personB rdf:type foaf:Person ;
          foaf:interest <http://en.wikipedia.org/wiki/Soccer> .

> Via an ontology, I would like to conclude that they are both  
> interested in
> sports:
>
> <owl:Class rdf:ID="Sports" />
> <owl:Class rdf:ID="Taekwondo">
>    <subClassOf rdf:resource="#Sports"/>
>    <label xml:lang="en">Taekwondo</label>
>    <label xml:lang="nl">Taekwondo</label>
>    <owl:sameAs
>        rdf:resource="http://en.wikipedia.org/wiki/Taekwondo" />
> </owl:Class>
> <owl:Class rdf:ID="Soccer">
>    <rdfs:subClassOf rdf:resource="#Sports" />
>    <label xml:lang="en">Soccer</label>
>    <label xml:lang="nl">Voetbal</label>
> </owl:Class>

These things are always much easier to read in Turtle, and it's closer  
to the SPARQL syntax... eg, is the label in your xml actual  
rdfs:label, or is it :label, it's hard for anyone to tell from this.  
If you print this out in Turtle the URL prefixes will be much clearer.

:Sports rdf:type owl:Class .

:Taekwondo rdf:type owl:Class ;
            rdfs:subClassOf :Sports ;
            rdfs:label "Taekwondo"@en ;
            owl:sameAs <http://en.wikipedia.org/wiki/Taekwondo> .

:Soccer rdf:type owl:Class ;
         rdfs:subClassOf :Sports ;
         rdfs:label "Soccer"@en .


Few questions at this stage:

1. :Soccer doesn't seem to have an owl:sameAs definition with <http://en.wikipedia.org/wiki/Soccer 
 >?
2. Are you sure that your reasoned model has all the statements you  
need?  Try writing it out in Turtle (model.writeAll(System.out,  
"Turtle", "") to check manually.
3. I don't think that the Jena createRDFSModel handles owl:SameAs  
(which is needed here).  Try Pellet or OWL_MEM_MICRO_RULE_INF (or FULL).

http://jena.sourceforge.net/inference/#owl

I think that referencing an owl:Class as the object of an  
ObjectProperty might put you in OWL FULL here.  There is a guide  
somewhere at the w3c which talks about using Classes as Individuals,  
specifically for interests, which might be relevant:

http://www.w3.org/TR/swbp-classes-as-values/

Then this SPARQL, you are only asking for personId, not person, which  
will make debugging hard, since the issue might be that the OPTIONAL  
personId doesn't exist, rather than the class relationships.  Maybe  
use * until you see the results you expect.


PREFIX foaf:   <http://xmlns.com/foaf/0.1/>
PREFIX rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX ont:    <http://localhost/f/sports.owl.rdf>
PREFIX rdfs:   <http://www.w3.org/2000/01/rdf-schema#>

SELECT ?personId ?interest
WHERE {
   ?person a foaf:Person .
   ?person foaf:interest ?interest .
   ?interest a ont:Sport .
   OPTIONAL { ?person foaf:maker ?personId } .
   OPTIONAL { ?person foaf:mbox ?personId } .
   OPTIONAL { ?person foaf:mbox_sha1sum ?personId } .
}


> I would like to get the information using SPARQL and that is where  
> things go
> wrong:
>
> Test for one person only using Jena:
>
>        Model schemaModel = ModelFactory.createDefaultModel().read("
> http://localhost/f/sports.owl.txt");
>        Model instanceModel =
> ModelFactory.createDefaultModel().read(fstUrl);
>        Model infModel = ModelFactory.createRDFSModel(schemaModel,
> instanceModel);
>        String queryString =
>            "PREFIX foaf:   <http://xmlns.com/foaf/0.1/> " +
>            "PREFIX rdf:    <http://www.w3.org/1999/02/22-rdf-syntax-ns# 
> > "
> +
>            "PREFIX ont:    <http://localhost/f/sports.owl.rdf> " +
>            "PREFIX rdfs:   <http://www.w3.org/2000/01/rdf-schema#> " +
>            "SELECT ?personId ?interest " +
>            " WHERE { " +
>            " ?person a foaf:Person . " +
>            " ?person foaf:interest ?interest . " +
>            " ?interest a ont:Sport . " +
>            " OPTIONAL { ?person foaf:maker ?personId } . " +
>            " OPTIONAL { ?person foaf:mbox ?personId } . " +
>            " OPTIONAL { ?person foaf:mbox_sha1sum ?personId } . " +
>            "}";
>        Query query = QueryFactory.create(queryString);
>        QueryExecution qe = QueryExecutionFactory.create(query,  
> infModel);
>        ResultSet results = qe.execSelect();
>        ResultSetFormatter.out(System.out, results);

In Jena I'd use:

OntModel model =  
ModelFactory.createOntologyModel( OWL_MEM_MICRO_RULE_INF );
model.read("http://localhost/f/sports.owl.txt");
model.read(fstUrl);

because I find that simpler than dealing with InfModels etc, the  
OntModel handles the reasoning.  If you want to see the "fully  
reasoned" content of the Model in triples (since that is what SPARQL  
queries against), be sure to use model.writeAll rather than  
model.write.  And use Turtle :)

hth,
James

Received on Wednesday, 26 November 2008 16:07:24 UTC