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