简体   繁体   English

OWL API-如何向OWL文件添加新的类,属性,个人?

[英]OWL API- how to add new classes, properties, individuals, to OWL file?

I want to add a new class, properties to the OWL file which is created from protege. 我想向由protege创建的OWL文件添加一个新的类,属性。 I need to update the owl file. 我需要更新猫头鹰文件。 This is the code that i have tried to add a class. 这是我试图添加一个类的代码。 But it doesnot updated the original OWL file. 但是它不会更新原始的OWL文件。 Only the output of netbeans IDE provide the updated OWL file. 只有netbeans IDE的输出提供更新的OWL文件。

 OWLDataFactory df = OWLManager.getOWLDataFactory();

 OWLEntity entity = df.getOWLEntity(EntityType.CLASS, IRI.create("#newclass"));

 OWLAxiom declare = df.getOWLDeclarationAxiom(entity);
 manager.addAxiom(ontology,declare );

You need to create an OWL storer object: 您需要创建一个OWL存储对象:

AbstractOWLStorer storer = new FunctionalSyntaxStorer();

Here I am creating a storer that will store the ontology in functional syntax format. 在这里,我正在创建一个存储器,它将以功能语法格式存储本体。 You can use a different constructor for different format (XML, etc.). 您可以将不同的构造函数用于不同的格式(XML等)。

storer.storeOntology(ontology, new FileDoumentTarget(new File(filePath)), new FunctionalSyntaxDocumentFormat());

For more specific details about the format you want to store the ontology, check the docs online: http://owlcs.github.io/owlapi/apidocs_4_0_2/org/semanticweb/owlapi/util/AbstractOWLStorer.html 有关要存储本体的格式的更多详细信息,请在线检查文档: http : //owlcs.github.io/owlapi/apidocs_4_0_2/org/semanticweb/owlapi/util/AbstractOWLStorer.html

You need to actually save the ontology back to the file. 您实际上需要将本体保存回文件中。 Use 采用

manager.saveOntology(ontology);

to achieve that. 实现这一目标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM