use of org.molgenis.semanticmapper.mapping.model.AttributeMapping in project molgenis by molgenis.
the class AlgorithmServiceImplTest method testApplyConvertException.
private void testApplyConvertException(String algorithmResult, AttributeType attributeType) {
AttributeMapping attributeMapping = mock(AttributeMapping.class);
String algorithm = "algorithm";
when(attributeMapping.getAlgorithm()).thenReturn(algorithm);
Attribute targetAttribute = when(mock(Attribute.class).getDataType()).thenReturn(attributeType).getMock();
when(attributeMapping.getTargetAttribute()).thenReturn(targetAttribute);
Entity sourceEntity = mock(Entity.class);
when(jsMagmaScriptEvaluator.eval(algorithm, sourceEntity, 3)).thenReturn(algorithmResult);
algorithmServiceImpl.apply(attributeMapping, sourceEntity, null);
}
use of org.molgenis.semanticmapper.mapping.model.AttributeMapping in project molgenis by molgenis.
the class AlgorithmServiceImplTest method testApplyWithInvalidScript.
@Test(expectedExceptions = ScriptException.class, expectedExceptionsMessageRegExp = "algorithm is not defined")
public void testApplyWithInvalidScript() {
AttributeMapping attributeMapping = mock(AttributeMapping.class);
String algorithm = "algorithm";
when(attributeMapping.getAlgorithm()).thenReturn(algorithm);
Entity sourceEntity = mock(Entity.class);
when(jsMagmaScriptEvaluator.eval(algorithm, sourceEntity, 3)).thenReturn(new ScriptException("algorithm is not defined"));
algorithmServiceImpl.apply(attributeMapping, sourceEntity, null);
}
use of org.molgenis.semanticmapper.mapping.model.AttributeMapping in project molgenis by molgenis.
the class AttributeMappingRepositoryImpl method toAttributeMapping.
private AttributeMapping toAttributeMapping(Entity attributeMappingEntity, EntityType sourceEntityType, EntityType targetEntityType) {
String identifier = attributeMappingEntity.getString(IDENTIFIER);
String targetAttributeName = attributeMappingEntity.getString(TARGET_ATTRIBUTE);
Attribute targetAttribute = targetEntityType.getAttribute(targetAttributeName);
String algorithm = attributeMappingEntity.getString(ALGORITHM);
String algorithmState = attributeMappingEntity.getString(ALGORITHM_STATE);
List<Attribute> sourceAttributes = retrieveAttributesFromAlgorithm(algorithm, sourceEntityType);
return new AttributeMapping(identifier, targetAttributeName, targetAttribute, algorithm, sourceAttributes, algorithmState);
}
use of org.molgenis.semanticmapper.mapping.model.AttributeMapping in project molgenis by molgenis.
the class EntityMappingRepositoryImpl method toEntityMapping.
private EntityMapping toEntityMapping(Entity entityMappingEntity) {
String identifier = entityMappingEntity.getString(EntityMappingMetaData.IDENTIFIER);
EntityType targetEntityType;
try {
targetEntityType = dataService.getEntityType(entityMappingEntity.getString(EntityMappingMetaData.TARGET_ENTITY_TYPE));
} catch (UnknownEntityException uee) {
LOG.error(uee.getMessage());
targetEntityType = null;
}
EntityType sourceEntityType;
try {
sourceEntityType = dataService.getEntityType(entityMappingEntity.getString(EntityMappingMetaData.SOURCE_ENTITY_TYPE));
} catch (UnknownEntityException uee) {
LOG.error(uee.getMessage());
sourceEntityType = null;
}
List<Entity> attributeMappingEntities = Lists.newArrayList(entityMappingEntity.getEntities(EntityMappingMetaData.ATTRIBUTE_MAPPINGS));
List<AttributeMapping> attributeMappings = attributeMappingRepository.getAttributeMappings(attributeMappingEntities, sourceEntityType, targetEntityType);
return new EntityMapping(identifier, sourceEntityType, targetEntityType, attributeMappings);
}
use of org.molgenis.semanticmapper.mapping.model.AttributeMapping in project molgenis by molgenis.
the class AlgorithmServiceImpl method autoGenerateAlgorithm.
@Override
@RunAsSystem
public void autoGenerateAlgorithm(EntityType sourceEntityType, EntityType targetEntityType, EntityMapping mapping, Attribute targetAttribute) {
LOG.debug("createAttributeMappingIfOnlyOneMatch: target= " + targetAttribute.getName());
Multimap<Relation, OntologyTerm> tagsForAttribute = ontologyTagService.getTagsForAttribute(targetEntityType, targetAttribute);
Map<Attribute, ExplainedAttribute> relevantAttributes = semanticSearchService.decisionTreeToFindRelevantAttributes(sourceEntityType, targetAttribute, tagsForAttribute.values(), null);
GeneratedAlgorithm generatedAlgorithm = algorithmGeneratorService.generate(targetAttribute, relevantAttributes, targetEntityType, sourceEntityType);
if (StringUtils.isNotBlank(generatedAlgorithm.getAlgorithm())) {
AttributeMapping attributeMapping = mapping.addAttributeMapping(targetAttribute.getName());
attributeMapping.setAlgorithm(generatedAlgorithm.getAlgorithm());
attributeMapping.getSourceAttributes().addAll(generatedAlgorithm.getSourceAttributes());
attributeMapping.setAlgorithmState(generatedAlgorithm.getAlgorithmState());
LOG.debug("Creating attribute mapping: " + targetAttribute.getName() + " = " + generatedAlgorithm.getAlgorithm());
}
}
Aggregations