Search in sources :

Example 21 with Relation

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);
}
Also used : Relation(org.molgenis.data.semantic.Relation) QueryRule(org.molgenis.data.QueryRule) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 22 with Relation

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);
}
Also used : Relation(org.molgenis.data.semantic.Relation) Ontology(org.molgenis.ontology.core.model.Ontology) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

Relation (org.molgenis.data.semantic.Relation)22 Attribute (org.molgenis.data.meta.model.Attribute)15 Test (org.testng.annotations.Test)15 LabeledResource (org.molgenis.data.semantic.LabeledResource)12 Model (org.eclipse.rdf4j.model.Model)11 LinkedHashModel (org.eclipse.rdf4j.model.impl.LinkedHashModel)11 AbstractMockitoTest (org.molgenis.test.AbstractMockitoTest)11 Iterator (java.util.Iterator)10 EntityType (org.molgenis.data.meta.model.EntityType)10 Entity (org.molgenis.data.Entity)9 OntologyTerm (org.molgenis.ontology.core.model.OntologyTerm)9 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)4 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)4 User (org.molgenis.data.security.auth.User)2 SemanticTag (org.molgenis.data.semantic.SemanticTag)2 Ontology (org.molgenis.ontology.core.model.Ontology)2 RunAsSystem (org.molgenis.security.core.runas.RunAsSystem)2 EntityMapping (org.molgenis.semanticmapper.mapping.model.EntityMapping)2 MappingProject (org.molgenis.semanticmapper.mapping.model.MappingProject)2 Instant (java.time.Instant)1