Skip to content

Commit

Permalink
Qanary component KG2KG-Translation of AnnotationOfInstance (#309)
Browse files Browse the repository at this point in the history
* Init for new component

* Re-initalize new component

* WIP

* Work in progress

* Work in progress, added queries for wikidataToDbpedia and reverse

* Work in progress, added updating triplestore

* Added Test file

* Refactored method names

* Added Exception handling, refactored code, added comments

* Adjusted Pojo equals()-method, refactored exceptions

* WIP: Tests, Structure refactoring

* Adjusted exceptions and tests, work in progress

* Added functionality for several oa:sameAs annotations

* Finished testing, clean up code

* Added Springdoc and swaggerUI

* Updated documentation

* set up docker

* Optimized README.adoc

* KG2KGTranslateAnnotationsOfInstance: small improvements

* KG2KGTranslateAnnotationsOfInstanceController: small improvements

* AnnotationOfInstancePojo: ensured formatting

* application.properties: improved component description

* Update annotationsOfInstanceResourceQuery.rq

* Update insert_one_annotation.rq

---------

Co-authored-by: Andreas Both <[email protected]>
  • Loading branch information
dschiese and anbo-de authored Oct 1, 2023
1 parent 71ea6a7 commit 48f942f
Show file tree
Hide file tree
Showing 22 changed files with 6,669 additions and 1 deletion.
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"]
80 changes: 80 additions & 0 deletions qanary-component-KG2KG-TranslateAnnotationsOfInstance/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
:toc:
:toclevels: 5
:toc-placement!:
:source-highlighter: highlight.js
ifdef::env-github[]
:tip-caption: :bulb:
:note-caption: :information_source:
:important-caption: :heavy_exclamation_mark:
:caution-caption: :fire:
:warning-caption: :warning:
endif::[]

# KG2KG Translation of AnnotationOfInstance

This component is intended to translate resources from https://dbpedia.org/[DBpedia] to https://www.wikidata.org/[Wikidata] and vice versa for existing annotations of type `qa:AnnotationOfInstance`.
For example, let's assume the resource http://dbpedia.org/resource/Albert_Einstein of the DBpedia knowledge graph is (was recognized by a component and hence) stored in the Qanary triplestore as part of an annotation of type `qa:AnnotationOfInstance`.
Then, this component will try to find the corresponding resource in the Wikidata knowledge graph (using the `owl:sameAs` property) and automatically replace the value with the mentioned annotation by the found resource URI (in our example, it would be http://www.wikidata.org/entity/Q937).
Obviously, the approach works the same way if a Wikidata resource is found in the original data.

---

toc::[]

---

## Processing

The component's process follows three steps:

--
. Fetching all existing annotations of type `qa:AnnotationOfInstance` from the Qanary Triplestore
. depending on whether a DBpedia or Wikidata resource is used in the annotation DBpedia is asked for the relation `owl:sameAs` to Wikidata or DBpedia
. for each existing annotation of type `qa:AnnotationOfInstance` all equivalent resources are stored in the Qanary triplestore with only the resource URI (from the original annotation) is replaced
--



## Input specification

[source,ttl]
----
@prefix qa: <http://www.wdaqua.eu/qa#> .
@prefix oa: <http://www.w3.org/ns/openannotation/core/> .
<urn:qanary:output> a qa:AnnotationOfInstance .
<urn:qanary:output> 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
]
] .
<urn:qanary:output> oa:hasBody <urn:dbr:Resource> ;
oa:annotatedBy "qanaryComponent" ;
oa:annotatedAt "2001-10-26T21:32:52"^^xsd:dateTime .
----

## 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:AnnotationOfInstance .
<urn:qanary:output> 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
]
] .
<urn:qanary:output> oa:hasBody <urn:dbr:Resource> ;
oa:annotatedBy <urn:qanary:KG2KGTranslateAnnotationsOfInstance> ;
oa:annotatedAt "2001-10-26T21:32:52"^^xsd:dateTime .
----
127 changes: 127 additions & 0 deletions qanary-component-KG2KG-TranslateAnnotationsOfInstance/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
<?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-KG2KG-TranslateAnnotationsOfInstance</artifactId>
<version>0.1.0</version>
<name>Qanary component KG2KG Translation of AnnotationOfInstance</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.6.7</version>
<relativePath></relativePath>
</parent>
<properties>
<java.version>17</java.version>
<docker.image.prefix>qanary</docker.image.prefix>
<docker.image.name>qanary-component-kg2kg-translateannotationsofinstance</docker.image.name>
<dockerfile-maven-version>1.4.13</dockerfile-maven-version>
<spingdoc.version>1.7.0</spingdoc.version>
<qanary.component.version>[3.7.0,4.0.0)</qanary.component.version>
<qanary.commons.version>[3.8.0,4.0.0)</qanary.commons.version>
</properties>
<dependencies>
<dependency>
<groupId>eu.wdaqua.qanary</groupId>
<artifactId>qa.component</artifactId>
<version>${qanary.component.version}</version>
</dependency>
<dependency>
<groupId>eu.wdaqua.qanary</groupId>
<artifactId>qa.commons</artifactId>
<version>${qanary.commons.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<scope>test</scope>
</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.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>${spingdoc.version}</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<version>2.6.7</version>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>
eu.wdaqua.qanary.component.Application
</mainClass>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<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>
<testResources>
<testResource>
<directory>src/test/resources</directory>
</testResource>
</testResources>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package eu.wdaqua.qanary.component;


import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;

@SpringBootApplication
@ComponentScan(basePackages = {"eu.wdaqua.qanary"})
public class Application {

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

@Bean
public QanaryComponent qanaryComponent(
@Value("${spring.application.name}") final String applicationName) {
return new KG2KGTranslateAnnotationsOfInstance(applicationName);
}
}
Loading

0 comments on commit 48f942f

Please sign in to comment.