Search in sources :

Example 1 with OntologyTerm

use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.

the class OntologyTermRepositoryTest method testFindExcatOntologyTerms.

@Test
public void testFindExcatOntologyTerms() {
    Entity synonymEntity1 = mock(Entity.class);
    when(synonymEntity1.get(OntologyTermSynonymMetaData.ID)).thenReturn("synonym-1");
    when(synonymEntity1.get(OntologyTermSynonymMetaData.ONTOLOGY_TERM_SYNONYM_ATTR)).thenReturn("Weight Reduction Diet");
    Entity synonymEntity2 = mock(Entity.class);
    when(synonymEntity2.get(OntologyTermSynonymMetaData.ID)).thenReturn("synonym-2");
    when(synonymEntity2.get(OntologyTermSynonymMetaData.ONTOLOGY_TERM_SYNONYM_ATTR)).thenReturn("Weight loss Diet");
    Entity synonymEntity3 = mock(Entity.class);
    when(synonymEntity3.get(OntologyTermSynonymMetaData.ID)).thenReturn("synonym-3");
    when(synonymEntity3.get(OntologyTermSynonymMetaData.ONTOLOGY_TERM_SYNONYM_ATTR)).thenReturn("Diet, Reducing");
    Entity ontologyTermEntity1 = mock(Entity.class);
    when(ontologyTermEntity1.getString(ID)).thenReturn("1");
    when(ontologyTermEntity1.get(ONTOLOGY)).thenReturn("34");
    when(ontologyTermEntity1.getString(ONTOLOGY_TERM_IRI)).thenReturn("http://www.test.nl/iri/1");
    when(ontologyTermEntity1.getString(ONTOLOGY_TERM_NAME)).thenReturn("Diet, Reducing");
    when(ontologyTermEntity1.get(ONTOLOGY_TERM_SYNONYM)).thenReturn(asList(synonymEntity1, synonymEntity2, synonymEntity3));
    Entity synonymEntity4 = mock(Entity.class);
    when(synonymEntity4.get(OntologyTermSynonymMetaData.ID)).thenReturn("synonym-4");
    when(synonymEntity4.get(OntologyTermSynonymMetaData.ONTOLOGY_TERM_SYNONYM_ATTR)).thenReturn("Weight");
    Entity ontologyTermEntity2 = mock(Entity.class);
    when(ontologyTermEntity2.getString(ID)).thenReturn("12");
    when(ontologyTermEntity2.get(ONTOLOGY)).thenReturn("34");
    when(ontologyTermEntity2.getString(ONTOLOGY_TERM_IRI)).thenReturn("http://www.test.nl/iri/2");
    when(ontologyTermEntity2.getString(ONTOLOGY_TERM_NAME)).thenReturn("Weight");
    when(ontologyTermEntity2.get(ONTOLOGY_TERM_SYNONYM)).thenReturn(singletonList(synonymEntity4));
    @SuppressWarnings("unchecked") ArgumentCaptor<Query<Entity>> queryCaptor = forClass(Query.class);
    when(dataService.findAll(eq(ONTOLOGY_TERM), queryCaptor.capture())).thenReturn(Stream.of(ontologyTermEntity1, ontologyTermEntity2));
    List<OntologyTerm> exactOntologyTerms = ontologyTermRepository.findExcatOntologyTerms(asList("1", "2"), of("weight"), 100);
    assertEquals(exactOntologyTerms, singletonList(OntologyTerm.create("http://www.test.nl/iri/2", "Weight", null, singletonList("Weight"))));
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 2 with OntologyTerm

use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.

the class OntologyTermRepositoryTest method testGetChildOntologyTermsByNodePath.

@Test
public void testGetChildOntologyTermsByNodePath() {
    Entity ontologyEntity = new DynamicEntity(ontologyMetaData);
    ontologyEntity.set(OntologyMetaData.ONTOLOGY_IRI, "http://www.molgenis.org");
    ontologyEntity.set(OntologyMetaData.ONTOLOGY_NAME, "molgenis");
    Entity nodePathEntity_1 = new DynamicEntity(ontologyTermNodePathMetaData);
    nodePathEntity_1.set(OntologyTermNodePathMetaData.NODE_PATH, "0[0].1[1]");
    Entity nodePathEntity_2 = new DynamicEntity(ontologyTermNodePathMetaData);
    nodePathEntity_2.set(OntologyTermNodePathMetaData.NODE_PATH, "0[0].1[1].0[2]");
    Entity nodePathEntity_3 = new DynamicEntity(ontologyTermNodePathMetaData);
    nodePathEntity_3.set(OntologyTermNodePathMetaData.NODE_PATH, "0[0].1[1].1[2]");
    Entity ontologyTerm_2 = new DynamicEntity(ontologyTermMetaData);
    ontologyTerm_2.set(ONTOLOGY, ontologyEntity);
    ontologyTerm_2.set(ONTOLOGY_TERM_IRI, "iri 2");
    ontologyTerm_2.set(ONTOLOGY_TERM_NAME, "name 2");
    ontologyTerm_2.set(OntologyTermMetaData.ONTOLOGY_TERM_NODE_PATH, asList(nodePathEntity_1, nodePathEntity_2));
    ontologyTerm_2.set(ONTOLOGY_TERM_SYNONYM, emptyList());
    Entity ontologyTerm_3 = new DynamicEntity(ontologyTermMetaData);
    ontologyTerm_3.set(ONTOLOGY, ontologyEntity);
    ontologyTerm_3.set(ONTOLOGY_TERM_IRI, "iri 3");
    ontologyTerm_3.set(ONTOLOGY_TERM_NAME, "name 3");
    ontologyTerm_3.set(OntologyTermMetaData.ONTOLOGY_TERM_NODE_PATH, singletonList(nodePathEntity_3));
    ontologyTerm_3.set(ONTOLOGY_TERM_SYNONYM, emptyList());
    when(dataService.findAll(ONTOLOGY_TERM, new QueryImpl<>(new QueryRule(OntologyTermMetaData.ONTOLOGY_TERM_NODE_PATH, QueryRule.Operator.FUZZY_MATCH, "\"0[0].1[1]\"")).and().eq(ONTOLOGY, ontologyEntity))).thenReturn(Stream.of(ontologyTerm_2, ontologyTerm_3));
    List<OntologyTerm> childOntologyTermsByNodePath = ontologyTermRepository.getChildOntologyTermsByNodePath(ontologyEntity, nodePathEntity_1);
    assertEquals(childOntologyTermsByNodePath.size(), 2);
    assertEquals(childOntologyTermsByNodePath.get(0), OntologyTerm.create("iri 2", "name 2", null, singletonList("name 2")));
    assertEquals(childOntologyTermsByNodePath.get(1), OntologyTerm.create("iri 3", "name 3", null, singletonList("name 3")));
}
Also used : DynamicEntity(org.molgenis.data.support.DynamicEntity) DynamicEntity(org.molgenis.data.support.DynamicEntity) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) Test(org.testng.annotations.Test) BeforeTest(org.testng.annotations.BeforeTest)

