From 75fabc0d9094e20ef6d8bb1b172867ae59fc50dc Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Thu, 23 Jan 2025 16:12:57 +0000 Subject: [PATCH 1/5] Preparatory reformating --- spec/index.html | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/spec/index.html b/spec/index.html index 7d1e8e2..0fe0103 100644 --- a/spec/index.html +++ b/spec/index.html @@ -5674,15 +5674,30 @@
RDFterm-equal
               xsd:boolean RDFterm-equal (RDF term term1, RDF term term2)
             
-

This function cannot be used directly in expressions. The purpose of this function is to define the semantics of the "=" operator when applied to two RDF terms that do not fall into any of the other, more concrete cases covered in the operator mapping table in Section .

+ +

This function cannot be used directly in expressions. The purpose + of this function is to define the semantics of the "=" operator when applied to + two RDF terms that do not fall into any of the other, more concrete cases + covered in the operator mapping table in Section + . +

+

The function is defined as follows:

term1 and term2 are equal RDF terms if any of the following is From 49052af4f80ff3efc542764f47a28428a8ffb6b3 Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Sun, 23 Feb 2025 17:06:00 +0000 Subject: [PATCH 2/5] GH-187: Revise RDFterm-equal; update RDF term equality --- spec/index.html | 468 ++++++++++++++++++++++++------------------------ 1 file changed, 237 insertions(+), 231 deletions(-) diff --git a/spec/index.html b/spec/index.html index 0fe0103..c9d3e75 100644 --- a/spec/index.html +++ b/spec/index.html @@ -511,7 +511,8 @@

Terminology

