Skip to content

Commit 89a3b0c

Browse files
authored
GH-5676 ShaclSail customizable inference (#5680)
1 parent 4b52685 commit 89a3b0c

File tree

79 files changed

+4327
-226
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+4327
-226
lines changed

.codex/skills/mvnf/scripts/mvnf.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ def main() -> int:
276276
print(f"Test selector: {test_selector} ({'failsafe' if args.it else 'surefire'})")
277277

278278
clean_cmd = mvn_cmd + common_flags + ["-pl", module, "clean"]
279-
install_cmd = mvn_cmd + (offline_flag + ["-T", "1C", "-Dmaven.repo.local=.m2_repo", "-Pquick", "clean", "install"])
279+
install_cmd = mvn_cmd + (offline_flag + ["-T", "1C", "-Dmaven.repo.local=.m2_repo", "-Pquick", "install"])
280280

281281
verify_cmd = mvn_cmd + common_flags + ["-pl", module]
282282
if test_selector is not None:
@@ -298,7 +298,7 @@ def main() -> int:
298298

299299
rc, _ = _run(install_cmd, repo_root, args.tail, log_paths[1], args.stream)
300300
if rc != 0:
301-
print("\n[mvnf] Root clean install failed.")
301+
print("\n[mvnf] Root install failed.")
302302
return rc
303303

304304
rc, _ = _run(verify_cmd, repo_root, args.tail, log_paths[2], args.stream)

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,4 @@ e2e/test-results
5555
.m2_repo/
5656
.serena/
5757
.vscode
58+
/.codex/environments/environment.toml

core/model-vocabulary/src/main/java/org/eclipse/rdf4j/model/vocabulary/CONFIG.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,12 @@ public static final class Shacl {
342342
public final static IRI rdfsSubClassReasoning = createIRI(NAMESPACE,
343343
"shacl.rdfsSubClassReasoning");
344344

345+
/**
346+
* <code>tag:rdf4j.org,2023:config/shacl.includeInferredStatements</code>
347+
*/
348+
public final static IRI includeInferredStatements = createIRI(NAMESPACE,
349+
"shacl.includeInferredStatements");
350+
345351
/**
346352
* <code>tag:rdf4j.org,2023:config/shacl.performanceLogging</code>
347353
*/

core/model-vocabulary/src/main/java/org/eclipse/rdf4j/model/vocabulary/RSX.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ public class RSX {
4040
/** <var>http://rdf4j.org/shacl-extensions#targetShape</var> */
4141
public final static IRI targetShape = create("targetShape");
4242

43+
public final static IRI rdfsSubClassReasoning = create("rdfsSubClassReasoning");
44+
public final static IRI includeInferredStatements = create("includeInferredStatements");
45+
4346
public final static IRI dataGraph = create("dataGraph");
4447
public final static IRI shapesGraph = create("shapesGraph");
4548

core/sail/inferencer/src/main/java/org/eclipse/rdf4j/sail/inferencer/fc/SchemaCachingRDFSInferencerConnection.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ void processForSchemaCache(Statement statement) {
114114
sail.addSubPropertyOfStatement(
115115
sail.getValueFactory().createStatement(subject, RDFS.SUBPROPERTYOF, RDFS.MEMBER));
116116
schemaChange = true;
117-
} else if (predicate.equals(RDF.TYPE)) {
117+
} else if (predicate.equals(RDF.TYPE) && object instanceof Resource) {
118118
if (!sail.hasType(((Resource) object))) {
119119
sail.addType((Resource) object);
120120
schemaChange = true;
@@ -276,11 +276,7 @@ private void addStatement(boolean actuallyAdd, Resource subject, IRI predicate,
276276

277277
}
278278

279-
if (predicate.equals(RDF.TYPE)) {
280-
if (!(object instanceof Resource)) {
281-
throw new SailException("Expected object to a a Resource: " + object.toString());
282-
}
283-
279+
if (predicate.equals(RDF.TYPE) && object instanceof Resource) {
284280
sail.resolveTypes((Resource) object)
285281
.stream()
286282
.peek(inferredType -> {

core/sail/shacl/src/main/java/org/eclipse/rdf4j/sail/shacl/ShaclSailBaseConfiguration.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ abstract class ShaclSailBaseConfiguration extends NotifyingSailWrapper {
3535
private boolean validationEnabled = ShaclSailConfig.VALIDATION_ENABLED_DEFAULT;
3636
private boolean cacheSelectNodes = ShaclSailConfig.CACHE_SELECT_NODES_DEFAULT;
3737
private boolean rdfsSubClassReasoning = ShaclSailConfig.RDFS_SUB_CLASS_REASONING_DEFAULT;
38+
private boolean includeInferredStatements = true;
3839
private boolean serializableValidation = ShaclSailConfig.SERIALIZABLE_VALIDATION_DEFAULT;
3940
private boolean performanceLogging = ShaclSailConfig.PERFORMANCE_LOGGING_DEFAULT;
4041
private boolean eclipseRdf4jShaclExtensions = ShaclSailConfig.ECLIPSE_RDF4J_SHACL_EXTENSIONS_DEFAULT;
@@ -146,6 +147,25 @@ public void setRdfsSubClassReasoning(boolean rdfsSubClassReasoning) {
146147
this.rdfsSubClassReasoning = rdfsSubClassReasoning;
147148
}
148149

150+
/**
151+
* Check if inferred statements from the base sail should be used during SHACL validation when
152+
* {@link #isRdfsSubClassReasoning()} is disabled.
153+
*
154+
* @return <code>true</code> if inferred statements should be considered, <code>false</code> otherwise.
155+
*/
156+
public boolean isIncludeInferredStatements() {
157+
return includeInferredStatements;
158+
}
159+
160+
/**
161+
* Allow SHACL validation to use inferred statements from the base sail when RDFS subclass reasoning is disabled.
162+
*
163+
* @param includeInferredStatements default true
164+
*/
165+
public void setIncludeInferredStatements(boolean includeInferredStatements) {
166+
this.includeInferredStatements = includeInferredStatements;
167+
}
168+
149169
/**
150170
* Disable the SHACL validation on commit()
151171
*/

0 commit comments

Comments
 (0)