Lab: OWL 1

From Info216
Revision as of 18:41, 4 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)
  • OntModel (createClass, createIndividual, createObjectProperty, CreateDatatypeProperty, createAllDifferent, createSymmetricProperty, createTransitiveProperty, createInverseFunctionalProperty)
  • OntClass, Individual, DatatypeProperty, ObjectProperty

Note that the OntModel interface extends InfModel and Model.


Extend the RDF and RDFS graphs from earlier to account for the following situation:

Consider the following situtations: 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".)

Create a graph from this scenario using OWL triples in RDFlib.. If you can, try to build on your example from labs 2 and 3!

# Task 2: Properties
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 make new triples for each one that describing them as any of the following: a reflexive , irreflexive, symmetric, asymmetric, transitive, or a functional property.

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.

Use OntModel.writeAll() to write out the whole ontology, including OWL's built-in axioms (note that sending it to WebVOWL may not work.) Add a reasoner to your OntModel, for example ModelFactory.createOntology(OntModelSpec.OWL_MEM_RULE_INF), and writeAll() again. Can you spot any inferences?

If you have more time...