Dear Mr Jean-Baptiste Lamy,
I try to save a dynamic created triple, but python says my onto.save() have something error. I realize it is my fault about calling the add_triple(), but I don't know how to handle it. can you give me some help? Code as follow: from owlready2 import * onto_path.append("d:\\") onto = get_ontology("http://www.lesfleursdunormal.fr/static/_downloads/pizza_onto.owl") onto.load() class Drug(Thing): def take(self): print('I took a drug') myClass = types.new_class("myClass",Drug.__bases__) onto.add_triple(myClass.storid,rdf_type,owl_class) onto.save() Thanks in advance for your attention! Best Regards, WJ |
Administrator
|
Hello,
I've investigated the problem. The problem is that you did not mentioned in which ontology the classes are created; the right code should be: from owlready2 import * onto_path.append("/tmp") onto = get_ontology("http://www.lesfleursdunormal.fr/static/_downloads/pizza_onto.owl") onto.load() with onto: class Drug(Thing): def take(self): print('I took a drug') with onto: myClass = types.new_class("myClass", Drug.__bases__) onto.add_triple(myClass.storid, rdf_type, owl_class) onto.save() The "with onto:" syntax indicates that the classes are created in ontology onto. Adding triple directly to the quadstore is OK (although not yet documented). However, please notice that, here, it is not necessary to add the triple (myClass.storid, rdf_type, owl_class), because the new class creation already asserts this triple. I'm considering adding an error for classes created with no associated ontology (this would lead to more clear error message in your situation). Best regards, Jean-Baptiste Lamy MCF, LIMICS, Université Paris 13 > Dear Mr Jean-Baptiste Lamy, > > I try to save a dynamic created triple, but python says my onto.save() have > something error. > I realize it is my fault about calling the add_triple(), but I don't know > how to handle it. > can you give me some help? > > Code as follow: > > from owlready2 import * > > onto_path.append("d:\\") > onto = > get_ontology("http://www.lesfleursdunormal.fr/static/_downloads/pizza_onto.owl") > onto.load() > > class Drug(Thing): > def take(self): print('I took a drug') > > myClass = types.new_class("myClass",Drug.__bases__) > onto.add_triple(myClass.storid,rdf_type,owl_class) > onto.save() > > > Thanks in advance for your attention! > Best Regards, > WJ > > > > _______________________________________________ > If you reply to this email, your message will be added to the discussion below: > http://owlready.8326.n8.nabble.com/How-to-save-the-triple-which-made-up-of-dynamic-created-class-tp100.html > To start a new topic under Owlready, email [hidden email] > To unsubscribe from Owlready, visit |
Thanks for your feedback !
It' works! I have another question :). In my code, I replace owl.Thing with Drug.__bases__ when dynamic creating class. The reason why I use a subclass' superclass rather than itself is that I failed to use any correct parameter in the function.Could you give me same typical example? Thanks in advance for your attention! Again! Best Wishes, WJ |
Free forum by Nabble | Edit this page |