Search in sources :

Example 1 with OntologyTag

use of org.molgenis.semanticsearch.semantic.OntologyTag in project molgenis by molgenis.

the class OntologyTagServiceImpl method addAttributeTag.

@Override
public OntologyTag addAttributeTag(String entity, String attribute, String relationIRI, List<String> ontologyTermIRIs) {
    boolean added = false;
    Entity attributeEntity = findAttributeEntity(entity, attribute);
    Tag tag = new Tag(tagMetadata);
    Stream<OntologyTerm> terms = ontologyTermIRIs.stream().map(ontologyService::getOntologyTerm);
    OntologyTerm combinedOntologyTerm = OntologyTerm.and(terms.toArray(OntologyTerm[]::new));
    Relation relation = Relation.forIRI(relationIRI);
    tag.setId(idGenerator.generateId());
    tag.setCodeSystem(null);
    tag.setRelationIri(relation.getIRI());
    tag.setRelationLabel(relation.getLabel());
    tag.setLabel(combinedOntologyTerm.getLabel());
    tag.setObjectIri(combinedOntologyTerm.getIRI());
    dataService.add(TAG, tag);
    Map<String, Entity> tags = Maps.newHashMap();
    for (Entity attrTag : attributeEntity.getEntities(AttributeMetadata.TAGS)) {
        tags.put(attrTag.get(TagMetadata.OBJECT_IRI).toString(), attrTag);
    }
    if (!tags.containsKey(tag.get(TagMetadata.OBJECT_IRI).toString())) {
        tags.put(tag.get(TagMetadata.OBJECT_IRI).toString(), tag);
        added = true;
    }
    attributeEntity.set(AttributeMetadata.TAGS, tags.values());
    dataService.update(ATTRIBUTE_META_DATA, attributeEntity);
    updateEntityTypeEntityWithNewAttributeEntity(entity, attribute, attributeEntity);
    return added ? OntologyTag.create(combinedOntologyTerm, relation) : null;
}
Also used : Entity(org.molgenis.data.Entity) Relation(org.molgenis.data.semantic.Relation) SemanticTag(org.molgenis.data.semantic.SemanticTag) OntologyTag(org.molgenis.semanticsearch.semantic.OntologyTag) OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm)

Example 2 with OntologyTag

use of org.molgenis.semanticsearch.semantic.OntologyTag in project molgenis by molgenis.

the class OntologyTagServiceImpl method tagAttributesInEntity.

@Override
@Transactional
public Map<String, OntologyTag> tagAttributesInEntity(String entity, Map<Attribute, OntologyTerm> tags) {
    Map<String, OntologyTag> result = new LinkedHashMap<>();
    for (Entry<Attribute, OntologyTerm> tag : tags.entrySet()) {
        OntologyTerm ontologyTerm = tag.getValue();
        OntologyTag ontologyTag = addAttributeTag(entity, tag.getKey().getName(), Relation.isAssociatedWith.getIRI(), Collections.singletonList(ontologyTerm.getIRI()));
        result.put(tag.getKey().getName(), ontologyTag);
    }
    return result;
}
Also used : OntologyTerm(org.molgenis.ontology.core.model.OntologyTerm) OntologyTag(org.molgenis.semanticsearch.semantic.OntologyTag) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

OntologyTerm (org.molgenis.ontology.core.model.OntologyTerm)2 OntologyTag (org.molgenis.semanticsearch.semantic.OntologyTag)2 Entity (org.molgenis.data.Entity)1 Relation (org.molgenis.data.semantic.Relation)1 SemanticTag (org.molgenis.data.semantic.SemanticTag)1 Transactional (org.springframework.transaction.annotation.Transactional)1