From 5603a21657cb589cea0cc7c1c7ec377ee338d59a Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Thu, 25 Sep 2025 12:10:34 +0200 Subject: [PATCH 1/8] Add missing value comparison operators for triple terms --- spec/index.html | 104 +++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 98 insertions(+), 6 deletions(-) diff --git a/spec/index.html b/spec/index.html index 3eabcac0..f4052cd2 100644 --- a/spec/index.html +++ b/spec/index.html @@ -5418,9 +5418,7 @@

Operator Mapping

Triple Term Triple Term - ( A.subject = B.subject ) &&
- ( A.predicate = B.predicate ) &&
- ( A.object = B.object ) + op:numeric-equal(compareTripleTerm(A, B), 0) xsd:boolean @@ -5445,9 +5443,7 @@

Operator Mapping

Triple Term Triple Term - ( A.subject != B.subject ) ||
- ( A.predicate != B.predicate ) ||
- ( A.object != B.object ) + fn:not(op:numeric-equal(compareTripleTerm(A, B), 0)) xsd:boolean @@ -5469,6 +5465,42 @@

Operator Mapping

xsd:boolean + + A < B + Triple Term + Triple Term + + op:numeric-equal(compareTripleTerm(A, B), -1) + + xsd:boolean + + + A <= B + Triple Term + Triple Term + + fn:not(op:numeric-equal(compareTripleTerm(A, B), 1)) + + xsd:boolean + + + A > B + Triple Term + Triple Term + + op:numeric-equal(compareTripleTerm(A, B), 1) + + xsd:boolean + + + A >= B + Triple Term + Triple Term + + fn:not(op:numeric-equal(compareTripleTerm(A, B), -1)) + + xsd:boolean +

@@ -6084,6 +6116,66 @@

sameValue

+
+
compareTripleTerm
+
+              xsd:integer compareTripleTerm (Triple term term1, Triple term term2)
+            
+ +

This function cannot be used directly in expressions. The purpose + of this function is to define the semantics of value-comparison operators on Triple Terms such as "=" and "<" operator + in Section . +

+ +

This function returns -1, 0, 1, or throws an error. + Comparison is performed pairwise on the components of the triple terms in the order subject, predicate, object until the result is determined. + An error is thrown if comparing two components results in an error.

+ +

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

+ +
    +
  1. If SUBJECT(A) = SUBJECT(B) evaluates to true, go to the next step. + If SUBJECT(A) < SUBJECT(B) evaluates to true, return -1. + If SUBJECT(A) > SUBJECT(B) evaluates to true, return 1. + If any of the evalutions cause an error, raise an error. +
  2. +
  3. If PREDICATE(A) = PREDICATE(B) evaluates to true, go to the next step. + If PREDICATE(A) < PREDICATE(B) evaluates to true, return -1. + If PREDICATE(A) > PREDICATE(B) evaluates to true, return 1. + If any of the evalutions cause an error, raise an error. +
  4. +
  5. If OBJECT(A) = OBJECT(B) evaluates to true, return 0. + If OBJECT(A) < OBJECT(B) evaluates to true, return -1. + If OBJECT(A) > OBJECT(B) evaluates to true, return 1. + If any of the evalutions cause an error, raise an error. +
  6. +
+ +

Examples:

+
+ + + + + + + + + + + + + + + + + + + +
compareTripleTermResults
compareTripleTerm(<<(:s :p :o)>>, <<(:s :p :o)>>)0
compareTripleTerm(<<(:s :p 123)>>, <<(:s :p 124)>>)-1
compareTripleTerm(<<(:s :p 123)>>, <<(:s :p 122)>>)1
+
+
+
isIRI
From e9924bdd1388df5f77c909d848e350b9e7dc5e3a Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Thu, 25 Sep 2025 12:13:49 +0200 Subject: [PATCH 2/8] Support triple terms in ORDER BY --- spec/index.html | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/index.html b/spec/index.html index f4052cd2..ffba75f7 100644 --- a/spec/index.html +++ b/spec/index.html @@ -3674,7 +3674,7 @@

ORDER BY

The "<" operator (see the Operator Mapping and 17.3.1 Operator Extensibility) defines the relative order of pairs of numerics, - xsd:strings, xsd:booleans and xsd:dateTimes. Pairs of + xsd:strings, xsd:booleans, xsd:dateTimes, and Triple Terms. Pairs of IRIs are ordered by comparing them as literals with datatype xsd:string.

SPARQL also fixes an order between some kinds of RDF terms that would not otherwise be ordered:

@@ -3683,6 +3683,7 @@

