Skip to content

#314: Made focusNode an explicit param of exprEval, SPARQL-based expressions now pre-bind all scope vars #370

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: gh-pages
Choose a base branch
from

Conversation

HolgerKnublauch
Copy link
Contributor

Two changes in this PR:

  • Instead of having focusNode as part of the scope, I have pulled it out into an explicit special variable. This is cleaner because this variable really has a special status (e.g. it's called this in SPARQL) and it usually has a value (except in sh:targetNode).
  • The SPARQL-based node expressions now accept the scope vars as parameters. This makes it possible to define user-defined (SPARQL) functions through custom node expression types. For map-based NEe, these would be simple name-value pairs for the input parameters. For list-based NEs, these could be arg1, arg2, arg3 etc. The NE document can specify the details, but the SPARQL document does not need to change further to accommodate the use cases.

Closes #314

@afs
Copy link
Contributor

afs commented Apr 22, 2025

@HolgerKnublauch
Copy link
Contributor Author

Interestingly I was also trying to add links to the githack renderings, but they were (for me) still caching an earlier version, and didn't show the second commit. So I elected not to include the link. But it renders fine now...

Copy link
Member

@TallTed TallTed left a comment

Choose a reason for hiding this comment

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

Tweaks for clarity. I feel strongly that SPARQL keywords (like SELECT) should be presented within <code> elements.

Co-authored-by: Ted Thibodeau Jr <[email protected]>
@HolgerKnublauch HolgerKnublauch requested a review from TallTed April 25, 2025 06:14
@afs
Copy link
Contributor

afs commented Apr 25, 2025

Not sure where to put comment but if this is @HolgerKnublauch's active PR ...

sh:expression The node expression that must return true.

Node expressions return lists.

does not return true as one of its output nodes,

Is that the right behaviour? Wouldn't it be better to make it the conjunction of the list so any violation is a violation. That stops the case where an accidental mistake adding value when only one is expected can make it pass.

sh:expression is already being called multiple times for each value node so better would be to require a single valued expression.

@HolgerKnublauch
Copy link
Contributor Author

I have no strong opinion on sh:expression. I believe in the original draft it had to return exactly [ true ]. However, I have the feeling that when a NE returns multiple values, the general interpretation should be "or". For example, sh:class ( ex:Class1 ex:Class2 ) should be satisfied if either class is present among the types.

One approach moving forward is to move this constraint component into the NE document and let it evolve there. So when people have more experience with NEs, we can adjust the semantics accordingly. It doesn't really need to be in Core.

@afs
Copy link
Contributor

afs commented Apr 25, 2025

sh:class ( ex:Class1 ex:Class2 )

As in node expression [ sh:class ( ex:Class1 ex:Class2 ) ] or the property value of the result of a single node-expr returning a list for sh:class?

As a property shape, it's "and"-like [ sh:path ... ; sh:class ex:Class1 ; sh:class ex:Class2 ]

For sh:expression the safe choice is to define the requirement to be exactly [ true ].

Others are not naturally an "or":

  • sh:targetNode is a foreach.
  • aggregates
  • sparql:lessThan - "and" is more natural
  • sh:minInclusive, sh:minCount would be strange if an "or" because then one value overrides another

What would

[ sh:add ( 
    [ :function1 (...) ] 
    [ :function2 (...) ] 
    ) ]

be? a list of N*M results?

sh:add and the rest would need to be implemented,with defined error handling, and not simply be the same as sparql:add which is 2 numbers only.

Maybe nodes expression evaluation should be defined to return "node or list of nodes" and node-expr functions declare which they are.

@HolgerKnublauch
Copy link
Contributor Author

Ok, this change to sh:expression is fine for me. Changed to [ true ] on the branch.

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.

Add sh:SPARQLFunction
4 participants