Thank you very much for your reply. I did try the example code but found that I couldn't just create the datatype without creating an instance and data property. In Protege, for example, it seems possible just to create a new datatype.
I also found that my modification of your code created some extra classes as well but I expect I was doing something stupid there...
Thank you again!
from owlready2 import *
onto_path.append('/home/spc93/ontology/')
onto = get_ontology('
http://test.org/owlready2_test_datatypes_2.owl')
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)
declare_datatype(Hex, '
http://test.org/datatype#mynewtype', parser, unparser)
with onto:
class p(Thing >> Hex): pass
class C(Thing): pass
c1 = C()
c1.p.append(Hex(14))
onto.save()
Steve Collins