use of org.molgenis.data.semantic.Relation 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.data.semantic.Relation in project molgenis by molgenis.
the class OntologyTagServiceTest method testGetTagsForAttribute.
@Test
public void testGetTagsForAttribute() {
EntityType emd = entityTypeFactory.create("org.molgenis.SNP");
Attribute attribute = attrFactory.create().setName("Chr");
attribute.setTags(asList(chromosomeNameTagEntity, geneAnnotationTagEntity));
Relation instanceOf = Relation.valueOf("instanceOf");
Ontology edamOntology = Ontology.create("EDAM", "http://edamontology.org", "The EDAM ontology.");
OntologyTerm chromosomeName = OntologyTerm.create("http://edamontology.org/data_0987", "Chromosome name", "Name of a chromosome.");
OntologyTerm geneAnnotation = OntologyTerm.create("http://edamontology.org/data_0919", "Gene annotation (chromosome)", "This includes basic information. e.g. chromosome number...");
when(ontologyService.getOntology("http://edamontology.org")).thenReturn(edamOntology);
when(ontologyService.getOntologyTerm("http://edamontology.org/data_0987")).thenReturn(chromosomeName);
when(ontologyService.getOntologyTerm("http://edamontology.org/data_0919")).thenReturn(geneAnnotation);
Multimap<Relation, OntologyTerm> expected = LinkedHashMultimap.create();
expected.put(instanceOf, chromosomeName);
expected.put(instanceOf, geneAnnotation);
assertEquals(ontologyTagService.getTagsForAttribute(emd, attribute), expected);
}
Aggregations