diff --git a/src/main/java/com/wse/qanaryexplanationservice/services/ExplanationService.java b/src/main/java/com/wse/qanaryexplanationservice/services/ExplanationService.java index ab0f4a1..0198d7e 100644 --- a/src/main/java/com/wse/qanaryexplanationservice/services/ExplanationService.java +++ b/src/main/java/com/wse/qanaryexplanationservice/services/ExplanationService.java @@ -6,9 +6,7 @@ import com.wse.qanaryexplanationservice.repositories.QanaryRepository; import eu.wdaqua.qanary.commons.triplestoreconnectors.QanaryTripleStoreConnector; import org.apache.commons.lang3.StringUtils; -import org.apache.jena.query.QuerySolution; -import org.apache.jena.query.QuerySolutionMap; -import org.apache.jena.query.ResultSet; +import org.apache.jena.query.*; import org.apache.jena.rdf.model.ResourceFactory; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -49,16 +47,18 @@ public String getTemplateComponentInputExplanation(String graphUri, QanaryCompon public String explainComponentMethods(ExplanationMetaData explanationMetaData) throws IOException { QuerySolutionMap qsm = new QuerySolutionMap(); AtomicReference prefixExplanation = new AtomicReference<>(); + AtomicInteger i = new AtomicInteger(1); StringBuilder explanationItems = new StringBuilder(); qsm.add("graph", ResourceFactory.createResource(explanationMetaData.getGraph().toASCIIString())); - String query = QanaryTripleStoreConnector.readFileFromResourcesWithMap(SELECT_ALL_LOGGED_METHODS, qsm); + String query = explanationMetaData.getRequestQuery() == null ? + QanaryTripleStoreConnector.readFileFromResourcesWithMap(SELECT_ALL_LOGGED_METHODS, qsm) : + transformQueryStringToQuery(explanationMetaData.getRequestQuery(), qsm); + logger.debug("Query: {}", query); ResultSet loggedMethodsResultSet = qanaryRepository.selectWithResultSet(query); List variables = loggedMethodsResultSet.getResultVars(); - AtomicInteger i = new AtomicInteger(1); - if (!explanationMetaData.isDoGenerative()) { loggedMethodsResultSet.forEachRemaining(querySolution -> { if(prefixExplanation.get() == null) { @@ -72,6 +72,12 @@ public String explainComponentMethods(ExplanationMetaData explanationMetaData) t return prefixExplanation + explanationItems.toString(); } + public String transformQueryStringToQuery(String queryString, QuerySolutionMap querySolutionMap) { + ParameterizedSparqlString pq = new ParameterizedSparqlString(queryString, querySolutionMap); + Query query = QueryFactory.create(pq.toString()); + return query.toString(); + } + /** * Controller called method to start the process explaining several components with both approaches; * the rulebased and the generative one.