SPARQL查询:如何从EARL文档中获取行号和字符号?

发布于 2024-12-08 16:31:15 字数 1778 浏览 0 评论 0 原文

这可能是一个相当新手的问题,但 RDF 图和 sparql 查询让我感到困惑。 这是我需要搜索的(EARL,评估和报告语言)RDF 文件的相关部分:

<earl:Assertion>
<earl:subject rdf:nodeID="A1"/>
<earl:assertedBy rdf:nodeID="A2"/>
<earl:test rdf:resource="http://www.w3.org/TR/xhtml1/#C_2"/>
<earl:mode rdf:resource="http://www.w3.org/ns/earl#automatic"/>
<earl:result>
  <earl:TestResult>
    <earl:pointer>
      <pnt:EquivalentPointers>
        <pnt:groupPointer>
          <pnt:LineCharPointer>
            <pnt:charNumber rdf:datatype="http://www.w3.org/2001/XMLSchema#positiveInteger"
            >108</pnt:charNumber>
            <pnt:lineNumber rdf:datatype="http://www.w3.org/2001/XMLSchema#positiveInteger"
            >9</pnt:lineNumber>
          </pnt:LineCharPointer>
        </pnt:groupPointer>
        <pnt:groupPointer>
          <pnt:CharOffsetPointer>
            <pnt:offset rdf:datatype="http://www.w3.org/2001/XMLSchema#positiveInteger"
            >935</pnt:offset>
          </pnt:CharOffsetPointer>
        </pnt:groupPointer>
      </pnt:EquivalentPointers>
    </earl:pointer>
    <earl:outcome rdf:resource="http://www.w3.org/ns/earl#failed"/>
    <dct:description rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >A space character is missing before '/&gt;'.</dct:description>
  </earl:TestResult>
</earl:result>
</earl:Assertion>

我想从这段摘录中获得什么:lineNumber(和 charNumber),earl:outcome 失败的事实,以及描述。到目前为止,我所能得到的只是行号,但结果却给出了行号 +"^^http://www.w3.org/2001/XMLSchema#positiveInteger”。我不知道为什么会这样。

感谢您的帮助!

This might be a rather novice question but RDF graphs and sparql queries just confuse me.
This is the relevant part of an (EARL, Evaluation And Report Language) RDF file that I need to search:

<earl:Assertion>
<earl:subject rdf:nodeID="A1"/>
<earl:assertedBy rdf:nodeID="A2"/>
<earl:test rdf:resource="http://www.w3.org/TR/xhtml1/#C_2"/>
<earl:mode rdf:resource="http://www.w3.org/ns/earl#automatic"/>
<earl:result>
  <earl:TestResult>
    <earl:pointer>
      <pnt:EquivalentPointers>
        <pnt:groupPointer>
          <pnt:LineCharPointer>
            <pnt:charNumber rdf:datatype="http://www.w3.org/2001/XMLSchema#positiveInteger"
            >108</pnt:charNumber>
            <pnt:lineNumber rdf:datatype="http://www.w3.org/2001/XMLSchema#positiveInteger"
            >9</pnt:lineNumber>
          </pnt:LineCharPointer>
        </pnt:groupPointer>
        <pnt:groupPointer>
          <pnt:CharOffsetPointer>
            <pnt:offset rdf:datatype="http://www.w3.org/2001/XMLSchema#positiveInteger"
            >935</pnt:offset>
          </pnt:CharOffsetPointer>
        </pnt:groupPointer>
      </pnt:EquivalentPointers>
    </earl:pointer>
    <earl:outcome rdf:resource="http://www.w3.org/ns/earl#failed"/>
    <dct:description rdf:datatype="http://www.w3.org/2001/XMLSchema#string"
    >A space character is missing before '/>'.</dct:description>
  </earl:TestResult>
</earl:result>
</earl:Assertion>

What I want to get from this excerpt: lineNumber (and charNumber), the fact that the earl:outcome was failed, and the description. So far all I was able to get was the line number, the result however gave the line number +"^^http://www.w3.org/2001/XMLSchema#positiveInteger". I don't know why this happened.

Thanks for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

别靠近我心 2024-12-15 16:31:15

以下查询从您的示例中提取所有失败的结果(请注意,我必须为 pnt: 编写一个 URI,因为您没有说明它是什么,并且它没有在 prefix.cc):

