Search in sources :

Example 81 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AlgorithmServiceImplIT method testGetAgeScript.

@Test
public void testGetAgeScript() throws ParseException {
    String idAttrName = "id";
    EntityType entityType = entityTypeFactory.create("LL");
    entityType.addAttribute(attrMetaFactory.create().setName(idAttrName).setDataType(INT), ROLE_ID);
    entityType.addAttribute(attrMetaFactory.create().setName("dob").setDataType(DATE));
    Entity source = new DynamicEntity(entityType);
    source.set(idAttrName, 1);
    source.set("dob", LocalDate.of(1973, Month.AUGUST, 28));
    Attribute targetAttribute = attrMetaFactory.create().setName("age");
    targetAttribute.setDataType(INT);
    AttributeMapping attributeMapping = new AttributeMapping(targetAttribute);
    attributeMapping.setAlgorithm("Math.floor((new Date(2015, 2, 12) - $('dob').value())/(365.2425 * 24 * 60 * 60 * 1000))");
    Object result = algorithmService.apply(attributeMapping, source, entityType);
    assertEquals(result, 41);
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) ExplainedQueryString(org.molgenis.semanticsearch.explain.bean.ExplainedQueryString) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 82 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AlgorithmServiceImplIT method testCreateAttributeMappingIfOnlyOneMatch.

@Test
public void testCreateAttributeMappingIfOnlyOneMatch() {
    EntityType targetEntityType = entityTypeFactory.create("target");
    Attribute targetAttribute = attrMetaFactory.create().setName("targetHeight");
    targetAttribute.setDescription("height");
    targetEntityType.addAttribute(targetAttribute);
    EntityType sourceEntityType = entityTypeFactory.create("source");
    Attribute sourceAttribute = attrMetaFactory.create().setName("sourceHeight");
    sourceAttribute.setDescription("height");
    sourceEntityType.addAttribute(sourceAttribute);
    User owner = userFactory.create();
    owner.setUsername("flup");
    owner.setPassword("geheim");
    owner.setId("12345");
    owner.setActive(true);
    owner.setEmail("flup@blah.com");
    owner.setFirstName("Flup");
    owner.setLastName("de Flap");
    MappingProject project = new MappingProject("project", owner);
    project.addTarget(targetEntityType);
    EntityMapping mapping = project.getMappingTarget("target").addSource(sourceEntityType);
    Map<Attribute, ExplainedAttribute> matches = ImmutableMap.of(sourceAttribute, ExplainedAttribute.create(sourceAttribute, singletonList(ExplainedQueryString.create("height", "height", "height", 100)), true));
    LinkedHashMultimap<Relation, OntologyTerm> ontologyTermTags = LinkedHashMultimap.create();
    when(semanticSearchService.decisionTreeToFindRelevantAttributes(sourceEntityType, targetAttribute, ontologyTermTags.values(), null)).thenReturn(matches);
    when(ontologyTagService.getTagsForAttribute(targetEntityType, targetAttribute)).thenReturn(ontologyTermTags);
    algorithmService.autoGenerateAlgorithm(sourceEntityType, targetEntityType, mapping, targetAttribute);
    assertEquals(mapping.getAttributeMapping("targetHeight").getAlgorithm(), "$('sourceHeight').value();");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) Relation(org.molgenis.data.semantic.Relation) User(org.molgenis.data.security.auth.User) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 83 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AlgorithmServiceImplIT method testWhenSourceDoesNotMatchThenNoMappingGetsCreated.

@Test
public void testWhenSourceDoesNotMatchThenNoMappingGetsCreated() {
    EntityType targetEntityType = entityTypeFactory.create("target");
    Attribute targetAttribute = attrMetaFactory.create().setName("targetHeight");
    targetAttribute.setDescription("height");
    targetEntityType.addAttribute(targetAttribute);
    EntityType sourceEntityType = entityTypeFactory.create("source");
    Attribute sourceAttribute = attrMetaFactory.create().setName("sourceHeight");
    sourceAttribute.setDescription("weight");
    sourceEntityType.addAttribute(sourceAttribute);
    User owner = userFactory.create();
    owner.setUsername("flup");
    owner.setPassword("geheim");
    owner.setId("12345");
    owner.setActive(true);
    owner.setEmail("flup@blah.com");
    owner.setFirstName("Flup");
    owner.setLastName("de Flap");
    MappingProject project = new MappingProject("project", owner);
    project.addTarget(targetEntityType);
    EntityMapping mapping = project.getMappingTarget("target").addSource(sourceEntityType);
    when(semanticSearchService.findAttributes(sourceEntityType, Sets.newHashSet("targetHeight", "height"), Collections.emptyList())).thenReturn(emptyMap());
    when(ontologyTagService.getTagsForAttribute(targetEntityType, targetAttribute)).thenReturn(LinkedHashMultimap.create());
    algorithmService.autoGenerateAlgorithm(sourceEntityType, targetEntityType, mapping, targetAttribute);
    assertNull(mapping.getAttributeMapping("targetHeight"));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) EntityMapping(org.molgenis.semanticmapper.mapping.model.EntityMapping) MappingProject(org.molgenis.semanticmapper.mapping.model.MappingProject) User(org.molgenis.data.security.auth.User) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 84 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AlgorithmServiceImplIT method testDotAnnotationWithMref.

