Assign missing datatypes

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

Assign missing datatypes

Mike Bergman
Hi,

I have been unsuccessful in finding ways to assign custom or non-owlready2 datatypes to properties. I specifically want to assign xsd.anyURI, xsd.hexBinary and wgs84. For the first option, I tried the 'normstr' for anyURI, but that did not work either.

Is there a recipe for setting new datatypes?

Thanks! Continues to be great . . .

Best, Mike
Reply | Threaded
Open this post in threaded view
|

Re: Assign missing datatypes

Jiba
Administrator
Hi,

You're right, there is no way to add custom datatype in Owlready... I've added the declare_datatype() global function for that, in the development version on BitBucket.

Here is an example:

class Hex(object):
    def __init__(self, value):
    self.value = value
   
def parser(s):
    return Hex(int(s, 16))
   
def unparser(x):
    h = hex(x.value)[2:]
    if len(h) % 2 != 0: return "0%s" % h
    return h
   
declare_datatype(Hex, "http://www.w3.org/2001/XMLSchema#hexBinary", parser, unparser)

onto = world.get_ontology("http://www.test.org/t.owl")
   
with onto:
    class p(Thing >> Hex): pass
    class C(Thing): pass
    c1 = C()
    c1.p.append(Hex(14))


Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Assign missing datatypes

Mike Bergman
Hi jiba,

Thank you, most excellent! I assume this enhancement may make it into the next formal release, correct?

BTW, one of the reasons I liked owlready2 during my early due dligence was the responsiveness you have shown to user requests since you first released the package. While I can not contribute code, please let me know if you ever need any documentation assistance.

Best, Mike
Reply | Threaded
Open this post in threaded view
|

Re: Assign missing datatypes

Jiba
Administrator
Hi,

> I assume this enhancement may make it into the next formal release, correct?

Of course!

For sure, Owlready documentation could be improved. Could you have a look at it ? There are certainly missing information, but it's difficult to me to identify them.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Assign missing datatypes

phiofx
In reply to this post by Mike Bergman
would it make sense to collect common custom datatypes in a distinct module? Almost everyone using owlready will come to this post at some point :-). Maybe something like the community providers structure?  
Reply | Threaded
Open this post in threaded view
|

Re: Assign missing datatypes

Jiba
Administrator
Hi,

This is an interesting idea. You may either propose some structure, or possiby we can add a subpackage in owlready with various user-contributed modules for custom datatype.

Jiba