Java 将属性添加到单个并将它们全部插入my file.owl
我有一个班,Java 将属性添加到单个并将它们全部插入my file.owl,java,jena,owl,Java,Jena,Owl,我有一个班,MAN。我想添加一个具有以下属性的个人,jack: hasage="50" hasadress="france" 如何创建我的个人jack,向他添加属性并将它们保存到我的文件database.owl?这是接线。我使用Eclipse和Jena API JenaOWLModel-owlModel; OntModel模型; owlModel=ProtegeOWL.createJenaOWLModelFromURI(“file:///C:/database.owl"); model=o
MAN
。我想添加一个具有以下属性的个人,jack
:
hasage="50"
hasadress="france"
如何创建我的个人jack
,向他添加属性并将它们保存到我的文件database.owl
?这是接线。我使用Eclipse和Jena API
JenaOWLModel-owlModel;
OntModel模型;
owlModel=ProtegeOWL.createJenaOWLModelFromURI(“file:///C:/database.owl");
model=owlModel.getOntModel();
我请求你帮助我,我的论文答辩还需要五天时间。这段代码工作得很好。我可以在我的file.owl文件中保存个人,但我无法为这些个人添加属性并使用保存 请帮帮我该怎么办,我真的很担心,提前多谢了
public class testins {
static JenaOWLModel owlModel ;
public static void main(String[] args) {
OntModel model;
javax.swing.JDialog jDialog1 = new javax.swing.JDialog();
try{
owlModel = ProtegeOWL.createJenaOWLModelFromURI("file:///D:/file.owl");// the link of my owl file
model = owlModel.getOntModel();
JOptionPane.showMessageDialog(jDialog1,
"loaded with success","Information",JOptionPane.INFORMATION_MESSAGE);
}
catch(Exception e){
JOptionPane.showMessageDialog(jDialog1,
"error",
"Information",
JOptionPane.INFORMATION_MESSAGE);
}
OWLNamedClass theAlert = owlModel.getOWLNamedClass("Alert"); //my class Alert
theAlert.createOWLIndividual("indivname1"); //i add here an indevidual
theAlert.createOWLIndividual("indivname2"); //i add here another indevidual
// now how to add to those two Individuals properties ?? each individual has 2
// properties , the property witch its name est_evaluer and the second est_analyser those
// to properties will contain values so here is my problem how to add those values to an
// individual and save all of them
Collection errors ;
String fileName ;
fileName= ("D:/file.owl");
errors = new ArrayList();
//here i'll save it and it work ,it mean that i find in my file "file.owl"
//individuals i added witch are "indivname1" and "indivname2" in my class ALERT
// so now my problem is how to add properties to those indiviuals i add , and save them also
try{ owlModel.save(new File(fileName).toURI(), FileUtils.langXMLAbbrev, errors);
System.out.println("File saved with " + errors.size() + " errors.");
}
catch(Exception e){
}
}
}您没有说明您使用的名称空间是什么。所以我假设
http://example.org/example#
,根据需要进行调整
String NS = "http://example.org/example#";
// create ex:Man class
OntClass man = model.createClass( NS + "Man" );
// create individual ex:jack
Individual jack = model.createIndividual( NS + "jack", man );
// create some properties - probably better to use FOAF here really
DatatypeProperty age = model.createDatatypeProperty( NS + "age" );
DatatypeProperty address = model.createDatatypeProperty( NS + "address" );
jack.addProperty( age, model.createTypedLiteral( 50 ) )
.addProperty( address, model.createLiteral( "France" ) );
问题是什么呢?对于@fGo的评论,到目前为止你做了什么?那它怎么办还没起作用?Jena的OntModel接口提供了创建个体的方法,而个体(和资源)接口提供了添加属性断言的方法。它们不适合你的需要吗?我真的找不到那些方法?我有这些防御措施?还有10天,我真的需要帮助?lot@FreedomOfSpeech它们都在Jena的javadocs中;这些都是很好的起点。thanx很多,但是如何保存我的模型呢?我添加到其中的新个人+属性。请参阅文档: