Search in sources :

Example 11 with AttributeMapping

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);
}
Also used : Entity(org.molgenis.data.Entity) Attribute(org.molgenis.data.meta.model.Attribute) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping)

Example 12 with AttributeMapping

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);
}
Also used : Entity(org.molgenis.data.Entity) ScriptException(org.molgenis.script.core.ScriptException) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) Test(org.testng.annotations.Test) AbstractMockitoTest(org.molgenis.test.AbstractMockitoTest)

Example 13 with AttributeMapping

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);
}
Also used : Attribute(org.molgenis.data.meta.model.Attribute) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping)

Example 14 with AttributeMapping

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);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) UnknownEntityException(org.molgenis.data.UnknownEntityException) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping)

Example 15 with AttributeMapping

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());
    }
}
Also used : Relation(org.molgenis.data.semantic.Relation) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) GeneratedAlgorithm(org.molgenis.semanticmapper.algorithmgenerator.bean.GeneratedAlgorithm) RunAsSystem(org.molgenis.security.core.runas.RunAsSystem)

Aggregations

AttributeMapping (org.molgenis.semanticmapper.mapping.model.AttributeMapping)22 Test (org.testng.annotations.Test)16 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)15 Entity (org.molgenis.data.Entity)15 Attribute (org.molgenis.data.meta.model.Attribute)15 DynamicEntity (org.molgenis.data.support.DynamicEntity)13 EntityType (org.molgenis.data.meta.model.EntityType)11 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)8 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)8 MappingTarget (org.molgenis.semanticmapper.mapping.model.MappingTarget)5 MappingProject (org.molgenis.semanticmapper.mapping.model.MappingProject)4 ExplainedQueryString (org.molgenis.semanticsearch.explain.bean.ExplainedQueryString)4 Menu (org.molgenis.core.ui.menu.Menu)3 UnknownEntityException (org.molgenis.data.UnknownEntityException)1 User (org.molgenis.data.security.auth.User)1 Relation (org.molgenis.data.semantic.Relation)1 OntologyTerm (org.molgenis.ontology.core.model.OntologyTerm)1 ScriptException (org.molgenis.script.core.ScriptException)1 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)1 GeneratedAlgorithm (org.molgenis.semanticmapper.algorithmgenerator.bean.GeneratedAlgorithm)1