1

我通过 Protege 创建了我的本体。我的本体有一些类和实例。现在我将通过 jena 添加其他类和实例,这就是为什么我编写下面的代码来在这个类中创建一个新类和一个实例。新类的名称是“person”,新实例的名称是“base”。当我在 java 中运行此代码时,它可以正常工作并创建类和实例。但是当我回到 protege 时,我看不到新课程和新实例。你有什么想法可以帮助我。谢谢

public void create_model(){                   
    modelMem = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM);
    ModelMaker modelMaker = ModelFactory.createFileModelMaker("Ontologies/VBnet.owl");
    Model modeltmp = modelMaker.createDefaultModel();
    modelMem = ModelFactory.createOntologyModel(OntModelSpec.OWL_DL_MEM, modeltmp);
    System.out.println("Model has been Successfully Built");

}
public void addFile() {
    System.out.println("Loading from FOAF instance File");
    InputStream inFoafInstance =FileManager.get().open("Ontologies/VBnet.owl");
    modelMem.read(inFoafInstance, defaultNameSpace);
    //inFoafInstance.close();
    System.out.println(modelMem.toString());

}
public void adddata() {
   OntClass person = modelMem.createClass(defaultNameSpace + "Person");
   Individual l1 = modelMem.createIndividual( defaultNameSpace + "base", person );
   for (Iterator i = l1.listRDFTypes(true); i.hasNext(); )
       System.out.println( l1.getURI() + " is asserted in class " + i.next() );
}

public static void main(String[] args) {
    AddInfo add=new AddInfo();
    add.create_model();
    add.addFile();
    add.adddata();
}
4

1 回答 1

4

您似乎没有保存更改后的模型:

OutputStream out = new FileOutputStream("altered.rdf");
modelMem.write( out, "RDF/XML-ABBREV"); // readable rdf/xml
out.close();
于 2010-10-26T09:11:14.507 回答