3

I am using Virtuoso Opensource 7.2.4 and have a dataset which consists of some data, for example:

@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 . 

and if I do the following simple SPARQL query

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 .
}

I get the following results. Note that the values of latitude and longitude are rounded to a less precise value.

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

This happens when I set the result format to HTML, XML, JSON, etc. If I ask for results in Turtle, I can the results with the correct precision.

@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 ] ] .

The problem is when I query using Apache Jena [v3.1.0], I get the rounded results. I guess, it asks for application/sparql-results+json as the first preference. What is the best way to make Virtuoso return the non-truncated values in the result (configuring either Virtuoso or Jena)?

This behavior is the same in the DBpedia SPARQL endpoint as it can be seen in the HTML Result vs the Turtle Result for the query

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 .
}
Nandana
  • 1,240
  • 8
  • 17
  • 1
    `org.apache.jena.sparql.engine.http.QueryEngineHttp::setSelectContentType("TURTLE")` – UninformedUser May 23 '16 at 04:35
  • Thanks! Apparently only "application/sparql-results+xml", "application/sparql-results+json", "text/tab-separated-values", "text/csv" are the standard result formats defined in SPARQL 1.1. It is not possible to send other types as Jena does a check for valid formats (and even if it doesn't, it won't know how to parse them). I wonder if this can be fixed in the server side in Virtuoso. – Nandana May 23 '16 at 07:20
  • 1
    TSV should work - it is lossless as a SPARQL result format. It is Turtle terms written as one line per result row making it, in effect, "Turtle results". – AndyS May 23 '16 at 08:56
  • Ok, I missed that. In that case `WebContent.contentTypeTextTSV`. – UninformedUser May 23 '16 at 09:36
  • Thanks @AndyS AKSW. I tried but Jena fails to parse the response from Virtuoso with a ResultSetException: TSV Results malformed, not a variable: "farola". Code snippet: http://pastebin.com/raw/JgM0f53e Exception: http://pastebin.com/raw/eKut5Gwp TSV: http://pastebin.com/raw/cgqQ5xxi – Nandana May 23 '16 at 10:05
  • Anyways, it seems Virtuoso still rounds up the values in TSV even though it is a lossless result format :( – Nandana May 23 '16 at 10:07
  • Are the values actually rounded, or are they just printed that way in the results table? – Joshua Taylor May 23 '16 at 14:36
  • @JoshuaTaylor that's how the server send them (not just the HTML view). I get the same results using Jena as a client. – Nandana May 23 '16 at 14:43
  • Oh dear - the TSV output is not right for SPARQL results. – AndyS May 25 '16 at 13:33
  • Virtuoso-specific questions, especially where they may herald a bug (as appears possible here), are often best raised to Virtuoso-specific areas such as the [Open Source Project Issues Page](https://github.com/openlink/virtuoso-opensource/issues/), the [Virtuoso Users mailing list](https://lists.sourceforge.net/lists/listinfo/virtuoso-users/), or the [OpenLink Support Forums](http://boards.openlinksw.com/support/index.php). (ObDisclaimer: I work for [OpenLink Software](http://www.openlinksw.com/), producer of [Virtuoso](http://virtuoso.openlinksw.com/).) – TallTed Jun 06 '16 at 17:12
  • Thanks @TallTed I actually posted in the user list but didn't get any reply https://sourceforge.net/p/virtuoso/mailman/message/35107930/ . I will report it as a bug. – Nandana Jun 06 '16 at 17:24

2 Answers2

3

As a workaround, you can convert values to strings in the query:

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 .
}
marat
  • 1,247
  • 9
  • 14
  • Hello, If I want to return it as _double_ I have seen that when I type something like ```(DOUBLE(?moment) AS ?mm)``` it returns an error... Same goes if I try ```DECIMAL```, ```FLOOR```. – NikSp Nov 15 '22 at 08:07
1

This is currently being investigated as Issue#1006 on the GitHub project. As noted there, full values are known to be stored in the database; the truncation issue is seen with some (but not all) output data formats (e.g., text/turtle shows no truncation).

We'll update this answer when the issue is resolved.

TallTed
  • 9,069
  • 2
  • 22
  • 37
  • according to [Issue#1006](https://github.com/openlink/virtuoso-opensource/issues/1006) the problem has been resolved in version 7.2.7 – marat Nov 16 '22 at 09:41