Save ontology file OWL API -
i saving owl file shown in owl api example file.
file file = file.createtempfile("sample", "saving"); owlontologyformat format = manager.getontologyformat(ontology); owlxmlontologyformat owlxmlformat = new owlxmlontologyformat(); if (format.isprefixowlontologyformat()) { owlxmlformat.copyprefixesfrom(format.asprefixowlontologyformat()); } manager.saveontology(ontology, owlxmlformat, iri.create(file.touri()));
i tried following code.
file file = new file("sample.owl"); owlontologyformat format = manager.getontologyformat(ontology); owlxmlontologyformat owlxmlformat = new owlxmlontologyformat(); if (format.isprefixowlontologyformat()) { owlxmlformat.copyprefixesfrom(format.asprefixowlontologyformat()); } manager.saveontology(ontology, owlxmlformat, iri.create(file.touri()));
both methods failed save file. please help.
edit:
following codes creating ontology , manager
manager = owlmanager.createowlontologymanager(); reasonerfactory = (owlreasonerfactory) pelletreasonerfactory.getinstance(); datafactory = manager.getowldatafactory(); pm = new defaultprefixmanager(base_url); file file = new file(filename); owlontology ontology = null; try { ontology = manager.loadontologyfromontologydocument(file); } catch (owlontologycreationexception e) { system.out.println("fail load file. " + e); }
for information, following code able save (modified) ontology original file.
manager.saveontology(ontology);
thank you.
the following code should read existing ontology file (test.owl
) , save in different format (test-format.owl
). make sure original file exists , contains axioms (the getaxiomcount()
method.
//create manager owlontologymanager manager = owlmanager.createowlontologymanager(); //file existing ontology - make sure it's there! file file = new file("/home/test.owl"); //load ontology file owlontology ontology = manager.loadontologyfromontologydocument(file); //check if ontology contains axioms system.out.println("number of axioms: " + ontology.getaxiomcount()); //create file new format file fileformated = new file("/home/test-format.owl"); //save ontology in different format owlontologyformat format = manager.getontologyformat(ontology); owlxmlontologyformat owlxmlformat = new owlxmlontologyformat(); if (format.isprefixowlontologyformat()) { owlxmlformat.copyprefixesfrom(format.asprefixowlontologyformat()); } manager.saveontology(ontology, owlxmlformat, iri.create(fileformated.touri()));
Comments
Post a Comment