Search in sources :

Example 1 with AlgorithmEvaluation

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));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) ResponseEntity(org.springframework.http.ResponseEntity) AlgorithmEvaluation(org.molgenis.semanticmapper.service.impl.AlgorithmEvaluation) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)

Example 2 with AlgorithmEvaluation

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) EntityType(org.molgenis.data.meta.model.EntityType) AlgorithmEvaluation(org.molgenis.semanticmapper.service.impl.AlgorithmEvaluation) AggregateQueryImpl(org.molgenis.data.support.AggregateQueryImpl) QueryImpl(org.molgenis.data.support.QueryImpl)

Aggregations

Attribute (org.molgenis.data.meta.model.Attribute)2 EntityType (org.molgenis.data.meta.model.EntityType)2 AlgorithmEvaluation (org.molgenis.semanticmapper.service.impl.AlgorithmEvaluation)2 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)2 ResponseEntity (org.springframework.http.ResponseEntity)2 AggregateQueryImpl (org.molgenis.data.support.AggregateQueryImpl)1 QueryImpl (org.molgenis.data.support.QueryImpl)1