Module: OpenBEL::Nanopub::FacetFilter
- Included in:
- NanopubFacets, Routes::Datasets, Routes::Nanopubs
- Defined in:
- lib/openbel/api/nanopub/facet_filter.rb
Constant Summary collapse
- EMPTY =
[]
- NANOPUB_PARTS =
[:citation, :experiment_context, :metadata]
Instance Method Summary collapse
- #make_filter(category, name, value) ⇒ Object
- #map_citation_facets(citation) ⇒ Object
- #map_experiment_context_facets(experiment_context) ⇒ Object
- #map_metadata_facets(metadata) ⇒ Object
- #map_nanopub_facets(nanopub) ⇒ Object
Instance Method Details
#make_filter(category, name, value) ⇒ Object
74 75 76 77 78 79 80 |
# File 'lib/openbel/api/nanopub/facet_filter.rb', line 74 def make_filter(category, name, value) { :category => category, :name => name, :value => value } end |
#map_citation_facets(citation) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/openbel/api/nanopub/facet_filter.rb', line 18 def map_citation_facets(citation) if citation and citation.id [ self.make_filter(:citation, :id, citation.id) ] else EMPTY end end |
#map_experiment_context_facets(experiment_context) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/openbel/api/nanopub/facet_filter.rb', line 28 def map_experiment_context_facets(experiment_context) if experiment_context experiment_context.flat_map { |annotation| name = annotation[:name] value = annotation[:value] if value.respond_to?(:each) value.map { |v| [:experiment_context, name, v] } else # HACK: nested array will be flattened out by flat_map; # otherwise we would have each data value unrolled [[:experiment_context, name, value]] end }.select { |(_, _, value)| value != nil }.map { |filter| self.make_filter(*filter) } else EMPTY end end |
#map_metadata_facets(metadata) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/openbel/api/nanopub/facet_filter.rb', line 52 def () if .flat_map { |name, value| if value.respond_to?(:each) value.map { |v| [:metadata, name, v] } else # HACK: nested array will be flattened out by flat_map; # otherwise we would have each data value unrolled [[:metadata, name, value]] end }.select { |_, _, value| value != nil }.map { |filter| self.make_filter(*filter) } else EMPTY end end |
#map_nanopub_facets(nanopub) ⇒ Object
10 11 12 13 14 15 16 |
# File 'lib/openbel/api/nanopub/facet_filter.rb', line 10 def map_nanopub_facets(nanopub) NANOPUB_PARTS.reduce([]) { |facets, nanopub_part| part = nanopub.send(nanopub_part) new_facets = self.send(:"map_#{nanopub_part}_facets", part) facets.concat(new_facets) } end |