ontology - How to add an individual to a class using OWL API? -
i wand add individual class, , referenced doc in owl api official site.
here code.
public void addindividualstoclass(string classname, string indname) throws owlontologystorageexception{ /* * add individual input class */ owlclass tclass = fac.getowlclass(iri.create(ns + classname)); owlnamedindividual tindividual = fac.getowlnamedindividual(iri.create(ns + indname)); owlclassassertionaxiom classassertion = fac.getowlclassassertionaxiom(tclass, tindividual); manager.addaxiom(ont, classassertion); manager.saveontology(ont, new streamdocumenttarget(new bytearrayoutputstream())); }
then, eclipse throws exception.
exception in thread "main" java.lang.illegalargumentexception: comparison method violates general contract! @ java.util.comparabletimsort.mergelo(comparabletimsort.java:714) @ java.util.comparabletimsort.mergeat(comparabletimsort.java:451) @ java.util.comparabletimsort.mergecollapse(comparabletimsort.java:376) @ java.util.comparabletimsort.sort(comparabletimsort.java:182) @ java.util.comparabletimsort.sort(comparabletimsort.java:146) @ java.util.arrays.sort(arrays.java:472) @ java.util.collections.sort(collections.java:155) @ org.coode.owlapi.owlxml.renderer.owlxmlobjectrenderer.visit(owlxmlobjectrenderer.java:184) @ uk.ac.manchester.cs.owl.owlapi.owlontologyimpl.accept(owlontologyimpl.java:1630) @ org.coode.owlapi.owlxml.renderer.owlxmlrenderer.render(owlxmlrenderer.java:106) @ org.coode.owlapi.owlxml.renderer.owlxmlontologystorer.storeontology(owlxmlontologystorer.java:73) @ org.semanticweb.owlapi.util.abstractowlontologystorer.storeontology(abstractowlontologystorer.java:174) @ uk.ac.manchester.cs.owl.owlapi.owlontologymanagerimpl.saveontology(owlontologymanagerimpl.java:870) @ uk.ac.manchester.cs.owl.owlapi.owlontologymanagerimpl.saveontology(owlontologymanagerimpl.java:861) @ test.addindividualstoclass(test.java:146) @ test.main(test.java:155)
can me?
this should work. should take @ examples.java on owl-api page @ http://owlapi.sourceforge.net/index.html
public static void createnewonto() throws owlontologycreationexception, owlontologystorageexception { owlontologymanager manager = owlmanager.createowlontologymanager(); iri ontologyiri = iri.create("http://example.com/owlapi/families"); owlontology ont = manager.createontology(ontologyiri); owldatafactory factory = manager.getowldatafactory(); owlindividual john = factory.getowlnamedindividual(iri .create(ontologyiri + "#john")); owlindividual mary = factory.getowlnamedindividual(iri .create(ontologyiri + "#mary")); owlindividual susan = factory.getowlnamedindividual(iri .create(ontologyiri + "#susan")); owlindividual bill = factory.getowlnamedindividual(iri .create(ontologyiri + "#bill")); owlobjectproperty haswife = factory.getowlobjectproperty(iri .create(ontologyiri + "#haswife")); owlobjectpropertyassertionaxiom axiom1 = factory .getowlobjectpropertyassertionaxiom(haswife, john, mary); addaxiom addaxiom1 = new addaxiom(ont, axiom1); // apply change using manager. manager.applychange(addaxiom1); system.out.println("rdf/xml: "); manager.saveontology(ont, new streamdocumenttarget(system.out)); }
Comments
Post a Comment