Skip to content

Commit

Permalink
merge main (#5126)
Browse files Browse the repository at this point in the history
  • Loading branch information
hmottestad authored Sep 13, 2024
2 parents 985beac + 5c956e1 commit ccf7377
Show file tree
Hide file tree
Showing 110 changed files with 2,320 additions and 166 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,13 @@ public static Set<Value> getPropertyValues(Model model, Resource subject, IRI pr
var fallbackObjects = model.filter(subject, fallbackProperty, null).objects();

if (!fallbackObjects.isEmpty() && !preferredObjects.equals(fallbackObjects)) {
logger.warn("Discrepancy between use of the old and new config vocabulary.");
var msg = "Discrepancy between use of the old and new config vocabulary.";
// depending on whether preferred is set, we log on warn or debug
if (preferredObjects.isEmpty()) {
logger.debug(msg);
} else {
logger.warn(msg);
}

if (preferredObjects.containsAll(fallbackObjects)) {
return preferredObjects;
Expand Down Expand Up @@ -235,7 +241,13 @@ public static Optional<Resource> getSubjectByType(Model model, IRI type, IRI leg
private static void logDiscrepancyWarning(Optional<? extends Value> preferred,
Optional<? extends Value> fallback) {
if (!fallback.isEmpty() && !preferred.equals(fallback)) {
logger.warn("Discrepancy between use of the old and new config vocabulary.");
var msg = "Discrepancy between use of the old and new config vocabulary.";
// depending on whether preferred is set, we log on warn or debug
if (preferred.isEmpty()) {
logger.debug(msg);
} else {
logger.warn(msg);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ public void testGetLiteralValue_no_discrepancy() {
var result = Configurations.getLiteralValue(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).contains(literal("label"));
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand All @@ -116,7 +117,21 @@ public void testGetLiteralValue_useLegacy_onlyNew() {
System.setProperty("org.eclipse.rdf4j.model.vocabulary.useLegacyConfig", "");

assertThat(result).contains(literal("label"));
assertLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
public void testGetLiteralValue_onlyLegacy() {

var subject = bnode();
var m = new ModelBuilder().subject(subject)
.add(RDFS.COMMENT, "comment")
.build();

var result = Configurations.getLiteralValue(m, subject, RDFS.LABEL, RDFS.COMMENT);

assertThat(result).contains(literal("comment"));
assertLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand Down Expand Up @@ -158,6 +173,7 @@ public void testGetResourceValue_no_discrepancy() {
var result = Configurations.getResourceValue(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).contains(iri("urn:label"));
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand All @@ -183,6 +199,7 @@ public void testGetIRIValue_no_discrepancy() {
var result = Configurations.getIRIValue(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).contains(iri("urn:label"));
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand All @@ -197,6 +214,7 @@ public void testGetPropertyValues_no_legacy() {
var result = Configurations.getPropertyValues(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).hasSize(2);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand All @@ -213,6 +231,7 @@ public void testGetPropertyValues_no_discrepancy() {
var result = Configurations.getPropertyValues(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).hasSize(2);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand All @@ -229,6 +248,7 @@ public void testGetPropertyValues_useLegacy_no_discrepancy() {
var result = Configurations.getPropertyValues(m, subject, RDFS.LABEL, RDFS.COMMENT);
assertThat(result).hasSize(2);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.WARN);
assertNotLogged("Discrepancy between use of the old and new config vocabulary.", Level.DEBUG);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ private QueryValueEvaluationStepSupplier() {
}

public static QueryValueEvaluationStep prepareStr(QueryValueEvaluationStep arg, ValueFactory valueFactory) {
return make(arg, "Unkown constant argument for STR()", bs -> str(arg, valueFactory, bs));
return make(arg, "Unknown constant argument for STR()", bs -> str(arg, valueFactory, bs));
}

private static Value str(QueryValueEvaluationStep arg, ValueFactory valueFactory, BindingSet bindings) {
Expand All @@ -67,7 +67,7 @@ private static Value str(QueryValueEvaluationStep arg, ValueFactory valueFactory
return valueFactory.createLiteral(literal.getLabel());
}
} else {
throw new ValueExprEvaluationException("Unkown constant argument for STR()");
throw new ValueExprEvaluationException("Unknown constant argument for STR()");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class PeekMarkIterator<E> implements CloseableIteration<E> {

private boolean closed;

PeekMarkIterator(CloseableIteration<E> iterator) {
public PeekMarkIterator(CloseableIteration<E> iterator) {
this.iterator = iterator;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ private void processError() throws IOException, QueryResultParseException {
} else if (errTypeFlag == QUERY_EVALUATION_ERROR) {
errType = QueryErrorType.QUERY_EVALUATION_ERROR;
} else {
throw new QueryResultParseException("Unkown error type: " + errTypeFlag);
throw new QueryResultParseException("Unknown error type: " + errTypeFlag);
}

String msg = readString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ abstract class ShaclSailBaseConfiguration extends NotifyingSailWrapper {
private static final Logger logger = LoggerFactory.getLogger(ShaclSailBaseConfiguration.class);

// Field used to control if the new SPARQL based validation should be enabled or disabled. Enabled by default.
final boolean sparqlValidation;
boolean sparqlValidation;

private boolean parallelValidation = ShaclSailConfig.PARALLEL_VALIDATION_DEFAULT;
private boolean logValidationPlans = ShaclSailConfig.LOG_VALIDATION_PLANS_DEFAULT;
Expand Down Expand Up @@ -375,4 +375,5 @@ public Set<IRI> getShapesGraphs() {
public void setShapesGraphs(Set<IRI> shapesGraphs) {
this.shapesGraphs = shapesGraphs;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,13 @@ public ValidationResultIterator performValidation() {
validationResults = new ValidationResultIterator(iterator, effectiveValidationResultsLimitPerConstraint);
return validationResults;
} catch (Throwable e) {
logger.warn("Error validating SHACL Shape {}", shape.getId(), e);
logger.warn("Error validating SHACL Shape\n{}", shape, e);
logger.warn("Internal error while trying to validate SHACL Shape {}", shape.getId(), e);
logger.warn("Internal error while trying to validate SHACL Shape\n{}", shape, e);
if (e instanceof Error) {
throw e;
}
throw new SailException("Error validating SHACL Shape " + shape.getId() + "\n" + shape, e);
throw new SailException(
"Internal error while trying to validate SHACL Shape " + shape.getId() + "\n" + shape, e);
} finally {
handlePostLogging(before, validationResults);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,53 @@
import org.eclipse.rdf4j.model.vocabulary.SHACL;

public enum SourceConstraintComponent {
MaxCountConstraintComponent(SHACL.MAX_COUNT_CONSTRAINT_COMPONENT, false),
MinCountConstraintComponent(SHACL.MIN_COUNT_CONSTRAINT_COMPONENT, false),

DatatypeConstraintComponent(SHACL.DATATYPE_CONSTRAINT_COMPONENT, true),
NodeKindConstraintComponent(SHACL.NODE_KIND_CONSTRAINT_COMPONENT, true),
ClassConstraintComponent(SHACL.CLASS_CONSTRAINT_COMPONENT, true),

PatternConstraintComponent(SHACL.PATTERN_CONSTRAINT_COMPONENT, true),
UniqueLangConstraintComponent(SHACL.UNIQUE_LANG_CONSTRAINT_COMPONENT, false),
LanguageInConstraintComponent(SHACL.LANGUAGE_IN_CONSTRAINT_COMPONENT, true),
MaxLengthConstraintComponent(SHACL.MAX_LENGTH_CONSTRAINT_COMPONENT, true),
MinLengthConstraintComponent(SHACL.MIN_LENGTH_CONSTRAINT_COMPONENT, true),

InConstraintComponent(SHACL.IN_CONSTRAINT_COMPONENT, true),
HasValueConstraintComponent(SHACL.HAS_VALUE_CONSTRAINT_COMPONENT, false),
HasValueInConstraintComponent(DASH.HasValueInConstraintComponent, false),
ClosedConstraintComponent(SHACL.CLOSED_CONSTRAINT_COMPONENT, true),

MinExclusiveConstraintComponent(SHACL.MIN_EXCLUSIVE_CONSTRAINT_COMPONENT, true),
MaxExclusiveConstraintComponent(SHACL.MAX_EXCLUSIVE_CONSTRAINT_COMPONENT, true),
MaxInclusiveConstraintComponent(SHACL.MAX_INCLUSIVE_CONSTRAINT_COMPONENT, true),
MinInclusiveConstraintComponent(SHACL.MIN_INCLUSIVE_CONSTRAINT_COMPONENT, true),

AndConstraintComponent(SHACL.AND_CONSTRAINT_COMPONENT, true),
OrConstraintComponent(SHACL.OR_CONSTRAINT_COMPONENT, true),
NotConstraintComponent(SHACL.NOT_CONSTRAINT_COMPONENT, true),
XoneConstraintComponent(SHACL.XONE_CONSTRAINT_COMPONENT, true),

DisjointConstraintComponent(SHACL.DISJOINT_CONSTRAINT_COMPONENT, true),
EqualsConstraintComponent(SHACL.EQUALS_CONSTRAINT_COMPONENT, true),
LessThanConstraintComponent(SHACL.LESS_THAN_CONSTRAINT_COMPONENT, true),
MaxCountConstraintComponent(SHACL.MAX_COUNT_CONSTRAINT_COMPONENT, ProducesValidationResultValue.NEVER),
MinCountConstraintComponent(SHACL.MIN_COUNT_CONSTRAINT_COMPONENT, ProducesValidationResultValue.NEVER),

DatatypeConstraintComponent(SHACL.DATATYPE_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
NodeKindConstraintComponent(SHACL.NODE_KIND_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
ClassConstraintComponent(SHACL.CLASS_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),

PatternConstraintComponent(SHACL.PATTERN_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
UniqueLangConstraintComponent(SHACL.UNIQUE_LANG_CONSTRAINT_COMPONENT, ProducesValidationResultValue.NEVER),
LanguageInConstraintComponent(SHACL.LANGUAGE_IN_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
MaxLengthConstraintComponent(SHACL.MAX_LENGTH_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
MinLengthConstraintComponent(SHACL.MIN_LENGTH_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),

InConstraintComponent(SHACL.IN_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
HasValueConstraintComponent(SHACL.HAS_VALUE_CONSTRAINT_COMPONENT, ProducesValidationResultValue.NEVER),
HasValueInConstraintComponent(DASH.HasValueInConstraintComponent, ProducesValidationResultValue.NEVER),
ClosedConstraintComponent(SHACL.CLOSED_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),

MinExclusiveConstraintComponent(SHACL.MIN_EXCLUSIVE_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
MaxExclusiveConstraintComponent(SHACL.MAX_EXCLUSIVE_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
MaxInclusiveConstraintComponent(SHACL.MAX_INCLUSIVE_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
MinInclusiveConstraintComponent(SHACL.MIN_INCLUSIVE_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),

AndConstraintComponent(SHACL.AND_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
OrConstraintComponent(SHACL.OR_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
NotConstraintComponent(SHACL.NOT_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
XoneConstraintComponent(SHACL.XONE_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),

DisjointConstraintComponent(SHACL.DISJOINT_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
EqualsConstraintComponent(SHACL.EQUALS_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
LessThanConstraintComponent(SHACL.LESS_THAN_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
LessThanOrEqualsConstraintComponent(SHACL.LESS_THAN_OR_EQUALS_CONSTRAINT_COMPONENT,
true),
ProducesValidationResultValue.ALWAYS),

QualifiedMaxCountConstraintComponent(SHACL.QUALIFIED_MAX_COUNT_CONSTRAINT_COMPONENT,
false),
ProducesValidationResultValue.NEVER),
QualifiedMinCountConstraintComponent(SHACL.QUALIFIED_MIN_COUNT_CONSTRAINT_COMPONENT,
false),
NodeConstraintComponent(SHACL.NODE_CONSTRAINT_COMPONENT, true),
PropertyConstraintComponent(SHACL.PROPERTY_CONSTRAINT_COMPONENT, false),
ProducesValidationResultValue.NEVER),
NodeConstraintComponent(SHACL.NODE_CONSTRAINT_COMPONENT, ProducesValidationResultValue.ALWAYS),
PropertyConstraintComponent(SHACL.PROPERTY_CONSTRAINT_COMPONENT, ProducesValidationResultValue.NEVER),

SPARQLConstraintComponent(SHACL.SPARQL_CONSTRAINT_COMPONENT, true);
SPARQLConstraintComponent(SHACL.SPARQL_CONSTRAINT_COMPONENT, ProducesValidationResultValue.SOMETIMES);

private final IRI iri;
private final boolean producesValidationResultValue;
private final ProducesValidationResultValue producesValidationResultValue;

SourceConstraintComponent(IRI iri, boolean producesValidationResultValue) {
SourceConstraintComponent(IRI iri, ProducesValidationResultValue producesValidationResultValue) {
this.iri = iri;
this.producesValidationResultValue = producesValidationResultValue;
}
Expand All @@ -72,6 +72,16 @@ public IRI getIri() {
}

public boolean producesValidationResultValue() {
return producesValidationResultValue;
return producesValidationResultValue != ProducesValidationResultValue.NEVER;
}

public boolean alwaysProducesValidationResultValue() {
return producesValidationResultValue == ProducesValidationResultValue.ALWAYS;
}

private enum ProducesValidationResultValue {
ALWAYS,
NEVER,
SOMETIMES
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public ValidationQuery(Collection<Namespace> namespaces, String query, List<Vari
propertyShapeWithValue = false;
valueIndex = variables.size();
assert constraintComponent == null
|| !constraintComponent.getConstraintComponent().producesValidationResultValue();
|| !constraintComponent.getConstraintComponent().alwaysProducesValidationResultValue();
}
} else {
targetIndex = variables.size() - 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,18 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public abstract class SimpleAbstractConstraintComponent extends AbstractConstraintComponent {
public abstract class AbstractSimpleConstraintComponent extends AbstractConstraintComponent {

private static final Logger logger = LoggerFactory.getLogger(SimpleAbstractConstraintComponent.class);
private static final Logger logger = LoggerFactory.getLogger(AbstractSimpleConstraintComponent.class);

private Resource id;
TargetChain targetChain;

public SimpleAbstractConstraintComponent(Resource id) {
public AbstractSimpleConstraintComponent(Resource id) {
this.id = id;
}

public SimpleAbstractConstraintComponent() {
public AbstractSimpleConstraintComponent() {

}

Expand Down Expand Up @@ -159,15 +159,24 @@ private PlanNode getPlanNodeForOverrideTargetNode(ConnectionsGroup connectionsGr
validationSettings.getDataGraph(), scope);
allTargets = getFilterAttacherWithNegation(negatePlan, allTargets);

return Unique.getInstance(allTargets, true);
if (effectiveTarget.size() > 1) {
allTargets = Unique.getInstance(allTargets, true);
}
return allTargets;
} else {
return effectiveTarget.extend(overrideTargetPlanNode, connectionsGroup,
PlanNode extend = effectiveTarget.extend(overrideTargetPlanNode, connectionsGroup,
validationSettings.getDataGraph(), scope,
EffectiveTarget.Extend.right,
false,
p -> getFilterAttacherWithNegation(negatePlan, p)
);

if (effectiveTarget.size() > 1) {
extend = Unique.getInstance(extend, true);
}

return extend;

}

} else {
Expand All @@ -184,14 +193,22 @@ private PlanNode getPlanNodeForOverrideTargetNode(ConnectionsGroup connectionsGr

allTargets = getFilterAttacherWithNegation(negatePlan, allTargets);

return Unique.getInstance(allTargets, true);
if (effectiveTarget.size() > 1) {
allTargets = Unique.getInstance(allTargets, true);
}

return allTargets;

} else {

overrideTargetPlanNode = effectiveTarget.extend(overrideTargetPlanNode, connectionsGroup,
validationSettings.getDataGraph(), scope,
EffectiveTarget.Extend.right, false, null);

if (effectiveTarget.size() > 1) {
overrideTargetPlanNode = Unique.getInstance(overrideTargetPlanNode, true);
}

planNode = new BulkedExternalInnerJoin(overrideTargetPlanNode,
connectionsGroup.getBaseConnection(),
validationSettings.getDataGraph(), path.get()
Expand Down Expand Up @@ -314,13 +331,25 @@ String literalToString(Literal literal) {
@Override
public PlanNode getAllTargetsPlan(ConnectionsGroup connectionsGroup, Resource[] dataGraph, Scope scope,
StatementMatcher.StableRandomVariableProvider stableRandomVariableProvider) {

if (scope == Scope.propertyShape) {
PlanNode allTargetsPlan = getTargetChain()
.getEffectiveTarget(Scope.nodeShape, connectionsGroup.getRdfsSubClassOfReasoner(),
stableRandomVariableProvider)
.getPlanNode(connectionsGroup, dataGraph, Scope.nodeShape, true, null);

return Unique.getInstance(new ShiftToPropertyShape(allTargetsPlan), true);
EffectiveTarget effectiveTarget = getTargetChain()
.getEffectiveTarget(
Scope.nodeShape,
connectionsGroup.getRdfsSubClassOfReasoner(),
stableRandomVariableProvider
);

PlanNode allTargetsPlan = effectiveTarget
.getPlanNode(
connectionsGroup,
dataGraph, Scope.nodeShape,
true,
null
);

return Unique.getInstance(new ShiftToPropertyShape(allTargetsPlan), effectiveTarget.size() > 1);
}
return EmptyNode.getInstance();
}
Expand Down
Loading

0 comments on commit ccf7377

Please sign in to comment.