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:data开发者_开发百科type="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!
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" }
}
]
}
}
精彩评论