Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Heuristic:AKSW RDFUnit JUnit Input Model Filtering

From Leeroopedia
Knowledge Sources
Domains Debugging, JUnit, SHACL
Last Updated 2026-10-16 00:00 GMT

Overview

Filter SHACL violation results in JUnit integration to only include failing nodes that are part of the input data model, preventing false positives from schema-level resources.

Description

When RDFUnit runs SHACL validation through the JUnit runner (`RdfUnitJunitRunner`), the validation process may produce violation results for nodes that exist in the schema graph rather than the input data model. This happens because the test execution combines the input data with schema definitions, and SHACL shapes may reference schema-level resources (e.g., RDFS/OWL definitions) that are not part of the user's actual data.

The `ShaclResultStatement.evaluate()` method filters results using `nodeIsPartOfInputModel()`, which checks whether each failing node appears as either a subject or an object in the test input model. Only violations against nodes actually present in the input data are reported as failures; schema-level violations are silently dropped. This prevents false-positive test failures caused by schema resources that legitimately violate shape constraints but are not part of the data being tested.

Usage

Use this heuristic when debugging JUnit SHACL tests that show fewer violations than expected. The filtering is automatic and cannot be disabled through the JUnit runner API. If you need to see all violations including schema-level ones, use the programmatic API (`RDFUnitStaticValidator`) directly instead of the JUnit runner.

The Insight (Rule of Thumb)

  • Action: Be aware that JUnit SHACL validation only reports violations for nodes present in the `@TestInput` model.
  • Value: The `nodeIsPartOfInputModel()` check filters by subject and object presence in the input model.
  • Trade-off: Prevents schema-level false positives but may hide legitimate violations if the input model is incomplete.
  • Compatibility: Applies only to `RdfUnitJunitRunner`; programmatic validation via `RDFUnitStaticValidator` does not apply this filter.

Reasoning

SHACL validation combines the data model and schema model into a single graph for query execution. Without filtering, violation results would include failures for schema-level resources (e.g., an RDFS class definition that does not conform to a shape targeting instances). These are not real data quality issues—they are artifacts of combining schema and data. The input model filter ensures only violations against the user's actual data are surfaced as JUnit test failures.

Code Evidence

Filtering logic from `ShaclResultStatement.java:29-46`:

@Override
public void evaluate() {
    final Collection<TestCaseResult> testCaseResults = rdfUnitJunitStatusTestExecutor
        .runTest(testCase);
    final Collection<ShaclLiteTestCaseResult> remainingResults = new ArrayList<>();
    for (TestCaseResult t : testCaseResults) {
        ShaclLiteTestCaseResult r = (ShaclLiteTestCaseResult) t;
        if (!nodeIsPartOfInputModel(r)) {
            continue;
        }
        remainingResults.add(r);
    }
    // ...
    assertThat(b.toString(), remainingResults.isEmpty());
}

Input model check from `ShaclResultStatement.java:48-55`:

private boolean nodeIsPartOfInputModel(ShaclLiteTestCaseResult r) {
    boolean isResourceAsSubject =
        r.getFailingNode().isResource() &&
            testCase.getTestInputModel()
                .contains(r.getFailingNode().asResource(), null, (RDFNode) null);
    boolean asObject = testCase.getTestInputModel().contains(null, null, r.getFailingNode());
    return isResourceAsSubject || asObject;
}

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment