Adding custom datatype

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

Adding custom datatype

dguidi
Hi,
I would like to add a custom datatype for holding JSON objects.

Following the docs, I've done something like:

declare_datatype(jsonObject, "http://myorg/myschema#jsonObject", parser, unparser)

and I then added a DataProperty "has_json" that binds a Class to a jsonObject datatype.

However, if I save the ontology and I open it with Protege, strange things happens - the "has_json" property is defined both as ObjectProperty and DataProperty.

If instead I create the datatype inside Protege, then the resulting ontology will have an extra definition, which is not present in the ontology saved by owlready2:

<rdfs:Datatype rdf:about="http://myorg/myschema#jsonObject">

I noticed that if I add this definition to the ontology generated by owlready2, then the it looks fine when I open it in Protege ("has_json" is defined only as DataPrtoperty).

Is there a way for me to manually add a triple like that in owlready2 before saving the ontology?

Many thanks.

Reply | Threaded
Open this post in threaded view
|

Re: Adding custom datatype

Jiba
Administrator
Hi,

You can add the triple manually as follows:

onto._add_obj_triple_spo(onto.world._abbreviate("http://myorg/myschema#jsonObject"), rdf_type, rdfs_datatype)


In the examples I tested, the datatype was actually already defined (i.e. in RDFS or XSD).

I'm going to add an option in declare_datatype() for adding the datatype definition triple.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Adding custom datatype

dguidi
Many thanks Jiba,

That worked straight away, the ontology loads OK now in Protege.

I'm very impressed about owlready2, keep up the good work!