Casting

Sorry, this is a bit late in the proceedings to be asking questions  
like this, but I've just hit something I don't follow.

I have a bunch of data that has latitude and longitude values encoded  
as plain literals, like:

[] :name "The Red Lion" ;
    :lat "-1.03" ;
    :long "51.2" .

Yes, I know that's not ideal, but such is life.

Now, if you want to FILTER on those values to narrow down, like:

SELECT ?name
WHERE {
   ?place :name ?name ;
          :lat ?lat ;
          :long ?long .
   FILTER(xsd:integer(?lat) = -1 && xsd:integer(?long) = 51)
}

it doesn't work. From my reading of http://www.w3.org/TR/xpath- 
functions/#casting-from-strings (which may well be flawed) it's an  
error to cast from "-1.03" to "-1"^^xsd:integer. I think you can do  
xsd:integer(xsd:double(?lat)) OK, but I don't think it will be  
obvious to many people why one is legal, and one is not. If that is  
the case.

I'd be interested to know what other people's implementations do.  
Obviously the "right" solution is to fix the data.

- Steve

Received on Monday, 16 April 2007 17:32:00 UTC