diff --git a/doc/test/URI1/URI1.html b/doc/test/URI1/URI1.html
index b82b7878..37e8fd9a 100644
--- a/doc/test/URI1/URI1.html
+++ b/doc/test/URI1/URI1.html
@@ -139,7 +139,7 @@
Test information
Applicable for
diff --git a/doc/test/URI1/URI1.jsonld b/doc/test/URI1/URI1.jsonld
index 59d858d1..ad562035 100644
--- a/doc/test/URI1/URI1.jsonld
+++ b/doc/test/URI1/URI1.jsonld
@@ -91,7 +91,7 @@
],
"http://www.w3.org/ns/dcat#endpointURL": [
{
- "@id": "https://foops.linkeddata.es/assess/test/URL1"
+ "@id": "https://foops.linkeddata.es/assess/test/URI1"
}
],
"http://www.w3.org/ns/dcat#keyword": [
diff --git a/doc/test/URI1/URI1.ttl b/doc/test/URI1/URI1.ttl
index 2ab59a70..51100ee2 100644
--- a/doc/test/URI1/URI1.ttl
+++ b/doc/test/URI1/URI1.ttl
@@ -28,7 +28,7 @@ The test will pass if the vocabulary is resolvable in any of the following RDF s
dcterms:identifier "https://w3id.org/foops/test/URI1" ;
dcat:keyword "URI resolvable"@en , "Test"@en , "Resolvable"@en;
dcat:endpointDescription
;
- dcat:endpointURL ;
+ dcat:endpointURL ;
dpv:isApplicableFor ;
ftr:supportedBy ;
;
diff --git a/doc/test/URI2/URI2.html b/doc/test/URI2/URI2.html
index d7b768e6..d71a2ea1 100644
--- a/doc/test/URI2/URI2.html
+++ b/doc/test/URI2/URI2.html
@@ -137,7 +137,7 @@ Test information
Applicable for
diff --git a/doc/test/URI2/URI2.jsonld b/doc/test/URI2/URI2.jsonld
index 443f2003..cf5122ce 100644
--- a/doc/test/URI2/URI2.jsonld
+++ b/doc/test/URI2/URI2.jsonld
@@ -85,7 +85,7 @@
],
"http://www.w3.org/ns/dcat#endpointURL": [
{
- "@id": "https://foops.linkeddata.es/assess/test/URL2"
+ "@id": "https://foops.linkeddata.es/assess/test/URI2"
}
],
"http://www.w3.org/ns/dcat#keyword": [
diff --git a/doc/test/URI2/URI2.ttl b/doc/test/URI2/URI2.ttl
index 260369c5..29c7ea07 100644
--- a/doc/test/URI2/URI2.ttl
+++ b/doc/test/URI2/URI2.ttl
@@ -26,7 +26,7 @@ This check verifies if the ontology URI is equal to the ontology ID. The test pa
dcterms:identifier "https://w3id.org/foops/test/URI2" ;
dcat:keyword "Consistent ontology ID"@en , "Test"@en , "Findable"@en ;
dcat:endpointDescription
;
- dcat:endpointURL ;
+ dcat:endpointURL ;
dpv:isApplicableFor ;
ftr:supportedBy ;
;
diff --git a/src/main/java/fair/Constants.java b/src/main/java/fair/Constants.java
index 85d1cec1..bba5a2a6 100644
--- a/src/main/java/fair/Constants.java
+++ b/src/main/java/fair/Constants.java
@@ -755,6 +755,22 @@ public static String getFullListOfTestsMetadata() {
// " {\"@id\": \""+URI2_URL+"\", \"title\": \""+URI2_TITLE+"\", \"description\": \""+URI2_DESC+"\", \"endpointURL:\"" + FOOPS_TESTS_ENDPOINT + URI2 + "\", \"isDefinedBy: {\"@id:\"" + URI2_URL + "\"}, \"landingPage: {\"@id:\"" + FOOPS_DOC_BASE_URL + URI2 + "/" + URI2 + ".html\"}}\n" +
// "]";
}
+
+ public static String JSON_LD_BENCHMARK_SCORE_TEMPLATE =
+ "{\n" + FTR_CONTEXT +
+ " \"@id\": \"$SCORE_ID\",\n" +
+ " \"@type\": \"https://w3id.org/ftr#BenchmarkScore\",\n" +
+ " \"outputFromAlgorithm\": {\n" +
+ " \"@id\": \"https://w3id.org/foops/algorithm/$BENCHMARK_ID\",\n" +
+ " \"@type\": \"https://w3id.org/ftr#ScoringAlgorithm\",\n" +
+ " \"title\": \"$BENCHMARK_TITLE\",\n" +
+ " \"description\": \"$BENCHMARK_DESCRIPTION\"\n" +
+ " },\n" +
+ " \"value\": \"$SCORE_VALUE\",\n" +
+ " \"log\": \"$SCORE_LOG\",\n" +
+ " \"scoredTestResults\": $TEST_RESULT_SET_LIST \n" +
+ "}\n";
+
}
diff --git a/src/main/java/fair/FOOPS.java b/src/main/java/fair/FOOPS.java
index 298ef0be..86d084ab 100644
--- a/src/main/java/fair/FOOPS.java
+++ b/src/main/java/fair/FOOPS.java
@@ -41,6 +41,7 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Date;
+import java.util.List;
public class FOOPS {
private static final Logger logger = LoggerFactory.getLogger(FOOPS.class);
@@ -435,5 +436,52 @@ public static void main(String[] args){
}
}
}
+
+ public String exportBenchmarkScore(String benchmarkId) {
+ String template = Constants.JSON_LD_BENCHMARK_SCORE_TEMPLATE;
+ String scoreId = "urn:foops:" + java.util.UUID.randomUUID();
+ String benchmarkTitle;
+ String benchmarkDescription;
+ float scoreFloat = getTotalScore() * 100;
+ int scoreInt = (int) scoreFloat;
+ int totalPassed = 0;
+ int totalRun = 0;
+
+ for (Check c : this.checksToRun.getChecks()) {
+ totalPassed += c.getTotal_passed_tests();
+ totalRun += c.getTotal_tests_run();
+ }
+
+ String log = "The score was obtained as follows: all passed tests are added and divided " +
+ "by the total number of tests run. " +
+ "Since " + totalPassed + "/" + totalRun + " tests passed, your score is " + scoreInt + "%";
+
+ String testResultSetNoContext = fillTestResultSetTemplate()
+ .replace(Constants.FTR_CONTEXT, "");
+ template = template.replace("$TEST_RESULT_SET_LIST", testResultSetNoContext);
+
+ template = template.replace("$SCORE_ID", scoreId);
+ template = template.replace("$BENCHMARK_ID", benchmarkId);
+ template = template.replace("$SCORE_VALUE", String.valueOf(scoreInt));
+ template = template.replace("$SCORE_LOG", log);
+
+ if ("ALL".equals(benchmarkId)) {
+ benchmarkTitle = "General Benchmark for FAIR Principles";
+ benchmarkDescription = "This algorithm represents how each test is scored. "
+ + "All passed tests are added and divided by the total number of tests run.";
+ } else if ("PRE".equals(benchmarkId)) {
+ benchmarkTitle = "Priority Benchmark for FAIR Principles";
+ benchmarkDescription = "This algorithm represents how each test is scored. "
+ + "It only runs the priority FOOPS! tests.";
+ } else {
+ benchmarkTitle = "Unknown Benchmark";
+ benchmarkDescription = "No description available.";
+ }
+
+ template = template.replace("$BENCHMARK_TITLE", benchmarkTitle);
+ template = template.replace("$BENCHMARK_DESCRIPTION", benchmarkDescription);
+
+ return template;
+ }
}
diff --git a/src/main/java/server/FOOPSController.java b/src/main/java/server/FOOPSController.java
index c9957cda..c8d25481 100644
--- a/src/main/java/server/FOOPSController.java
+++ b/src/main/java/server/FOOPSController.java
@@ -438,6 +438,39 @@ public String assessPOST(
}
}
+
+ @Operation(
+ summary = "Returns a benchmark score for a resource following the FTR specification.",
+ description = "Returns a BenchmarkScore according to the FTR specification. " +
+ "Available benchmark identifiers: ALL, PRE.\n" +
+ "Example request JSON:\n" +
+ "```\n" +
+ "{\n" +
+ " \"resource_identifier\": \"https://w3id.org/example#\"\n" +
+ "}\n" +
+ "```"
+ )
+ @CrossOrigin(origins = "*")
+ @PostMapping(path = "assess/scoringAlgorithm/{identifier}", consumes = "application/json", produces = "application/json")
+ public String postBenchmarkScore(@PathVariable String identifier,
+ @RequestBody OntologyAssessmentRequest body) {
+ FOOPS f = null;
+ try {
+ String targetResource = body.getResourceIdentifier();
+ logger.info("Received benchmark score request - benchmark: " + identifier + ", resource: " + targetResource);
+ f = new FOOPS(targetResource, false);
+ f.fairTest();
+ return applyOstrailsStatusMapping(f.exportBenchmarkScore(identifier));
+ } catch (FileTooLargeException el) {
+ throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR,
+ "File sent for assessment is too big (max 50MB)");
+ } catch (Exception e) {
+ logger.error("Error " + e.getMessage());
+ throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "Malformed JSON request");
+ } finally {
+ if (f != null) f.removeTemporaryFolders();
+ }
+ }
private String applyOstrailsStatusMapping(String jsonLD) {
return jsonLD
diff --git a/src/test/java/fair/FOOPSTest.java b/src/test/java/fair/FOOPSTest.java
index 7ffdb51f..5aefaf79 100644
--- a/src/test/java/fair/FOOPSTest.java
+++ b/src/test/java/fair/FOOPSTest.java
@@ -412,4 +412,31 @@ public void testVersionInJsonLdResultSetOutput(){
}
}
+ /**
+ * This test verifies that the benchmark score endpoint returns a valid
+ * BenchmarkScore JSON-LD with the required fields (scoring algorithm feature)
+ */
+ @Test
+ public void testExportBenchmarkScore() {
+ try {
+ ClassLoader classLoader = getClass().getClassLoader();
+ File is = new File(classLoader.getResource("ontology_100.ttl").getFile());
+ FOOPS f = new FOOPS(is.toString(), true);
+ f.fairTest();
+ String result = f.exportBenchmarkScore("ALL");
+ assertNotNull(result);
+ assertTrue("Result must contain BenchmarkScore type", result.contains("ftr#BenchmarkScore"));
+ assertTrue("Result must contain outputFromAlgorithm", result.contains("outputFromAlgorithm"));
+ assertTrue("Result must contain algorithm ALL", result.contains("https://w3id.org/foops/algorithm/ALL"));
+ assertTrue("Result must contain value", result.contains("\"value\""));
+ assertTrue("Result must contain log", result.contains("\"log\""));
+ assertTrue("Result must contain scoredTestResults", result.contains("scoredTestResults"));
+ assertTrue("Result must contain TestResultSet", result.contains("ftr#TestResultSet"));
+ f.removeTemporaryFolders();
+ } catch (Exception e) {
+ logger.error("Could not load the resource file");
+ fail();
+ }
+ }
+
}