Skip to content

Commit

Permalink
Merge branch 'master' into updated_insert_query_for_qb_sina
Browse files Browse the repository at this point in the history
  • Loading branch information
dschiese authored Jan 23, 2024
2 parents 73f356a + 182009b commit 3194924
Show file tree
Hide file tree
Showing 51 changed files with 209 additions and 341 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 Expand Up @@ -152,12 +151,12 @@ public QanaryMessage process(QanaryMessage myQanaryMessage) throws Exception {
return myQanaryMessage;
}

// // second, let's try to find a firstname and lastname, if that works we stop
// myQanaryMessage = this.processForFirstNameAndLastName(myQanaryMessage);
// if( myQanaryMessage != null ) {
// logger.info("Found firstname and lastname. Processing finished.");
// return myQanaryMessage;
// }
// second, let's try to find a firstname and lastname, if that works we stop
myQanaryMessage = this.processForFirstNameAndLastName(myQanaryMessage);
if( myQanaryMessage != null ) {
logger.info("Found firstname and lastname. Processing finished.");
return myQanaryMessage;
}

logger.warn("Nothing could be done here.");
return myQanaryMessage;
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
Loading

0 comments on commit 3194924

Please sign in to comment.