估算半径时出现xsd:decimal问题

时间:2017-04-26 10:29:49

标签: xsd sparql rdf owl fuseki

我想提取位于给定纬度和经度20公里范围内的物品。下面我提供我的查询。它唯一的问题与?lat?long有关。它们具有类似"41.3823035"^^xsd:decimal的格式。在本体文件中,纬度和经度的格式为xsd:float。 当我运行查询时,我收到错误:

Error 500: Infinite or NaN
Fuseki - version 2.4.1 (Build date: 2016-11-04T18:59:20+0000)

如果我将?lat替换为41.38,将?long替换为2.22,则可行。

PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX owl: <http://www.test.com/my-ontology.owl#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
PREFIX oo:  <http://www.w3.org/2002/07/owl#>
PREFIX oa: <http://www.w3.org/ns/oa#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX lfn: <http://www.dotnetrdf.org/leviathan#>
PREFIX fn: <http://www.w3.org/2005/xpath-functions#>
PREFIX afn: <http://jena.hpl.hp.com/ARQ/function#>

SELECT DISTINCT ?id ?kwds ?lat WHERE {
    ?p owl:id 123 .
    ?p rdf:type ?service .
    ?service rdfs:subClassOf ?family .
    ?otherService rdfs:subClassOf ?family .
    ?item rdf:type ?otherService .
    ?item owl:id ?id .
    ?item owl:latitude ?lat .
    ?item owl:longitude ?long .
    BIND ((lfn:degrees-to-radians(?lat)) AS ?lat1) .
    BIND ((lfn:degrees-to-radians(?long)) AS ?lon1) .
    BIND ((lfn:degrees-to-radians(41.384697)) AS ?lat2) .
    BIND ((lfn:degrees-to-radians(2.150849)) AS ?lon2) .
    BIND ((?lon2-?lon1) AS ?dlon) .
    BIND ((?lat2-?lat1) AS ?dlat) .
    BIND ((lfn:sq(lfn:sin(?dlat/2))+lfn:cos(?lat1)*lfn:cos(?lat2)*lfn:sin(?dlon/2) ) AS ?a) .
    BIND ((2*lfn:sin-1(lfn:sqrt(?a))) AS ?c) .
    BIND ((xsd:float(fn:round((6371*?c)))) AS ?dist) .
    FILTER ( ?dist < 25 ) .
}

更新

问题是由此行BIND ((2*lfn:sin-1(lfn:sqrt(?a))) AS ?c) .引起的。对于latlon(0.0)的某些值,它会返回NaN

1 个答案:

答案 0 :(得分:0)

我通过将IF添加到BIND语句来解决了这个问题:

BIND (IF(?c != "NaN"^^xsd:double,xsd:float(fn:round((6371*?c))),999999) AS ?dist)