Skip to content

Issue 414: list constraints #416

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 7 commits into
base: feat/memberShape
Choose a base branch
from
Open

Conversation

jeswr
Copy link
Member

@jeswr jeswr commented Jun 28, 2025

Closes #414. This PR implements sh:minListLength, sh:maxListLength and sh:uniqList.


My interpretation of the following from the definition of 2.1.1 Constraints, Parameters and Constraint Components is that because the sh:MemberShapeConstraintComponent now has multiple parameters; there can only be one occurrence of sh:memberShape in a given shape - and I have updated the sh:maxCount accordingly.

Some constraint components declare only a single parameter. For example sh:ClassConstraintComponent has the single parameter sh:class. These parameters may be used multiple times in the same shape, and each value of such a parameter declares an individual constraint. The interpretation of such declarations is conjunction, i.e. all constraints apply. The following example specifies that the values of ex:customer have to be SHACL instances of both ex:Customer and ex:Person.


⚠️⚠️ ⚠️
This is currently targeted to #403 branch for a smaller diff in the GH UI. #403 should be merged and this targeted to gh-pages rather than merging this branch into #403

@jeswr jeswr marked this pull request as ready for review June 28, 2025 12:43
Copy link
Contributor

@HolgerKnublauch HolgerKnublauch left a comment

Choose a reason for hiding this comment

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

I think you have linked the new constraint parameters to the same constraint component for memberShape. I believe it would be better to introduce separate constraint components for each of them. It makes the definition more modular but, more importantly, it is perfectly sensible to use for example sh:minListLength without a sh:memberShape constraint.

</table>
<div class="def def-text">
<div class="def-header">TEXTUAL DEFINITION</div>
<div class="def-text-body" data-validator="MemberShape">
Let <code>$memberShape</code> be a <a>value</a> of <code>sh:memberShape</code>.
Each <a>value node</a> <code>v</code> must be a <a href="#syntax-rule-SHACL-list">SHACL list</a> - a <a>failure</a> MUST be produced if <code>v</code> is not a SHACL list.
For each <a>value node</a> <code>v</code> that is a valid SHACL list, a <a>failure</a> MUST be produced for each violation of the following conditions:
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that FAILURE is not the right word here. It should be "validation result". Failure is used when a node shape fails to evaluate due to some low-level problem. Normal constraint violations are validation results.

If <code>sh:maxListLength</code> is present, the number of members in the list <code>v</code> MUST be less than or equal to the value of <code>sh:maxListLength</code>.
</li>
<li>
If <code>sh:uniqList</code> is present and has the value <code>true</code>, the members of the list <code>v</code> MUST be unique.
Copy link
Contributor

Choose a reason for hiding this comment

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

I still don't like the name uniqList, and would prefer uniqueMembers. The abbreviation uniq is not really necessary for such a short word, and not the list is unique but its members are.

@jeswr
Copy link
Member Author

jeswr commented Jun 29, 2025

I think you have linked the new constraint parameters to the same constraint component for memberShape. I believe it would be better to introduce separate constraint components for each of them. It makes the definition more modular but, more importantly, it is perfectly sensible to use for example sh:minListLength without a sh:memberShape constraint.

Makes sense! Following this approach; I expect similarly to sh:memberShape - there should be an error if sh:minListLength is declared and the focus node is not a valid SHACL list. This would mean that if both sh:memberShape and sh:minListLength are declared - and the focus node is not a valid list then both constraints would independently trigger validation results which look like

sh:result [
rdf:type sh:ValidationResult ;
sh:focusNode _:b4 ;
sh:resultMessage "Value does not conform to Shape ex:IRIListShape. See details for more information." ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MemberShapeConstraintComponent ;
sh:sourceShape ex:IRIListShape ;
sh:value _:b4 ;
sh:detail [
rdf:type sh:ValidationResult ;
sh:focusNode _:b4 ;
sh:resultMessage "Value is a malformed SHACL List. _:b4 is missing rdf:rest property." ;
sh:resultSeverity sh:Violation ;
sh:sourceConstraintComponent sh:MemberShapeConstraintComponent ;
sh:sourceShape ex:IRIListShape ;
sh:value _:b4 ;
] ;
] ;

I guess we can expect similar behaviour if there are multiple sh:memberShape declarations in #403

Is this the behaviour you would expect for validation results?

@jeswr jeswr changed the title Issue 403: list constraints Issue 414: list constraints Jun 29, 2025
@HolgerKnublauch
Copy link
Contributor

I wouldn't worry too much about malformed lists. Usually people use tools to produce them, including editing TTL source code. So if they are reported twice, this shouldn't be the end of the world.

@jeswr
Copy link
Member Author

jeswr commented Jun 29, 2025

I also saw a comment about lists not being valid objects of sh:targetNode but it's now not appearing in the GH UI - was this comment deleted because the statement doesn't hold, or is GH doing weird things?

@HolgerKnublauch
Copy link
Contributor

Yeah my fault. I deleted the comment because I understood later what you did.

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.

2 participants