【问题标题】:Protege Reasoner popups errors after writing dataTypeProperties using JenaProtege Reasoner 使用 Jena 编写 dataTypeProperties 后弹出错误
【发布时间】:2014-09-18 02:59:34
【问题描述】:

我在 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 文件并运行 reasoner (Fact++),它会弹出如下错误:

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

有人能指出错误的原因吗?

【问题讨论】:

    标签: rdf jena owl ontology protege


    【解决方案1】:

    我很确定问题在于您正在使用单个函数public void setDataTypeProperty() 来编写字符串、整数和日期时间。您的函数将所有值写入纯文字。你应该检查TypedLiterals

    在耶拿尝试model.createTypedLiteral(arg0)

    【讨论】:

    • 我使用了model.createTypedLiteral() 但是现在的问题是日期是用java格式写的,而不是XMLSchema#dateTime格式。现在看起来像这样:&lt;File rdf:about="http://www.semanticweb.org/administrator/ontologies/2014/2/untitled-ontology-5#5d1b7615-b5c7-45d5-aaa4-2d80915fe130"&gt; &lt;created rdf:datatype="java:java.util.Date"&gt;Sat Jul 26 16:03:42 PKT 2014&lt;/created&gt; &lt;hasPath rdf:datatype="http://www.w3.org/2001/XMLSchema#string" &gt;/Untitled Document&lt;/hasPath&gt; &lt;/File&gt;
    • 错误的数据类型。不是 java:java.util.Date,而是w3.org/2001/XMLSchema#dateTime。此外,2014 年 7 月 26 日星期六 16:03:42 PKT 不是合法的 XSD 日期时间。要么尝试使用日历(不是 java 日期),要么更好地控制并使用不同的 createTypedLiteral 调用来命名您想要的数据类型。
    • @AndyS 我试过日历,但它也写错了&lt;created rdf:datatype="java:java.util.Date"&gt;Sat Jul 26 17:37:27 PKT 2014&lt;/created&gt;请有人指导如何通过model.createTypedLiteral(date)存储xml日期
    • 如果您的数据类型为java:java.util.Date,听起来您实际上并没有使用日历。
    • @SyedRahmanMashwani Calendar#getTime() 返回一个日期,因此您仍然传递的是日期,而不是日历。如果你像安迪建议的那样做resource.addProperty(…,model.createTypedLiteral(cal)),你会得到什么?
    猜你喜欢
    • 1970-01-01
    • 2023-01-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多