From 75fabc0d9094e20ef6d8bb1b172867ae59fc50dc Mon Sep 17 00:00:00 2001
From: Andy Seaborne 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:
Returns TRUE if
+ Finalize when
+ RDF Concepts issue 154
+ has been resolved.
+
+ The function is defined as follows:
+ This will be renamed
- 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.
+
+ 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)`
+
+ 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
xsd:boolean RDFterm-equal (RDF term term1, RDF term term2)
-
-
term1
and term2
are equal RDF terms, as defined below.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.term1
and term2
+ are equal RDF terms, as defined below.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.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 Terminology
language tag
NOT IN
Functions on RDF Terms
+
+ sameTerm
+ xsd:boolean sameTerm (RDF term term1, RDF term term2)
+ 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
+ if any of the following is true:
+
+
+
+
+
+
+
+
+ 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
.
-
-
- term1
and term2
- are equal RDF terms, as defined below.sameValue
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.term1
and term2
are equal RDF terms if any of the following is
- true:
-
+
+
term1
and term2
+ are equal RDF terms, as defined below.
+ Proposal 2:
+ follow "there is one NaN" so `sameValue("NaN"^^xsd:double, "NaN"^^xsd:float)` is true.
+
+ A processor providing only the datatypes required by this spec
+ returns `error` because it can not know that `ex:romanNumeral`
+ is a number.
+ 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:
-name1 | -name2 | -
---|---|
"Alice" | -"Ms A." | -
"Ms A." | -"Alice" | -
Examples:
+RDFterm-equal | +Results | +
---|---|
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/> | -
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:
-name1 | -name2 | -
---|---|
"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)) -} --
aLabel | -bLabel | -
---|---|
"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.
@@ -5978,6 +5983,7 @@isIRI
xsd:boolean isBLANK (RDF term term)@@ -7227,12 +7233,12 @@
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
+ IRIs that are
+ equal as IRIs.
term1
and term2
are
+ literals that are
+ equal as literal terms.
term1
and term2
are
+ blank nodes that are
+ equal as blank nodes.
term1
and term2
are
+ triple terms that are
+ equal as triple terms; that
+ is, the
subject,
predicate, and
- object components are pair-wise the same term.
+ object components are pair-wise
+ the same term.
RDFterm-equal | +sameValue | Results | |
---|---|---|---|
true | |||
|
- + | sameValue(2, "2") |
+ false |
sameValue(4, "iv"^^my:romanNumeral) |
- error or extension | +error, or true by extension | +|
sameValue(1e10, "NaN"^^xsd:double) |
+ false | ||
sameValue("NaN"^^xsd:double, "NaN"^^xsd:double) |
@@ -5927,8 +5915,6 @@
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("abc"@en--rtl, "abc"@en)
sameTerm(2, 2.0)
xsd:boolean sameValue (RDF term term1, RDF term term2)@@ -5761,31 +5761,37 @@
+ 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.
term1
and term2
are
+ equal RDF terms,
+ the return TRUE.
+ term1
and term2
are
- equal RDF terms.
+ term1
and term2
both
+ literals
+ and the SPARQL processor can determine the values are equal,
+ then return TRUE.
term1
and term2
both
+ literals
+ and the SPARQL processor can determine the values can not be equal,
+ then 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 @@
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 @@
SPARQL language extensions may treat additional types as being derived from XML schema datatypes.
+SPARQL provides a subset of the functions and operators defined by @@ -4826,6 +4826,7 @@
xsd:boolean
and a lexical value of "false".
The SPARQL grammar identifies a set of operators @@ -4925,7 +4926,7 @@
+ 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. +
SPARQL language extensions may provide additional associations between operators and @@ -5314,6 +5374,7 @@
This section defines the operators and functions introduced by the SPARQL query language. @@ -5678,7 +5739,7 @@
|term1| and |term2| are the - same RDF terms + same RDF term if one of the following is true:
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.
+term1
and term2
are
equal RDF terms,
- the return TRUE.
+ then return TRUE.
term1
or term2
is an
+ IRI or a
+ blank node
+ then return FALSE.
+ 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.
term1
and term2
both
+ term1
and term2
are both
+ literals
+ and one or both of these literals are known to be
+ ill-typed,
+ then produce a type error.
+ term1
and term2
are
+ both "NaN" for either xsd:double or xsd:float, then
+ return TRUE.
+ 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.
term1
and term2
both
+ term1
and term2
are both
literals
and the SPARQL processor can determine the values can not be equal,
then return FALSE.
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.
- 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 @@
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(2, +2)
sameValue(2.0, 2)
sameValue(2, "2")
sameValue(4, "iv"^^my:romanNumeral)
sameValue(1e10, "NaN"^^xsd:double)
sameValue("NaN"^^xsd:double, "NaN"^^xsd:float)
sameValue( <<(:s :p 123)>> , <<(:s :p 123.0)>> )
+ This function was called `RDFterm-equal` up until SPARQL 1.1. +