language tag
  • - base direction + + base direction
  • datatype IRI @@ -5669,6 +5670,94 @@
    NOT IN

    Functions on RDF Terms

    + +
    +
    sameTerm
    +
     xsd:boolean  sameTerm (RDF term term1, RDF term term2)
    +

    Returns TRUE if term1 and term2 are the same RDF term as + defined in [[[RDF12-CONCEPTS]]] [[RDF12-CONCEPTS]]; returns FALSE otherwise.

    + +

    + Finalize when + RDF Concepts issue 154 + has been resolved. +

    + +

    + term1 and term2 are equal RDF terms + if any of the following is true:

    +
      +
    • + term1 is an IRI + and term2 is an IRI + such that these two IRIs are equal as per + the notion of IRI equality of + [[RDF12-CONCEPTS]]. +
    • +
    • + term1 is a literal and + term2 is a literal such + that these two literals are equal as per the + notion of + Literal term equality + of [[RDF12-CONCEPTS]]. +
    • +
    • + term1 and term2 are the same + blank node +
    • +
    • + term1 and term2 are both + triple terms and the + subject, + predicate, and + object components are pair-wise the same term. +
    • +
    + +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    sameTerm(<http://example/>, <http://example/>)true
    sameTerm(<http://example/>, <https://example/>)false
    sameTerm("abc", "abc")true
    sameTerm("abc"@en, "abc")false
    sameTerm("abc"@en, "abc"@EN)true
    sameTerm("abc"@en--rtl, "abc"@en)true
    sameTerm(2, 2.0)false
    sameTerm(2, "2"^^xsd:integer)true
    sameTerm(2, "02"^^xsd:integer)false
    +
    + +
    RDFterm-equal
    @@ -5682,51 +5771,117 @@ 
    RDFterm-equal
    .

    -

    The function is defined as follows:

    -
      - -
    • Returns TRUE if term1 and term2 - are equal RDF terms, as defined below.
    • +

      + This will be renamed sameValue

      -
    • Produces a type error if term1 and term2 are both - literals having the same - datatype IRI; - this datatype IRI is not in the set of - recognized datatype IRIs; - and the lexical forms - of the two literals are different from one another.
    • - -
    • Returns FALSE otherwise.
    • - -
    -

    - term1 and term2 are equal RDF terms if any of the following is - true:

    -
      -
    • - term1 is an IRI and term2 is an IRI - such that these two IRIs are equal as per the notion of IRI equality of - [[RDF12-CONCEPTS]]. -
    • -
    • - term1 is a literal and - term2 is a literal such that - these two literals are equal as per the notion of Literal term equality of - [[RDF12-CONCEPTS]]. +
        +
      1. If one or both arguments are known to be ill-typed, + then produce a type error.
      2. -
      3. - term1 is a literal and - term2 is a literal - such that the datatype IRI - of each of these two literals is in the set of - recognized datatype IRIs - and both literals have the same literal value. +
      4. Returns TRUE if term1 and term2 + are equal RDF terms, as defined below.
      5. -
      6. - term1 and term2 are the same - blank node. +
      7. If the SPARQL processor can determine the values of both terms + and it can determine the values are equal, then return TRUE.
      8. -
    +
  • If the SPARQL processor can determine that the values of the terms + can not be equal, the return FALSE.
  • + + +
    +

    If the function is to become callable as + `sameValue(term1, term2)`, add a rule + that if there is an + operation mapping for "=" + for the arguments, an implementation MUST return the same boolean value + from `sameValue(term1, term2)`. +

    +
    +
    +

    + The treatment of `NaN` can not be consistent with both "same term means same value" + and "`fn:numeric-equal(NaN, NaN)` is false". So it is an arbitrary choice with + arguments for all three possible choices. + For pattern matching, `"NaN"^^xsd:double` must match itself and + `"NaN"^^xsd:double` does not pattern match `"NaN"^^xsd:float`. +

    +

    + The operator mapping for `=` goes to `fn:numeric-compare` which is false. + The `sameValue` result could be made an error (or false) as a special case. +

    +

    + `"NaN"^^xsd:double = "NaN"^^xsd:float` is also handled by the + operator mapping and is false – `xsd:float` is promoted to `xsd:double`. + A reading of IEEE 754 is that `"NaN"^^xsd:double` and `"NaN"^^xsd:float` + are the same term also suggests that `sameValue` is true. +

    +

    + Proposal 1: follow "sameTerm means sameValue" and `sameValue("NaN"^^xsd:double, "NaN"^^xsd:double)` + and `sameValue("NaN"^^xsd:float, "NaN"^^xsd:float)` are trues. +
    + Proposal 2: + follow "there is one NaN" so `sameValue("NaN"^^xsd:double, "NaN"^^xsd:float)` is true. +

    +

    + Ref: XSD schema 1.1 special values + "are members of the datatype's ·value space·. ". It is not clear whether "special value" literals + added to the value spaces of `xsd:double` and `xsd:float` are "the same" literals. +

    + Ref: (wikipedia) IEEE_754 Special Values + IEEE 754 specifies a special value called "Not a Number" (NaN). + suggests they are the same. +

    +
    + +
    +

    A literal is + ill-typed + if the datatype is one handled by the SPARQL processor and + the lexical form is not in + the lexical space + of the datatype. +

    +

    + The function `RDFterm-equal` returns true or false in cases where + the SPARQL processor can determine that the values of the + arguments are equal or are not equal. If the SPARQL processor + can not be sure, it returns `error`. +

    +
    +
    +

    + The Operator Mapping for "`=`"" + is the function + fn:numeric-equal` + which returns `false` when comparing arguments involving `NaN`. + However, `sameTerm("NaN"^^xsd:double, "NaN"^^xsd:double)` is true; + `sameValue` treats "NaN" as the "same value". + `sameTerm("NaN"^^xsd:double, "NaN"^^xsd:float)` is `true`. +

    +
    + +
    +

    + @@ Describe error as extension +

    +

    + Possible examples: + `sameValue("abc"^^xsd:string, "IV"^^ex:romanNumeral)` +
    + A processor providing only the datatypes required by this spec + returns `error` because it can not know that `ex:romanNumeral` + is a number. +

    +

    + sameValue("32"^^x:meters, "3200"^^x:centimeters) +

    +

    + sameValue("abc"^^xsd:integer, "123"^^xsd:integer) -- `error` by (1) + argument 1 is + ill-typed. +

    +
    +

    An extended implementation may support additional datatypes for literals. An implementation processing a query that tests for equivalence of literals with non-recognized datatypes @@ -5734,198 +5889,48 @@

    RDFterm-equal
    is unable to determine whether or not the values of the compared literals are equivalent. For example, an unextended implementation will produce an error when testing either "iiii"^^my:romanNumeral = "iv"^^my:romanNumeral or "iiii"^^my:romanNumeral != - "iv"^^my:romanNumeral.

    -
    -
    -PREFIX foaf:       <http://xmlns.com/foaf/0.1/>
    -
    -_:a  foaf:name       "Alice".
    -_:a  foaf:mbox       <mailto:alice@work.example> .
    +                  "iv"^^my:romanNumeral.
    +            

    -_:b foaf:name "Ms A.". -_:b foaf:mbox <mailto:alice@work.example> . -
    -
    -

    This query finds the people who have multiple foaf:name triples:

    -
    -PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    -SELECT ?name1 ?name2
    -WHERE {
    -    ?x foaf:name  ?name1 ;
    -       foaf:mbox  ?mbox1 .
    -    ?y foaf:name  ?name2 ;
    -       foaf:mbox  ?mbox2 .
    -    FILTER (?mbox1 = ?mbox2 && ?name1 != ?name2)
    -}
    -

    Query result:

    -
    - - - - - - - - - - - - - - - -
    name1name2
    "Alice""Ms A."
    "Ms A.""Alice"
    -
    -
    +

    Examples:

    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    RDFterm-equalResults
    sameValue(2, +2)true
    sameValue(2.0, 2)true
     
    sameValue(4, "iv"^^my:romanNumeral)error or extension
    sameValue("NaN"^^xsd:double, "NaN"^^xsd:double)true
    sameValue("NaN"^^xsd:double, "NaN"^^xsd:float)true
    -

    In this query for documents that were annotated at a specific date and time (New - Year's Day 2005, measures in timezone +00:00), the RDF terms are not the same, but have - equivalent values according to their datatype:

    -
    -
    -PREFIX a:          <http://www.w3.org/2000/10/annotation-ns#>
    -PREFIX dc:         <http://purl.org/dc/elements/1.1/>
     
    -_:b   a:annotates   <http://www.w3.org/TR/rdf-sparql-query/> .
    -_:b   dc:date       "2004-12-31T19:00:00-05:00"^^<http://www.w3.org/2001/XMLSchema#dateTime> .
    -
    -
    -PREFIX a:      <http://www.w3.org/2000/10/annotation-ns#>
    -PREFIX dc:     <http://purl.org/dc/elements/1.1/>
    -PREFIX xsd:    <http://www.w3.org/2001/XMLSchema#>
     
    -SELECT ?annotates
    -WHERE {
    -    ?annot  a:annotates  ?annotates .
    -    ?annot  dc:date      ?date .
    -    FILTER ( ?date = xsd:dateTime("2005-01-01T00:00:00Z") ) 
    -}
    -                
    -
    - - - - - - - - - -
    annotates
    <http://www.w3.org/TR/rdf-sparql-query/>
    -
    -
    -
    -
    -
    sameTerm
    -
     xsd:boolean  sameTerm (RDF term term1, RDF term term2)
    -

    Returns TRUE if term1 and term2 are the same RDF term as - defined in [[[RDF12-CONCEPTS]]] [[RDF12-CONCEPTS]]; returns FALSE otherwise.

    -
    -
    -PREFIX foaf:       <http://xmlns.com/foaf/0.1/>
    -
    -_:a  foaf:name       "Alice".
    -_:a  foaf:mbox       <mailto:alice@work.example> .
     
    -_:b  foaf:name       "Ms A.".
    -_:b  foaf:mbox       <mailto:alice@work.example> .
    -              
    -
    -

    This query finds the people who have multiple foaf:name triples:

    -
    -PREFIX foaf: <http://xmlns.com/foaf/0.1/>
    -SELECT ?name1 ?name2
    -WHERE {
    -    ?x foaf:name  ?name1 ;
    -       foaf:mbox  ?mbox1 .
    -    ?y foaf:name  ?name2 ;
    -       foaf:mbox  ?mbox2 .
    -    FILTER (sameTerm(?mbox1, ?mbox2) && !sameTerm(?name1, ?name2))
    -}
    -                
    -

    Query result:

    -
    - - - - - - - - - - - - - - - -
    name1name2
    "Alice""Ms A."
    "Ms A.""Alice"
    -
    -
    -
    -

    Unlike RDFterm-equal, sameTerm can be used to test for non-equivalent typed literals with unsupported datatypes:

    -
    -
    -PREFIX :          <http://example.org/WMterms#>
    -PREFIX t:         <http://example.org/types#>
    -
    -_:c1  :label        "Container 1" .
    -_:c1  :weight       "100"^^t:kilos .
    -_:c1  :displacement  "100"^^t:liters .
    -
    -_:c2  :label        "Container 2" .
    -_:c2  :weight       "100"^^t:kilos .
    -_:c2  :displacement  "85"^^t:liters .
    -
    -_:c3  :label        "Container 3" .
    -_:c3  :weight       "85"^^t:kilos .
    -_:c3  :displacement  "85"^^t:liters .
    -              
    -
    -
    -PREFIX  :      <http://example.org/WMterms#>
    -PREFIX  t:     <http://example.org/types#>
    -
    -SELECT ?aLabel1 ?bLabel
    -WHERE { 
    -   ?a  :label        ?aLabel .
    -   ?a  :weight       ?aWeight .
    -   ?a  :displacement ?aDisp .
    -
    -   ?b  :label        ?bLabel .
    -   ?b  :weight       ?bWeight .
    -   ?b  :displacement ?bDisp .
    -
    -   FILTER ( sameTerm(?aWeight, ?bWeight) && !sameTerm(?aDisp, ?bDisp)) 
    -}
    -                
    -
    - - - - - - - - - - - - - - - -
    aLabelbLabel
    "Container 1""Container 2"
    "Container 2""Container 1"
    -
    -
    -
    -

    The test for boxes with the same weight may also be done with the '=' operator - (RDFterm-equal) as the test for - "100"^^t:kilos = "85"^^t:kilos will result in an error, eliminating that - potential solution.

    -
    isIRI
    @@ -5978,6 +5983,7 @@ 
    isIRI
    +
    isBLANK
     xsd:boolean  isBLANK (RDF term term)
    @@ -7227,12 +7233,12 @@
    CONCAT
    fn:concat function. If all input literals are literals with the same language tag - and same base direction + and same base direction then the returned string literal is a literal with that language tag and base direction. If all input literals are literals with the same language tag, - but not all the same base direction, + but not all the same base direction, the returned literal is a literal with that language tag and no base direction.

    @@ -12255,7 +12261,7 @@

    Changes between SPARQL 1.1 Query Language and SPARQL 1.2 Query Language

    base direction: `LANGDIR`, `hasLANG`, hasLANGDIR, and `STRLANGDIR`
  • Define parser input as being an - RDF string. + RDF string. Exclude Unicode surrogates from Unicode escape sequences.
  • Remove concepts of plain and simple literals, in favor of explicit mentions of `xsd:string`
  • Migrate XML Schema references to 1.1
  • From 85ef5b78a410ceda744e8bace1723591e01a0654 Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Mon, 24 Feb 2025 16:41:30 +0000 Subject: [PATCH 3/5] GH-25: Rename RDFterm-equal to sameValue --- spec/index.html | 126 +++++++++++++++++++++--------------------------- 1 file changed, 56 insertions(+), 70 deletions(-) diff --git a/spec/index.html b/spec/index.html index c9d3e75..17a6183 100644 --- a/spec/index.html +++ b/spec/index.html @@ -5281,7 +5281,7 @@

    Operator Mapping

    RDF term RDF term - RDFterm-equal(A, B) + sameValue(A, B) xsd:boolean @@ -5292,7 +5292,7 @@

    Operator Mapping

    RDF term RDF term - fn:not(RDFterm-equal(A, B)) + fn:not(sameValue(A, B)) xsd:boolean @@ -5672,49 +5672,38 @@
    NOT IN

    Functions on RDF Terms

    -
    sameTerm
    +
    SameTerm
     xsd:boolean  sameTerm (RDF term term1, RDF term term2)

    Returns TRUE if term1 and term2 are the same RDF term as defined in [[[RDF12-CONCEPTS]]] [[RDF12-CONCEPTS]]; returns FALSE otherwise.

    - -

    - Finalize when - RDF Concepts issue 154 - has been resolved. -

    -

    - term1 and term2 are equal RDF terms - if any of the following is true:

    + |term1| and |term2| are + equal RDF terms + if one of the following is true: +

    -
    @@ -5758,10 +5747,11 @@
    sameTerm
    -
    -
    RDFterm-equal
    +
    + +
    SameValue
    -              xsd:boolean RDFterm-equal (RDF term term1, RDF term term2)
    +              xsd:boolean sameValue (RDF term term1, RDF term term2)
                 

    This function cannot be used directly in expressions. The purpose @@ -5771,21 +5761,19 @@

    RDFterm-equal
    .

    -

    - This will be renamed sameValue

    -
    1. If one or both arguments are known to be ill-typed, then produce a type error.
    2. -
    3. Returns TRUE if term1 and term2 - are equal RDF terms, as defined below. +
    4. Returns TRUE if term1 and term2 are + equal RDF terms.
    5. If the SPARQL processor can determine the values of both terms and it can determine the values are equal, then return TRUE.
    6. If the SPARQL processor can determine that the values of the terms - can not be equal, the return FALSE.
    7. + can not be equal, the return FALSE. +
    @@ -5842,7 +5830,7 @@
    RDFterm-equal
    of the datatype.

    - The function `RDFterm-equal` returns true or false in cases where + The function `sameValue` returns true or false in cases where the SPARQL processor can determine that the values of the arguments are equal or are not equal. If the SPARQL processor can not be sure, it returns `error`. @@ -5859,30 +5847,26 @@

    RDFterm-equal
    `sameTerm("NaN"^^xsd:double, "NaN"^^xsd:float)` is `true`.

    +
    +

    This function was previously called `RDFterm-equal`.

    +

    - @@ Describe error as extension -

    -

    - Possible examples: - `sameValue("abc"^^xsd:string, "IV"^^ex:romanNumeral)` -
    - A processor providing only the datatypes required by this spec - returns `error` because it can not know that `ex:romanNumeral` - is a number. -

    -

    - sameValue("32"^^x:meters, "3200"^^x:centimeters) -

    -

    - sameValue("abc"^^xsd:integer, "123"^^xsd:integer) -- `error` by (1) - argument 1 is - ill-typed. + A SPARQL processor may support datatypes beyond those required. + Suppose `ex:romanNumeral` is the datatype IRI + roman numerals + which are integer numbers. The SPARQL processor may then be able + to detemine if two literals have the same value, for example, + `sameValue(4, "IV"^^ex:romanNumeral)` can then return `true` + because argument bot represent the value 4. + For `sameValue("abc"^^xsd:string, "IV"^^ex:romanNumeral)` + can return `false` because `xsd:string` and `ex:romanNumeral` + have different value spaces so the arguments can not be the same value.

    -

    +

    An extended implementation may support additional datatypes for literals. An implementation processing a query that tests for equivalence of literals with non-recognized datatypes (and non-identical lexical form and datatype IRI) returns an error, indicating that it @@ -5897,7 +5881,7 @@

    RDFterm-equal
    - + @@ -5909,12 +5893,16 @@
    RDFterm-equal
    - - + + - + + + + + @@ -5927,8 +5915,6 @@
    RDFterm-equal
    RDFterm-equalsameValue Results
    true
     sameValue(2, "2")false
    sameValue(4, "iv"^^my:romanNumeral)error or extensionerror, or true by extension
    sameValue(1e10, "NaN"^^xsd:double)false
    sameValue("NaN"^^xsd:double, "NaN"^^xsd:double)
    - -
    @@ -12271,10 +12257,10 @@

    Changes between SPARQL 1.1 Query Language and SPARQL 1.2 Query Language

  • Editorial changes:
      -
    • Define RDFterm-equal using an actual function signature in
    • +
    • Give a actual function signature to
    • Improve wording of blank nodes in
    • Improve display on mobile
    • -
    • Move RDFterm-equal and sameTerm to
    • +
    • Move `sameValue` (was `RDFterm-equal`) and `sameTerm` to
    • Add note on deduplication of triples produced by CONSTRUCT to
    • Remove historical notes on rdf:langString datatype from
    • Remove inconsistencies between the definitions of the set functions
    • @@ -12299,7 +12285,7 @@

      Changes between SPARQL 1.1 Query Language and SPARQL 1.2 Query Language

    • editorial-query-3: Incorrect link for DELETE DATA in
    • clarification-query-1: Fix explanation of IN and NOT IN in and
    • clarification-query-2: Remove unneeded reference to the semantics above in
    • -
    • clarification-query-3: Rephrase equality definition in
    • +
    • clarification-query-3: Rephrase equality definition in
    • errata-query-1: Let V be an empty set instead of empty multiset in Function ALP definition
    • errata-query-2: Fix grammar of PropertyListPathNotEmpty in
    • errata-query-4: Fix CONCAT definition for zero and one argument in
    • From 8a849e1af7e57e5fba54603cc7a671c268570e4e Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Thu, 6 Mar 2025 08:59:59 +0000 Subject: [PATCH 4/5] Only literal sameValue can be extended --- spec/index.html | 76 ++++++++++++++++++++++++++----------------------- 1 file changed, 41 insertions(+), 35 deletions(-) diff --git a/spec/index.html b/spec/index.html index 17a6183..1b7eace 100644 --- a/spec/index.html +++ b/spec/index.html @@ -5672,19 +5672,19 @@
      NOT IN

      Functions on RDF Terms

      -
      SameTerm
      +
      sameTerm
       xsd:boolean  sameTerm (RDF term term1, RDF term term2)

      Returns TRUE if term1 and term2 are the same RDF term as defined in [[[RDF12-CONCEPTS]]] [[RDF12-CONCEPTS]]; returns FALSE otherwise.

      - |term1| and |term2| are - equal RDF terms + |term1| and |term2| are the + same RDF terms if one of the following is true:

      • term1 and term2 are - IRIs that are - equal as IRIs. + IRIs that are the + same as IRIs.
      • term1 and term2 are literals that are @@ -5729,7 +5729,7 @@
        SameTerm
        sameTerm("abc"@en--rtl, "abc"@en) - true + false sameTerm(2, 2.0) @@ -5749,7 +5749,7 @@
        SameTerm
      -
      SameValue
      +
      sameValue
                     xsd:boolean sameValue (RDF term term1, RDF term term2)
                   
      @@ -5761,31 +5761,37 @@
      SameValue
      .

      +

      + Revise for triple terms. +
      + Consider adding non-literal `=` to operator mapping table. +

      + +

      The result of this function is determined by going through the following steps.

        -
      1. If one or both arguments are known to be ill-typed, +
      2. If term1 and term2 are + equal RDF terms, + the return TRUE. +
      3. +
      4. If both arguments are literals, + literals + and one or both arguments are known to be ill-typed, then produce a type error.
      5. -
      6. Returns TRUE if term1 and term2 are - equal RDF terms. +
      7. If term1 and term2 both + literals + and the SPARQL processor can determine the values are equal, + then return TRUE.
      8. -
      9. If the SPARQL processor can determine the values of both terms - and it can determine the values are equal, then return TRUE. +
      10. If term1 and term2 both + literals + and the SPARQL processor can determine the values can not be equal, + then return FALSE.
      11. -
      12. If the SPARQL processor can determine that the values of the terms - can not be equal, the return FALSE. +
      13. Otherwise, return FALSE.
      - -
      -

      If the function is to become callable as - `sameValue(term1, term2)`, add a rule - that if there is an - operation mapping for "=" - for the arguments, an implementation MUST return the same boolean value - from `sameValue(term1, term2)`. -

      -
      -
      +

      The treatment of `NaN` can not be consistent with both "same term means same value" and "`fn:numeric-equal(NaN, NaN)` is false". So it is an arbitrary choice with @@ -5824,23 +5830,23 @@

      SameValue

      A literal is ill-typed - if the datatype is one handled by the SPARQL processor and - the lexical form is not in - the lexical space + if its datatype is handled by the SPARQL processor and + its lexical form is not in the + lexical space of the datatype.

      - The function `sameValue` returns true or false in cases where - the SPARQL processor can determine that the values of the - arguments are equal or are not equal. If the SPARQL processor - can not be sure, it returns `error`. + If the two arguments are literals, the function `sameValue` + returns `true` or `false` in cases where the SPARQL processor + can determine that the values of these literals are equal or are not equal. + If the SPARQL processor can not be sure, it returns `error`.

      - The Operator Mapping for "`=`"" + The Operator Mapping for "`=`" is the function - fn:numeric-equal` + `fn:numeric-equal` which returns `false` when comparing arguments involving `NaN`. However, `sameTerm("NaN"^^xsd:double, "NaN"^^xsd:double)` is true; `sameValue` treats "NaN" as the "same value". @@ -12257,7 +12263,7 @@

      Changes between SPARQL 1.1 Query Language and SPARQL 1.2 Query Language

    • Editorial changes:
        -
      • Give a actual function signature to
      • +
      • Give an actual function signature to
      • Improve wording of blank nodes in
      • Improve display on mobile
      • Move `sameValue` (was `RDFterm-equal`) and `sameTerm` to
      • From 0391ac471ac0d9a925d2d74d50e36d8598c864ac Mon Sep 17 00:00:00 2001 From: Andy Seaborne Date: Sun, 9 Mar 2025 20:28:14 +0000 Subject: [PATCH 5/5] Add = and != for IRIs, bnodes and triple terms --- spec/index.html | 228 ++++++++++++++++++++++++++---------------------- 1 file changed, 126 insertions(+), 102 deletions(-) diff --git a/spec/index.html b/spec/index.html index 1b7eace..c9cbb58 100644 --- a/spec/index.html +++ b/spec/index.html @@ -243,8 +243,7 @@ span.cancast:hover { background-color: #ffa; color: black; } -.SPARQLoperator { background-color: #FFFFbf; /* yellow */ - } +.SPARQLoperator { font-weight: 600; } /* ReSpec */ dfn { font-style: normal ; } @@ -4665,6 +4664,7 @@

        Operand Data Types

        SPARQL language extensions may treat additional types as being derived from XML schema datatypes.

    • +

      Filter Evaluation

      SPARQL provides a subset of the functions and operators defined by @@ -4826,6 +4826,7 @@

      Effective Boolean Value (EBV)

      with a datatype of xsd:boolean and a lexical value of "false".

  • +

    Operator Mapping

    The SPARQL grammar identifies a set of operators @@ -4925,7 +4926,7 @@

    Operator Mapping

    Logical Connectives - + A || B @@ -4934,7 +4935,7 @@

    Operator Mapping

    xsd:boolean (EBV) - + logical-or(A, B) xsd:boolean @@ -5275,32 +5276,91 @@

    Operator Mapping

    SPARQL Tests - - A = B - + A = B + IRI + IRI + + sameTerm(A, B) + + xsd:boolean + + + A = B + Blank Node + Blank Node + + sameTerm(A, B) + + xsd:boolean + + + A = B + Triple Term + Triple Term + + ( A.subject = B.subject ) &&
    + ( A.predicate = B.predicate ) &&
    + ( A.object = B.object ) + + xsd:boolean + + + A != B + IRI + IRI + fn:not(sameTerm(A, B)) + xsd:boolean + + + A != B + Blank Node + Blank Node + + fn:not(sameTerm(A, B) + + xsd:boolean + + + A != B + Triple Term + Triple Term + + ( A.subject != B.subject ) ||
    + ( A.predicate != B.predicate ) ||
    + ( A.object != B.object ) + + xsd:boolean + + + A = B RDF term RDF term - sameValue(A, B) - + sameValue(A, B) + xsd:boolean - - A != B - + A != B RDF term RDF term - fn:not(sameValue(A, B)) + fn:not(sameValue(A, B)) xsd:boolean -
    xsd:boolean function arguments marked with "(EBV)" are +

    + xsd:boolean function arguments marked with "(EBV)" are coerced to xsd:boolean by evaluating the effective boolean value of that argument. +

    +

    + Operators = and != applied to + triple terms + apply the operator to each of the components. +

    Operator Extensibility

    SPARQL language extensions may provide additional associations between operators and @@ -5314,6 +5374,7 @@

    Operator Extensibility

    BY clause.

    +

    Function Definitions

    This section defines the operators and functions introduced by the SPARQL query language. @@ -5678,7 +5739,7 @@

    sameTerm
    defined in [[[RDF12-CONCEPTS]]] [[RDF12-CONCEPTS]]; returns FALSE otherwise.

    |term1| and |term2| are the - same RDF terms + same RDF term if one of the following is true:

      @@ -5756,77 +5817,61 @@
      sameValue

      This function cannot be used directly in expressions. The purpose of this function is to define the semantics of the "=" operator when applied to - two RDF terms that do not fall into any of the other, more concrete cases + two RDF terms that do not fall into the concrete cases covered in the operator mapping table in Section .

      -

      - Revise for triple terms. -
      - Consider adding non-literal `=` to operator mapping table. -

      -

      The result of this function is determined by going through the following steps.

      +
      1. If term1 and term2 are equal RDF terms, - the return TRUE. + then return TRUE.
      2. -
      3. If both arguments are literals, +
      4. If term1 or term2 is an + IRI or a + blank node + then return FALSE. +
      5. If term1 and term2 are both literals - and one or both arguments are known to be ill-typed, + and one or both of these literals has a datatype that is + not handled by the SPARQL processor, then produce a type error.
      6. -
      7. If term1 and term2 both +
      8. If term1 and term2 are both + literals + and one or both of these literals are known to be + ill-typed, + then produce a type error. +
      9. +
      10. + `"NaN"^^xsd:double` and `"NaN"^^xsd:float` are considered to + represent the same value. + If term1 and term2 are + both "NaN" for either xsd:double or xsd:float, then + return TRUE. +
      11. +
      12. If term1 and term2 are both literals - and the SPARQL processor can determine the values are equal, + and the SPARQL processor can determine that their the values are equal, then return TRUE.
      13. -
      14. If term1 and term2 both +
      15. If term1 and term2 are both literals and the SPARQL processor can determine the values can not be equal, then return FALSE.
      16. -
      17. Otherwise, return FALSE. +
      18. + If term1 and term2 are both + triple terms, + apply the function `sameValue` pair-wise to each of the components. + Return TRUE if each component pair returns TRUE; + produce a type error if any component pair produces an error; + otherwise return FALSE.
      19. +
      20. Otherwise, return FALSE.
      -
      -

      - The treatment of `NaN` can not be consistent with both "same term means same value" - and "`fn:numeric-equal(NaN, NaN)` is false". So it is an arbitrary choice with - arguments for all three possible choices. - For pattern matching, `"NaN"^^xsd:double` must match itself and - `"NaN"^^xsd:double` does not pattern match `"NaN"^^xsd:float`. -

      -

      - The operator mapping for `=` goes to `fn:numeric-compare` which is false. - The `sameValue` result could be made an error (or false) as a special case. -

      -

      - `"NaN"^^xsd:double = "NaN"^^xsd:float` is also handled by the - operator mapping and is false – `xsd:float` is promoted to `xsd:double`. - A reading of IEEE 754 is that `"NaN"^^xsd:double` and `"NaN"^^xsd:float` - are the same term also suggests that `sameValue` is true. -

      -

      - Proposal 1: follow "sameTerm means sameValue" and `sameValue("NaN"^^xsd:double, "NaN"^^xsd:double)` - and `sameValue("NaN"^^xsd:float, "NaN"^^xsd:float)` are trues. -
      - Proposal 2: - follow "there is one NaN" so `sameValue("NaN"^^xsd:double, "NaN"^^xsd:float)` is true. -

      -

      - Ref: XSD schema 1.1 special values - "are members of the datatype's ·value space·. ". It is not clear whether "special value" literals - added to the value spaces of `xsd:double` and `xsd:float` are "the same" literals. -

      - Ref: (wikipedia) IEEE_754 Special Values - IEEE 754 specifies a special value called "Not a Number" (NaN). - suggests they are the same. -

      -
      -

      A literal is ill-typed @@ -5847,31 +5892,19 @@

      sameValue
      The Operator Mapping for "`=`" is the function `fn:numeric-equal` - which returns `false` when comparing arguments involving `NaN`. - However, `sameTerm("NaN"^^xsd:double, "NaN"^^xsd:double)` is true; - `sameValue` treats "NaN" as the "same value". - `sameTerm("NaN"^^xsd:double, "NaN"^^xsd:float)` is `true`. + which is defined to return `false` when comparing arguments involving `NaN`. + However, `sameTerm("NaN"^^xsd:double, "NaN"^^xsd:double)` is true. + The function `sameValue` defines `sameValue("NaN"^^xsd:double, "NaN"^^xsd:double)` + to be true because the arguments are the same element of the value space.

      -
      -
      -

      This function was previously called `RDFterm-equal`.

      -
      - -

      - A SPARQL processor may support datatypes beyond those required. - Suppose `ex:romanNumeral` is the datatype IRI - roman numerals - which are integer numbers. The SPARQL processor may then be able - to detemine if two literals have the same value, for example, - `sameValue(4, "IV"^^ex:romanNumeral)` can then return `true` - because argument bot represent the value 4. - For `sameValue("abc"^^xsd:string, "IV"^^ex:romanNumeral)` - can return `false` because `xsd:string` and `ex:romanNumeral` - have different value spaces so the arguments can not be the same value. + `sameValue` treats the values of `"NaN"^^xsd:double` and `"NaN"^^xsd:float` as being + the same. `sameValue("NaN"^^xsd:double, "NaN"^^xsd:float)` is `true`.

      - +

      + For xsd:double and xsd:float, `+0`, `-0` and `0` are same value. +

      An extended implementation may support additional datatypes for literals. An implementation processing a query that tests for equivalence of literals with non-recognized datatypes @@ -5890,22 +5923,6 @@

      sameValue
      sameValue Results - - sameValue(2, +2) - true - - - sameValue(2.0, 2) - true - - - sameValue(2, "2") - false - - - sameValue(4, "iv"^^my:romanNumeral) - error, or true by extension - sameValue(1e10, "NaN"^^xsd:double) false @@ -5918,9 +5935,16 @@
      sameValue
      sameValue("NaN"^^xsd:double, "NaN"^^xsd:float) true + + sameValue( <<(:s :p 123)>> , <<(:s :p 123.0)>> ) + true + +

      + This function was called `RDFterm-equal` up until SPARQL 1.1. +