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;
}
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;
}
Aggregations