Lab: Even More OWL

From info216
Revision as of 11:22, 14 April 2022 by Sinoa (talk | contribs) (Created page with " =Lab 12: Even more OWL= ==Topics== OWL ontology programming with owlready2. <!-- ==Tutorial== --> ==Classes and methods== In an earlier lab, you have already used these O...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

Lab 12: Even more OWL

Topics

OWL ontology programming with owlready2.


Classes and methods

In an earlier lab, you have already used these OWL concepts:

  • (sameAs, equivalentClass, equivalentProperty, differentFrom, disjointWith, inverseOf)
  • (ReflexiveProperty, IrreflexiveProperty, SymmetricProperty, AsymmetricProperty, TransitiveProperty, FunctionalProperty, InverseFunctionalProperty),
  • (oneOf, unionOf, intersectionOf. complementOf)
  • (Restriction, onProperty)
  • (someValuesFrom, allValuesFrom, hasValue)
  • (cardinality, minCardinality, maxCardinality)
  • (qualifiedCardinality, minQualifiedCardinality, maxQualifiedCardinality, onClass)


Owlready2

This lab will re-write the same OWL expressions as in an earlier lab, but using owlready2 instead of rdflib.

The Project description and section What can I do with Owlready2? gives a brief introduction to installing and getting started with owlready2. You will find more documentation at Welcome to Owlready2's Documentation

For example:

# A graduate is a student with at least one degree.
with onto:
    class Student(Thing): pass
    class Degree(Thing): pass
    class hasDegree(Student >> Degree): pass
    class Graduate(Student): 
        is_a = [hasDegree.some(Degree)]


Tasks

Re-write the same OWL expressions as in an earlier lab, but using owlready2 instead of rdflib:

  • anyone who is a graduate has at least one degree
  • anyone who is a university graduate has at least one degree from a university
  • a grade is either an A, B, C, D, E or F
  • a straight A student is a student that has only A grades
  • a graduate has no F grades
  • a student has a unique student number
  • each student has exactly one average grade
  • a course is either a bachelor, a master or a Ph.D course
  • a bachelor student takes only bachelor courses
  • a master student takes only master courses, except for at most one bachelor course
  • a Ph.D student takes only Ph.D courses, except for at most two masters courses
  • a Ph.D. student cannot take any bachelor course


Code to get started

(These need more testing!)

Empty an ontology (otherwise owlready2 remembers ontologies between sessions!):

Print an ontology:

Print an ontology without standard triples:

To print an ontology without standard triples, you must first run this code at the beginning of the program:


If You Have More Time

Populate the ontology with individals, such as:

with onto:
    cade = Student()
    infosci = Degree()
    cade.hasDegree.append(infosci)

Try to use Hermit as in the lecture to infer additional triples. IMPORANT: Neither Hermit/Pellet nor OWL-RL are able to reason with the full OWL-DL. But unlike OWL-RL, Owlready2 supports reaosning over many types of restrictions.

Useful readings