【问题标题】:Double values are truncated (rounded) in Virtuoso SRARQL resultsVirtuoso SRARQL 结果中的双精度值被截断(四舍五入)
【发布时间】:2016-05-22 22:30:57
【问题描述】:

我正在使用 Virtuoso Opensource 7.2.4 并且有一个包含一些数据的数据集,例如:

@prefix xsd: <http://www.w3.org/2001/XMLSchema#>
@prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> .
@prefix ap: <http://vocab.linkeddata.es/datosabiertos/def/urbanismo-infraestructuras/alumbrado-publico#> .


<http://linkeddata.es/resource/farolas/lapalma/0> a ap:PuntoDeAlumbrado ;
    geo:long "-17.774237421604201614"^^xsd:double ;
    geo:lat "28.60580329136699973"^^xsd:double . 

如果我执行以下简单的 SPARQL 查询

PREFIX geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
PREFIX ap: <http://vocab.linkeddata.es/datosabiertos/def/urbanismo-infraestructuras/alumbrado-publico#> 
select ?farola ?lat ?long where {
 ?farola a ap:PuntoDeAlumbrado; geo:lat ?lat; geo:long ?long .
}

我得到以下结果。请注意,纬度和经度的值会四舍五入为不太精确的值

+-------------------------------------------------+----------+----------+
|                     farola                      |   lat    |   long   |
+-------------------------------------------------+----------+----------+
| http://linkeddata.es/resource/farolas/lapalma/0 |  28.6058 | -17.7742 |
+-------------------------------------------------+----------+----------+

当我将结果格式设置为 HTML、XML、JSON 等时会发生这种情况。如果我在 Turtle 中请求结果,我可以得到正确精度的结果。

@prefix res: <http://www.w3.org/2005/sparql-results#> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
_:_ a res:ResultSet .
_:_ res:resultVariable "farola" , "lat" , "long" .
@prefix xsd:    <http://www.w3.org/2001/XMLSchema#> .
_:_ res:solution [
      res:binding [ res:variable "farola" ; res:value <http://linkeddata.es/resource/farolas/lapalma/0> ] ;
      res:binding [ res:variable "lat" ; res:value 28.60580329136699973 ] ;
      res:binding [ res:variable "long" ; res:value -17.774237421604201614 ] ] .

问题是当我使用 Apache Jena [v3.1.0] 进行查询时,我得到了四舍五入的结果。我想,它要求 application/sparql-results+json 作为第一偏好。让 Virtuoso 在结果中返回非截断值的最佳方法是什么(配置 Virtuoso 或 Jena)?

DBpedia SPARQL 端点中的这种行为与查询的HTML ResultTurtle Result 中的行为相同

prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
select ?lat ?long where {
 <http://dbpedia.org/resource/Liberty_Tower_(Manhattan)>  geo:long ?long; geo:lat ?lat .
}

【问题讨论】:

  • org.apache.jena.sparql.engine.http.QueryEngineHttp::setSelectContentType("TURTLE")
  • 谢谢!显然,只有“application/sparql-results+xml”、“application/sparql-results+json”、“text/tab-separated-values”、“text/csv”是 SPARQL 1.1 中定义的标准结果格式。无法发送其他类型,因为 Jena 会检查有效格式(即使没有,它也不知道如何解析它们)。我想知道这是否可以在 Virtuoso 的服务器端修复。
  • TSV 应该可以工作 - 它作为 SPARQL 结果格式是无损的。它是 Turtle 术语,每个结果行写成一行,实际上是“Turtle results”。
  • 好吧,我错过了。在那种情况下WebContent.contentTypeTextTSV.
  • 感谢@AndyS AKSW。我尝试过,但 Jena 无法使用 ResultSetException 解析来自 Virtuoso 的响应:TSV 结果格式错误,而不是变量:“farola”。代码 sn-p:pastebin.com/raw/JgM0f53e 异常:pastebin.com/raw/eKut5Gwp TSV:pastebin.com/raw/cgqQ5xxi

标签: sparql virtuoso linked-data rounding


【解决方案1】:

作为一种解决方法,您可以在查询中将值转换为字符串:

prefix geo: <http://www.w3.org/2003/01/geo/wgs84_pos#> 
select (str(?lat) as ?lat) (str(?long) as ?long) where {
  <http://dbpedia.org/resource/Liberty_Tower_(Manhattan)>  geo:long ?long; geo:lat ?lat .
}

【讨论】:

    【解决方案2】:

    目前正在Issue#1006 上对GitHub project 进行调查。如那里所述,已知完整的值存储在数据库中。某些(但不是全部)输出数据格式会出现截断问题(例如,text/turtle 未显示截断)。

    问题解决后,我们会更新此答案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-05-09
      • 1970-01-01
      • 1970-01-01
      • 2013-08-21
      • 1970-01-01
      • 2013-02-09
      • 1970-01-01
      相关资源
      最近更新 更多