How to create owl file using JENA?

雨燕双飞 提交于 2019-12-04 17:03:12

Your question isn't very clear. If you're asking about how to save the model that you have created, you need to write it out to a file:

OntModel m = .... your model .... ;
FileWriter out = null;
try {
  // XML format - long and verbose
  out = new FileWriter( "mymodel.xml" );
  m.write( out, "RDF/XML-ABBREV" );

  // OR Turtle format - compact and more readable
  // use this variant if you're not sure which to use!
  out = new FileWriter( "mymodel.ttl" );
  m.write( out, "Turtle" );
}
finally {
  if (out != null) {
    try {out.close()} catch (IOException ignore) {}
  }
}

See the Jena documentation for more details on writing RDF.

Alternatively, if your question is about how to add instances of your ontology, see the examples in the ontology API documentation. As a hint, roughly speaking you want to get an OntClass object that corresponds to the OWL class you want to create an instance of:

OntModel m = ... your model ... ;
String ns = "http://example.com/example#";
OntClass foo = m.getOntClass( ns + "Foo" );
Individual fubar = foo.createInstance( ns + "fubar" );

If that doesn't address your issue, please update your question with more details, and, ideally, a sample of the code that you have already tried.

Update

OK, I've seen your updated code. For Protégé, you only need to write the file in XML, so you can remove the lines to write the Turtle format. But your real problem is lines like this:

jenaModel.createIndividual("compoundURI" )

"compoundURI" is not a valid URI - which is what the error message is telling you. You need a full URI that conforms to one of the valid URI schemes like HTTP. So, something like:

jenaModel.createIndividual( OT.NS + compoundURI );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!