New datatype

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

New datatype

steve.collins@diamond.ac.uk
Hello, I'd appreciate help with the following:

Is it possible to create a new datatype without creating a new data property or individual?

Thanks for any advice!
Steve Collins
Reply | Threaded
Open this post in threaded view
|

Re: New datatype

Jiba
Administrator
Reply | Threaded
Open this post in threaded view
|

Re: New datatype

steve.collins@diamond.ac.uk
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