java SPARQL 类型转换?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4439400/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SPARQL Type Conversion?
提问by Bailz
I have the following SPARQL query:
我有以下 SPARQL 查询:
PREFIX ssn: <http://purl.oclc.org/NET/ssnx/ssn#>
PREFIX dtp: <http://dtp-126.sncs.abdn.ac.uk#>
PREFIX dbp: <http://dbpedia.org/resource/>
SELECT ?value ?time WHERE {
dtp:CD7514 ssn:madeObservation ?observation .
?observation ssn:observedProperty ?property .
?property ssn:hasValue <http://dbpedia.org/resource/Temperature> .
?observation ssn:observationResult ?observationValue .
?observationValue ssn:hasValue ?value .
?observationValue ssn:observationSamplingTime ?time
FILTER(?time > 1291908000)
}
Which, in a nutshell, is selecting all temperature sensor observations from a sensor, dtp:CD7514, and filtering out values less than the given timestamp.
简而言之,就是从传感器 dtp:CD7514 中选择所有温度传感器观测值,并过滤掉小于给定时间戳的值。
However, adding the filter constraint returns 0 results (when there are observations that match this time region!)
但是,添加过滤器约束会返回 0 个结果(当存在与此时间区域匹配的观察值时!)
Is it possible that ?time is a varchar/text/String data type and therefore the comparison can't be done? If so, is it possible to do the conversion within SPARQL?
是否有可能 ?time 是 varchar/text/String 数据类型,因此无法进行比较?如果是这样,是否可以在 SPARQL 中进行转换?
采纳答案by Bailz
The solution to this was merely to add quotes around the timestamp.
对此的解决方案仅仅是在时间戳周围添加引号。
回答by Steve Harris
That's only going to work if the time value you're matching has the same number of digits, as it will do a strong compare. A better fix would be:
只有当您匹配的时间值具有相同的位数时,这才会起作用,因为它会进行强有力的比较。更好的解决方法是:
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
...
FILTER(xsd:integer(?time) > 1291908000)
That will cast the value in ?time to an integer, and then do a numeric compare on it.
这会将 ?time 中的值转换为整数,然后对其进行数字比较。