Skip to content

Commit

Permalink
Merge pull request #277 from WDAqua/initializeGraph
Browse files Browse the repository at this point in the history
Added query to insert required triples on graph init.
  • Loading branch information
anbo-de authored Jun 11, 2024
2 parents d238d6b + e5cfbee commit ea172a2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion qanary_commons/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>eu.wdaqua.qanary</groupId>
<artifactId>qa.commons</artifactId>
<version>3.13.0</version>
<version>3.14.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 @@ -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;
Expand Down Expand Up @@ -54,6 +55,7 @@ public class QanaryQuestion<T> {
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";

/**
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
PREFIX qa: <http://www.wdaqua.eu/qa#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>

INSERT {
GRAPH ?graph {
qa:AnnotationOfLogQuery rdfs:subClassOf qa:AnnotationOfLog .

}
}

0 comments on commit ea172a2

Please sign in to comment.