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);
}
Aggregations