use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.
the class OntologyTermRepositoryTest method testGetOntologyTerm.
@Test
public void testGetOntologyTerm() {
when(dataService.findOne(ONTOLOGY_TERM, QueryImpl.EQ(ONTOLOGY_TERM_IRI, "http://www.test.nl/iri"))).thenReturn(ontologyTermEntity);
String[] iris = { "http://www.test.nl/iri" };
OntologyTerm ontologyTerm = ontologyTermRepository.getOntologyTerm(iris);
assertEquals(ontologyTerm, OntologyTerm.create("http://www.test.nl/iri", "Ontology term", singletonList("Ontology term")));
}
use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.
the class UnitResolverImpl method resolveUnit.
@Override
public Unit<? extends Quantity> resolveUnit(Attribute attr, EntityType entityType) {
Set<String> tokens = tokenize(attr.getLabel(), attr.getDescription());
// Option 1: Check if a term matches a unit
Unit<? extends Quantity> unit = null;
if (!tokens.isEmpty()) {
for (String term : tokens) {
try {
unit = Unit.valueOf(term);
break;
} catch (IllegalArgumentException e) {
// noop
}
}
if (isUnitEmpty(unit)) {
// Option 2: Search unit ontology for a match
OntologyTerm unitOntologyTerm = resolveUnitOntologyTerm(tokens.stream().map(this::convertNumberToOntologyTermStyle).collect(Collectors.toSet()));
if (unitOntologyTerm != null) {
// try label + synonym labels until hit
for (String synonymLabel : unitOntologyTerm.getSynonyms()) {
try {
unit = Unit.valueOf(synonymLabel);
break;
} catch (IllegalArgumentException e) {
// noop
}
}
}
}
}
if (isUnitEmpty(unit)) {
unit = null;
}
return unit;
}
use of org.molgenis.ontology.core.model.OntologyTerm 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.OntologyTerm in project molgenis by molgenis.
the class AlgorithmServiceImpl method autoGenerateAlgorithm.
@Override
@RunAsSystem
public void autoGenerateAlgorithm(EntityType sourceEntityType, EntityType targetEntityType, EntityMapping mapping, Attribute targetAttribute) {
LOG.debug("createAttributeMappingIfOnlyOneMatch: target= " + targetAttribute.getName());
Multimap<Relation, OntologyTerm> tagsForAttribute = ontologyTagService.getTagsForAttribute(targetEntityType, targetAttribute);
Map<Attribute, ExplainedAttribute> relevantAttributes = semanticSearchService.decisionTreeToFindRelevantAttributes(sourceEntityType, targetAttribute, tagsForAttribute.values(), null);
GeneratedAlgorithm generatedAlgorithm = algorithmGeneratorService.generate(targetAttribute, relevantAttributes, targetEntityType, sourceEntityType);
if (StringUtils.isNotBlank(generatedAlgorithm.getAlgorithm())) {
AttributeMapping attributeMapping = mapping.addAttributeMapping(targetAttribute.getName());
attributeMapping.setAlgorithm(generatedAlgorithm.getAlgorithm());
attributeMapping.getSourceAttributes().addAll(generatedAlgorithm.getSourceAttributes());
attributeMapping.setAlgorithmState(generatedAlgorithm.getAlgorithmState());
LOG.debug("Creating attribute mapping: " + targetAttribute.getName() + " = " + generatedAlgorithm.getAlgorithm());
}
}
use of org.molgenis.ontology.core.model.OntologyTerm in project molgenis by molgenis.
the class MappingServiceController method getSemanticSearchAttributeMapping.
/**
* This controller will first of all check if the user-defined search terms exist. If so, the searchTerms will be
* used directly in the SemanticSearchService. If the searchTerms are not defined by users, it will use the
* ontologyTermTags in the SemantiSearchService. If neither of the searchTerms and the OntologyTermTags exist, it
* will use the information from the targetAttribute in the SemanticSearchService
* <p>
* If string terms are sent to the SemanticSearchService, they will be first of all converted to the ontologyTerms
* using findTag method
*/
@PostMapping(value = "/attributeMapping/semanticsearch", consumes = APPLICATION_JSON_VALUE)
@ResponseBody
public List<ExplainedAttribute> getSemanticSearchAttributeMapping(@RequestBody Map<String, String> requestBody) {
String mappingProjectId = requestBody.get("mappingProjectId");
String target = requestBody.get("target");
String source = requestBody.get("source");
String targetAttributeName = requestBody.get("targetAttribute");
String searchTermsString = requestBody.get("searchTerms");
Set<String> searchTerms = new HashSet<>();
if (StringUtils.isNotBlank(searchTermsString)) {
searchTerms.addAll(Sets.newHashSet(searchTermsString.toLowerCase().split("\\s+or\\s+")).stream().filter(StringUtils::isNotBlank).map(String::trim).collect(Collectors.toSet()));
}
MappingProject project = mappingService.getMappingProject(mappingProjectId);
MappingTarget mappingTarget = project.getMappingTarget(target);
EntityMapping entityMapping = mappingTarget.getMappingForSource(source);
Attribute targetAttribute = entityMapping.getTargetEntityType().getAttribute(targetAttributeName);
// Find relevant attributes base on tags
Multimap<Relation, OntologyTerm> tagsForAttribute = ontologyTagService.getTagsForAttribute(entityMapping.getTargetEntityType(), targetAttribute);
Map<Attribute, ExplainedAttribute> relevantAttributes = semanticSearchService.decisionTreeToFindRelevantAttributes(entityMapping.getSourceEntityType(), targetAttribute, tagsForAttribute.values(), searchTerms);
// If no relevant attributes are found, return all source attributes
if (relevantAttributes.isEmpty()) {
return stream(entityMapping.getSourceEntityType().getAllAttributes()).map(ExplainedAttribute::create).collect(toList());
}
return newArrayList(relevantAttributes.values());
}
Aggregations