Adding Custom Datatypes to Property Restrictions

classic Classic list List threaded Threaded
2 messages Options
ehe
Reply | Threaded
Open this post in threaded view
|

Adding Custom Datatypes to Property Restrictions

ehe
This post was updated on .
Hi,

Since the datatype for rdfs:Literal is not present in owlready2, I wanted to define it according to the Hex- example and then use it in a property restriction:

prop_restriction = prop.some(RDFSLiteral)

to create something like this:

<owl:Restriction>
  <owl:onProperty rdf:resource="http://someproperty"/>
  <owl:someValuesFrom rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/>
</owl:Restriction>

This does not work with custom datatypes, neither with declare_datatype before this statement, nor with define_in_ontology.

The only solution I see at the moment is to add the IRI with _universal_abbrev_datatype in the base.py like 'locstring'. Any idea?

Erik


Edit: I found another workaround where the code does not need to be customized.
The solution is to declare the required Datatype class within the namespace and then pass it to the property restriction:

        onto = get_ontology('http://www.w3.org/2000/01/rdf-schema#')
        with onto:
                class Literal(DatatypeProperty):
                        pass

        prop_restriction = prop.some(onto.Literal)
Reply | Threaded
Open this post in threaded view
|

Re: Adding Custom Datatypes to Property Restrictions

Jiba
Administrator
Hi,

What is the exact problem you get ? I tried the following and it seems to work:


from owlready2 import *

class MyDataType(object):
  def __init__(self, value):
    self.value = value
def parser(s): return s
def unparser(x): return s

declare_datatype(MyDataType, "http://test.org/onto.owl#MyDataType", parser, unparser)

onto = get_ontology("http://test.org/onto.owl#")

define_datatype_in_ontology(MyDataType, "http://test.org/onto.owl#MyDataType", onto)

with onto:
    class p(Thing >> MyDataType): pass
    class C(Thing):
        is_a = [p.some(MyDataType)]
       
onto.save("/tmp/t.owl")


When opened in Protégé, the OWL file include the SOME restriction on the datatype, as expected.

Jiba