@Test
public void testDotAnnotationWithMref() throws ParseException {
    EntityType referenceEntityType = entityTypeFactory.create("reference");
    referenceEntityType.addAttribute(attrMetaFactory.create().setName("id"), ROLE_ID);
    referenceEntityType.addAttribute(attrMetaFactory.create().setName("label"));
    Entity referenceEntity1 = new DynamicEntity(referenceEntityType);
    referenceEntity1.set("id", "1");
    referenceEntity1.set("label", "label 1");
    Entity referenceEntity2 = new DynamicEntity(referenceEntityType);
    referenceEntity2.set("id", "2");
    referenceEntity2.set("label", "label 2");
    EntityType sourceEntityType = entityTypeFactory.create("source");
    sourceEntityType.addAttribute(attrMetaFactory.create().setName("id"), ROLE_ID);
    sourceEntityType.addAttribute(attrMetaFactory.create().setName("source_mref").setDataType(MREF));
    Entity sourceEntity = new DynamicEntity(sourceEntityType);
    sourceEntity.set("id", "1");
    sourceEntity.set("source_mref", newArrayList(referenceEntity1, referenceEntity2));
    Attribute targetAttribute = attrMetaFactory.create().setName("target_label");
    AttributeMapping attributeMapping = new AttributeMapping(targetAttribute);
    attributeMapping.setAlgorithm("var result = [];$('source_mref').map(function(mref){result.push(mref.val.label)});result");
    Object result = algorithmService.apply(attributeMapping, sourceEntity, sourceEntityType);
    assertEquals(result, "[label 1, label 2]");
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) DynamicEntity(org.molgenis.data.support.DynamicEntity) Entity(org.molgenis.data.Entity) DynamicEntity(org.molgenis.data.support.DynamicEntity) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) AttributeMapping(org.molgenis.semanticmapper.mapping.model.AttributeMapping) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 85 with Attribute

use of org.molgenis.data.meta.model.Attribute in project molgenis by molgenis.

the class AlgorithmTemplateServiceImplTest method find.

@Test
public void find() {
    String sourceAttr0Name = "sourceAttr0";
    String sourceAttr1Name = "sourceAttr1";
    EntityType sourceEntityMeta = entityTypeFactory.create("source");
    Attribute sourceAttr0 = attrMetaFactory.create().setName(sourceAttr0Name);
    Attribute sourceAttr1 = attrMetaFactory.create().setName(sourceAttr1Name);
    sourceEntityMeta.addAttribute(sourceAttr0);
    sourceEntityMeta.addAttribute(sourceAttr1);
    ExplainedQueryString sourceAttr0Explain = ExplainedQueryString.create("a", "b", param0Name, 1.0);
    ExplainedQueryString sourceAttr1Explain = ExplainedQueryString.create("a", "b", param1Name, 0.5);
    Map<Attribute, ExplainedAttribute> attrResults = Maps.newHashMap();
    attrResults.put(sourceAttr0, ExplainedAttribute.create(sourceAttr0, singletonList(sourceAttr0Explain), false));
    attrResults.put(sourceAttr1, ExplainedAttribute.create(sourceAttr1, singletonList(sourceAttr1Explain), false));
    Stream<AlgorithmTemplate> templateStream = algorithmTemplateServiceImpl.find(attrResults);
    Map<String, String> model = Maps.newHashMap();
    model.put(param0Name, sourceAttr0Name);
    model.put(param1Name, sourceAttr1Name);
    AlgorithmTemplate expectedAlgorithmTemplate = new AlgorithmTemplate(script0, model);
    assertEquals(templateStream.collect(Collectors.toList()), Stream.of(expectedAlgorithmTemplate).collect(Collectors.toList()));
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) Attribute(org.molgenis.data.meta.model.Attribute) ExplainedAttribute(org.molgenis.semanticsearch.explain.bean.ExplainedAttribute) ExplainedQueryString(org.molgenis.semanticsearch.explain.bean.ExplainedQueryString) ExplainedQueryString(org.molgenis.semanticsearch.explain.bean.ExplainedQueryString) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

Attribute (org.molgenis.data.meta.model.Attribute)600 Test (org.testng.annotations.Test)351 EntityType (org.molgenis.data.meta.model.EntityType)321 Entity (org.molgenis.data.Entity)109 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)54 DynamicEntity (org.molgenis.data.support.DynamicEntity)53 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)47 Stream (java.util.stream.Stream)39 AttributeType (org.molgenis.data.meta.AttributeType)34 QueryImpl (org.molgenis.data.support.QueryImpl)29 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)29 UnexpectedEnumException (org.molgenis.util.UnexpectedEnumException)28 BeforeMethod (org.testng.annotations.BeforeMethod)20 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)18 WithMockUser (org.springframework.security.test.context.support.WithMockUser)18 Collectors.toList (java.util.stream.Collectors.toList)17 Relation (org.molgenis.data.semantic.Relation)17 Objects.requireNonNull (java.util.Objects.requireNonNull)16 MolgenisDataException (org.molgenis.data.MolgenisDataException)16 Package (org.molgenis.data.meta.model.Package)16