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

Principle:AKSW RDFUnit SPARQL Query Generation

From Leeroopedia
Knowledge Sources
Domains Semantic_Web, Query_Languages, Testing
Last Updated 2026-10-16 00:00 GMT

Overview

Technique for transforming abstract validation test cases into concrete, executable SPARQL queries with different result semantics (ASK, COUNT, SELECT, Extended SELECT).

Description

SPARQL Query Generation is the bridge between RDFUnit's abstract test case definitions and the actual SPARQL queries that get executed against RDF data. Each test case contains a SPARQL WHERE clause (derived from a pattern template or SHACL constraint) plus variable annotations. The query generation factories transform these into complete queries with different execution semantics:

  • ASK: Returns a boolean—whether any violations exist. Used for status-level result reporting.
  • COUNT: Returns the number of violating resources as an aggregate. Used for aggregated result reporting.
  • SELECT: Returns the focus node (`?this`) for each violation. Used for SHACL Lite result reporting.
  • Extended SELECT: Returns `?this` plus all annotated variables, ordered by focus node. Used for full SHACL result reporting with maximum detail.

The choice of query type affects both performance (ASK is fastest) and result granularity (Extended SELECT provides the most detail). The execution type is configured at validation time, allowing the same test suite to produce different result levels.

Usage

Use this principle when you need to control the trade-off between validation performance and result detail. ASK queries are fastest but only report pass/fail. COUNT queries give violation totals. SELECT and Extended SELECT queries return individual violating resources for detailed error reporting.

Theoretical Basis

All query types share the same WHERE clause from the test case; they differ in the SELECT clause:

# ASK: boolean violation check
ASK WHERE { ?this a ex:Person . FILTER NOT EXISTS { ?this ex:name ?n . } }

# COUNT: aggregate violation count
SELECT (COUNT(?this) AS ?total) WHERE { ?this a ex:Person . FILTER NOT EXISTS { ?this ex:name ?n . } }

# SELECT: individual violating nodes
SELECT ?this WHERE { ?this a ex:Person . FILTER NOT EXISTS { ?this ex:name ?n . } }

# Extended SELECT: all annotated variables
SELECT ?this ?property ?value WHERE { ... } ORDER BY ASC(?this)

When a query has GROUP BY, the COUNT factory wraps it in a sub-SELECT to compute the aggregate correctly (see JENA-766).

Related Pages

Implemented By

Page Connections

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