From e5cfbee2fc96956e824150209bacff714e30cbe8 Mon Sep 17 00:00:00 2001 From: Dennis Schiese Date: Thu, 6 Jun 2024 13:39:45 +0200 Subject: [PATCH] Added query to insert required triples on graph init. --- qanary_commons/pom.xml | 2 +- .../wdaqua/qanary/commons/QanaryQuestion.java | 23 +++++++++++++++++-- .../queries/insert_required_triples.rq | 9 ++++++++ 3 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 qanary_commons/src/main/resources/queries/insert_required_triples.rq diff --git a/qanary_commons/pom.xml b/qanary_commons/pom.xml index 79fe46cc..dbf04a0d 100644 --- a/qanary_commons/pom.xml +++ b/qanary_commons/pom.xml @@ -2,7 +2,7 @@ 4.0.0 eu.wdaqua.qanary qa.commons - 3.13.0 + 3.14.0 org.springframework.boot spring-boot-starter-parent diff --git a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/QanaryQuestion.java b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/QanaryQuestion.java index a352a713..453ab86c 100644 --- a/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/QanaryQuestion.java +++ b/qanary_commons/src/main/java/eu/wdaqua/qanary/commons/QanaryQuestion.java @@ -20,6 +20,7 @@ import org.springframework.util.MultiValueMap; import org.springframework.web.client.RestTemplate; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -54,6 +55,7 @@ public class QanaryQuestion { private QanaryConfigurator myQanaryConfigurator; private String FILENAME_SELECT_TRANSLATION_ANNOTATION = "/queries/select_all_AnnotationOfQuestionTranslation.rq"; + private String REQUIRED_TRIPLES = "/queries/insert_required_triples.rq"; private String FILENAME_SELECT_URI_TEXTUAL_REPRESENTATION = "/queries/select_uri_textual_representation.rq"; /** @@ -139,10 +141,28 @@ public QanaryQuestion(final URL questionUri, QanaryConfigurator qanaryConfigurat // loadTripleStore(sparqlquery, qanaryConfigurator); // TODO: remove qanaryConfigurator.getQanaryTripleStoreConnector().update(sparqlquery); + loadRequiredTriplesToTriplestore(qanaryConfigurator.getQanaryTripleStoreConnector()); initFromTriplestore(qanaryConfigurator); } + /** + * Function that inserts required triples for graph initialization + * @param qanaryTripleStoreConnector + */ + private void loadRequiredTriplesToTriplestore(QanaryTripleStoreConnector qanaryTripleStoreConnector) { + QuerySolutionMap querySolutionMap = new QuerySolutionMap(); + querySolutionMap.add("graph", ResourceFactory.createResource(namedGraph.toASCIIString())); + try { + String sparqlQuery = QanaryTripleStoreConnector.readFileFromResourcesWithMap(REQUIRED_TRIPLES, querySolutionMap); + qanaryTripleStoreConnector.update(sparqlQuery); + } catch(IOException e) { + logger.warn("Read query from file failed with message: {}", e.getMessage()); + } catch(SparqlQueryFailed e) { + logger.warn("Inserting required triples to triplestore failed, skipping."); + } + } + /** * create QanaryQuestion from the information available in the provided graph * (data is retrieved from the Qanary triplestore, see application.properties) @@ -197,8 +217,7 @@ public QanaryTripleStoreConnector getQanaryTripleStoreConnector() { /** * init object properties from a given triplestore URI - * - * @param triplestore + * * @throws URISyntaxException */ private void initFromTriplestore(final QanaryConfigurator myQanaryConfigurator) throws URISyntaxException { diff --git a/qanary_commons/src/main/resources/queries/insert_required_triples.rq b/qanary_commons/src/main/resources/queries/insert_required_triples.rq new file mode 100644 index 00000000..41c2f6ac --- /dev/null +++ b/qanary_commons/src/main/resources/queries/insert_required_triples.rq @@ -0,0 +1,9 @@ +PREFIX qa: +PREFIX rdfs: + +INSERT { + GRAPH ?graph { + qa:AnnotationOfLogQuery rdfs:subClassOf qa:AnnotationOfLog . + + } +} \ No newline at end of file