use of com.b2international.snowowl.core.domain.Concept in project snow-owl by b2ihealthcare.
the class FhirLookupRequest method doExecute.
@Override
protected LookupResult doExecute(ServiceProvider context, CodeSystem codeSystem) {
validateRequestedProperties(codeSystem);
final String acceptLanguage = extractLocales(request.getDisplayLanguage());
FhirCodeSystemLookupConverter converter = context.service(RepositoryManager.class).get(codeSystem.getToolingId()).optionalService(FhirCodeSystemLookupConverter.class).orElse(FhirCodeSystemLookupConverter.DEFAULT);
final String conceptExpand = converter.configureConceptExpand(request);
Concept concept = CodeSystemRequests.prepareSearchConcepts().one().filterByCodeSystemUri(codeSystem.getResourceURI()).filterById(request.getCode()).setLocales(acceptLanguage).setExpand(conceptExpand).buildAsync().execute(context).first().orElseThrow(() -> new NotFoundException("Concept", request.getCode()));
return LookupResult.builder().name(codeSystem.getName()).display(concept.getTerm()).version(codeSystem.getVersion()).designation(converter.expandDesignations(context, codeSystem, concept, request, acceptLanguage)).property(converter.expandProperties(context, codeSystem, concept, request)).build();
}
use of com.b2international.snowowl.core.domain.Concept in project snow-owl by b2ihealthcare.
the class SnomedConceptSearchRequestEvaluator method toConcept.
private Concept toConcept(ResourceURI codeSystem, SnomedConcept snomedConcept, String term, boolean requestedExpand) {
final Concept concept = toConcept(codeSystem, snomedConcept, snomedConcept.getIconId(), term, snomedConcept.getScore());
concept.setAlternativeTerms(FluentIterable.from(snomedConcept.getPreferredDescriptions()).transform(pd -> pd.getTerm()).toSortedSet(Comparator.naturalOrder()));
concept.setParentIds(snomedConcept.getParentIdsAsString());
concept.setAncestorIds(snomedConcept.getAncestorIdsAsString());
if (requestedExpand) {
concept.setInternalConcept(snomedConcept);
}
return concept;
}
use of com.b2international.snowowl.core.domain.Concept in project snow-owl by b2ihealthcare.
the class ConceptSearchRequestEvaluator method toConcept.
default Concept toConcept(ResourceURI codeSystem, IComponent concept, String iconId, String term, Float score) {
Concept result = new Concept(codeSystem, concept.getComponentType());
result.setId(concept.getId());
result.setReleased(concept.isReleased());
result.setIconId(iconId);
result.setTerm(term);
result.setScore(score);
result.setInternalConcept(concept);
return result;
}
use of com.b2international.snowowl.core.domain.Concept in project snow-owl by b2ihealthcare.
the class ConceptSuggestionRequest method doExecute.
@Override
protected Suggestions doExecute(BranchContext context) throws IOException {
TermFilter termFilter;
if (containsKey(TERM)) {
if (containsKey(MIN_OCCURENCE_COUNT)) {
termFilter = TermFilter.minTermMatch(getString(TERM), (Integer) get(MIN_OCCURENCE_COUNT)).withIgnoreStopwords();
} else {
termFilter = TermFilter.defaultTermMatch(getString(TERM)).withIgnoreStopwords();
}
} else {
// Gather tokens
final Multiset<String> tokenOccurrences = HashMultiset.create();
final EnglishStemmer stemmer = new EnglishStemmer();
// Get the suggestion base set of concepts
final ConceptSearchRequestBuilder baseRequestBuilder = new ConceptSearchRequestBuilder().filterByCodeSystemUri(context.service(ResourceURI.class)).setLimit(SCROLL_LIMIT).setLocales(locales());
if (containsKey(QUERY)) {
baseRequestBuilder.filterByInclusions(getCollection(QUERY, String.class));
}
if (containsKey(MUST_NOT_QUERY)) {
baseRequestBuilder.filterByExclusions(getCollection(MUST_NOT_QUERY, String.class));
}
baseRequestBuilder.stream(context).flatMap(Concepts::stream).flatMap(concept -> getAllTerms(concept).stream()).map(term -> term.toLowerCase(Locale.US)).flatMap(lowerCaseTerm -> TOKEN_SPLITTER.splitToList(lowerCaseTerm).stream()).map(token -> stemToken(stemmer, token)).forEach(tokenOccurrences::add);
topTokens = Multisets.copyHighestCountFirst(tokenOccurrences).elementSet().stream().filter(// skip short tokens
token -> token.length() > 2).limit(topTokenCount).collect(Collectors.toList());
int minShouldMatch = containsKey(MIN_OCCURENCE_COUNT) ? (Integer) get(MIN_OCCURENCE_COUNT) : DEFAULT_MIN_OCCURENCE_COUNT;
termFilter = TermFilter.minTermMatch(topTokens.stream().collect(Collectors.joining(" ")), minShouldMatch);
}
/*
* Run a search with the top tokens and minimum number of matches, excluding everything
* that was included previously.
*/
final Set<String> exclusions = newHashSet();
exclusions.addAll(getCollection(QUERY, String.class));
exclusions.addAll(getCollection(MUST_NOT_QUERY, String.class));
final ConceptSearchRequestBuilder resultRequestBuilder = new ConceptSearchRequestBuilder().filterByCodeSystemUri(context.service(ResourceURI.class)).filterByActive(true).filterByTerm(termFilter).setPreferredDisplay(getString(DISPLAY)).setLimit(limit()).setLocales(locales()).setSearchAfter(searchAfter()).sortBy(sortBy());
if (!exclusions.isEmpty()) {
resultRequestBuilder.filterByExclusions(exclusions);
}
final Concepts conceptSuggestions = resultRequestBuilder.build().execute(context);
return new Suggestions(topTokens, conceptSuggestions.getItems(), conceptSuggestions.getSearchAfter(), limit(), conceptSuggestions.getTotal());
}
Aggregations