seth

SETH is a software effort to deeply integrate Python with Web Ontology Language (OWL-DL dialect). The idea is to import ontologies directly into the programming context so that its classes are usable alongside standard Python classes. This provides a more natural mapping of OWL-DL than classic APIs, reflecting the OWL-DL semantics, while preserving the access to the classic Python objects. It can be seen as an object interface for OWL-DL. Such integration encourages separation of concerns among declarative and procedural and encourages a new wave of programming, where problems can be defined by using description logics and manipulated by dynamic scripting languages. The approach represents a unification, that allows both languages to be conveniently used for different subproblems in the software-engineering environment.

Releases

The project is hosted by the SourceForge at http://sourceforge.net/projects/seth-scripting/. Initial release, which demonstrates some of the intergation ideas is available for download, it is released under the MIT license. Please consult the INSTALL file before installation. SETH requires JVM 1.4, Pellet and JPype.

The latest version can be obtained using anonymous CVS (pserver) by entering:
cvs -d:pserver:anonymous@seth-scripting.cvs.sourceforge.net:/cvsroot/seth-scripting login
cvs -z3 -d:pserver:anonymous@seth-scripting.cvs.sourceforge.net:/cvsroot/seth-scripting co -P seth

Getting started

A sample session shows an in-line definition of a class Person (N3 language is used). This is implemented by calling a static method new of the metaclass Thing (new is used to hide the complex metaclass call). An instance is created by calling the Person's constructor, which in fact creates an in-line declaration of the OWL individual (John). The print statements show the Python's view of the respective objects, i.e. Person as a class and John as an instance of the class Person. We also show a more complex definition of the PersonWithSingleSon.

>>> from seth import Thing, Property
>>> Person = Thing.new('Person a owl:Class .')
>>> Man = Thing.new(' :Man a owl:Class ; rdfs:subClassOf :Person .')
>>> John = Person('John')
>>> print Person
<class 'seth.Meta.Person'>
>>> print John
<seth.Meta.Person object at 0xb7a29e4c>
>>> PersonWithSingleSon = Thing.new('PersonWithSingleSon', \
    """ a owl:Class ; rdfs:subClassOf [ a owl:Restriction ;
     owl:cardinality "1"^^ ;
     owl:onProperty :hasSon
                                         ];
     rdfs:subClassOf [ a owl:Restriction ;
     owl:cardinality "1"^^ ;
     owl:onProperty :hasChild ] .""")

A similar way can be used for in-line declarations of OWL properties. Compared to a class declaration the returned Python class can not be instantiated (i.e. returns None ).

>>> hasChild = Property.new('hasChild a owl:ObjectProperty .')
>>> print hasChild
<class 'seth.Meta.hasChild'>
>>> hasSon = Property.new('hasSon a owl:ObjectProperty ;
rdfs:subPropertyOf :hasChild .')

Properties are naturally used to assign relationships between OWL classes or individuals, which can be as simple as calling:

>>> Bob = PersonWithSingleSon()
>>> hasChild(Bob, John)

Assuming we have declared several instances of the class Person we can find them by iterating over the class list. It is also possible to ask any triple like queries (the query shown also demonstrates reasoning about the property assertions).

>>> for individual in Person.findInstances():
...     print individual, individual.name
<seth.Meta.Man object at 0xb7d0b64c> Peter
<seth.Meta.Person object at 0xb7d0b50c> John
<seth.Meta.Person object at 0xb7d0b6ec> Jane
>>> for who in hasSon.q(Bob):
...     who.name
'John'
>>> print hasSon.q(Bob, John)
1

You can find the sources for this example in the release bundle in examples/ThingTest.py

Links