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

Implementation:AKSW RDFUnit QueryGeneration Factories

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

Overview

Concrete factory classes that transform test cases into executable SPARQL queries with four result semantics: ASK, COUNT, SELECT, and Extended SELECT.

Description

RDFUnit provides four `QueryGenerationFactory` implementations, each producing a different SPARQL query type from the same test case:

  • QueryGenerationAskFactory: Converts the SELECT query from `QueryGenerationSelectFactory` into an ASK query (`query.setQueryAskType()`). Returns boolean violation check. Used by `StatusTestExecutor`.
  • QueryGenerationCountFactory:*** Wraps the test case WHERE clause in a `SELECT (COUNT(?this) AS ?total)` aggregate. Handles GROUP BY by wrapping in a sub-SELECT (JENA-766 workaround). Used by `AggregatedTestExecutor`.
  • QueryGenerationSelectFactory: Produces `SELECT ?this` (plus optional focus node variable) with the test case WHERE clause. Used by `ShaclSimpleTestExecutor` for SHACL Lite results.
  • QueryGenerationExtendedSelectFactory:*** Produces `SELECT ?this` plus all variable annotation names from the test case, ordered by `?this`. Used by `ShaclTestExecutor` for full SHACL results.

All factories implement `QueryGenerationFactory` with `getSparqlQuery(TestCase)` returning a Jena `Query` object and `getSparqlQueryAsString(TestCase)` returning a string.

Usage

  • Automatic selection:*** `TestExecutorFactory.createQueryGeneration()` selects the appropriate factory based on `TestCaseExecutionType`.
  • Manual query export:*** Use factories directly to export SPARQL queries from test cases (see `ExportTestCaseSparqlQueries` example).
  • Custom execution:*** Pass a factory to `TestExecutorFactory.createTestExecutor(executionType, qgf)` for custom execution.

Code Reference

Source Location

  • Repository: AKSW/RDFUnit
  • Files:
    • rdfunit-core/src/main/java/org/aksw/rdfunit/tests/query_generation/QueryGenerationAskFactory.java
    • rdfunit-core/src/main/java/org/aksw/rdfunit/tests/query_generation/QueryGenerationCountFactory.java
    • rdfunit-core/src/main/java/org/aksw/rdfunit/tests/query_generation/QueryGenerationSelectFactory.java
    • rdfunit-core/src/main/java/org/aksw/rdfunit/tests/query_generation/QueryGenerationExtendedSelectFactory.java

Signature

// Common interface
public interface QueryGenerationFactory {
    Query getSparqlQuery(TestCase testCase);
    String getSparqlQueryAsString(TestCase testCase);
}

// ASK: boolean violation check
public class QueryGenerationAskFactory implements QueryGenerationFactory { ... }

// COUNT: aggregate violation count
public class QueryGenerationCountFactory implements QueryGenerationFactory { ... }

// SELECT: individual violating nodes (SHACL Lite)
public class QueryGenerationSelectFactory implements QueryGenerationFactory { ... }

// Extended SELECT: all annotated variables (full SHACL)
public class QueryGenerationExtendedSelectFactory implements QueryGenerationFactory { ... }

Import

import org.aksw.rdfunit.tests.query_generation.QueryGenerationAskFactory;
import org.aksw.rdfunit.tests.query_generation.QueryGenerationCountFactory;
import org.aksw.rdfunit.tests.query_generation.QueryGenerationSelectFactory;
import org.aksw.rdfunit.tests.query_generation.QueryGenerationExtendedSelectFactory;
import org.aksw.rdfunit.tests.query_generation.QueryGenerationFactory;

I/O Contract

Inputs

Name Type Required Description
testCase TestCase Yes Test case with SPARQL WHERE clause and variable annotations

Outputs

Name Type Description
getSparqlQuery() Query Jena Query object ready for execution
getSparqlQueryAsString() String Complete SPARQL query string with prefix declarations

Usage Examples

Export All Query Types for a Test Case

import org.aksw.rdfunit.tests.query_generation.*;

List<QueryGenerationFactory> factories = Arrays.asList(
    new QueryGenerationAskFactory(),
    new QueryGenerationCountFactory(),
    new QueryGenerationSelectFactory(),
    new QueryGenerationExtendedSelectFactory()
);

for (TestCase testCase : testCases) {
    for (QueryGenerationFactory factory : factories) {
        System.out.println(factory.getSparqlQueryAsString(testCase));
        System.out.println("---");
    }
}

Use with TestExecutorFactory

// The factory is selected automatically based on execution type
TestExecutor executor = TestExecutorFactory.createTestExecutor(
    TestCaseExecutionType.shaclLiteTestCaseResult);
// Internally uses QueryGenerationSelectFactory

Related Pages

Implements Principle

Requires Environment

Uses Heuristics

Page Connections

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