gpt4 book ai didi

semantic-web - SPARQL 查询 : how to get line and char number from EARL document?

转载 作者:行者123 更新时间:2023-12-04 04:10:41 26 4
gpt4 key购买 nike

这可能是一个相当新手的问题,但 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”。我不知道为什么会这样。

感谢您的帮助!

最佳答案

以下查询从您的示例中提取所有失败的结果(请注意,我必须为 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" }
}
]
}
}

关于semantic-web - SPARQL 查询 : how to get line and char number from EARL document?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7687745/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com