java - 为个人添加属性并将它们全部插入我的 file.owl

标签 java jena owl

我有一个类(class),MAN。我想添加一个人,jack,具有以下属性:

 hasage="50"
 hasadress="france"

如何创建我的个人 jack 并向他添加属性并将它们保存到我的文件 database.owl 中?这是连接。我使用 Eclipse 和 Jena API。

  JenaOWLModel owlModel ;
  OntModel model;           
  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" ) );

关于java - 为个人添加属性并将它们全部插入我的 file.owl,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16860724/

相关文章:

java - SQL ORDER BY 子句可以与数据源中的任何列一起使用吗?

java - JavaFX TableView 中的重复列

java - 使用 Jena 和 AXIS 的 Web 服务上的 InvocationTargetException

java - 查询解决方案,保留 "< >"

sparql - OWL本体: SPARQL query a range or domain of an ObjectProperty when they're unionOf classes

java - Gradle 将已编译的 Java 类包含为模块依赖项

java - SWT UI 线程没有响应 - 打印错误

java - 读取 .owl 文件时出现 org.apache.jena.riot.RiotException

owl - 实例和子类之间的主要区别是什么?

owl - 选择用于开发本体的本体方法