Skip to content
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

GH-5130 sh:oneOrMorePath, sh:zeroOrMorePath, sh:zeroOrOnePath #5131

Merged
merged 7 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.rdf4j.model.vocabulary;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Namespace;

/**
* http://jena.hpl.hp.com/ARQ/function#.
Expand All @@ -27,6 +28,8 @@ private AFN() {

public static final String PREFIX = "afn";

public static final Namespace NS = Vocabularies.createNamespace(PREFIX, NAMESPACE);

/**
* http://jena.hpl.hp.com/ARQ/function#localname The LocalName QueryModelNode as a SPARQL function.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.rdf4j.model.vocabulary;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Namespace;

/**
* http://jena.hpl.hp.com/ARQ/property#.
Expand All @@ -27,6 +28,8 @@ private APF() {

public static final String PREFIX = "apf";

public static final Namespace NS = Vocabularies.createNamespace(PREFIX, NAMESPACE);

public static final IRI STR_SPLIT;

public static final IRI CONCAT;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.rdf4j.model.vocabulary;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Namespace;

/**
* Constants for EARL primitives and for the EARL namespace.
Expand All @@ -27,6 +28,8 @@ public class EARL {
*/
public static final String PREFIX = "earl";

public static final Namespace NS = Vocabularies.createNamespace(PREFIX, NAMESPACE);

public final static IRI ASSERTOR;

public final static IRI ASSERTION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.rdf4j.model.vocabulary;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Namespace;

