Search in sources :

Example 1 with Ontology

use of org.molgenis.ontology.core.meta.Ontology in project molgenis by molgenis.

the class OntologyImportServiceIT method verifyOwlAsSystem.

private void verifyOwlAsSystem() {
    // Verify two imported rows (organization and team, as these are interesting examples)
    List<Entity> entities = dataService.findAll("sys_ont_OntologyTerm").collect(Collectors.toList());
    Optional<Entity> organizationOpt = entities.stream().filter(e -> e.getString("ontologyTermName").equals("organization")).findFirst();
    assertTrue(organizationOpt.isPresent());
    Entity organization = organizationOpt.get();
    Optional<Entity> teamOpt = entities.stream().filter(e -> e.getString("ontologyTermName").equals("team")).findFirst();
    assertTrue(teamOpt.isPresent());
    Entity team = teamOpt.get();
    // Verify organization
    assertEquals(organization.getString("ontologyTermIRI"), "http://www.molgenis.org#Organization");
    assertEquals(organization.getString("ontologyTermName"), "organization");
    // verify organization ontologyTermSynonym
    Iterable<Entity> ontologyTermSynonym = organization.getEntities("ontologyTermSynonym");
    List<Entity> termSynonymRefList = new ArrayList<>();
    ontologyTermSynonym.forEach(termSynonymRefList::add);
    assertEquals(termSynonymRefList.size(), 1);
    Entity organizationOntologyTermSynonym = dataService.findOneById("sys_ont_OntologyTermSynonym", termSynonymRefList.get(0).getIdValue());
    assertEquals(organizationOntologyTermSynonym.getString("ontologyTermSynonym"), "organization");
    // verify organization ontology
    Ontology ontology = (Ontology) organization.get("ontology");
    assertEquals(ontology.getOntologyName(), "ontology-small");
    // Verify the team row
    assertEquals(team.getString("ontologyTermIRI"), "http://www.molgenis.org#Team");
    assertEquals(team.getString("ontologyTermName"), "team");
    // verify team dynamic annotations
    Iterable<Entity> dynamicAnnotationItr = team.getEntities("ontologyTermDynamicAnnotation");
    List<Entity> dynamicAnnotations = new ArrayList<>();
    dynamicAnnotationItr.forEach(dynamicAnnotations::add);
    assertEquals(dynamicAnnotations.size(), 2);
    Entity annotationOne = dataService.findOneById("sys_ont_OntologyTermDynamicAnnotation", dynamicAnnotations.get(0).getIdValue());
    assertEquals(annotationOne.getString("label"), "friday:2412423");
    Entity annotationTwo = dataService.findOneById("sys_ont_OntologyTermDynamicAnnotation", dynamicAnnotations.get(1).getIdValue());
    assertEquals(annotationTwo.getString("label"), "molgenis:1231424");
    // verify team ontology
    ontology = (Ontology) team.get("ontology");
    assertEquals(ontology.getOntologyName(), "ontology-small");
}
Also used : java.util(java.util) Autowired(org.springframework.beans.factory.annotation.Autowired) Assert.assertEquals(org.testng.Assert.assertEquals) Test(org.testng.annotations.Test) RunAsSystemAspect.runAsSystem(org.molgenis.security.core.runas.RunAsSystemAspect.runAsSystem) EntityTypePermission(org.molgenis.data.security.EntityTypePermission) User(org.molgenis.data.security.auth.User) Ontology(org.molgenis.ontology.core.meta.Ontology) PACKAGE_DEFAULT(org.molgenis.data.meta.DefaultPackage.PACKAGE_DEFAULT) MutableAcl(org.springframework.security.acls.model.MutableAcl) EntityTypeIdentity(org.molgenis.data.security.EntityTypeIdentity) ImportService(org.molgenis.data.importer.ImportService) Sid(org.springframework.security.acls.model.Sid) ADD(org.molgenis.data.DatabaseAction.ADD) Collections.emptySet(java.util.Collections.emptySet) ImmutableMap(com.google.common.collect.ImmutableMap) EntityTypePermissionUtils.getCumulativePermission(org.molgenis.data.security.EntityTypePermissionUtils.getCumulativePermission) EntityImportReport(org.molgenis.data.importer.EntityImportReport) READ(org.molgenis.data.security.EntityTypePermission.READ) Collectors(java.util.stream.Collectors) File(java.io.File) FileRepositoryCollection(org.molgenis.data.file.support.FileRepositoryCollection) SecurityUtils(org.molgenis.security.core.utils.SecurityUtils) PrincipalSid(org.springframework.security.acls.domain.PrincipalSid) WithMockUser(org.springframework.security.test.context.support.WithMockUser) WRITE(org.molgenis.data.security.EntityTypePermission.WRITE) Assert.assertTrue(org.testng.Assert.assertTrue) MutableAclService(org.springframework.security.acls.model.MutableAclService) Entity(org.molgenis.data.Entity) Entity(org.molgenis.data.Entity) Ontology(org.molgenis.ontology.core.meta.Ontology)