ORDER BY

  • Blank nodes
  • IRIs
  • RDF literals
  • +
  • Triple terms
  • SPARQL does not define a total ordering of all possible RDF terms. Here are a few examples of pairs of terms for which the relative order is undefined:

    From 7213f877799df4eeb5efda5445e59ca93d7f7af6 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Fri, 26 Sep 2025 07:30:12 +0200 Subject: [PATCH 3/8] Fix links to compareTripleTerm Co-authored-by: Olaf Hartig --- spec/index.html | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/index.html b/spec/index.html index ffba75f7..6037679e 100644 --- a/spec/index.html +++ b/spec/index.html @@ -5419,7 +5419,7 @@

    Operator Mapping

    Triple Term Triple Term - op:numeric-equal(compareTripleTerm(A, B), 0) + op:numeric-equal(compareTripleTerm(A, B), 0) xsd:boolean @@ -5444,7 +5444,7 @@

    Operator Mapping

    Triple Term Triple Term - fn:not(op:numeric-equal(compareTripleTerm(A, B), 0)) + fn:not(op:numeric-equal(compareTripleTerm(A, B), 0)) xsd:boolean @@ -5471,7 +5471,7 @@

    Operator Mapping

    Triple Term Triple Term - op:numeric-equal(compareTripleTerm(A, B), -1) + op:numeric-equal(compareTripleTerm(A, B), -1) xsd:boolean @@ -5480,7 +5480,7 @@

    Operator Mapping

    Triple Term Triple Term - fn:not(op:numeric-equal(compareTripleTerm(A, B), 1)) + fn:not(op:numeric-equal(compareTripleTerm(A, B), 1)) xsd:boolean @@ -5489,7 +5489,7 @@

    Operator Mapping

    Triple Term Triple Term - op:numeric-equal(compareTripleTerm(A, B), 1) + op:numeric-equal(compareTripleTerm(A, B), 1) xsd:boolean @@ -5498,7 +5498,7 @@

    Operator Mapping

    Triple Term Triple Term - fn:not(op:numeric-equal(compareTripleTerm(A, B), -1)) + fn:not(op:numeric-equal(compareTripleTerm(A, B), -1)) xsd:boolean From cba3ec1919ab5cf391d2c93dda9e9592687e69d9 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Fri, 26 Sep 2025 07:30:48 +0200 Subject: [PATCH 4/8] Apply suggestions from code review Co-authored-by: Olaf Hartig --- spec/index.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/spec/index.html b/spec/index.html index 6037679e..83854b2a 100644 --- a/spec/index.html +++ b/spec/index.html @@ -6124,8 +6124,10 @@
    compareTripleTerm

    This function cannot be used directly in expressions. The purpose - of this function is to define the semantics of value-comparison operators on Triple Terms such as "=" and "<" operator - in Section . + of this function is to define the semantics of comparison operators, + such as "=" and "<", + for the case of comparing Triple Terms. + The function is used in Section .

    This function returns -1, 0, 1, or throws an error. @@ -6138,17 +6140,17 @@

    compareTripleTerm
  • If SUBJECT(A) = SUBJECT(B) evaluates to true, go to the next step. If SUBJECT(A) < SUBJECT(B) evaluates to true, return -1. If SUBJECT(A) > SUBJECT(B) evaluates to true, return 1. - If any of the evalutions cause an error, raise an error. + If any of the evaluations causes an error, raise an error.
  • If PREDICATE(A) = PREDICATE(B) evaluates to true, go to the next step. If PREDICATE(A) < PREDICATE(B) evaluates to true, return -1. If PREDICATE(A) > PREDICATE(B) evaluates to true, return 1. - If any of the evalutions cause an error, raise an error. + If any of the evaluations causes an error, raise an error.
  • If OBJECT(A) = OBJECT(B) evaluates to true, return 0. If OBJECT(A) < OBJECT(B) evaluates to true, return -1. If OBJECT(A) > OBJECT(B) evaluates to true, return 1. - If any of the evalutions cause an error, raise an error. + If any of the evaluations causes an error, raise an error.
  • From 3f20202f932e7ddbee54b47f00580c4da53969dd Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Fri, 26 Sep 2025 07:33:00 +0200 Subject: [PATCH 5/8] Link to SUBJECT, PREDICATE, and OBJECT functions --- spec/index.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/index.html b/spec/index.html index 83854b2a..900a1db3 100644 --- a/spec/index.html +++ b/spec/index.html @@ -6137,19 +6137,19 @@
    compareTripleTerm

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

      -
    1. If SUBJECT(A) = SUBJECT(B) evaluates to true, go to the next step. - If SUBJECT(A) < SUBJECT(B) evaluates to true, return -1. - If SUBJECT(A) > SUBJECT(B) evaluates to true, return 1. +
    2. If SUBJECT(A) = SUBJECT(B) evaluates to true, go to the next step. + If SUBJECT(A) < SUBJECT(B) evaluates to true, return -1. + If SUBJECT(A) > SUBJECT(B) evaluates to true, return 1. If any of the evaluations causes an error, raise an error.
    3. -
    4. If PREDICATE(A) = PREDICATE(B) evaluates to true, go to the next step. - If PREDICATE(A) < PREDICATE(B) evaluates to true, return -1. - If PREDICATE(A) > PREDICATE(B) evaluates to true, return 1. +
    5. If PREDICATE(A) = PREDICATE(B) evaluates to true, go to the next step. + If PREDICATE(A) < PREDICATE(B) evaluates to true, return -1. + If PREDICATE(A) > PREDICATE(B) evaluates to true, return 1. If any of the evaluations causes an error, raise an error.
    6. -
    7. If OBJECT(A) = OBJECT(B) evaluates to true, return 0. - If OBJECT(A) < OBJECT(B) evaluates to true, return -1. - If OBJECT(A) > OBJECT(B) evaluates to true, return 1. +
    8. If OBJECT(A) = OBJECT(B) evaluates to true, return 0. + If OBJECT(A) < OBJECT(B) evaluates to true, return -1. + If OBJECT(A) > OBJECT(B) evaluates to true, return 1. If any of the evaluations causes an error, raise an error.
    From 189d62ef8d4e86f88829ebf49ed2819e9b1be529 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Fri, 26 Sep 2025 07:34:23 +0200 Subject: [PATCH 6/8] Remove obsolete sentence about triple terms in operator mapping table --- spec/index.html | 5 ----- 1 file changed, 5 deletions(-) diff --git a/spec/index.html b/spec/index.html index 900a1db3..28f3b5f9 100644 --- a/spec/index.html +++ b/spec/index.html @@ -5509,11 +5509,6 @@

    Operator Mapping

    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 From def10d9a0f8db2497e3b0972fb4945116e2e4c66 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Fri, 26 Sep 2025 07:36:36 +0200 Subject: [PATCH 7/8] Use term1/2 instead of A/B in func-compareTripleTerm --- spec/index.html | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/spec/index.html b/spec/index.html index 28f3b5f9..6d3834d0 100644 --- a/spec/index.html +++ b/spec/index.html @@ -6132,19 +6132,19 @@

    compareTripleTerm

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

      -
    1. If SUBJECT(A) = SUBJECT(B) evaluates to true, go to the next step. - If SUBJECT(A) < SUBJECT(B) evaluates to true, return -1. - If SUBJECT(A) > SUBJECT(B) evaluates to true, return 1. +
    2. If SUBJECT(term1) = SUBJECT(term2) evaluates to true, go to the next step. + If SUBJECT(term1) < SUBJECT(term2) evaluates to true, return -1. + If SUBJECT(term1) > SUBJECT(term2) evaluates to true, return 1. If any of the evaluations causes an error, raise an error.
    3. -
    4. If PREDICATE(A) = PREDICATE(B) evaluates to true, go to the next step. - If PREDICATE(A) < PREDICATE(B) evaluates to true, return -1. - If PREDICATE(A) > PREDICATE(B) evaluates to true, return 1. +
    5. If PREDICATE(term1) = PREDICATE(term2) evaluates to true, go to the next step. + If PREDICATE(term1) < PREDICATE(term2) evaluates to true, return -1. + If PREDICATE(term1) > PREDICATE(term2) evaluates to true, return 1. If any of the evaluations causes an error, raise an error.
    6. -
    7. If OBJECT(A) = OBJECT(B) evaluates to true, return 0. - If OBJECT(A) < OBJECT(B) evaluates to true, return -1. - If OBJECT(A) > OBJECT(B) evaluates to true, return 1. +
    8. If OBJECT(term1) = OBJECT(term2) evaluates to true, return 0. + If OBJECT(term1) < OBJECT(term2) evaluates to true, return -1. + If OBJECT(term1) > OBJECT(term2) evaluates to true, return 1. If any of the evaluations causes an error, raise an error.
    From bf53dac9b0cf6d623fad068b9b926f3de1865ff0 Mon Sep 17 00:00:00 2001 From: Ruben Taelman Date: Fri, 26 Sep 2025 07:38:01 +0200 Subject: [PATCH 8/8] Clarify next step in func-compareTripleTerm --- spec/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/index.html b/spec/index.html index 6d3834d0..02de2ab4 100644 --- a/spec/index.html +++ b/spec/index.html @@ -6132,12 +6132,12 @@
    compareTripleTerm

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

      -
    1. If SUBJECT(term1) = SUBJECT(term2) evaluates to true, go to the next step. +
    2. If SUBJECT(term1) = SUBJECT(term2) evaluates to true, go to step 2. If SUBJECT(term1) < SUBJECT(term2) evaluates to true, return -1. If SUBJECT(term1) > SUBJECT(term2) evaluates to true, return 1. If any of the evaluations causes an error, raise an error.
    3. -
    4. If PREDICATE(term1) = PREDICATE(term2) evaluates to true, go to the next step. +
    5. If PREDICATE(term1) = PREDICATE(term2) evaluates to true, go to step 3. If PREDICATE(term1) < PREDICATE(term2) evaluates to true, return -1. If PREDICATE(term1) > PREDICATE(term2) evaluates to true, return 1. If any of the evaluations causes an error, raise an error.