Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/test/URI1/URI1.html
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ <h4 class="miClase text-left text-separation">Test information</h4>
</div>
<div class="row row-equal">
<div class="col-md-3 well tag_div"> <strong>Endpoint URL</strong></div>
<div class="col-md-9 well"> <a href="https://foops.linkeddata.es/assess/test/URL1" target="_blank"> https://foops.linkeddata.es/assess/test/URL1 </a> </div>
<div class="col-md-9 well"> <a href="https://foops.linkeddata.es/assess/test/URI1" target="_blank"> https://foops.linkeddata.es/assess/test/URI1 </a> </div>
</div>
<div class="row row-equal">
<div class="col-md-3 well tag_div"> <strong>Applicable for</strong></div>
Expand Down
2 changes: 1 addition & 1 deletion doc/test/URI1/URI1.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion doc/test/URI1/URI1.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://w3id.org/foops/api> ;
dcat:endpointURL <https://foops.linkeddata.es/assess/test/URL1> ;
dcat:endpointURL <https://foops.linkeddata.es/assess/test/URI1> ;
dpv:isApplicableFor <https://schema.org/DefinedTermSet> ;
ftr:supportedBy <https://w3id.org/foops/> ;
<http://semanticscience.org/resource/SIO_000233> <https://w3id.org/foops/metric/URI1> ;
Expand Down
2 changes: 1 addition & 1 deletion doc/test/URI2/URI2.html
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ <h4 class="miClase text-left text-separation">Test information</h4>
</div>
<div class="row row-equal">
<div class="col-md-3 well tag_div"> <strong>Endpoint URL</strong></div>
<div class="col-md-9 well"> <a href="https://foops.linkeddata.es/assess/test/URL2" target="_blank"> https://foops.linkeddata.es/assess/test/URL2 </a> </div>
<div class="col-md-9 well"> <a href="https://foops.linkeddata.es/assess/test/URI2" target="_blank"> https://foops.linkeddata.es/assess/test/URI2 </a> </div>
</div>
<div class="row row-equal">
<div class="col-md-3 well tag_div"> <strong>Applicable for</strong></div>
Expand Down
2 changes: 1 addition & 1 deletion doc/test/URI2/URI2.jsonld
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down
2 changes: 1 addition & 1 deletion doc/test/URI2/URI2.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://w3id.org/foops/api> ;
dcat:endpointURL <https://foops.linkeddata.es/assess/test/URL2> ;
dcat:endpointURL <https://foops.linkeddata.es/assess/test/URI2> ;
dpv:isApplicableFor <https://schema.org/DefinedTermSet> ;
ftr:supportedBy <https://w3id.org/foops/> ;
<http://semanticscience.org/resource/SIO_000233> <https://w3id.org/foops/metric/URI2> ;
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/fair/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";


}

48 changes: 48 additions & 0 deletions src/main/java/fair/FOOPS.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
}

33 changes: 33 additions & 0 deletions src/main/java/server/FOOPSController.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 27 additions & 0 deletions src/test/java/fair/FOOPSTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

}