使用Jena编写dataTypeProperties后,Protege Reasoner弹出错误

时间:2014-07-26 09:27:45

标签: rdf jena owl ontology protege

我创建了本体论文章。我有一些dataTypeProperties,其范围设置为整数,日期时间和字符串。

在我的java应用程序中,我使用Jena api写入owl文件,我使用这种方法处理dataTypeProperties。:

public void setDataTypeProperty(String resourceURI, String propertyName, String propertyValue) 
{
    if (resourceURI==null)
    return;

    Model model = ModelFactory.createDefaultModel();

    //read model from file
    InputStream in = FileManager.get().open(inputFileName);

     if (in == null) 
     {
         throw new IllegalArgumentException( "File: " + inputFileName + " not found");
     }       
     model.read(in, "");
     try {
        in.close();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }


     // Add property to Model
     Resource resource = model.createResource(resourceURI);
     resource.addProperty(model.createProperty(baseURI+propertyName), model.createLiteral(propertyValue));


     //Writing model to file
        try {
            FileWriter out = new FileWriter( inputFileName );
            model.write( out, "RDF/XML-ABBREV" );
            out.close();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
}

写入owl文件后,它看起来像这样:

....
<File rdf:about="http://www.semanticweb.org/administrator/ontologies/2014/2/untitled-ontology-5#677f5c75-7527-45e2-8430-829466027034"> 
    <filePeakLocation>ismaila swabi</filePeakLocation> //String Datatype
    <filePeakDay>6</filePeakDay> //Integer Datatype 
    <fileLastAccessed>2014-07-26T13:17:49</fileLastAccessed> //dateTime
    <created>2014-07-26T13:17:27</created> //dateTime
    <hasPath>/examples/run.sh</hasPath>  //String Datatype
    <fileAccessedLocation>ismaila swabi_atTime_2014-07-26T13:17:49</fileAccessedLocation>
    <filePeakHour>13</filePeakHour> //Integer
</File>
....

现在的问题是,如果我在protege中打开我的owl文件并运行推理器(Fact ++),它会弹出如下错误:

enter image description here

推理器显示的所有错误都是具有整数或dataTime数据类型范围的属性。带范围的属性不会出错。

有人可以指出错误的原因吗?

1 个答案:

答案 0 :(得分:4)

我很确定问题是你使用这个函数public void setDataTypeProperty()来编写字符串,整数和日期时间。您的函数将所有值写为普通文字。你应该检查TypedLiterals

在jena中尝试model.createTypedLiteral(arg0)