2010-10-26 40 views
1

我通過Protege創建了我的本體論。我的本體有一些類和實例。現在我要通過jena添加其他類和實例,這就是爲什麼我編寫下面的代碼來創建一個新類和一個實例在這個類。新類的名稱是「person」,新實例的名稱是「base」。當我在java中運行這段代碼時,它沒有任何錯誤,並創建類和實例。但是當我回到保護區時,我看不到新的課程,也看不到新的實例。你有什麼想法來幫助我。 感謝使用jena修改預定義的本體論

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

你似乎並沒有把保存在改變模式:

OutputStream out = new FileOutputStream("altered.rdf"); 
modelMem.write(out, "RDF/XML-ABBREV"); // readable rdf/xml 
out.close();