Skip to content

Conversation

simonstey
Copy link
Contributor

@simonstey simonstey self-assigned this Aug 15, 2025
@simonstey simonstey linked an issue Aug 15, 2025 that may be closed by this pull request
@simonstey
Copy link
Contributor Author

Do we want to have the SPARQL function sections being populated dynamically (from https://github.com/w3c/sparql-query/blob/main/sparql-ns.ttl ) or just updated on demand?

@HolgerKnublauch
Copy link
Contributor

I am afraid the proper process would be:

  1. We create a new TTL file that owl:imports the base file
  2. In that file we add triples that are useful for rendering, e.g.:
    a) grouping by category
    b) deep links into the SPARQL spec
  3. Then the content can be created dynamically, if we have a TTL parser available.
  4. Maybe the TTL will be accepted by the sparql main document too, but I am not sure about the update cycle.

This is of course a lot of work but will be paying off on the long term because the info will be machine readable, e.g. for syntax-directed editors.

BTW the diff is huge - what happened?

@simonstey
Copy link
Contributor Author

I am afraid the proper process would be:

1. We create a new TTL file that owl:imports the base file

2. In that file we add triples that are useful for rendering, e.g.:
   a) grouping by category
   b) deep links into the SPARQL spec

3. Then the content can be created dynamically, if we have a TTL parser available.

4. Maybe the TTL will be accepted by the sparql main document too, but I am not sure about the update cycle.

This is of course a lot of work but will be paying off on the long term because the info will be machine readable, e.g. for syntax-directed editors.

BTW the diff is huge - what happened?

I messed up the formatting.. will fix that next

@afs
Copy link
Contributor

afs commented Aug 15, 2025

  1. deep links into the SPARQL spec

If contributed back to RDF & SPARQL WG, I'm sure that could get incorporated into sparql-ns.

