/** * Retrieve a term from its owner vocabulary. For this to work properly, the term identifier must contain a known * vocabulary prefix. * * @param termId the term identifier, in the format {@code <vocabulary prefix>:<term id>}, for example * {@code HP:0002066} * @return the requested term, or {@code null} if the term doesn't exist in the vocabulary, or no matching * vocabulary is available */ public VocabularyTerm resolveTerm(String termId) { return this.manager.resolveTerm(termId); }
/** * Retrieve a vocabulary given its identifier. This is a shortcut for {@link #getVocabulary(String)} which allows * scripts to use the shorter {@code $services.vocabularies.hpo} notation for accessing a vocabulary. * * @param vocabularyId the vocabulary identifier, which is also used as a prefix in every term identifier from that * vocabulary, or a {@link Vocabulary#getAliases() known alias} for it, for example {@code MIM}, * {@code HP} or {@code HPO} * @return the requested vocabulary, or {@code null} if it doesn't exist or isn't available in the platform */ public Vocabulary get(String vocabularyId) { return this.manager.getVocabulary(vocabularyId); }
/** * Retrieves a list of vocabulary ids that are available for use with {@link #getVocabulary(String)}. * * @return a list of {@link Vocabulary#getIdentifier() vocabulary identifiers}, one for each vocabulary * @since 1.3 */ public List<String> getAvailableVocabularies() { return this.manager.getAvailableVocabularies(); }
@Override public Vocabularies getAllVocabularies() { Vocabularies result = new Vocabularies(); List<String> vocabularyIDs = this.vm.getAvailableVocabularies(); List<org.phenotips.vocabularies.rest.model.Vocabulary> availableVocabs = vocabularyIDs.stream() .map(vocabularyID -> this.vm.getVocabulary(vocabularyID)) .map(vocab -> this.objectFactory.createLinkedVocabularyRepresentation(vocab, getVocabularyLinks(), this::getCategoriesForVocabulary)) .collect(Collectors.toList()); result.withVocabularies(availableVocabs); result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return result; }
if (!this.vm.hasCategory(category)) { this.logger.error("The requested vocabulary category [{}] does not exist.", category); throw new WebApplicationException(Response.Status.NOT_FOUND); final List<VocabularyTerm> termSuggestions = this.vm.search(input, category, maxResults);
/** * Suggest the terms that best match the user's input, in all vocabularies * {@link Vocabulary#getSupportedCategories() supporting the target category of terms}. * * @param input the text to search for * @param category the category of terms to search in * @param maxResults the maximum number of terms to be returned * @return a list of suggestions, possibly empty * @since 1.4 */ public List<VocabularyTerm> search(String input, String category, int maxResults) { return this.manager.search(input, category, maxResults); } }
@Override public Vocabularies getAllVocabularies() { Vocabularies result = new Vocabularies(); List<String> vocabularyIDs = this.vm.getAvailableVocabularies(); List<org.phenotips.vocabularies.rest.model.Vocabulary> availableVocabs = new ArrayList<>(); for (String vocabularyID : vocabularyIDs) { Vocabulary vocab = this.vm.getVocabulary(vocabularyID); org.phenotips.vocabularies.rest.model.Vocabulary rep = this.objectFactory.createVocabularyRepresentation(vocab); rep.withLinks(this.autolinker.get().forSecondaryResource(VocabularyResource.class, this.uriInfo) .withActionableResources(VocabularyTermSuggestionsResource.class) .withExtraParameters("vocabulary-id", vocabularyID) .withGrantedRight(userIsAdmin() ? Right.ADMIN : Right.VIEW) .build()); availableVocabs.add(rep); } result.withVocabularies(availableVocabs); result.withLinks(this.autolinker.get().forResource(getClass(), this.uriInfo).build()); return result; }
private void addTerms(String item, List<VocabularyTerm> holder) { if (StringUtils.isNotBlank(item)) { VocabularyTerm term = this.vocabularyManager.resolveTerm(item); if (term != null) { holder.add(term); } } } }
/** * Retrieve a vocabulary given its identifier. * * @param vocabularyId the vocabulary identifier, which is also used as a prefix in every term identifier from that * vocabulary, or a {@link Vocabulary#getAliases() known alias} for it, for example {@code MIM}, * {@code hpo}, {@code HP} or {@code HPO} * @return the requested vocabulary, or {@code null} if it doesn't exist or isn't available in the platform */ public Vocabulary getVocabulary(String vocabularyId) { return this.manager.getVocabulary(vocabularyId); }
/** * Retrieve a term from its owner vocabulary. For this to work properly, the term identifier must contain a known * vocabulary prefix. * * @param termId the term identifier, in the format {@code <vocabulary prefix>:<term id>}, for example * {@code HP:0002066} * @return the requested term, or {@code null} if the term doesn't exist in the vocabulary, or no matching * vocabulary is available * @deprecated use {@link VocabularyScriptService#resolveTerm(String) $services.vocabularies.resolveTerm} instead */ @Deprecated public VocabularyTerm resolveTerm(String termId) { return this.manager.resolveTerm(termId); }
/** * Retrieve a vocabulary given its identifier. * * @param vocabularyId the vocabulary identifier, which is also used as a prefix in every term identifier from that * vocabulary, or a {@link Vocabulary#getAliases() known alias} for it, for example {@code MIM}, * {@code hpo}, {@code HP} or {@code HPO} * @return the requested vocabulary, or {@code null} if it doesn't exist or isn't available in the platform * @deprecated use {@link VocabularyScriptService#getVocabulary(String) $services.vocabularies.getVocabulary} instead */ @Deprecated public Vocabulary getOntology(String vocabularyId) { return this.manager.getVocabulary(vocabularyId); }
private void addTerms(String item, List<VocabularyTerm> holder) { if (StringUtils.isNotBlank(item)) { VocabularyTerm term = this.vocabularyManager.resolveTerm(item); if (term != null) { holder.add(term); } } } }
private Vocabulary getHGNCVocabulary() { try { return vocabularyManager.getVocabulary("HGNC"); } catch (Exception ex) { // this should not happen except when mocking, but does not hurt to catch in any case this.logger.error("Error loading component [{}]", ex.getMessage(), ex); return null; } }
/** * Builds a set of {@link VocabularyTerm} objects from a collection of term ID strings. * * @param termIds a collection of term IDs as strings; all IDs must be prefixed with the vocabulary identifier * @return a set of {@link VocabularyTerm} objects corresponding with the provided term IDs */ private Set<VocabularyTerm> buildTermsFromIDs(@Nonnull final Collection<String> termIds) { final Set<VocabularyTerm> terms = new HashSet<>(); for (final String termId : termIds) { if (StringUtils.isBlank(termId)) { continue; } final VocabularyTerm term = this.vocabularyManager.resolveTerm(termId); if (term == null) { this.logger.warn("A term with id: {} could not be found in existing vocabularies, and will be ignored.", termId); continue; } terms.add(term); } return Collections.unmodifiableSet(terms); }
private Vocabulary getHGNCVocabulary() { try { return this.vocabularyManager.getVocabulary(HGNC); } catch (Exception ex) { // this should not happen except when mocking, but does not hurt to catch in any case this.logger.error("Error loading component [{}]", ex.getMessage(), ex); return null; } } }
@Override public Response resolveTerm(String termId) { VocabularyTerm term = this.vm.resolveTerm(termId); if (term == null) { return Response.status(Response.Status.NOT_FOUND).build(); } JSONObject rep = term.toJSON(); rep.put("links", this.autolinker.get().forResource(getClass(), this.uriInfo) .withExtraParameters("vocabulary-id", term.getVocabulary().getIdentifier()).build()); return Response.ok(rep, MediaType.APPLICATION_JSON_TYPE).build(); } }
private Vocabulary getHGNCVocabulary() { try { return this.vocabularyManager.getVocabulary("HGNC"); } catch (Exception ex) { // this should not happen except when mocking, but does not hurt to catch in any case this.logger.error("Error loading component [{}]", ex.getMessage(), ex); return null; } }
/** * Returns a set with {@code termId} and the IDs of its ancestor terms. * * @param termId the term ID * @return a set with {@code termId} and the IDs of all its ancestor terms */ private Collection<String> getSelfAndAncestorTermIds(@Nonnull final String termId) { // The collection that will contain termId and the IDs of its ancestors. final Collection<String> ancestors = new HashSet<>(); ancestors.add(termId); // Find the term in the vocabulary, and if it exists, retrieve its ancestors, if any. final VocabularyTerm vocabularyTerm = this.vocabularyManager.resolveTerm(termId); if (vocabularyTerm != null) { for (VocabularyTerm ancestor : vocabularyTerm.getAncestors()) { ancestors.add(ancestor.getId()); } } else { this.logger.warn("Could not find term with ID: {} in indexed vocabularies.", termId); } return ancestors; }
/** * Retrieve a vocabulary given its identifier. This is a shortcut for {@link #getOntology(String)} which allows * scripts to use the shorter {@code $services.ontologies.hpo} notation for accessing a vocabulary. * * @param vocabularyId the vocabulary identifier, which is also used as a prefix in every term identifier from that * vocabulary, or a {@link Vocabulary#getAliases() known alias} for it, for example {@code MIM}, * {@code HP} or {@code HPO} * @return the requested vocabulary, or {@code null} if it doesn't exist or isn't available in the platform * @deprecated use {@link VocabularyScriptService#get(String) $services.vocabularies.get} instead */ @Deprecated public Vocabulary get(String vocabularyId) { return this.manager.getVocabulary(vocabularyId); } }
/** * Returns a set with {@code termId} and the IDs of its ancestor terms. * * @param termId the term ID * @return a set with {@code termId} and the IDs of all its ancestor terms */ private Collection<String> getSelfAndAncestorTermIds(@Nonnull final String termId) { // The collection that will contain termId and the IDs of its ancestors. final Collection<String> ancestors = new HashSet<>(); ancestors.add(termId); // Find the term in the vocabulary, and if it exists, retrieve its ancestors, if any. final VocabularyTerm vocabularyTerm = this.vocabularyManager.resolveTerm(termId); if (vocabularyTerm != null) { for (VocabularyTerm ancestor : vocabularyTerm.getAncestors()) { ancestors.add(ancestor.getId()); } } else { this.logger.warn("Could not find term with ID: {} in indexed vocabularies.", termId); } return ancestors; }