Class: NCBO::ResourceIndex
- Inherits:
-
Object
- Object
- NCBO::ResourceIndex
- Defined in:
- lib/ncbo_resource_index.rb,
lib/ncbo_resource_index/data.rb
Defined Under Namespace
Classes: Annotation, Annotations, RankedElements
Class Method Summary collapse
- .element_annotations(element, concepts, resource, options = {}) ⇒ Object
- .find_by_concept(concepts, options = {}) ⇒ Object
- .find_by_element(element, resource, options = {}) ⇒ Object
- .ontologies(options) ⇒ Object
- .popular_concepts(resources = nil, options = {}) ⇒ Object
- .ranked_elements(concepts, options = {}) ⇒ Object
- .resources(options) ⇒ Object
- .resources_hash(options) ⇒ Object
Instance Method Summary collapse
- #element_annotations(element, concepts, resource) ⇒ Object
- #find_by_concept(concepts = [], options = {}) ⇒ Object
- #find_by_element(element, resource, options = {}) ⇒ Object
-
#initialize(args = {}) ⇒ ResourceIndex
constructor
A new instance of ResourceIndex.
- #ontologies(options = {}) ⇒ Object
- #options ⇒ Object
- #popular_concepts(resources = nil, options = {}) ⇒ Object
- #ranked_elements(concepts = [], options = {}) ⇒ Object
- #resources(options = {}) ⇒ Object
- #resources_hash(options = {}) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ ResourceIndex
Returns a new instance of ResourceIndex.
13 14 15 16 17 18 19 20 21 22 23 24 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 |
# File 'lib/ncbo_resource_index.rb', line 13 def initialize(args = {}) = {} # Shared with Annotator [:resource_index_location] = "http://rest.bioontology.org/resource_index/" [:filterNumber] = true [:isStopWordsCaseSensitive] = false [:isVirtualOntologyId] = true [:levelMax] = 0 [:longestOnly] = false [:ontologiesToExpand] = [] [:ontologiesToKeepInResult] = [] [:mappingTypes] = [] [:minTermSize] = 3 [:scored] = true [:semanticTypes] = [] [:stopWords] = [] [:wholeWordOnly] = true [:withDefaultStopWords] = true [:withSynonyms] = true # RI-specific [:conceptids] = [] [:mode] = :union [:elementid] = [] [:resourceids] = [] [:elementDetails] = false [:withContext] = true [:offset] = 0 [:limit] = 10 [:format] = :xml [:counts] = false [:request_timeout] = 300 .merge!(args) @ontologies = nil [:resourceids] ||= [] # Check to make sure mappingTypes are capitalized fix_params raise ArgumentError, ":apikey is required, you can obtain one at http://bioportal.bioontology.org/accounts/new" if [:apikey].nil? end |
Class Method Details
.element_annotations(element, concepts, resource, options = {}) ⇒ Object
87 88 89 |
# File 'lib/ncbo_resource_index.rb', line 87 def self.element_annotations(element, concepts, resource, = {}) new().element_annotations(element, concepts) end |
.find_by_concept(concepts, options = {}) ⇒ Object
58 59 60 |
# File 'lib/ncbo_resource_index.rb', line 58 def self.find_by_concept(concepts, = {}) new().find_by_concept(concepts) end |
.find_by_element(element, resource, options = {}) ⇒ Object
73 74 75 |
# File 'lib/ncbo_resource_index.rb', line 73 def self.find_by_element(element, resource, = {}) new().find_by_element(element, resource) end |
.ontologies(options) ⇒ Object
182 183 184 |
# File 'lib/ncbo_resource_index.rb', line 182 def self.ontologies() new().ontologies end |
.popular_concepts(resources = nil, options = {}) ⇒ Object
160 161 162 |
# File 'lib/ncbo_resource_index.rb', line 160 def self.popular_concepts(resources = nil, = {}) new().popular_concepts(resources) end |
.ranked_elements(concepts, options = {}) ⇒ Object
134 135 136 |
# File 'lib/ncbo_resource_index.rb', line 134 def self.ranked_elements(concepts, = {}) new().ranked_elements(concepts) end |
.resources(options) ⇒ Object
197 198 199 |
# File 'lib/ncbo_resource_index.rb', line 197 def self.resources() new().resources end |
.resources_hash(options) ⇒ Object
212 213 214 |
# File 'lib/ncbo_resource_index.rb', line 212 def self.resources_hash() new().resources_hash end |
Instance Method Details
#element_annotations(element, concepts, resource) ⇒ Object
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/ncbo_resource_index.rb', line 91 def element_annotations(element, concepts, resource) [:conceptids] = concepts unless concepts.nil? || concepts.empty? raise ArgumentError, ":conceptids must be included" if [:conceptids].nil? || [:conceptids].empty? raise ArgumentError, ":resourceids must be an array" unless [:resourceids].kind_of? Array resource = resource.upcase concept_annotations = [] concepts.each do |concept| split_concept = concept.split("/") ontology_id = split_concept[0] concept_id = split_concept[1] virtual = [:isVirtualOntologyId] ? "/virtual" : "" result_xml = open(["#{@options[:resource_index_location]}", "details/#{@options[:elementDetails]}", virtual, "/concept/#{ontology_id}", "/resource/#{resource}", "/#{@options[:offset]}", "/#{@options[:limit]}", "?conceptid=#{CGI.escape(concept_id)}", "&elementid=#{CGI.escape(element)}", "&apikey=#{@options[:apikey]}"].join("")).read annotations = Parser::ResourceIndex.parse_element_annotations(result_xml) concept_annotations << annotations end if concept_annotations.length > 1 # Merge the two result sets primary_annotations = Annotations.new primary_annotations.annotations = [] primary_annotations.resource = resource concept_annotations.each do |result| primary_annotations.annotations.concat result.annotations end elsif concept_annotations.length == 1 primary_annotations = concept_annotations[0] else primary_annotations = nil end primary_annotations end |
#find_by_concept(concepts = [], options = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ncbo_resource_index.rb', line 62 def find_by_concept(concepts = [], = {}) [:conceptids] = concepts unless concepts.nil? || concepts.empty? .merge!() unless .empty? fix_params raise ArgumentError, ":conceptids must be included" if [:conceptids].nil? || [:conceptids].empty? result_xml = resource_index_post Parser::ResourceIndex.parse_results(result_xml) end |
#find_by_element(element, resource, options = {}) ⇒ Object
77 78 79 80 81 82 83 84 85 |
# File 'lib/ncbo_resource_index.rb', line 77 def find_by_element(element, resource, = {}) [:elementid] = element unless element.nil? || element.empty? [:resourceids] = [resource] unless resource.nil? || resource.empty? .merge!() unless .empty? fix_params raise ArgumentError, ":elementid must be included" if [:elementid].nil? || [:elementid].empty? raise ArgumentError, ":resourceids must be included" if [:resourceids].nil? || [:resourceids].empty? Parser::ResourceIndex.parse_results(resource_index_post) end |
#ontologies(options = {}) ⇒ Object
186 187 188 189 190 191 192 193 194 195 |
# File 'lib/ncbo_resource_index.rb', line 186 def ontologies( = {}) .merge!() unless .empty? if @ontologies.nil? ontologies_xml = open("#{@options[:resource_index_location]}ontologies?apikey=#{@options[:apikey]}").read @ontologies = Parser::ResourceIndex.parse_included_ontologies(ontologies_xml) else @ontologies end end |
#options ⇒ Object
224 225 226 |
# File 'lib/ncbo_resource_index.rb', line 224 def end |
#popular_concepts(resources = nil, options = {}) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/ncbo_resource_index.rb', line 164 def popular_concepts(resources = nil, = {}) [:resourceids] = resources [:resourceids] = [resources] unless resources.nil? || resources.empty? || resources.kind_of?(Array) .merge!() unless .empty? fix_params if [:resourceids].nil? || [:resourceids].empty? [:resourceids] = self.resources.collect {|resource| resource[:resourceId]} end popular_concepts = {} [:resourceids].each do |resource| popular_concepts_xml = open("#{@options[:resource_index_location]}most-used-concepts/#{resource}?apikey=#{@options[:apikey]}&offset=#{@options[:offset]}&limit=#{@options[:limit]}").read popular_concepts[resource] = Parser::ResourceIndex.parse_popular_concepts(popular_concepts_xml) end popular_concepts end |
#ranked_elements(concepts = [], options = {}) ⇒ Object
138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
# File 'lib/ncbo_resource_index.rb', line 138 def ranked_elements(concepts = [], = {}) [:conceptids] = concepts unless concepts.nil? || concepts.empty? [:resourceids] ||= [] .merge!() unless .empty? fix_params raise ArgumentError, ":conceptids must be included" if [:conceptids].nil? || [:conceptids].empty? raise ArgumentError, ":resourceids must be an array" unless [:resourceids].kind_of? Array result_url = ["#{@options[:resource_index_location]}", "elements-ranked-by-concepts/#{@options[:resourceids].join(",")}", "?offset=#{@options[:offset]}", "&limit=#{@options[:limit]}", "&conceptids=#{@options[:conceptids].join(",")}", "&ontologiesToKeepInResult=#{@options[:ontologiesToKeepInResult].join(",")}", "&isVirtualOntologyId=#{@options[:isVirtualOntologyId]}", "&apikey=#{@options[:apikey]}", "&mode=#{@options[:mode]}"].join("") result_xml = open(result_url).read Parser::ResourceIndex.parse_ranked_element_results(result_xml) end |
#resources(options = {}) ⇒ Object
201 202 203 204 205 206 207 208 209 210 |
# File 'lib/ncbo_resource_index.rb', line 201 def resources( = {}) .merge!() unless .empty? if @resources.nil? resources_xml = open("#{@options[:resource_index_location]}resources?apikey=#{@options[:apikey]}").read @resources = Parser::ResourceIndex.parse_resources(resources_xml) else @resources end end |
#resources_hash(options = {}) ⇒ Object
216 217 218 219 220 221 222 |
# File 'lib/ncbo_resource_index.rb', line 216 def resources_hash( = {}) .merge!() unless .empty? resources = resources() resources_hash = {} resources.each {|res| resources_hash[res[:resourceId].downcase.to_sym] = res} resources_hash end |