Example 3 with OntologyTerm

use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.

the class OntologyTermTest method testAnd.

@Test
public void testAnd() {
    OntologyTerm term1 = OntologyTerm.create("iri1", "label 1");
    OntologyTerm term2 = OntologyTerm.create("iri2", "label 2");
    OntologyTerm term3 = OntologyTerm.create("iri3", "label 3");
    Assert.assertEquals(OntologyTerm.create("iri1,iri2", "(label 1 and label 2)"), OntologyTerm.and(term1, term2));
    Assert.assertEquals(OntologyTerm.create("iri1,iri2,iri3", "(label 1 and label 2 and label 3)"), OntologyTerm.and(term1, term2, term3));
}
Also used : OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) Test(org.testng.annotations.Test)

Example 4 with OntologyTerm

use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.

the class OntologyTermRepository method getOntologyTerm.

/**
 * Retrieves an {@link OntologyTerm} for one or more IRIs
 *
 * @param iris Array of {@link OntologyTerm} IRIs
 * @return combined {@link OntologyTerm} for the iris.
 */
public OntologyTerm getOntologyTerm(String[] iris) {
    List<OntologyTerm> ontologyTerms = Lists.newArrayList();
    for (String iri : iris) {
        OntologyTerm ontologyTerm = toOntologyTerm(dataService.findOne(ONTOLOGY_TERM, QueryImpl.EQ(ONTOLOGY_TERM_IRI, iri)));
        if (ontologyTerm == null) {
            return null;
        }
        ontologyTerms.add(ontologyTerm);
    }
    return OntologyTerm.and(ontologyTerms.toArray(new OntologyTerm[0]));
}
Also used : OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm)

