Solution to exercises on semantics and reasoning

Exercise 1

1.1 RDFS

The ontology astronomy_ont.ttl (available here) should look something like this:

@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
@prefix owl: <http://www.w3.org/2002/07/owl#> .
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
@prefix exo: <http://example.org/ont/> .

exo:Astronomoical_object a owl:Class .

exo:Solar_system a owl:Class ;
    rdfs:subClassOf exo:Astronomoical_object .

exo:Planet a owl:Class ;
    rdfs:subClassOf exo:Astronomoical_object .

exo:Star a owl:Class ;
    rdfs:subClassOf exo:Astronomoical_object .

exo:Moon a owl:Class ;
    rdfs:subClassOf exo:Astronomoical_object .

exo:orbitsStar a owl:ObjectProperty ;
    rdfs:domain exo:Astronomoical_object ;
    rdfs:range exo:Star ;
    rdfs:subPropertyOf exo:orbits .

exo:orbitsPlanet a owl:ObjectProperty ;
    rdfs:domain exo:Moon ;
    rdfs:range exo:Planet ;
    rdfs:subPropertyOf exo:orbits .

exo:orbits a owl:ObjectProperty ;
    rdfs:domain exo:Astronomoical_object ;
    rdfs:range exo:Astronomoical_object .

exo:discovered a owl:DatatypeProperty ;
    rdfs:domain exo:Astronomoical_object ;
    rdfs:range xsd:date .

exo:density a owl:DatatypeProperty ;
    rdfs:domain exo:Astronomoical_object ;
    rdfs:range xsd:decimal .

One then tanslates this together with the downloaded astronomy.ttl into astronomy.lore with:

java -jar triplelore.jar -o astronomy.lore astronomy.ttl astronomy_ont.ttl

Then, one translates and loads the result directly into the database with

java -jar lore.jar <flags> astronomy.lore

where <flags> are the common connection details to the database.

You should now in your database have one schema per prefix, and one table per property and class within the corresponding prefix schema.

1.2 SPARQL

1.2.1

The first SPARQL query orbits.sparql would look like:

PREFIX exo: <http://example.org/ont/>

SELECT ?obj ?orbits
WHERE {
    ?obj exo:orbits ?orbits .
}

Note that this query could also have been answered as easily in SQL with

SELECT *
FROM exo.orbits;

1.2.2

The second query planets.sparql would look like:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX exo: <http://example.org/ont/>

SELECT ?planet
WHERE {
    ?planet rdf:type exo:Planet .
}

Note that this query could also have been answered as easily in SQL with

SELECT *
FROM exo.planet;

1.2.3

Why is e.g. exd:earth inferred to be a planet but not e.g. exd:mercury nor exd:neptune? Answer: exd:earth is inferred to be a planet because it has something (exd:moon) which exo:orbitsPlanet it, and exo:orbitsPlanet has range exo:Planet. However, exd:mercury does not have anything orbiting it. exd:neptune has moons, and they are set to orbit it, but via the more general exo:orbits-property, which only has range exo:Astronomical_body.

3. Rules

1.-7.: The rules can be found here. 8. Use SPARQL to query for all exo:equals-relationships:

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX exo: <http://example.org/ont/> 
PREFIX exd: <http://example.org/data/> 

SELECT ?object ?equals 
WHERE {
  ?object exo:equals ?equals .
}

Also query for all exo:unequals-relationships.

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX exo: <http://example.org/ont/> 
PREFIX exd: <http://example.org/data/> 

SELECT ?object ?unequals 
WHERE {
  ?object exo:unequals ?unequals .
}
  1. If one adds e.g. exd:earth exo:orbits exd:earth . and query with
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> 
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> 
PREFIX exo: <http://example.org/ont/> 
PREFIX exd: <http://example.org/data/> 

SELECT ?desc 
WHERE {
    ?blank exo:inconsistency ?desc .
}

we get:

-------------------------------------------------------------------------------------------------
| desc                                                                                          |
=================================================================================================
| "http://example.org/data/earth and http://example.org/data/earth are both equal and unequal!" |
| "http://example.org/data/earth is unequal to itself!"                                         |
-------------------------------------------------------------------------------------------------

4. Meaning from structure in RDF, revisited

  1. The RDFS statements can be seen here. You should see that they all have rdf:type rdfs:Property after loading the rules.
  2. The rules encoding ex:pong as equality can be found here.
  3. The rules encoding ex:pong as superproperty can be found here.

5

No, in general this is not possible. For example, the rule:

[eq3: (?x exo:equals ?y) (?x ?r ?z) -> (?y ?r ?z) ]

cannot be expressed in Lore, as we cannot have variables bound to properties, as this would result in variables as tables/relations, which is not allowed.

One could, of course, write one rule per property for ?r, but this results in a lot of rules, and a very manual process!