你的问题不是很清楚。如果您询问如何保存已创建的模型,则需要将其写入文件:
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) {} } }
见 耶拿文件 有关编写RDF的更多详细信息。
或者,如果您的问题是关于如何添加本体的实例,请参阅中的示例 本体API文档 。作为一个提示,粗略地说你想得到一个 OntClass 对应于要创建实例的OWL类的对象:
OntClass
OntModel m = ... your model ... ; String ns = "http://example.com/example#"; OntClass foo = m.getOntClass( ns + "Foo" ); Individual fubar = foo.createInstance( ns + "fubar" );
如果这不能解决您的问题,请更新您的问题并提供更多详细信息,最好是您已经尝试过的代码示例。
的 更新 强>
好的,我已经看到了你的更新代码。对于Prot,我们只需要用XML编写文件,这样就可以删除行来编写Turtle格式。但你真正的问题是这样的行:
jenaModel.createIndividual("compoundURI" )
"compoundURI" 不是有效的URI - 这是错误消息告诉您的内容。您需要一个符合HTTP之类的有效URI方案的完整URI。所以,像:
"compoundURI"
jenaModel.createIndividual( OT.NS + compoundURI );