use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.
the class MappingServiceController method viewAttributeMapping.
/**
* Displays an {@link AttributeMapping}
*
* @param mappingProjectId ID of the {@link MappingProject}
* @param target name of the target entity
* @param source name of the source entity
* @param targetAttribute name of the target attribute
*/
@GetMapping("/attributeMapping")
public String viewAttributeMapping(@RequestParam() String mappingProjectId, @RequestParam() String target, @RequestParam() String source, @RequestParam() String targetAttribute, Model model) {
MappingProject project = mappingService.getMappingProject(mappingProjectId);
MappingTarget mappingTarget = project.getMappingTarget(target);
EntityMapping entityMapping = mappingTarget.getMappingForSource(source);
AttributeMapping attributeMapping = entityMapping.getAttributeMapping(targetAttribute);
if (attributeMapping == null) {
attributeMapping = entityMapping.addAttributeMapping(targetAttribute);
}
EntityType refEntityType = attributeMapping.getTargetAttribute().getRefEntity();
if (refEntityType != null) {
Iterable<Entity> refEntities = () -> dataService.findAll(refEntityType.getId()).iterator();
model.addAttribute("categories", refEntities);
}
Multimap<Relation, OntologyTerm> tagsForAttribute = ontologyTagService.getTagsForAttribute(entityMapping.getTargetEntityType(), attributeMapping.getTargetAttribute());
model.addAttribute("tags", tagsForAttribute.values());
model.addAttribute("dataExplorerUri", menuReaderService.getMenu().findMenuItemPath(DataExplorerController.ID));
model.addAttribute("mappingProject", project);
model.addAttribute("entityMapping", entityMapping);
model.addAttribute("sourceAttributesSize", Iterables.size(entityMapping.getSourceEntityType().getAtomicAttributes()));
model.addAttribute("attributeMapping", attributeMapping);
model.addAttribute("attributes", newArrayList(dataService.getEntityType(source).getAtomicAttributes()));
model.addAttribute("hasWritePermission", hasWritePermission(project, false));
return VIEW_ATTRIBUTE_MAPPING;
}
use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.
the class AlgorithmServiceImplIT method testWhenSourceHasMultipleMatchesThenFirstMappingGetsCreated.
@Test
public void testWhenSourceHasMultipleMatchesThenFirstMappingGetsCreated() {
EntityType targetEntityType = entityTypeFactory.create("target");
Attribute targetAttribute = attrMetaFactory.create().setName("targetHeight");
targetAttribute.setDescription("height");
targetEntityType.addAttribute(targetAttribute);
EntityType sourceEntityType = entityTypeFactory.create("source");
Attribute sourceAttribute1 = attrMetaFactory.create().setName("sourceHeight1");
sourceAttribute1.setDescription("height");
Attribute sourceAttribute2 = attrMetaFactory.create().setName("sourceHeight2");
sourceAttribute2.setDescription("height");
sourceEntityType.addAttributes(Arrays.asList(sourceAttribute1, sourceAttribute2));
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> mappings = ImmutableMap.of(sourceAttribute1, ExplainedAttribute.create(sourceAttribute1), sourceAttribute2, ExplainedAttribute.create(sourceAttribute2));
LinkedHashMultimap<Relation, OntologyTerm> ontologyTermTags = LinkedHashMultimap.create();
when(semanticSearchService.decisionTreeToFindRelevantAttributes(sourceEntityType, targetAttribute, ontologyTermTags.values(), null)).thenReturn(mappings);
when(ontologyTagService.getTagsForAttribute(targetEntityType, targetAttribute)).thenReturn(ontologyTermTags);
algorithmService.autoGenerateAlgorithm(sourceEntityType, targetEntityType, mapping, targetAttribute);
assertEquals(mapping.getAttributeMapping("targetHeight").getSourceAttributes().get(0), sourceAttribute1);
}
use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.
the class SemanticSearchServiceHelperTest method testCreateShouldQueryRule.
@Test
public void testCreateShouldQueryRule() {
String multiOntologyTermIri = "http://www.molgenis.org/1,http://www.molgenis.org/2";
OntologyTerm ontologyTerm_1 = OntologyTerm.create("http://www.molgenis.org/1", "molgenis label in the gcc");
OntologyTerm ontologyTerm_2 = OntologyTerm.create("http://www.molgenis.org/2", "molgenis label 2 in the genetics", singletonList("label 2"));
when(ontologyService.getOntologyTerm(ontologyTerm_1.getIRI())).thenReturn(ontologyTerm_1);
when(ontologyService.getOntologyTerm(ontologyTerm_2.getIRI())).thenReturn(ontologyTerm_2);
QueryRule actualShouldQueryRule = semanticSearchServiceHelper.createShouldQueryRule(multiOntologyTermIri);
String expectedShouldQueryRuleToString = "SHOULD (DIS_MAX ('label' FUZZY_MATCH 'gcc molgenis label', 'description' FUZZY_MATCH 'gcc molgenis label'), DIS_MAX ('label' FUZZY_MATCH '2 label', 'description' FUZZY_MATCH '2 label', 'label' FUZZY_MATCH '2 genetics molgenis label', 'description' FUZZY_MATCH '2 genetics molgenis label'))";
assertEquals(actualShouldQueryRule.toString(), expectedShouldQueryRuleToString);
assertEquals(actualShouldQueryRule.getOperator(), QueryRule.Operator.SHOULD);
}
use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.
the class SemanticSearchServiceHelperTest method testCreateTargetAttributeQueryTerms.
@Test
public void testCreateTargetAttributeQueryTerms() {
Attribute targetAttribute_1 = attrMetaFactory.create().setName("targetAttribute 1");
targetAttribute_1.setDescription("Height");
Attribute targetAttribute_2 = attrMetaFactory.create().setName("targetAttribute 2");
targetAttribute_2.setLabel("Height");
Multimap<Relation, OntologyTerm> tags = LinkedHashMultimap.create();
OntologyTerm ontologyTerm1 = OntologyTerm.create("http://onto/standingheight", "Standing height", "Description is not used", singletonList("body_length"));
OntologyTerm ontologyTerm2 = OntologyTerm.create("http://onto/sittingheight", "Sitting height", "Description is not used", singletonList("sitting_length"));
OntologyTerm ontologyTerm3 = OntologyTerm.create("http://onto/height", "Height", "Description is not used", singletonList("sature"));
tags.put(Relation.isAssociatedWith, ontologyTerm1);
tags.put(Relation.isRealizationOf, ontologyTerm2);
tags.put(Relation.isDefinedBy, ontologyTerm3);
// Case 1
QueryRule actualTargetAttributeQueryTerms_1 = semanticSearchServiceHelper.createDisMaxQueryRuleForAttribute(Sets.newLinkedHashSet(asList("targetAttribute 1", "Height")), tags.values());
String expecteddisMaxQueryRuleToString_1 = "DIS_MAX ('label' FUZZY_MATCH '1 targetattribute', 'description' FUZZY_MATCH '1 targetattribute', 'label' FUZZY_MATCH 'height', 'description' FUZZY_MATCH 'height', 'label' FUZZY_MATCH 'length body', 'description' FUZZY_MATCH 'length body', 'label' FUZZY_MATCH 'standing height', 'description' FUZZY_MATCH 'standing height', 'label' FUZZY_MATCH 'length sitting', 'description' FUZZY_MATCH 'length sitting', 'label' FUZZY_MATCH 'sitting height', 'description' FUZZY_MATCH 'sitting height', 'label' FUZZY_MATCH 'sature', 'description' FUZZY_MATCH 'sature', 'label' FUZZY_MATCH 'height', 'description' FUZZY_MATCH 'height')";
assertEquals(actualTargetAttributeQueryTerms_1.toString(), expecteddisMaxQueryRuleToString_1);
// Case 2
QueryRule expecteddisMaxQueryRuleToString_2 = semanticSearchServiceHelper.createDisMaxQueryRuleForAttribute(Sets.newHashSet("Height"), tags.values());
String expectedTargetAttributeQueryTermsToString_2 = "DIS_MAX ('label' FUZZY_MATCH 'height', 'description' FUZZY_MATCH 'height', 'label' FUZZY_MATCH 'length body', 'description' FUZZY_MATCH 'length body', 'label' FUZZY_MATCH 'standing height', 'description' FUZZY_MATCH 'standing height', 'label' FUZZY_MATCH 'length sitting', 'description' FUZZY_MATCH 'length sitting', 'label' FUZZY_MATCH 'sitting height', 'description' FUZZY_MATCH 'sitting height', 'label' FUZZY_MATCH 'sature', 'description' FUZZY_MATCH 'sature', 'label' FUZZY_MATCH 'height', 'description' FUZZY_MATCH 'height')";
assertEquals(expecteddisMaxQueryRuleToString_2.toString(), expectedTargetAttributeQueryTermsToString_2);
// Case 3
QueryRule expecteddisMaxQueryRuleToString_3 = semanticSearchServiceHelper.createDisMaxQueryRuleForAttribute(Sets.newHashSet("targetAttribute 3"), tags.values());
String expectedTargetAttributeQueryTermsToString_3 = "DIS_MAX ('label' FUZZY_MATCH '3 targetattribute', 'description' FUZZY_MATCH '3 targetattribute', 'label' FUZZY_MATCH 'length body', 'description' FUZZY_MATCH 'length body', 'label' FUZZY_MATCH 'standing height', 'description' FUZZY_MATCH 'standing height', 'label' FUZZY_MATCH 'length sitting', 'description' FUZZY_MATCH 'length sitting', 'label' FUZZY_MATCH 'sitting height', 'description' FUZZY_MATCH 'sitting height', 'label' FUZZY_MATCH 'sature', 'description' FUZZY_MATCH 'sature', 'label' FUZZY_MATCH 'height', 'description' FUZZY_MATCH 'height')";
assertEquals(expecteddisMaxQueryRuleToString_3.toString(), expectedTargetAttributeQueryTermsToString_3);
}
use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.
the class SemanticSearchServiceHelper method createShouldQueryRule.
/**
* Create a boolean should query for composite tags containing multiple ontology terms
*
* @return return a boolean should queryRule
*/
public QueryRule createShouldQueryRule(String multiOntologyTermIri) {
QueryRule shouldQueryRule = new QueryRule(new ArrayList<>());
shouldQueryRule.setOperator(Operator.SHOULD);
for (String ontologyTermIri : multiOntologyTermIri.split(COMMA_CHAR)) {
OntologyTerm ontologyTerm = ontologyService.getOntologyTerm(ontologyTermIri);
List<String> queryTerms = parseOntologyTermQueries(ontologyTerm);
Double termFrequency = getBestInverseDocumentFrequency(queryTerms);
shouldQueryRule.getNestedRules().add(createBoostedDisMaxQueryRuleForTerms(queryTerms, termFrequency));
}
return shouldQueryRule;
}
Aggregations