Example 5 with OntologyTerm

use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.

the class MappingServiceControllerTest method testViewMappingProject.

@Test
public void testViewMappingProject() {
    when(mappingService.getMappingProject("hop hop hop")).thenReturn(mappingProject);
    when(dataService.getEntityTypeIds()).thenReturn(Stream.of("LifeLines", "entity1", "entity2"));
    when(mappingService.getCompatibleEntityTypes(hop)).thenReturn(Stream.of(lifeLines, target1, target2));
    when(dataService.getEntityType("HOP")).thenReturn(hop);
    OntologyTerm ontologyTermAge = OntologyTerm.create("iri1", "label1");
    OntologyTerm ontologyTermDateOfBirth = OntologyTerm.create("iri2", "label2");
    when(ontologyTagService.getTagsForAttribute(hop, ageAttr)).thenReturn(ImmutableMultimap.of(isAssociatedWith, ontologyTermAge));
    when(ontologyTagService.getTagsForAttribute(hop, dobAttr)).thenReturn(ImmutableMultimap.of(isAssociatedWith, ontologyTermDateOfBirth));
    when(dataService.getMeta()).thenReturn(metaDataService);
    when(metaDataService.getPackages()).thenReturn(asList(system, base));
    // system package, not a valid choice
    when(system.getId()).thenReturn(PACKAGE_SYSTEM);
    when(base.getId()).thenReturn("base");
    when(dataService.getEntityType("entity1")).thenReturn(target1);
    when(dataService.getEntityType("entity2")).thenReturn(target2);
    String view = controller.viewMappingProject("hop hop hop", model);
    assertEquals(view, "view-single-mapping-project");
    Mockito.verify(model).addAttribute("entityTypes", asList(target1, target2));
    Mockito.verify(model).addAttribute("packages", singletonList(base));
    Mockito.verify(model).addAttribute("compatibleTargetEntities", asList(lifeLines, target1, target2));
    Mockito.verify(model).addAttribute("selectedTarget", "HOP");
    Mockito.verify(model).addAttribute("mappingProject", mappingProject);
    Mockito.verify(model).addAttribute("hasWritePermission", true);
    Mockito.verify(model).addAttribute("attributeTagMap", ImmutableMap.of("dob", singletonList(ontologyTermDateOfBirth), "age", singletonList(ontologyTermAge)));
}
Also used : OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Aggregations

OntologyTerm (org.molgenis.ontology.core.model.OntologyTerm)30 Test (org.testng.annotations.Test)13 Relation (org.molgenis.data.semantic.Relation)9 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)8 ExplainedAttribute (org.molgenis.semanticsearch.explain.bean.ExplainedAttribute)8 Attribute (org.molgenis.data.meta.model.Attribute)7 EntityType (org.molgenis.data.meta.model.EntityType)7 Ontology (org.molgenis.ontology.core.model.Ontology)7 QueryRule (org.molgenis.data.QueryRule)6 Entity (org.molgenis.data.Entity)5 Sets (com.google.common.collect.Sets)3 java.util (java.util)3 Objects.requireNonNull (java.util.Objects.requireNonNull)3 Collectors (java.util.stream.Collectors)3 StringUtils (org.apache.commons.lang3.StringUtils)3 QueryParser (org.apache.lucene.queryparser.classic.QueryParser)3 DataService (org.molgenis.data.DataService)3 Operator (org.molgenis.data.QueryRule.Operator)3 AttributeMetadata (org.molgenis.data.meta.model.AttributeMetadata)3 SemanticTag (org.molgenis.data.semantic.SemanticTag)3