use of org.molgenis.semanticmapper.service.impl.AlgorithmEvaluation in project molgenis by molgenis.
the class MappingServiceController method testScript.
/**
* Tests an algoritm by computing it for all entities in the source repository.
*
* @param mappingServiceRequest the {@link MappingServiceRequest} sent by the client
* @return Map with the results and size of the source
*/
@PostMapping(value = "/mappingattribute/testscript", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public Map<String, Object> testScript(@RequestBody MappingServiceRequest mappingServiceRequest) {
EntityType targetEntityType = dataService.getEntityType(mappingServiceRequest.getTargetEntityName());
Attribute targetAttribute = targetEntityType != null ? targetEntityType.getAttribute(mappingServiceRequest.getTargetAttributeName()) : null;
Repository<Entity> sourceRepo = dataService.getRepository(mappingServiceRequest.getSourceEntityName());
Iterable<AlgorithmEvaluation> algorithmEvaluations = algorithmService.applyAlgorithm(targetAttribute, mappingServiceRequest.getAlgorithm(), sourceRepo);
List<Object> calculatedValues = newArrayList(Iterables.transform(algorithmEvaluations, AlgorithmEvaluation::getValue));
return ImmutableMap.of("results", calculatedValues, "totalCount", Iterables.size(sourceRepo));
}
use of org.molgenis.semanticmapper.service.impl.AlgorithmEvaluation in project molgenis by molgenis.
the class MappingServiceController method validateAttributeMapping.
@PostMapping("/validateAttrMapping")
@ResponseBody
public AttributeMappingValidationReport validateAttributeMapping(@Valid @RequestBody MappingServiceRequest mappingServiceRequest) {
String targetEntityName = mappingServiceRequest.getTargetEntityName();
EntityType targetEntityType = dataService.getEntityType(targetEntityName);
String targetAttributeName = mappingServiceRequest.getTargetAttributeName();
Attribute targetAttr = targetEntityType.getAttribute(targetAttributeName);
if (targetAttr == null) {
throw new UnknownAttributeException(targetEntityType, targetAttributeName);
}
String algorithm = mappingServiceRequest.getAlgorithm();
Long offset = mappingServiceRequest.getOffset();
Long num = mappingServiceRequest.getNum();
Query<Entity> query = new QueryImpl<>().offset(offset.intValue()).pageSize(num.intValue());
String sourceEntityName = mappingServiceRequest.getSourceEntityName();
Iterable<Entity> sourceEntities = () -> dataService.findAll(sourceEntityName, query).iterator();
long total = dataService.count(sourceEntityName, new QueryImpl<>());
long nrSuccess = 0, nrErrors = 0;
Map<String, String> errorMessages = new LinkedHashMap<>();
for (AlgorithmEvaluation evaluation : algorithmService.applyAlgorithm(targetAttr, algorithm, sourceEntities)) {
if (evaluation.hasError()) {
errorMessages.put(evaluation.getEntity().getIdValue().toString(), evaluation.getErrorMessage());
++nrErrors;
} else {
++nrSuccess;
}
}
return new AttributeMappingValidationReport(total, nrSuccess, nrErrors, errorMessages);
}
Aggregations