Skip to content

Commit

Permalink
Merge pull request #329 from dschiese/updatedComponents
Browse files Browse the repository at this point in the history
Updated components
  • Loading branch information
dschiese authored Jan 16, 2024
2 parents 46cd407 + 22992fd commit 182009b
Show file tree
Hide file tree
Showing 49 changed files with 199 additions and 330 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>eu.wdaqua.qanary.component</groupId>
<artifactId>qanary-component-KG2KG-TranslateAnnotationsOfInstance</artifactId>
<version>0.1.4</version>
<version>0.2.0</version>
<name>Qanary component KG2KG Translation of AnnotationOfInstance</name>
<parent>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class KG2KGTranslateAnnotationsOfInstance extends QanaryComponent {
- depending on what is given the other resource is returned
*/

private static final String ANNOTATION_OF_INSTANCE_RESOURCES_QUERY = "/queries/annotationsOfInstanceResourceQuery.rq";
private static final String ANNOTATION_OF_INSTANCE_RESOURCES_QUERY = "/queries/select_all_AnnotationOfInstance.rq";
private static final String DBPEDIA_TO_WIKIDATA_QUERY = "/queries/dbpediaToWikidata.rq";
private static final String WIKIDATA_TO_DBPEDIA_QUERY = "/queries/wikidataToDbpedia.rq";
private static final String INSERT_ANNOTATION_QUERY = "/queries/insert_one_annotation.rq";
Expand Down Expand Up @@ -99,7 +99,7 @@ public ResultSet fetchAnnotations(String graphID, final QanaryUtils qanaryUtils)
*/
public String getRequestQuery(String graphID) throws IOException {
QuerySolutionMap bindingsForQuery = new QuerySolutionMap();
bindingsForQuery.add("graphID", ResourceFactory.createResource(graphID));
bindingsForQuery.add("graph", ResourceFactory.createResource(graphID));

return QanaryTripleStoreConnector.readFileFromResourcesWithMap(ANNOTATION_OF_INSTANCE_RESOURCES_QUERY, bindingsForQuery);
}
Expand All @@ -109,9 +109,9 @@ public List<AnnotationOfInstancePojo> createAnnotationObjets(ResultSet resultSet

while (resultSet.hasNext()) {
QuerySolution entry = resultSet.next();
String entryResource = entry.get("resource").toString();
String entryResource = entry.get("hasBody").toString();
double score = entry.get("score").asLiteral().getDouble();
String targetQuestion = entry.get("targetQuestion").toString();
String targetQuestion = entry.get("hasSource").toString();
int start = entry.get("start").asLiteral().getInt();
int end = entry.get("end").asLiteral().getInt();
String annotationId = entry.get("annotationId").toString();
Expand Down

This file was deleted.

3 changes: 1 addition & 2 deletions qanary-component-NED-AGDISTIS/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>qanary-component-NED-AGDISTIS</artifactId>
<groupId>eu.wdaqua.qanary.component</groupId>
<version>4.4.0</version>

<version>4.5.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
public class Agdistis extends QanaryComponent {
private static final Logger LOGGER = LoggerFactory.getLogger(Agdistis.class);

private final String FILENAME_SPOTS_FROM_GRAPH = "/queries/select_all_spots_from_graph.rq";
private final String FILENAME_SPOTS_FROM_GRAPH = "/queries/select_all_AnnotationOfSpotInstance.rq";
private final String FILENAME_INSERT_ANNOTATION = "/queries/insert_one_annotation.rq";

private final String applicationName;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void init() throws URISyntaxException, QanaryExceptionNoOrMultipleQuestio
ReflectionTestUtils.setField(this.mockedAgdistis, "myRestTemplate", this.myRestTemplate);
ReflectionTestUtils.setField(this.mockedAgdistis, "myCacheOfResponses", this.myCacheOfResponses);
ReflectionTestUtils.setField(this.mockedAgdistis, "apiUrl", this.apiUrl);
ReflectionTestUtils.setField(this.mockedAgdistis, "FILENAME_SPOTS_FROM_GRAPH", "/queries/select_all_spots_from_graph.rq");
ReflectionTestUtils.setField(this.mockedAgdistis, "FILENAME_SPOTS_FROM_GRAPH", "/queries/select_all_AnnotationOfSpotInstance.rq");
ReflectionTestUtils.setField(this.mockedAgdistis, "FILENAME_INSERT_ANNOTATION", "/queries/insert_one_annotation.rq");

this.mockedQanaryQuestion = Mockito.mock(QanaryQuestion.class);
Expand Down
2 changes: 1 addition & 1 deletion qanary-component-NED-DiambiguationClass-OKBQA/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>eu.wdaqua.qanary.component</groupId>
<artifactId>qanary-component-NED-DiambiguationClass-OKBQA</artifactId>
<version>3.1.4</version>
<version>3.2.0</version>

<parent>
<groupId>org.springframework.boot</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class DiambiguationClass extends QanaryComponent {

private final String applicationName;
private String FILENAME_INSERT_ANNOTATION = "/queries/insert_one_annotation.rq";
private String FILENAME_SELECT_ANNOTATED_LANGUAGES = "/queries/select_annotated_languages.rq";
private String FILENAME_SELECT_ANNOTATED_LANGUAGES = "/queries/select_all_AnnotationOfQuestionLanguage.rq";

public DiambiguationClass(@Value("${spring.application.name}") final String applicationName) {
this.applicationName = applicationName;
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion qanary-component-NED-Tagme/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>eu.wdaqua.qanary.component</groupId>
<artifactId>qanary-component-NED-Tagme</artifactId>
<version>3.2.0</version>
<version>3.3.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ GRAPH ?graph {
a oa:TextPositionSelector ;
oa:start ?start ;
oa:end ?end ;
qa:score ?score .
] .
qa:score ?score
]
] .
?a oa:hasBody ?answer ;
oa:annotatedBy ?application ;
Expand All @@ -22,4 +22,4 @@ GRAPH ?graph {
WHERE {
BIND (IRI(str(RAND())) AS ?a) .
BIND (now() as ?time) .
}
}
6 changes: 5 additions & 1 deletion qanary-component-QB-BirthDataWikidata/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<groupId>eu.wdaqua.qanary.component</groupId>
<artifactId>qanary-component-QB-BirthDataWikidata</artifactId>
<version>3.4.0</version>

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
Expand Down Expand Up @@ -34,6 +33,11 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>eu.wdaqua.qanary</groupId>
<artifactId>qa.commons</artifactId>
<version>[3.5.4,4.0.0]</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-to-slf4j</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
@Component
public class BirthDataQueryBuilder extends QanaryComponent {
private static final Logger logger = LoggerFactory.getLogger(BirthDataQueryBuilder.class);

public static final String FILENAME_ANNOTATIONS = "/queries/getAnnotation.rq";
public static final String FILENAME_ANNOTATIONS_NAMED_ENTITY_FILTERED_FOR_WIKIDATA = "/queries/getAnnotationOfNamedEntityLinkedToSpecificKnowledgeGraph.rq";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.springframework.test.context.web.WebAppConfiguration;

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

import static org.junit.jupiter.api.Assertions.*;

Expand All @@ -27,7 +29,7 @@ class QueryTest {
void filenameAnnotationsQueryTest() throws IOException {
QuerySolutionMap bindingsForFirstname = new QuerySolutionMap();
bindingsForFirstname.add("graph", ResourceFactory.createResource("urn:graph"));
bindingsForFirstname.add("value", ResourceFactory.createStringLiteral("FIRST_NAME"));
bindingsForFirstname.add("hasBody", ResourceFactory.createStringLiteral("FIRST_NAME"));

String sparqlCheckFirstname = QanaryTripleStoreConnector.readFileFromResourcesWithMap(
TestConfiguration.FILENAME_ANNOTATIONS, bindingsForFirstname
Expand All @@ -37,17 +39,18 @@ void filenameAnnotationsQueryTest() throws IOException {
assertFalse(sparqlCheckFirstname.isEmpty());
assertFalse(sparqlCheckFirstname.isBlank());

assertEquals(TestConfiguration.getTestQuery("queries/getAnnotationTest.rq"), sparqlCheckFirstname);
assertEquals(TestConfiguration.getTestQuery("queries/getAnnotationTest.rq").concat("\n"),sparqlCheckFirstname);
}

@Test
void filenameAnnotationsFilteredQueryTest() throws IOException {
QuerySolutionMap bindingsForAnnotation = new QuerySolutionMap();
bindingsForAnnotation.add("graph", ResourceFactory.createResource("urn:graph"));
bindingsForAnnotation.add("source", ResourceFactory.createResource("urn:source"));
bindingsForAnnotation.add("filterStart", ResourceFactory.createTypedLiteral(String.valueOf(5), XSDDatatype.XSDint));
bindingsForAnnotation.add("hasSource", ResourceFactory.createResource("urn:source"));
bindingsForAnnotation.add("start", ResourceFactory.createTypedLiteral(String.valueOf(5), XSDDatatype.XSDint));

String sparqlGetAnnotation = QanaryTripleStoreConnector.readFileFromResourcesWithMap(

TestConfiguration.FILENAME_ANNOTATIONS_NAMED_ENTITY_FILTERED_FOR_WIKIDATA,
bindingsForAnnotation
);
Expand All @@ -56,7 +59,7 @@ void filenameAnnotationsFilteredQueryTest() throws IOException {
assertFalse(sparqlGetAnnotation.isEmpty());
assertFalse(sparqlGetAnnotation.isBlank());

assertEquals(TestConfiguration.getTestQuery("queries/getAnnotationFilteredTest.rq"), sparqlGetAnnotation);
assertEquals(TestConfiguration.getTestQuery("queries/getAnnotationFilteredTest.rq").concat("\n"), sparqlGetAnnotation);
}

@Test
Expand All @@ -73,7 +76,7 @@ void questionAnswerFromWikidataByPersonTest() throws IOException {
assertFalse(sparql.isEmpty());
assertFalse(sparql.isBlank());

assertEquals(TestConfiguration.getTestQuery("queries/getQuestionAnswerFromWikidataByPersonTest.rq"), sparql);
assertEquals(TestConfiguration.getTestQuery("queries/getQuestionAnswerFromWikidataByPersonTest.rq").concat("\n"), sparql);
}

@Test
Expand All @@ -90,7 +93,7 @@ void wikidataQueryFirstAndLastNameTest() throws IOException {
assertFalse(sparql.isEmpty());
assertFalse(sparql.isBlank());

assertEquals(TestConfiguration.getTestQuery("queries/getQuestionAnswerFromWikidataByFirstnameLastnameTest.rq"), sparql);
assertEquals(TestConfiguration.getTestQuery("queries/getQuestionAnswerFromWikidataByFirstnameLastnameTest.rq").concat("\n"), sparql);
}

}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package eu.wdaqua.component.birthdatawikidata.qb;

import java.io.IOException;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ResourceUtils;

import java.io.*;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Scanner;
import java.util.stream.Collectors;

import eu.wdaqua.component.qb.birthdata.wikidata.BirthDataQueryBuilder;

@org.springframework.boot.test.context.TestConfiguration
public class TestConfiguration {

protected static final String FILENAME_ANNOTATIONS = BirthDataQueryBuilder.FILENAME_ANNOTATIONS;
protected static final String FILENAME_ANNOTATIONS_NAMED_ENTITY_FILTERED_FOR_WIKIDATA = BirthDataQueryBuilder.FILENAME_ANNOTATIONS_NAMED_ENTITY_FILTERED_FOR_WIKIDATA;
protected static final String FILENAME_WIKIDATA_BIRTHDATA_QUERY_PERSON = BirthDataQueryBuilder.FILENAME_WIKIDATA_BIRTHDATA_QUERY_PERSON;
Expand All @@ -20,9 +27,17 @@ public class TestConfiguration {
* @throws IOException
*/
protected static String getTestQuery(String testQueryFilename) throws IOException {
String path = TestConfiguration.class.getClassLoader().getResource(testQueryFilename).getPath();
// String path = TestConfiguration.class.getClassLoader().getResource(testQueryFilename).getPath();
// File file = ResourceUtils.getFile(ResourceUtils.CLASSPATH_URL_PREFIX + testQueryFilename);
// return new String(Files.readAllBytes(file.toPath()));

return new String(Files.readAllBytes(Paths.get(path)));
try (InputStream inputStream = TestConfiguration.class.getClassLoader().getResourceAsStream(testQueryFilename)) {
if (inputStream != null) {
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
return reader.lines().collect(Collectors.joining("\n"));
} else {
throw new IOException("Resource not found: " + testQueryFilename);
}
}
}

}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
PREFIX qa: <http://www.wdaqua.eu/qa#>
PREFIX oa: <http://www.w3.org/ns/openannotation/core/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT *
Expand All @@ -19,4 +18,3 @@ WHERE
FILTER ( ?start = "5"^^<http://www.w3.org/2001/XMLSchema#int> )
FILTER regex(?wikidataResource, ?regexForResourceFilter, "i")
}
ORDER BY DESC(?annotationScore)
Original file line number Diff line number Diff line change
@@ -1,20 +1,25 @@
PREFIX qa: <http://www.wdaqua.eu/qa#>
PREFIX oa: <http://www.w3.org/ns/openannotation/core/>
PREFIX dbr: <http://dbpedia.org/resource/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>

SELECT *
FROM <urn:graph>
WHERE
{ ?annotation oa:hasBody ?wikidataResource ;
qa:score ?annotationScore ;
oa:hasTarget ?target
FILTER ( ?wikidataResource = "FIRST_NAME" )
?target oa:hasSource ?source ;
oa:hasSelector ?textSelector .
?textSelector
rdf:type oa:TextPositionSelector ;
{ ?annotationId
rdf:type qa:AnnotationOfInstance ;
oa:hasTarget _:b0 .
_:b0 rdf:type oa:SpecificResource ;
oa:hasSource ?hasSource ;
oa:hasSelector _:b1 .
_:b1 rdf:type oa:TextPositionSelector ;
oa:start ?start ;
oa:end ?end
oa:end ?end .
?annotationId
oa:hasBody "FIRST_NAME" ;
oa:annotatedBy ?annotatedBy ;
oa:annotatedAt ?annotatedAt
OPTIONAL
{ ?annotationId
qa:score ?score
}
}
ORDER BY DESC(?annotationScore)
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>eu.wdaqua.qanary.component</groupId>
<artifactId>qanary-component-QB-ComicCharacterAlterEgoSimpleDBpedia</artifactId>
<version>3.2.4</version>

<version>3.3.0</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class ComicCharacterAlterEgoSimpleDBpediaQueryBuilder extends QanaryCompo
private final String applicationName;

private String FILENAME_INSERT_ANNOTATION = "/queries/insert_one_annotation.rq";
private String FILENAME_SELECT_ANNOTATION = "/queries/select_annotation.rq";
private String FILENAME_SELECT_ANNOTATION = "/queries/select_all_AnnotationOfSpotInstance.rq";
private String FILENAME_DBPEDIA_QUERY = "/queries/dbpedia_query.rq";

public ComicCharacterAlterEgoSimpleDBpediaQueryBuilder(@Value("${spring.application.name}") final String applicationName) {
Expand Down Expand Up @@ -75,7 +75,7 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {

QuerySolutionMap bindingsForSelect = new QuerySolutionMap();
bindingsForSelect.add("graph", ResourceFactory.createResource(qanaryQuestion.getOutGraph().toASCIIString()));
bindingsForSelect.add("targetQuestion", ResourceFactory.createResource(qanaryQuestion.getUri().toASCIIString()));
bindingsForSelect.add("hasSource", ResourceFactory.createResource(qanaryQuestion.getUri().toASCIIString()));

// get the template of the INSERT query
String sparql = this.loadQueryFromFile(FILENAME_SELECT_ANNOTATION, bindingsForSelect);
Expand All @@ -89,8 +89,8 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
while (resultSet.hasNext()) {
QuerySolution result = resultSet.next();
logger.info("result: \n{}", result);
int start = result.get("startOfSpecificResource").asLiteral().getInt();
int end = result.get("endOfSpecificResource").asLiteral().getInt();
int start = result.get("start").asLiteral().getInt();
int end = result.get("end").asLiteral().getInt();
String name = question.substring(start, end);
logger.warn("annotation found for name '{}' (at {},{})", name, start, end);

Expand Down
Loading

0 comments on commit 182009b

Please sign in to comment.