如何在Jena上正确实例化数据属性?

时间:2012-06-24 10:21:49

标签: jena ontology owl

我写了以下Jena代码。但这是一个错误,我不知道如何解决这个问题。

这是代码

Resource   subject   = null;
Property   property  = null;
Statement  statement = null;

...

OntModel domainModel = ModelFactory.createOntologyModel(ProfileRegistry.OWL_DL_LANG);
domainModel.read((new FileInputStream(bootstrapInOwl)), null);

subject = domainModel.getIndividual(bootbase + "Frame" + frameNum);                     
property = domainModel.getOntProperty(bootbase + "hasDuration");                
statement = domainModel.createLiteralStatement(subject, property, 12000);
domainModel.add(statement);

以下是错误消息

Exception in thread "main" java.lang.NullPointerException
    at com.hp.hpl.jena.rdf.model.impl.StatementImpl.<init>(StatementImpl.java:29)
    at com.hp.hpl.jena.rdf.model.impl.ModelCom.createStatement(ModelCom.java:1116)
    at com.hp.hpl.jena.rdf.model.impl.ModelCom.createLiteralStatement(ModelCom.java:626)
    at soctrace.Intology.manageOntologies2(Intology.java:217)
    at soctrace.Intology.main(Intology.java:56)

属性hasDuration域名为Frame类,而其范围为int

感谢您的回复!

1 个答案:

答案 0 :(得分:2)

以下两行中的一行似乎返回null指针:

subject = domainModel.getIndividual(bootbase + "Frame" + frameNum);                     
property = domainModel.getOntProperty(bootbase + "hasDuration");

验证您是否在寻找现有的URI。