Module: Hookkaido
- Extended by:
- Configuration
- Defined in:
- lib/hookkaido.rb,
lib/hookkaido/error.rb,
lib/hookkaido/request.rb,
lib/hookkaido/version.rb,
lib/hookkaido/sources/ols.rb
Defined Under Namespace
Modules: Sources Classes: BadGateway, BadRequest, Error, GatewayTimeout, InternalServerError, NotFound, Request, ServiceUnavailable
Constant Summary collapse
- VERSION =
"0.1.1"
Class Method Summary collapse
-
.ontologies(verbose: false) ⇒ Object
List available ontology IDs (lowercased).
-
.search(term, ontologies: [], per: 25, page: 1, verbose: false) ⇒ Object
Search OLS for terms in specific ontologies matching a user-provided term.
Methods included from Configuration
Class Method Details
.ontologies(verbose: false) ⇒ Object
List available ontology IDs (lowercased)
16 17 18 |
# File 'lib/hookkaido.rb', line 16 def self.ontologies(verbose: false) Sources::OLS.ontologies(verbose: verbose, timeout: timeout) end |
.search(term, ontologies: [], per: 25, page: 1, verbose: false) ⇒ Object
Search OLS for terms in specific ontologies matching a user-provided term. Return: { results:, page:, per:, total: }
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/hookkaido.rb', line 25 def self.search(term, ontologies: [], per: 25, page: 1, verbose: false) raise ArgumentError, 'term cannot be blank' if term.to_s.strip.empty? requested = Array(ontologies).flat_map { |t| t.is_a?(String) && t.include?(',') ? t.split(',') : [t] } requested = requested.map { |t| t.to_s.strip.downcase }.reject(&:empty?) requested = ['uberon'] if requested.empty? requested = requested.uniq.first(3) # Uberon is a union of many other ontologies, so can return a lot of results # - put other results first. requested.push('uberon') if requested.delete('uberon') # Validate against OLS catalog #available = ontologies(verbose: verbose) #targets = (requested & available) #targets = ['uberon'] if targets.empty? targets = requested per_page = per.to_i start = [(page.to_i - 1), 0].max * per_page payload = Sources::OLS.search( term, ontologies: targets, rows: per_page, start: start, verbose: verbose, timeout: timeout ) results = payload[:results] || [] total = payload[:total].to_i # De-duplicate by IRI uniq = {} results.each { |r| uniq[r[:iri]] ||= r if r[:iri] } { results: uniq.values, page: page.to_i, per: per_page, total: total } end |