Skip to content

Commit

Permalink
Merge pull request #51 from WSE-research/revert-49-revert-48-explanat…
Browse files Browse the repository at this point in the history
…ion_api_Qanary

Added adjusted pipeline explanation
  • Loading branch information
dschiese authored Aug 20, 2024
2 parents 04f6876 + a00fb5e commit 2188f5b
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
</parent>
<groupId>com.wse</groupId>
<artifactId>qanary-explanation-service</artifactId>
<version>3.6.0</version>
<version>3.7.0</version>
<name>Qanary explanation service</name>
<description>Webservice for rule-based explanation of QA-Systems as well as specific components</description>
<properties>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,10 @@ public ResponseEntity<?> getComposedExplanation(
}
}

@GetMapping("/explain/pipeline/{graph}")
@Operation()
public ResponseEntity<?> getPipelineExplanation(@PathVariable String graph) throws IOException {
return new ResponseEntity<>(explanationService.getPipelineExplanation(graph), HttpStatus.OK);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,13 @@ public ResultSet getPipelineInformation(String graphUri) throws IOException {
return qanaryRepository.selectWithResultSet(sparql);
}

public String getPipelineExplanation(String graph) throws IOException {
return tmplExpService.getPipelineOutputExplanation(
this.getPipelineInformation(graph),
graph
);
}

public String getComposedExplanation(QanaryExplanationData body) throws IOException {
String graph = body.getGraph();
String component = body.getComponent();
Expand All @@ -163,6 +170,7 @@ public String getComposedExplanation(QanaryExplanationData body) throws IOExcept
if (component == null) {
inputExplanation = explainPipelineInput(graph);
outputExplanation = explainPipelineOutput(graph);
return getPipelineExplanation(graph);
} else {
QanaryComponent qanaryComponent = new QanaryComponent(component);
inputExplanation = getTemplateComponentInputExplanation(graph, qanaryComponent);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -592,14 +592,21 @@ public String getPipelineInputExplanation(String question) {

// Computes the explanation itself
public String getPipelineOutputExplanation(ResultSet results, String graphUri) {
String explanation = getStringFromFile("/explanations/pipeline/en_prefix").replace("${graph}", graphUri);
String explanation = getStringFromFile("/explanations/pipeline/en_prefix")
.replace("${graph}", graphUri);
String componentTemplate = getStringFromFile("/explanations/pipeline/en_list_item");
String questionId = "";
List<String> explanations = new ArrayList<>();
while (results.hasNext()) {
QuerySolution querySolution = results.next();
if(querySolution.get("questionId") != null)
questionId = querySolution.get("questionId").toString();
explanations.add(replaceProperties(convertQuerySolutionToMap(querySolution), componentTemplate));
}
return explanation + " " + StringUtils.join(explanations, ", ");
return explanation
.replace("${questionId}", questionId)
.replace("${question}", qanaryRepository.getQuestionFromQuestionId(questionId + "/raw"))
+ " " + StringUtils.join(explanations, ", ");
}

// Composes the passed explanations
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/explanations/pipeline/en_prefix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
The QA pipeline executed the following components on the graph "${graph}":
The QA pipeline received the question "${question}" with the questionId "${questionId}" and executed the following components on the knowledge graph "${graph}":
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.wse.qanaryexplanationservice.services;

import com.wse.qanaryexplanationservice.helper.pojos.QanaryComponent;
import com.wse.qanaryexplanationservice.repositories.QanaryRepository;
import org.apache.jena.query.*;
import org.apache.jena.rdf.model.*;
import org.junit.jupiter.api.Assertions;
Expand All @@ -14,6 +15,7 @@
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.mock.mockito.SpyBean;
import org.springframework.test.context.junit.jupiter.SpringExtension;

Expand All @@ -24,6 +26,8 @@
import java.util.*;

import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

@ExtendWith(SpringExtension.class)
@SpringBootTest
Expand Down Expand Up @@ -139,6 +143,13 @@ class ComponentExplanationTests {
private final ResultSet resultSet = serviceDataForTests.createResultSet(serviceDataForTests.getQuerySolutionMapList());
@SpyBean
private TemplateExplanationsService templateExplanationsService;
@MockBean
private QanaryRepository qanaryRepository;

@BeforeEach
public void setup() {
when(qanaryRepository.getQuestionFromQuestionId(any())).thenReturn("test");
}

@Test
public void createTextualExplanationTest() {
Expand Down

0 comments on commit 2188f5b

Please sign in to comment.