Skip to content

Latest commit

 

History

History
158 lines (122 loc) · 5.13 KB

File metadata and controls

158 lines (122 loc) · 5.13 KB

Query Builder

Intention

Receives 3 optional data structures: AnnotationOfClass, AnnotationOfRelation, and AnnotationOfInstance.

Behavior

Depending on the availability of them, generates a query over DBpedia and stores it.

As a Qanary component, it reads the question and the annotations produced by upstream components from the Qanary triplestore (the shared process memory), performs its task — build a formal query from the annotations and execute it to obtain the answer — and writes the result back as standard Qanary (Web Annotation / qa:) annotations. See Input specification / Output specification below for the exact annotation contract.

Characteristics

  • Task type: Query Building and Execution (QBE).

  • Knowledge base: DBpedia.

  • External service: http://dbpedia.org/sparql}

  • Offline build: builds and (where present) tests run offline.

Implementation

  • Language: Java (JDK 21).

  • Major frameworks: Spring Boot 3.5 (spring-boot-starter-parent); the Qanary component framework eu.wdaqua.qanary:qa.component 4.0.0 (transitively Spring Boot Admin client + Apache Jena 5).

  • Main component class: src/main/java/eu/wdaqua/qanary/component/simplequerybuilderandexecutor/qbe/QueryBuilder.java (extends eu.wdaqua.qanary.component.QanaryComponent).

  • Tests: 4 test class(es) under src/test/java/ (QanaryServiceControllerTest.java, QueryTest.java, SwaggerUiAvailabilityTest.java, TestConfiguration.java).

Build and run

Targets the current Qanary framework 4.0.0 (Spring Boot 3, Java 21). Install the framework first (mvn install in the Qanary repository), then build with JDK 21:

JAVA_HOME=/path/to/jdk21 mvn clean package
docker build --build-arg JAR_FILE=target/qanary-component-qbe-simplequerybuilderandexecutor.jar -t qanary/qanary-component-qbe-simplequerybuilderandexecutor .

Input specification

@prefix qa: <http://www.wdaqua.eu/qa#> .
@prefix oa: <http://www.w3.org/ns/openannotation/core/> .

<urn:qanary:input> a qa:AnnotationOfClass .
<urn:qanary:input> oa:hasTarget [
        a oa:SpecificResource ;
        oa:hasSource ?q ;
    ];
    oa:hasBody ?uri .
@prefix qa: <http://www.wdaqua.eu/qa#> .
@prefix oa: <http://www.w3.org/ns/openannotation/core/> .

<urn:qanary:input> a qa:AnnotationOfRelation .
<urn:qanary:input> oa:hasTarget [
        a oa:SpecificResource ;
        oa:hasSource ?q ;
    ];
    oa:hasBody ?uri .
@prefix qa: <http://www.wdaqua.eu/qa#> .
@prefix oa: <http://www.w3.org/ns/openannotation/core/> .

<urn:qanary:input> a qa:AnnotationOfInstance .
<urn:qanary:input> oa:hasTarget [
    a   oa:SpecificResource;
        oa:hasSource ?q ;
        oa:hasSelector  [
            a oa:TextPositionSelector ;
            oa:start "0"^^xsd:nonNegativeInteger ;
            oa:end  "5"^^xsd:nonNegativeInteger
        ]
    ] .
<urn:qanary:input> oa:hasBody <dbr:Resource> .

Output specification

@prefix qa: <http://www.wdaqua.eu/qa#> .
@prefix oa: <http://www.w3.org/ns/openannotation/core/> .

<urn:qanary:output> a qa:AnnotationOfAnswerSPARQL ;
    oa:hasTarget <answerID> ;
    oa:hasBody "sparql query" ;
    oa:annotatedAt "2001-10-26T21:32:52"^^xsd:dateTime ;
    oa:annotatedBy <urn:qanary:QB#applicationName > .
@prefix qa: <http://www.wdaqua.eu/qa#> .
@prefix oa: <http://www.w3.org/ns/openannotation/core/> .
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .

<urn:qanary:output> a qa:AnnotationOfAnswerJson ;
    oa:hasTarget <answerID> ;
    oa:hasBody "jsonString"^^xsd:string ;
    oa:annotatedBy <urn:qanary:QB#applicationName > ;
    oa:annotatedAt "2001-10-26T21:32:52"^^xsd:dateTime .

Remark: in SparqlExecuter ?answer a qa:AnswerJson is used

Build and run

This component targets the current Qanary framework 4.0.0 (Spring Boot 3, Java 21, Apache Jena 5). Install the framework first (mvn install in the Qanary repository), then build clean:

JAVA_HOME=/path/to/jdk21 mvn clean package
java -jar target/qanary-component-qbe-simplequerybuilderandexecutor.jar

Docker:

mvn clean package
docker build --build-arg JAR_FILE=target/qanary-component-qbe-simplequerybuilderandexecutor.jar \
  -t qanary/qanary-component-qbe-simplequerybuilderandexecutor .

Configuration is in src/main/resources/config/application.properties (server.port, spring.application.name, spring.boot.admin.url).

Tests

mvn test runs the full-context QanaryServiceControllerTest and QueryTest (the latter validates the generated SPARQL). The Spring Boot Admin client failing to reach a non-running pipeline is logged but non-fatal.

ℹ️
the migration to Jena 5 replaced the removed QueryExecutionFactory.sparqlService(endpoint, query) with QueryExecutionHTTP.service(endpoint).query(query).build().