Search in sources :

Example 1 with AlgorithmTemplate

use of org.molgenis.semanticmapper.service.impl.AlgorithmTemplate in project molgenis by molgenis.

the class AlgorithmGeneratorServiceImpl method generate.

@Override
public GeneratedAlgorithm generate(Attribute targetAttribute, Map<Attribute, ExplainedAttribute> sourceAttributes, EntityType targetEntityType, EntityType sourceEntityType) {
    String algorithm = StringUtils.EMPTY;
    AlgorithmState algorithmState = null;
    Set<Attribute> mappedSourceAttributes = null;
    if (sourceAttributes.size() > 0) {
        AlgorithmTemplate algorithmTemplate = algorithmTemplateService.find(sourceAttributes).findFirst().orElse(null);
        if (algorithmTemplate != null) {
            algorithm = algorithmTemplate.render();
            mappedSourceAttributes = AlgorithmGeneratorHelper.extractSourceAttributesFromAlgorithm(algorithm, sourceEntityType);
            algorithm = convertUnitForTemplateAlgorithm(algorithm, targetAttribute, targetEntityType, mappedSourceAttributes, sourceEntityType);
            algorithmState = GENERATED_HIGH;
        } else {
            Entry<Attribute, ExplainedAttribute> firstEntry = sourceAttributes.entrySet().stream().findFirst().get();
            Attribute sourceAttribute = firstEntry.getKey();
            algorithm = generate(targetAttribute, Arrays.asList(sourceAttribute), targetEntityType, sourceEntityType);
            mappedSourceAttributes = AlgorithmGeneratorHelper.extractSourceAttributesFromAlgorithm(algorithm, sourceEntityType);
            algorithmState = firstEntry.getValue().isHighQuality() ? GENERATED_HIGH : GENERATED_LOW;
        }
    }
    return GeneratedAlgorithm.create(algorithm, mappedSourceAttributes, algorithmState);
}
Also used : ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) AlgorithmState(org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState) AlgorithmTemplate(org.molgenis.semanticmapper.service.impl.AlgorithmTemplate)

Aggregations

Attribute (org.molgenis.data.meta.model.Attribute)1 AlgorithmState (org.molgenis.semanticmapper.mapping.model.AttributeMapping.AlgorithmState)1 AlgorithmTemplate (org.molgenis.semanticmapper.service.impl.AlgorithmTemplate)1 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)1