Lab: OWL 1

Revision as of 08:51, 6 March 2020 by Say004 (talk | contribs)

Lab 7: RDFS Plus / Basic OWL


Basic OWL ontology programming with RDFlib and owlrl.

WebVOWL visualisation.



  • OWL (sameAs, equivalentClass, equivalentProperty, differentFrom, disjointWith, inverseOf)


Task 1

Write OWL triples that corresponds to the following text. .If you can, try to build on your example from labs 2 and 7, or extend the triples at the bottom of the page.

Cade and Emma are two different persons. All the countries mentioned above are different. The country USA above is the same as the DBpedia resource (dbr:United_States) and the GeoNames resource (gn:6252001). The person class (the RDF type the Cade and Emma resources) in your graph is the same as FOAF's,'s and AKT's person classes (they are,, and, respectively. Nothing can be any two of a person, a university, or a city at the same time. The property you have used in your RDF/RDFS graph to represent that 94709 is the US zip code of Berkeley, California in US is a subproperty of VCard's postal code-property ( No two US cities can have the same postal code. The property you have used for Emma living in Valencia is the same property as FOAF's based near-property (, and it is the inverse of DBpedia's hometown property (, dbo:hometown). (This is not completely precise: but "hometown" is perhaps the inverse of a subproperty of "based near".)

Task 2

g.add((ex.Cade, ex.married, ex.Mary))
g.add((ex.Cade, ex.livesWith, ex.Mary))
g.add((ex.Cade, ex.sibling, ex.Andrew))
g.add((ex.Cade, ex.sibling, ex.Anna))
g.add((ex.Cade, ex.hasFather, ex.Bob))
g.add((ex.Bob, ex.fatherOf, ex.Cade))

Look through the predicates(properties) above and add new triples for each one that describes them as any of the following: a reflexive , irreflexive, symmetric, asymmetric, transitive, or a functional property. e.g

g.add((ex.married, RDF.type, OWL.SymmetricProperty))

Task 3

Print/Serialize the ontology. Then use owlrl to infer additional triples. Can you spot any inferences?

# These three lines add inferred triples to the graph.
owl = owlrl.CombinedClosure.RDFS_OWLRL_Semantics(g, False, False, False)

If you have more time...

Write the ontology to a TURTLE file, and try to visualise it using . WebVOWL is oriented towards visualising classes and their properties, so the individuals may not show.

Triples you can use for tasks

@prefix ex: <> .
@prefix foaf: <> .
@prefix rdf: <> .
@prefix rdfs: <> .
@prefix xml: <> .
@prefix xsd: <> .

ex:Cade a foaf:Person ;
    ex:address [ a ex:Address ;
            ex:city ex:Berkeley ;
            ex:country ex:USA ;
            ex:postalCode "94709"^^xsd:string ;
            ex:state ex:California ;
            ex:street "1516_Henry_Street"^^xsd:string ] ;
    ex:age 27 ;
    ex:characteristic ex:Kind ;
    ex:degree [ ex:degreeField ex:Biology ;
            ex:degreeLevel "Bachelor"^^xsd:string ;
            ex:degreeSource ex:University_of_California ;
            ex:year "2011-01-01"^^xsd:gYear ] ;
    ex:interest ex:Bird,
        ex:Travelling ;
    ex:married ex:Mary ;
    ex:meeting ex:Meeting1 ;
    ex:visit ex:Canada,
        ex:Germany ;
    foaf:knows ex:Emma ;
    foaf:name "Cade_Tracey"^^xsd:string .

ex:Mary a ex:Student,
        foaf:Person ;
    ex:age 26 ;
    ex:characteristic ex:Kind ;
    ex:interest ex:Biology,
        ex:Hiking .

ex:Emma a foaf:Person ;
    ex:address [ a ex:Address ;
            ex:city ex:Valencia ;
            ex:country ex:Spain ;
            ex:postalCode "46020"^^xsd:string ;
            ex:street "Carrer_de_la Guardia_Civil_20"^^xsd:string ] ;
    ex:age 26 ;
    ex:degree [ ex:degreeField ex:Chemistry ;
            ex:degreeLevel "Master"^^xsd:string ;
            ex:degreeSource ex:University_of_Valencia ;
            ex:year "2015-01-01"^^xsd:gYear ] ;
    ex:expertise ex:Air_Pollution,
        ex:Waste_Management ;
    ex:interest ex:Bike_Riding,
        ex:Travelling ;
    ex:meeting ex:Meeting1 ;
    ex:visit ( ex:Portugal ex:Italy ex:France ex:Germany ex:Denmark ex:Sweden ) ;
    foaf:name "Emma_Dominguez"^^xsd:string .

ex:Meeting1 a ex:Meeting ;
    ex:date "August, 2014"^^xsd:string ;
    ex:involved ex:Cade,
        ex:Emma ;
    ex:location ex:Paris .

ex:Paris a ex:City ;
    ex:capitalOf ex:France ;
    ex:locatedIn ex:France .

ex:France ex:capital ex:Paris .