ffa*_*ffa 4 sparql linked-data
可以在SPARQL查询中以某种方式使用数值作为字符串值吗?例如,考虑以下RDF数据,查询和所需结果:
@prefix gr: <http://purl.org/goodrelations/v1#>.
@prefix xsd: <http://www.w3.org/2001/XMLSchema#>.
:o a gr:QuantitativeValueFloat;
gr:hasMinValueFloat "1,0"^^xsd:float
gr:hasMaxValueFloat "10,0"^^xsd:float
Run Code Online (Sandbox Code Playgroud)
PREFIX gr: <http://purl.org/goodrelations/v1#>
SELECT ?o ?v
WHERE {
?o a gr:QuantitativeValueFloat;
gr:hasMinValueFloat ?vMin;
gr:hasMaxValueFloat ?vMax.
CONCAT((?vMin, ?vMax) as ?v)
}
Run Code Online (Sandbox Code Playgroud)
-----------------
| o | v |
=================
| :o | 1,0-10,0 |
-----------------
Run Code Online (Sandbox Code Playgroud)
在RDF中,所有文字都有一个词法形式,可以使用str函数获得.SPARQL还包含某些文字的简写.例如,你可以写1而不是"1"^^ xsd:integer,但它们是相同的,你可以通过str(1)或str("1"^^ xsd:整数)得到"1" ).这意味着你可以做你正在尝试用str和concat做的事情:
select ?xy where {
values ?x { 1 } #-- short for "1"^^xsd:integer
values ?y { 2.5 } #-- short for "2.5"^^xsd:decimal
bind(concat(str(?x),"--",str(?y)) as ?xy)
}
Run Code Online (Sandbox Code Playgroud)
------------
| xy |
============
| "1--2.5" |
------------
Run Code Online (Sandbox Code Playgroud)
这应该有效,即使文字的词法形式对于该数据类型不合法,就像你有"10,0"^^ xd:float的数据一样,它应该是"10.0"^^ xsd:float,用点(.)而不是逗号(,).(我意识到分隔符有不同的约定,但SPARQL使用点.)