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