Search in sources :

Example 1 with Ontology

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

the class TagWizardController method viewTagWizard.

/**
 * Displays on tag wizard button press
 *
 * @param target The target entity name
 * @param model  the model
 * @return name of the tag wizard view
 */
@GetMapping
public String viewTagWizard(@RequestParam(required = false, value = "selectedTarget") String target, Model model) {
    List<String> entityTypeIds = dataService.findAll(ENTITY_TYPE_META_DATA, EntityType.class).map(EntityType::getId).collect(toList());
    if (StringUtils.isEmpty(target)) {
        Optional<String> findFirst = entityTypeIds.stream().findFirst();
        if (findFirst.isPresent()) {
            target = findFirst.get();
        }
    }
    if (StringUtils.isEmpty(target)) {
        throw new UnknownEntityException("There are no entities available!");
    }
    List<Ontology> ontologies = ontologyService.getOntologies();
    EntityType emd = dataService.getEntityType(target);
    List<Attribute> attributes = newArrayList(emd.getAttributes());
    Map<String, Multimap<Relation, OntologyTerm>> taggedAttributes = attributes.stream().collect(toMap((Attribute::getName), (x -> ontologyTagService.getTagsForAttribute(emd, x))));
    model.addAttribute("entity", emd);
    model.addAttribute("entityTypeIds", entityTypeIds);
    model.addAttribute("attributes", attributes);
    model.addAttribute("ontologies", ontologies);
    model.addAttribute("taggedAttributes", taggedAttributes);
    model.addAttribute("relations", Relation.values());
    return VIEW_TAG_WIZARD;
}
Also used : EntityType(org.molgenis.data.meta.model.EntityType) Multimap(com.google.common.collect.Multimap) Ontology(org.molgenis.ontology.core.model.Ontology) Attribute(org.molgenis.data.meta.model.Attribute) UnknownEntityException(org.molgenis.data.UnknownEntityException)

Example 2 with Ontology

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

the class OntologyTagServiceImpl method removeAttributeTag.

@Override
public void removeAttributeTag(EntityType entityType, SemanticTag<Attribute, OntologyTerm, Ontology> removeTag) {
    Attribute attribute = removeTag.getSubject();
    Entity attributeEntity = findAttributeEntity(entityType.getId(), attribute.getName());
    List<Entity> tags = new ArrayList<>();
    for (Entity tagEntity : attributeEntity.getEntities(AttributeMetadata.TAGS)) {
        SemanticTag<Attribute, OntologyTerm, Ontology> tag = asTag(attribute, tagEntity);
        if (!removeTag.equals(tag)) {
            tags.add(tagEntity);
        }
    }
    attributeEntity.set(AttributeMetadata.TAGS, tags);
    dataService.update(ATTRIBUTE_META_DATA, attributeEntity);
}
Also used : Entity(org.molgenis.data.Entity) Ontology(org.molgenis.ontology.core.model.Ontology) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm)

Example 3 with Ontology

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

the class OntologyTagServiceImpl method asTag.

private <SubjectType> SemanticTag<SubjectType, OntologyTerm, Ontology> asTag(SubjectType subjectType, Entity tagEntity) {
    String identifier = tagEntity.getString(TagMetadata.ID);
    Relation relation = asRelation(tagEntity);
    Ontology ontology = asOntology(tagEntity);
    OntologyTerm ontologyTerm = asOntologyTerm(tagEntity);
    if (relation == null || ontologyTerm == null) {
        return null;
    }
    return new SemanticTag<>(identifier, subjectType, relation, ontologyTerm, ontology);
}
Also used : Relation(org.molgenis.data.semantic.Relation) Ontology(org.molgenis.ontology.core.model.Ontology) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) SemanticTag(org.molgenis.data.semantic.SemanticTag)

Example 4 with Ontology

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

the class UnitResolverImpl method resolveUnitOntologyTerm.

private OntologyTerm resolveUnitOntologyTerm(Set<String> tokens) {
    OntologyTerm unitOntologyTerm;
    Ontology unitOntology = ontologyService.getOntology(UNIT_ONTOLOGY_IRI);
    if (unitOntology != null) {
        if (!tokens.isEmpty()) {
            List<String> ontologyIds = Arrays.asList(unitOntology.getId());
            List<OntologyTerm> ontologyTerms = ontologyService.findExcatOntologyTerms(ontologyIds, tokens, Integer.MAX_VALUE);
            if (ontologyTerms != null && !ontologyTerms.isEmpty()) {
                if (ontologyTerms.size() == 1) {
                    unitOntologyTerm = ontologyTerms.get(0);
                } else {
                    // multiple unit ontology terms detected, pick first
                    unitOntologyTerm = ontologyTerms.get(0);
                }
            } else {
                unitOntologyTerm = null;
            }
        } else {
            unitOntologyTerm = null;
        }
    } else {
        LOG.warn("Unit resolver is missing required unit ontology [" + UNIT_ONTOLOGY_IRI + "]");
        unitOntologyTerm = null;
    }
    return unitOntologyTerm;
}
Also used : Ontology(org.molgenis.ontology.core.model.Ontology) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm)

Example 5 with Ontology

use of org.molgenis.ontology.core.model.Ontology 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

Ontology (org.molgenis.ontology.core.model.Ontology)6 OntologyTerm (org.molgenis.ontology.core.model.OntologyTerm)5 AbstractMolgenisSpringTest (org.molgenis.data.AbstractMolgenisSpringTest)2 Relation (org.molgenis.data.semantic.Relation)2 SemanticTag (org.molgenis.data.semantic.SemanticTag)2 Test (org.testng.annotations.Test)2 Multimap (com.google.common.collect.Multimap)1 Entity (org.molgenis.data.Entity)1 UnknownEntityException (org.molgenis.data.UnknownEntityException)1 Attribute (org.molgenis.data.meta.model.Attribute)1 EntityType (org.molgenis.data.meta.model.EntityType)1 OntologyTag (org.molgenis.semanticsearch.semantic.OntologyTag)1