Example 2 with Ontology

use of org.molgenis.ontology.core.meta.Ontology in project molgenis by molgenis.

the class InformationContentServiceTest method createWordIDF.

@Test
public void createWordIDF() {
    String ontologyIri = "http://www.molgenis.org";
    Ontology ontology = ontologyFactory.create();
    ontology.setOntologyIri(ontologyIri);
    when(dataService.findOne(ONTOLOGY, new QueryImpl<>().eq(OntologyMetaData.ONTOLOGY_IRI, ontologyIri))).thenReturn(ontology);
    when(dataService.count(ONTOLOGY_TERM, new QueryImpl<>().eq(OntologyTermMetaData.ONTOLOGY, ontology))).thenReturn((long) 100);
    QueryRule queryRule = new QueryRule(singletonList(new QueryRule(OntologyTermMetaData.ONTOLOGY_TERM_SYNONYM, Operator.FUZZY_MATCH, "hear")));
    queryRule.setOperator(Operator.DIS_MAX);
    QueryRule finalQuery = new QueryRule(asList(new QueryRule(OntologyTermMetaData.ONTOLOGY, Operator.EQUALS, ontology), new QueryRule(Operator.AND), queryRule));
    when(dataService.count(ONTOLOGY_TERM, new QueryImpl<>(finalQuery))).thenReturn((long) 30);
    QueryRule queryRule2 = new QueryRule(singletonList(new QueryRule(OntologyTermMetaData.ONTOLOGY_TERM_SYNONYM, Operator.FUZZY_MATCH, "impair")));
    queryRule2.setOperator(Operator.DIS_MAX);
    QueryRule finalQuery2 = new QueryRule(asList(new QueryRule(OntologyTermMetaData.ONTOLOGY, Operator.EQUALS, ontology), new QueryRule(Operator.AND), queryRule2));
    when(dataService.count(ONTOLOGY_TERM, new QueryImpl<>(finalQuery2))).thenReturn((long) 10);
    Map<String, Double> expectedWordIDF = informationContentService.createWordIDF("hearing impairment", ontologyIri);
    Assert.assertEquals(expectedWordIDF.get("hear").intValue(), 2);
    Assert.assertEquals(expectedWordIDF.get("impair").intValue(), 3);
}
Also used : QueryImpl(org.molgenis.data.support.QueryImpl) Ontology(org.molgenis.ontology.core.meta.Ontology) QueryRule(org.molgenis.data.QueryRule) Test(org.testng.annotations.Test) AbstractMolgenisSpringTest(org.molgenis.data.AbstractMolgenisSpringTest)

Example 3 with Ontology

use of org.molgenis.ontology.core.meta.Ontology in project molgenis by molgenis.

the class OntologyImportServiceIT method verifyOboAsSystem.

private void verifyOboAsSystem() {
    List<Entity> ontologies = dataService.findAll("sys_ont_Ontology").collect(Collectors.toList());
    Ontology ontology = (Ontology) ontologies.get(0);
    assertEquals(ontology.getOntologyName(), "ontology-small");
    List<Entity> synonyms = dataService.findAll("sys_ont_OntologyTerm").collect(Collectors.toList());
    verifyOboRow(synonyms, "molgenis ontology core", "http://purl.obolibrary.org/obo/TEMP#molgenis-ontology-core");
    verifyOboRow(synonyms, "molgenis", "http://purl.obolibrary.org/obo/TEMP#molgenis");
    verifyOboRow(synonyms, "Thing", "http://purl.obolibrary.org/obo/TEMP#Thing");
}
Also used : Entity(org.molgenis.data.Entity) Ontology(org.molgenis.ontology.core.meta.Ontology)

Aggregations

Ontology (org.molgenis.ontology.core.meta.Ontology)3 Entity (org.molgenis.data.Entity)2 Test (org.testng.annotations.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 File (java.io.File)1 java.util (java.util)1 Collections.emptySet (java.util.Collections.emptySet)1 Collectors (java.util.stream.Collectors)1 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)1 ADD (org.molgenis.data.DatabaseAction.ADD)1 QueryRule (org.molgenis.data.QueryRule)1 FileRepositoryCollection (org.molgenis.data.file.support.FileRepositoryCollection)1 EntityImportReport (org.molgenis.data.importer.EntityImportReport)1 ImportService (org.molgenis.data.importer.ImportService)1 PACKAGE_DEFAULT (org.molgenis.data.meta.DefaultPackage.PACKAGE_DEFAULT)1 EntityTypeIdentity (org.molgenis.data.security.EntityTypeIdentity)1 EntityTypePermission (org.molgenis.data.security.EntityTypePermission)1 READ (org.molgenis.data.security.EntityTypePermission.READ)1 WRITE (org.molgenis.data.security.EntityTypePermission.WRITE)1 EntityTypePermissionUtils.getCumulativePermission (org.molgenis.data.security.EntityTypePermissionUtils.getCumulativePermission)1