Skip to content

Commit

Permalink
Merge pull request #303 from WDAqua/qanary-component-QB-DateOfDeathDB…
Browse files Browse the repository at this point in the history
…pedia

Qanary component qanary-component-QB-DateOfDeathDBpedia
  • Loading branch information
dschiese authored Aug 24, 2023
2 parents 7e14fd2 + f3cd66b commit 4577bbf
Show file tree
Hide file tree
Showing 17 changed files with 1,124 additions and 2 deletions.
7 changes: 7 additions & 0 deletions qanary-component-QB-DateOfDeathDBpedia/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
FROM openjdk:17

# Add the service itself
ARG JAR_FILE
ADD target/${JAR_FILE} /qanary-service.jar

ENTRYPOINT ["java", "-jar", "/qanary-service.jar"]
103 changes: 103 additions & 0 deletions qanary-component-QB-DateOfDeathDBpedia/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
# QB DateOfDeathDBpedia component

## Description
This component is intended to create and store a SPARQL query which can be executed on dbpedia to receive the date of death for a given person.

## Input specification
[source, ttl]
----
@prefix qa: <http://www.wdaqua.eu/qa#> .
@prefix oa: <http://www.w3.org/ns/openannotation/core/> .

<urn:qanary:input> oa:hasBody <dbr:Resource> ;
qa:score "0.5"^^xsd:decimal ;
oa:hasTarget [
a oa:SpecificResource;
oa:hasSource <urn:qanary:myQanaryQuestion> ;
oa:hasSelector [
a oa:TextPositionSelector ;
oa:start "0"^^xsd:nonNegativeInteger ;
oa:end "5"^^xsd:nonNegativeInteger
]
] .
----

## Output specification
[source, ttl]
----
@prefix qa: <http://www.wdaqua.eu/qa#> .
@prefix oa: <http://www.w3.org/ns/openannotation/core/> .

<urn:qanary:output> a qa:AnnotationOfAnswerSPARQL ;
oa:hasTarget <urn:qanary:myQanaryQuestion> ;
oa:hasBody "sparql query" ;
qa:score "1.0"^^xsd:float ;
oa:annotatedAt "2001-10-26T21:32:52"^^xsd:dateTime ;
oa:annotatedBy <urn:qanary:applicationName > .
----

## Created SPARQL query
[source, sparql]
----
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>

SELECT * WHERE {
?resource dbo:deathDate ?answer .# date of death
?resource rdfs:label ?label .# get the persons name
FILTER(LANG(?label) = "en") .# only English names
VALUES ?resource { ?dbpediaResource } .# only for this specific resource
}
ORDER BY ?resource
----
### Explanation
- This component expects an annotation of named entities within the Qanary triplestore. Hence, previously another component capable of recognizing and disambiguating (NER/NED) DBpedia named entities needs to be executed.
- e.g., the NED component using https://github.com/WDAqua/Qanary-question-answering-components/tree/master/qanary_component-NED-DBpedia-Spotlight[Qanary DBpedia Spotlight component]

## Example

### Question:
```
What is the date of death of Stephen Hawking?
```
### Created SPARQL-Query (stored in triplestore)

[source,sparql]
----
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX dct: <http://purl.org/dc/terms/>
PREFIX foaf: <http://xmlns.com/foaf/0.1/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
PREFIX dbo: <http://dbpedia.org/ontology/>
PREFIX xsd: <http://www.w3.org/2001/XMLSchema#>
SELECT * WHERE {
?resource dbo:deathDate ?answer .# date of death
?resource rdfs:label ?label .# get the persons name
FILTER(LANG(?label) = "en") .# only English names
VALUES ?resource { <http://dbpedia.org/resource/Stephen_Hawking> } .# only for this specific resource
}
ORDER BY ?resource
----

## Build and Run
### Build with Maven
```
mvn package
```
or (excludes the buidling of a corresponding Docker container):
```
mvn package -Ddockerfile.skip
```
### Run
To run the built JAR-file execute
```
java -jar target/qanary-component-QB-DateOfDeathDBpedia-X.Y.Z.jar
```
where X, Y and Z represent the current version of the component.
187 changes: 187 additions & 0 deletions qanary-component-QB-DateOfDeathDBpedia/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>eu.wdaqua.qanary.component</groupId>
<artifactId>qanary-component-QB-DateOfDeathDBpedia</artifactId>
<version>0.1.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
</parent>
<properties>
<java.version>17</java.version>
<qanary.version>[3.7.0,4.0.0)</qanary.version>
<docker.image.prefix>qanary</docker.image.prefix>
<docker.image.name>qanary-component-qb-dateofdeathdbpedia</docker.image.name>
<dockerfile-maven-version>1.4.13</dockerfile-maven-version>
<spingdoc.version>1.7.0</spingdoc.version>
</properties>

<dependencies>
<dependency>
<groupId>eu.wdaqua.qanary</groupId>
<artifactId>qa.component</artifactId>
<version>${qanary.version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
<version>2.20.0</version>
<exclusions>
<exclusion>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
<exclusions>
<exclusion>
<artifactId>hamcrest-core</artifactId>
<groupId>org.hamcrest</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.14.5</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>1.14.5</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-inline</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.10.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${spingdoc.version}</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-webmvc-core</artifactId>
<version>${spingdoc.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>
eu.wdaqua.qanary.component.dateofdeathrealpersons.qb.Application
</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- https://github.com/spotify/dockerfile-maven -->
<!-- build Docker image: mvn dockerfile:build -->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>${dockerfile-maven-version}</version>
<executions>
<execution>
<id>default</id>
<goals>
<goal>build</goal>
<goal>push</goal>
</goals>
</execution>
<execution>
<id>default-2</id>
<goals>
<goal>tag</goal>
<goal>push</goal>
</goals>
<configuration>
<tag>latest</tag>
</configuration>
</execution>
</executions>
<configuration>
<repository>${docker.image.prefix}/${docker.image.name}</repository>
<tag>${project.version}</tag>
<buildArgs>
<JAR_FILE>${project.build.finalName}.jar</JAR_FILE>
</buildArgs>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@

package eu.wdaqua.qanary.component.dateofdeathrealpersons.qb;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

import eu.wdaqua.qanary.component.QanaryComponentConfiguration;
import eu.wdaqua.qanary.component.QanaryComponent;

@SpringBootApplication
@EnableAutoConfiguration
@ComponentScan(basePackages = {"eu.wdaqua.qanary"})
/**
* basic class for wrapping functionality to a Qanary component
* note: there is no need to change something here
*/
public class Application {

/**
* this method is needed to make the QanaryComponent in this project known
* to the QanaryServiceController in the qanary_component-template
*
* @return
*/
@Bean
public QanaryComponent qanaryComponent(
@Value("${spring.application.name}") final String applicationName) {
return new QueryBuilderDateOfDeathDBpedia(applicationName);
}

@Autowired
public QanaryComponentConfiguration qanaryComponentConfiguration;

public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
Loading

0 comments on commit 4577bbf

Please sign in to comment.