Search in sources :

Example 6 with Concept

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();
}
Also used : Concept(com.b2international.snowowl.core.domain.Concept) NotFoundException(com.b2international.commons.exceptions.NotFoundException) RepositoryManager(com.b2international.snowowl.core.RepositoryManager)

Example 7 with Concept

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;
}
Also used : SnomedConcept(com.b2international.snowowl.snomed.core.domain.SnomedConcept) Concept(com.b2international.snowowl.core.domain.Concept)

Example 8 with 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;
}
Also used : Concept(com.b2international.snowowl.core.domain.Concept)

Example 9 with Concept

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());
}
Also used : Multiset(com.google.common.collect.Multiset) OptionKey(com.b2international.snowowl.core.request.ConceptSearchRequestEvaluator.OptionKey) Set(java.util.Set) IOException(java.io.IOException) Multisets(com.google.common.collect.Multisets) Min(javax.validation.constraints.Min) Collectors(java.util.stream.Collectors) TextConstants(com.b2international.index.compat.TextConstants) List(java.util.List) Concepts(com.b2international.snowowl.core.domain.Concepts) Concept(com.b2international.snowowl.core.domain.Concept) Suggestions(com.b2international.snowowl.core.domain.Suggestions) ImmutableList(com.google.common.collect.ImmutableList) HashMultiset(com.google.common.collect.HashMultiset) Locale(java.util.Locale) EnglishStemmer(org.tartarus.snowball.ext.EnglishStemmer) Sets.newHashSet(com.google.common.collect.Sets.newHashSet) BranchContext(com.b2international.snowowl.core.domain.BranchContext) Splitter(com.google.common.base.Splitter) ResourceURI(com.b2international.snowowl.core.ResourceURI) Suggestions(com.b2international.snowowl.core.domain.Suggestions) ResourceURI(com.b2international.snowowl.core.ResourceURI) Concepts(com.b2international.snowowl.core.domain.Concepts) EnglishStemmer(org.tartarus.snowball.ext.EnglishStemmer)

Aggregations

Concept (com.b2international.snowowl.core.domain.Concept)9 Concepts (com.b2international.snowowl.core.domain.Concepts)4 Set (java.util.Set)3 Collectors (java.util.stream.Collectors)3 ResourceURI (com.b2international.snowowl.core.ResourceURI)2 ServiceProvider (com.b2international.snowowl.core.ServiceProvider)2 CodeSystemRequests (com.b2international.snowowl.core.codesystem.CodeSystemRequests)2 CodeSystem (com.b2international.snowowl.fhir.core.model.codesystem.CodeSystem)2 SnomedConcept (com.b2international.snowowl.snomed.core.domain.SnomedConcept)2 List (java.util.List)2 Map (java.util.Map)2 NotFoundException (com.b2international.commons.exceptions.NotFoundException)1 ExtendedLocale (com.b2international.commons.http.ExtendedLocale)1 Options (com.b2international.commons.options.Options)1 OptionsBuilder (com.b2international.commons.options.OptionsBuilder)1 TextConstants (com.b2international.index.compat.TextConstants)1 RepositoryManager (com.b2international.snowowl.core.RepositoryManager)1 CodeSystem (com.b2international.snowowl.core.codesystem.CodeSystem)1 BranchContext (com.b2international.snowowl.core.domain.BranchContext)1 ConceptMapMapping (com.b2international.snowowl.core.domain.ConceptMapMapping)1