prefix pnt: <http://example.org/pnt#>
prefix earl: <http://www.w3.org/ns/earl#>
prefix dct: <http://purl.org/dc/terms/>

select ?result ?desc ?charNo ?lineNo {
  ?assert a earl:Assertion;
          earl:result ?result.

  ?result earl:outcome earl:failed;
          earl:pointer/pnt:groupPointer ?gpt;
          dct:description ?desc.

  ?gpt pnt:charNumber ?charNo;
       pnt:lineNumber ?lineNo.
}

此查询以纯文本形式提供以下结果:

$ arq --graph=./src/main/resources/earl.rdf --file=./src/main/resources/earl.sparql
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| result | desc                                                                                              | charNo                                                    | lineNo                                                  |
====================================================================================================================================================================================================================================
| _:b0   | "A space character is\n          missing before '/>'."^^<http://www.w3.org/2001/XMLSchema#string> | "108"^^<http://www.w3.org/2001/XMLSchema#positiveInteger> | "9"^^<http://www.w3.org/2001/XMLSchema#positiveInteger> |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

根据 RDF 示例,您想要的两个数字使用 XSD 类型进行数据类型化你提供的。 ^^ 装饰只是使用 Turtle 语法来表达数据类型。如果我们选择 JSON 格式的输出,您可以清楚地看到这一点:

$ arq --graph=./src/main/resources/earl.rdf --file=./src/main/resources/earl.sparql --results=json
{
  "head": {
    "vars": [ "result" , "desc" , "charNo" , "lineNo" ]
  } ,
  "results": {
    "bindings": [
      {
        "result": { "type": "bnode" , "value": "b0" } ,
        "desc": { "datatype": "http://www.w3.org/2001/XMLSchema#string" , "type": "typed-literal" , "value": "A space character is\n          missing before '/>'." } ,
        "charNo": { "datatype": "http://www.w3.org/2001/XMLSchema#positiveInteger" , "type": "typed-literal" , "value": "108" } ,
        "lineNo": { "datatype": "http://www.w3.org/2001/XMLSchema#positiveInteger" , "type": "typed-literal" , "value": "9" }
      }
    ]
  }
}

The following query pulls out all failed results from your sample (note that I had to make up a URI for pnt:, since you didn't say what it was and it's not listed at prefix.cc):

prefix pnt: <http://example.org/pnt#>
prefix earl: <http://www.w3.org/ns/earl#>
prefix dct: <http://purl.org/dc/terms/>

select ?result ?desc ?charNo ?lineNo {
  ?assert a earl:Assertion;
          earl:result ?result.

  ?result earl:outcome earl:failed;
          earl:pointer/pnt:groupPointer ?gpt;
          dct:description ?desc.

  ?gpt pnt:charNumber ?charNo;
       pnt:lineNumber ?lineNo.
}

This query gives the following result in plain text:

$ arq --graph=./src/main/resources/earl.rdf --file=./src/main/resources/earl.sparql
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
| result | desc                                                                                              | charNo                                                    | lineNo                                                  |
====================================================================================================================================================================================================================================
| _:b0   | "A space character is\n          missing before '/>'."^^<http://www.w3.org/2001/XMLSchema#string> | "108"^^<http://www.w3.org/2001/XMLSchema#positiveInteger> | "9"^^<http://www.w3.org/2001/XMLSchema#positiveInteger> |
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

The two numbers you want are datatyped with XSD types, according to the RDF sample you provided. The ^^ decorations simply express the datatypes using the Turtle syntax. You can see this clearly if we select output in JSON instead:

$ arq --graph=./src/main/resources/earl.rdf --file=./src/main/resources/earl.sparql --results=json
{
  "head": {
    "vars": [ "result" , "desc" , "charNo" , "lineNo" ]
  } ,
  "results": {
    "bindings": [
      {
        "result": { "type": "bnode" , "value": "b0" } ,
        "desc": { "datatype": "http://www.w3.org/2001/XMLSchema#string" , "type": "typed-literal" , "value": "A space character is\n          missing before '/>'." } ,
        "charNo": { "datatype": "http://www.w3.org/2001/XMLSchema#positiveInteger" , "type": "typed-literal" , "value": "108" } ,
        "lineNo": { "datatype": "http://www.w3.org/2001/XMLSchema#positiveInteger" , "type": "typed-literal" , "value": "9" }
      }
    ]
  }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文