/**
* @see <a href=
Expand All @@ -20,6 +21,10 @@ public class GEOF {

public static final String NAMESPACE = "http://www.opengis.net/def/function/geosparql/";

public static final String PREFIX = "geof";

public static final Namespace NS = Vocabularies.createNamespace(PREFIX, NAMESPACE);

public static final IRI DISTANCE;

public static final IRI BUFFER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.rdf4j.model.vocabulary;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Namespace;

/**
* http://jena.hpl.hp.com/ARQ/list#.
Expand All @@ -27,6 +28,8 @@ private LIST() {

public static final String PREFIX = "list";

public static final Namespace NS = Vocabularies.createNamespace(PREFIX, NAMESPACE);

public static final IRI MEMBER;

public static final IRI INDEX;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.rdf4j.model.vocabulary;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Namespace;

/**
* @version 1.4.0
Expand All @@ -25,6 +26,8 @@ public class SP {

public static final String PREFIX = "sp";

public static final Namespace NS = Vocabularies.createNamespace(PREFIX, NAMESPACE);

/**
* http://spinrdf.org/sp#Path The base class of SPARQL property path expressions. Paths are used by sp:TriplePath
* triple paths.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.rdf4j.model.vocabulary;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Namespace;

/**
* http://spinrdf.org/spif#.
Expand All @@ -27,6 +28,8 @@ private SPIF() {

public static final String PREFIX = "spif";

public static final Namespace NS = Vocabularies.createNamespace(PREFIX, NAMESPACE);

public static final IRI MOD_FUNCTION;

public static final IRI PARSE_DATE_FUNCTION;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.rdf4j.model.vocabulary;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Namespace;

/**
* @version 1.4.0
Expand All @@ -25,6 +26,8 @@ public class SPIN {

public static final String PREFIX = "spin";

public static final Namespace NS = Vocabularies.createNamespace(PREFIX, NAMESPACE);

/**
* http://spinrdf.org/spin#Function Metaclass for functions that can be used in SPARQL expressions (e.g. FILTER or
* BIND). The function themselves are classes that are instances of this metaclass. Function calls are instances of
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.rdf4j.model.vocabulary;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Namespace;

/**
* http://spinrdf.org/spinx#.
Expand All @@ -27,6 +28,8 @@ private SPINX() {

public static final String PREFIX = "spinx";

public static final Namespace NS = Vocabularies.createNamespace(PREFIX, NAMESPACE);

public static final IRI JAVA_SCRIPT_CODE_PROPERTY;

public static final IRI JAVA_SCRIPT_FILE_PROPERTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
package org.eclipse.rdf4j.model.vocabulary;

import org.eclipse.rdf4j.model.IRI;
import org.eclipse.rdf4j.model.Namespace;

/**
* SPIN Standard Module library.
Expand All @@ -27,6 +28,8 @@ private SPL() {

public static final String PREFIX = "spl";

public static final Namespace NS = Vocabularies.createNamespace(PREFIX, NAMESPACE);

/**
* http://spinrdf.org/spl#Argument Provides metadata about an argument of a SPIN Function or Template.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,8 @@ public static List<IRI> getSupportedShaclPredicates() {
SHACL.TARGET_PROP,
SHACL.INVERSE_PATH,
SHACL.ALTERNATIVE_PATH,
// SHACL.ONE_OR_MORE_PATH,
// SHACL.ZERO_OR_MORE_PATH,
SHACL.NODE,
SHACL.QUALIFIED_MAX_COUNT,
SHACL.QUALIFIED_MIN_COUNT,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,12 @@ public SourceConstraintComponent getConstraintComponent() {

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {

PlanNode planNode = constraintComponents.stream()
.map(c -> c.getAllTargetsPlan(connectionsGroup, dataGraph, Scope.nodeShape,
new StatementMatcher.StableRandomVariableProvider()))
new StatementMatcher.StableRandomVariableProvider(), validationSettings))
.distinct()
.reduce((nodes, nodes2) -> UnionNode.getInstanceDedupe(connectionsGroup, nodes, nodes2))
.orElse(EmptyNode.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,10 +255,11 @@ constraintComponent, getSeverity(), t.getScope(), t.getContexts(),

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
PlanNode planNode = constraintComponents.stream()
.map(c -> c.getAllTargetsPlan(connectionsGroup, dataGraph, Scope.propertyShape,
new StatementMatcher.StableRandomVariableProvider()))
new StatementMatcher.StableRandomVariableProvider(), validationSettings))
.distinct()
.reduce((nodes, nodes2) -> UnionNode.getInstanceDedupe(connectionsGroup, nodes, nodes2))
.orElse(EmptyNode.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@

import org.eclipse.rdf4j.model.Namespace;
import org.eclipse.rdf4j.model.Resource;
import org.eclipse.rdf4j.model.Statement;
import org.eclipse.rdf4j.sail.shacl.ast.paths.Path;
import org.eclipse.rdf4j.sail.shacl.ast.targets.EffectiveTarget;
import org.eclipse.rdf4j.sail.shacl.wrapper.data.ConnectionsGroup;
Expand Down Expand Up @@ -337,8 +336,10 @@ public String getNamespacesForSparql() {
return ShaclPrefixParser.toSparqlPrefixes(namespaces);
}

public Stream<EffectiveTarget.StatementsAndMatcher> getRoot(ConnectionsGroup connectionsGroup, Resource[] dataGraph,
Path path, StatementMatcher currentStatementMatcher, List<Statement> currentStatements) {
public Stream<EffectiveTarget.SubjectObjectAndMatcher> getRoot(ConnectionsGroup connectionsGroup,
Resource[] dataGraph,
Path path, StatementMatcher currentStatementMatcher,
List<EffectiveTarget.SubjectObjectAndMatcher.SubjectObject> currentStatements) {
assert traceBackFunction != null;
return traceBackFunction.getRoot(connectionsGroup, dataGraph, path, currentStatementMatcher, currentStatements);
}
Expand Down Expand Up @@ -411,12 +412,12 @@ public int hashCode() {

public interface TraceBack {

Stream<EffectiveTarget.StatementsAndMatcher> getRoot(
Stream<EffectiveTarget.SubjectObjectAndMatcher> getRoot(
ConnectionsGroup connectionsGroup,
Resource[] dataGraph,
Path path,
StatementMatcher currentStatementMatcher,
List<Statement> currentStatements);
List<EffectiveTarget.SubjectObjectAndMatcher.SubjectObject> currentStatements);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,8 @@ public boolean requiresEvaluation(ConnectionsGroup connectionsGroup, Scope scope

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
throw new UnsupportedOperationException();
}

Expand Down Expand Up @@ -171,6 +172,9 @@ static PlanNode getAllTargetsIncludingThoseAddedByPath(ConnectionsGroup connecti
null);

allTargets = UnionNode.getInstance(connectionsGroup, addedTargets.getPlanNode(), addedByPath);

allTargets = Unique.getInstance(new TrimToTarget(allTargets, connectionsGroup), false, connectionsGroup);

return allTargets;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,8 @@ private PlanNode getAllTargetsBasedOnPredicate(ConnectionsGroup connectionsGroup

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
if (scope == Scope.propertyShape) {
PlanNode allTargetsPlan = getTargetChain()
.getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(),
Expand Down Expand Up @@ -252,7 +253,7 @@ public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[]

}

return Unique.getInstance(allTargetsPlan, false, connectionsGroup);
return Unique.getInstance(new TrimToTarget(allTargetsPlan, connectionsGroup), false, connectionsGroup);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.rdf4j.sail.shacl.ast.ValidationApproach;
import org.eclipse.rdf4j.sail.shacl.ast.ValidationQuery;
import org.eclipse.rdf4j.sail.shacl.ast.paths.Path;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AllTargetsPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BufferedPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalInnerJoin;
Expand Down Expand Up @@ -135,7 +136,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
connectionsGroup.getPreviousStateConnection(),
b -> new ValidationTuple(b.getValue("a"), b.getValue("c"), scope, true,
validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

top = UnionNode.getInstance(connectionsGroup, top, bulkedExternalInnerJoin);

Expand Down Expand Up @@ -218,7 +219,7 @@ private PlanNode getPlanNodeForOverrideTargetNode(ConnectionsGroup connectionsGr
Set.of()),
false, null,
BulkedExternalInnerJoin.getMapper("a", "c", scope, validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);
planNode = connectionsGroup.getCachedNodeFor(planNode);
}
}
Expand Down Expand Up @@ -331,7 +332,8 @@ String literalToString(Literal literal) {

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {

if (scope == Scope.propertyShape) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,11 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
PlanNode planNode = and.stream()
.map(c -> c.getAllTargetsPlan(connectionsGroup, dataGraph, scope,
new StatementMatcher.StableRandomVariableProvider()))
new StatementMatcher.StableRandomVariableProvider(), validationSettings))
.distinct()
.reduce((nodes, nodes2) -> UnionNode.getInstanceDedupe(connectionsGroup, nodes, nodes2))
.orElse(EmptyNode.getInstance());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.eclipse.rdf4j.sail.shacl.ast.ValidationApproach;
import org.eclipse.rdf4j.sail.shacl.ast.ValidationQuery;
import org.eclipse.rdf4j.sail.shacl.ast.paths.Path;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AbstractBulkJoinPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.AllTargetsPlanNode;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BufferedSplitter;
import org.eclipse.rdf4j.sail.shacl.ast.planNodes.BulkedExternalInnerJoin;
Expand Down Expand Up @@ -171,7 +172,7 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections
false,
null,
BulkedExternalInnerJoin.getMapper("a", "c", scope, validationSettings.getDataGraph()),
connectionsGroup);
connectionsGroup, AbstractBulkJoinPlanNode.DEFAULT_VARS);

if (connectionsGroup.getAddedStatements() != null) {
// filter by type against the added statements
Expand Down Expand Up @@ -236,7 +237,8 @@ public PlanNode generateTransactionalValidationPlan(ConnectionsGroup connections

@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider,
ValidationSettings validationSettings) {
if (scope == Scope.propertyShape) {
PlanNode allTargetsPlan = getTargetChain()
.getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(),
Expand Down
Loading
Loading