- Introduced examples for various SPARQL functions to enhance documentation and usability.
- Added a new prefix for shnex-sparql to categorize examples.
- Updated existing functions with example usage, including arithmetic, logical, string, numeric, and date functions.
- Ensured all aggregate functions also include example usage for clarity.
rdfs:label "W3C SHACL SPARQL Functions Vocabulary"@en ;
rdfs:comment "This vocabulary defines SPARQL functions for use with SHACL."@en ;
sh:declare [
sh:prefix "shnex" ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should declare sparql instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addressed in 530b33d

@afs
Copy link
Contributor

afs commented Aug 17, 2025

SPARQL functions work on arguments that are single RDF terms. In [ sparql:agg-count ( ?values ) ] there isn't a term for ?values. (The pain of lists not being first class in RDF.)

SPARQL Aggregates tied into the way GROUP BY works (e.g. SUM(?X+1)) to produce sets - the design means the lists are solely within aggregates a don't leak out to general evaluation. SPARQL Aggregates are not directly usable as node expressions.

shnex has it's own aggregates and that's probably the way to go - I think that defining an adaption layer to get SPARQL aggregates to work is not that different from shnex's aggregates so there is no advantage to SPARQL aggregates.

shnex aggregates working on lists which integrates with the way shnex is e.g. sh:values.

[ sparql:coalesce ( ?optionalValue "default" ) ] is n-ary including a "no result" error.
It is also special because of it's error handling - ditto logical-and, and logical-or.

I don't see that node expressions can have variables other than the environment : #498 (comment)

shnex-sparql:infixOperator
a rdf:Property ;
rdfs:label "infix operator"@en ;
rdfs:comment "Indicates the infix operator symbol used in SPARQL syntax for this function, enabling conversion from functional form to infix notation."@en ;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is infix used in node expressions?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not but the information is useful to capture IMHO, to produce human-readable syntax.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would also need infix precedence.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would also need infix precedence.

which means? 🤔

shnex-sparql:example """[ sparql:plus ( 38 4 ) ]""" ;
.

sparql:subtract
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This has the same URI as the entry in /ns/sparql.ttl.

But both graphs have triples with subject sparql:subtract and properties rdfs:comment and rdfs:isDefinedBy with different object.

It would be better to only include the SHACL Node Expression additions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, if necessary create a fresh property to avoid clashes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@afs

This has the same URI as the entry in /ns/sparql.ttl.

what has the same URI? shnex-sparql:example ?

rdfs:comment "This function tests whether a string matches a regular expression pattern, optionally with a specified flag (e.g., i for case-insensitive)."@en ;
shnex-sparql:category "string" ;
rdfs:isDefinedBy <http://www.w3.org/TR/sparql12-query/#func-regex> ;
shnex-sparql:example """[ sparql:regex ( "hello123" "[0-9]+" ) ]""" ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does the "specified flag" go? It seems this should have either multiple examples, or one that includes the optional "specified flag".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
shnex-sparql:example """[ sparql:regex ( "hello123" "[0-9]+" ) ]""" ;
shnex-sparql:example """[ sparql:regex ( "HeLLo123" "^hello" "i" ) ]""" ;

sparql:day
a sparql:Function ;
rdfs:label "day"@en ;
rdfs:comment "This function returns the day component of an xsd:dateTime or xsd:date."@en ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rdfs:comment "This function returns the day component of an xsd:dateTime or xsd:date."@en ;
rdfs:comment "This function returns the day (0–31) component of an xsd:dateTime or xsd:date."@en ;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rdfs:comment "This function returns the day component of an xsd:dateTime or xsd:date."@en ;
rdfs:comment "This function returns the day (1-31) component of an xsd:dateTime or xsd:date."@en ;

shouldn't it be 1-31 then?

sparql:month
a sparql:Function ;
rdfs:label "month"@en ;
rdfs:comment "This function returns the month component of an xsd:dateTime or xsd:date."@en ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rdfs:comment "This function returns the month component of an xsd:dateTime or xsd:date."@en ;
rdfs:comment "This function returns the month component (0–12) of an xsd:dateTime or xsd:date."@en ;

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
rdfs:comment "This function returns the month component of an xsd:dateTime or xsd:date."@en ;
rdfs:comment "This function returns the month component (1-12) of an xsd:dateTime or xsd:date."@en ;

shouldn't it be 1-12 then?

sparql:seconds
a sparql:Function ;
rdfs:label "seconds"@en ;
rdfs:comment "This function returns the second component (0–60, including leap seconds) of an xsd:dateTime value."@en ;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is "including leap seconds", the range must reach 61 (possibly higher; I do not know the maximum number of leap seconds that might be applied in any given year).

Suggested change
rdfs:comment "This function returns the second component (0–60, including leap seconds) of an xsd:dateTime value."@en ;
rdfs:comment "This function returns the second component (0–61, including leap seconds) of an xsd:dateTime value."@en ;

Copy link
Contributor

@afs afs Sep 18, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This counting from zero.
60 would be the leap second.

But xsd:dateTime does not support leap seconds.
"a decimal number greater than or equal to 0 and less than 60."
Discussion: https://www.w3.org/TR/xmlschema11-2/#d-t-values

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in which case it should actually be:

Suggested change
rdfs:comment "This function returns the second component (0–60, including leap seconds) of an xsd:dateTime value."@en ;
rdfs:comment "This function returns the second (0–59) component of an xsd:dateTime value."@en ;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

59.5 is legal.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so [0,60) then?

what about removing the value range altogether?

Suggested change
rdfs:comment "This function returns the second component (0–60, including leap seconds) of an xsd:dateTime value."@en ;
rdfs:comment "This function returns the seconds component of an xsd:dateTime value."@en ;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about removing the value range altogether?

+1

@afs
Copy link
Contributor

afs commented Sep 18, 2025

s/second/seconds/ to reduce the ambiguity of "the second component of".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support all SPARQL functions as Node Expressions
4 participants