我有一個函數,當我點擊添加按鈕時,在RDF文件中添加類Person
的實例(及其屬性值)。我可以添加第一個實例,但是當我嘗試添加第二個實例時,它會將第一個實例替換爲第二個實例。如何增加資源?
我認爲這是因爲我沒有增加Resource P1 = model.createResource(personURI+"Name")
,添加第一個實例後。
如何將java中的Resource
從P1
增加到P2
到P3
等?
public class ActionAjoutPersonne implements ActionListener
{
public void actionPerformed(ActionEvent evt)
{
Onto f = new Onto();
Resource p1 = f.model.createResource(f.uriBase+tabTF[0].getText());
p1.addProperty(f.aPourPrenom, tabTF[0].getText());
p1.addProperty(f.aPourNom, tabTF[1].getText());
p1.addProperty(f.aDateNaiss, tabTF[2].getText());
if (tabTF[3].getText().equals("F"))
{
p1.addProperty(f.aGenre, tabTF[3].getText());
p1.addProperty(RDF.type, f.femme);
}
else if (tabTF[3].getText().equals("H"))
{
p1.addProperty(f.aGenre, tabTF[3].getText());
p1.addProperty(RDF.type, f.homme);
}
StringWriter sw = new StringWriter();
f.model.write(sw, "RDF/XML-ABBREV");
String owlCode = sw.toString();
File file = new File("d:/teste20.rdf");
try{
FileWriter fw = new FileWriter(file);
fw.write(owlCode);
fw.close();
} catch(FileNotFoundException fnfe){
fnfe.printStackTrace();}
catch(IOException ioe){
ioe.printStackTrace();
}
}
}
看來您使用相同的URL創建了多個資源。你能提供完整的代碼片段嗎? – CheatEx
嗨,謝謝你的回答。我編輯了我的文章並添加了按鈕添加的代碼。謝謝 –