Module: Vendor::Envo

Defined in:
lib/vendor/envo.rb

Overview

A middle-layer wrapper between Hookkaido and TaxonWorks, constrained to the Environment Ontology (ENVO). AssertedEnvironment terms are ENVO-only by design (see AssertedEnvironment), so, unlike AnatomicalPart's use of Hookkaido, the ontology here is never caller-supplied.

Constant Summary collapse

ONTOLOGY =
'envo'.freeze
URI_PATTERN =

ENVO terms are published as OBO Library PURLs, e.g. http://purl.obolibrary.org/obo/ENVO_00002007

%r{\Ahttp://purl\.obolibrary\.org/obo/ENVO_\d+\z}

Class Method Summary collapse

Class Method Details

.local_id(uri) ⇒ String?

PURL_PREFIX is fixed by URI_PATTERN (and enforced by valid_uri? on every AssertedEnvironment#uri), so the local id is always the final path segment - safe to display in place of the full PURL.

Parameters:

  • uri (String, nil)

    a well-formed ENVO OBO Library PURL

Returns:

  • (String, nil)

    the local id, e.g. "ENVO_00002007"



40
41
42
# File 'lib/vendor/envo.rb', line 40

def self.local_id(uri)
  uri&.split('/')&.last
end

.search(term, per: 25, page: 1) ⇒ Hash

Returns { results:, page:, per:, total: }.

Parameters:

  • term (String)

    search string to match against ENVO labels/synonyms

Returns:

  • (Hash)

    { results:, page:, per:, total: }



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vendor/envo.rb', line 16

def self.search(term, per: 25, page: 1)
  payload = ::Hookkaido.search(term, ontologies: [ONTOLOGY], per:, page:)

  # OLS's `ontology: envo` scope includes terms merely referenced inside
  # ENVO's OWL graph (e.g. imported CHEBI/PATO classes), not only terms
  # minted under the ENVO_ namespace - filter to real ENVO PURLs so we
  # never offer a result AssertedEnvironment's own validation would reject.
  payload.merge(results: payload[:results].select { |r| valid_uri?(r[:iri]) })
rescue => e
  Rails.logger.warn "Vendor::Envo.search error: #{e.message}"
  { results: [], page:, per:, total: 0 }
end

.valid_uri?(uri) ⇒ Boolean

Returns true if uri is a well-formed ENVO OBO Library PURL.

Parameters:

  • uri (String, nil)

Returns:

  • (Boolean)

    true if uri is a well-formed ENVO OBO Library PURL



31
32
33
# File 'lib/vendor/envo.rb', line 31

def self.valid_uri?(uri)
  uri.present? && URI_PATTERN.match?(uri)
end