[ 
https://issues.apache.org/jira/browse/JENA-2292?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17498046#comment-17498046
 ] 

Andy Seaborne commented on JENA-2292:
-------------------------------------

The results are correct. It is a matter of what the engine knows just because 
something is a datatype.

This is nothing to do with {{geo:wktLiteral}} so let's use datatype 
{{{}:dtype{}}}.

A datatype is a mapping function from the lexical space to a value space.

If the SPARQL evaluator doesn't know something to be definitely true, it raises 
an error for "unknown", and does not return false. (RDF open world assumption).

For a datatype we don't understand, we can still know that two things are 
(representations of) the same value if the lexical forms are the same.
But 

Returning "false" for different lexical forms may be wrong - "123" and 
"+000123" are the same value as integers but different lexical forms.

The rule is that if the LHS and RHS are the same string we know they must be 
same value, so "=" is true and "!=" is false. Otherwise we don't know and it is 
an error for "unknown" because the whole expression if now uncertain. (And 
before anyone mentions it, not all things in SPARQL expressions are proper 
functions. {{{}COALESCE{}}}, {{IF}} and {{BOUND}} aren't functions because they 
don't evaluate their arguments before calling the function itself; they operate 
on un-evaluated expressions.

 
{noformat}
"abc"^^:dtype = "abc"^^:dtype
{noformat}
True. Same lexical forms mean same value.

 
{noformat}
"abc"^^:dtype = "def"^^:dtype
{noformat}
Unknown. Different lexical forms, no idea.

 
{noformat}
"abc"^^:dtype != "abc"^^:dtype
{noformat}
must be false. Must be same value so "!=" is false.

 
{noformat}
"abc"^^:dtype != "def"^^:dtype
{noformat}
Unknown. Different lexical forms, no idea.

 

c.f.
{noformat}
PREFIX : <http://example/>

SELECT * {
   BIND ("abc"^^:dtype AS ?a)
   BIND ("def"^^:dtype AS ?b)
   BIND (COALESCE(?a != ?b, false) AS ?X)
}
{noformat}

> WKT literal (in)equality check fails 
> -------------------------------------
>
>                 Key: JENA-2292
>                 URL: https://issues.apache.org/jira/browse/JENA-2292
>             Project: Apache Jena
>          Issue Type: Bug
>          Components: GeoSPARQL
>    Affects Versions: Jena 4.4.0
>            Reporter: Lorenz Bühmann
>            Priority: Major
>
> The inequality check of WKT literals fails in filter expression:
> {code:sql}
> PREFIX geo: <http://www.opengis.net/ont/geosparql#>
> SELECT * {
>   VALUES ?wkt1 {"Point(11.416666666667 53.633333333333)"^^geo:wktLiteral 
> "Point(11.575 48.1375)"^^geo:wktLiteral}
>   VALUES ?wkt2 {"Point(11.416666666667 53.633333333333)"^^geo:wktLiteral 
> "Point(11.575 48.1375)"^^geo:wktLiteral}
>   FILTER(?wkt1 != ?wkt2)
> } 
> {code}
> Equality check on the other hand works:
> {code:sql}
> PREFIX geo: <http://www.opengis.net/ont/geosparql#>
> SELECT * {
>   VALUES ?wkt1 {"Point(11.416666666667 53.633333333333)"^^geo:wktLiteral 
> "Point(11.575 48.1375)"^^geo:wktLiteral}
>   VALUES ?wkt2 {"Point(11.416666666667 53.633333333333)"^^geo:wktLiteral 
> "Point(11.575 48.1375)"^^geo:wktLiteral}
>   FILTER(?wkt1 = ?wkt2)
> } 
> {code}
> I don't know if this is intended by SPARQL itself for non-standard datatypes, 
> while checking code it goes into
> {code:java}
> case VSPACE_UNKNOWN:
> {
>     // One or two unknown value spaces, or one has a lang tag (but not both).
>     Node node1 = nv1.asNode() ;
>     Node node2 = nv2.asNode() ;
>     if ( ! SystemARQ.ValueExtensions )
>         // No value extensions => raw rdfTermEquals
>         return NodeFunctions.rdfTermEquals(node1, node2) ;
>     // Some "value spaces" are know to be not equal (no overlap).
>     // Like one literal with a language tag, and one without can't be sameAs.
>     if ( ! node1.isLiteral() || ! node2.isLiteral() )
>         // Can't both be non-literals - that's VSPACE_NODE
>         // One or other not a literal => not sameAs
>         return false ;
>     // Two literals at this point.
>     if ( NodeFunctions.sameTerm(node1, node2) )
>         return true ;
>     if ( ! node1.getLiteralLanguage().equals("") ||
>          ! node2.getLiteralLanguage().equals("") )
>         // One had lang tag but weren't sameNode => not equals
>         return false ;
>     raise(new ExprEvalException("Unknown equality test: "+nv1+" and "+nv2)) ;
>     throw new ARQInternalErrorException("raise returned (sameValueAs)") ;
> } {code}
> and here indeed {{NodeFunctions.sameTerm(node1, node2)}} returns false but 
> this isn't forwarded as return value but instead an exception is thrown, 
> thus, inequality check in a filter always leads to error and thus false.
> It also will fail for equality check of non equal WKT literals of course, all 
> cases here:
> {code:sql}
> PREFIX geo: <http://www.opengis.net/ont/geosparql#>
> SELECT * {
>   BIND("Point(11.416666666667 53.633333333333)"^^geo:wktLiteral = 
> "Point(11.416666666667 53.633333333333)"^^geo:wktLiteral AS ?equal_true)
>   BIND("Point(11.416666666667 53.633333333333)"^^geo:wktLiteral = 
> "Point(11.575 48.1375)"^^geo:wktLiteral AS ?equal_false)
>   
>   BIND("Point(11.416666666667 53.633333333333)"^^geo:wktLiteral != 
> "Point(11.575 48.1375)"^^geo:wktLiteral AS ?not_equal_true)
>   BIND("Point(11.416666666667 53.633333333333)"^^geo:wktLiteral != 
> "Point(11.416666666667 53.633333333333)"^^geo:wktLiteral AS ?not_equal_false)
> } 
> {code}
> Result:
> {noformat}
> +------------+-------------+----------------+-----------------+
> | equal_true | equal_false | not_equal_true | not_equal_false |
> +------------+-------------+----------------+-----------------+
> | true       |             |                | false           |
> +------------+-------------+----------------+-----------------+{noformat}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to