我有一个函数,当我点击添加按钮时,在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
嗨,谢谢你的回答。我编辑了我的文章并添加了按钮添加的代码。谢谢 –