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 = {}) @options = {} # Shared with Annotator @options[:resource_index_location] = "http://rest.bioontology.org/resource_index/" @options[:filterNumber] = true @options[:isStopWordsCaseSensitive] = false @options[:isVirtualOntologyId] = true @options[:levelMax] = 0 @options[:longestOnly] = false @options[:ontologiesToExpand] = [] @options[:ontologiesToKeepInResult] = [] @options[:mappingTypes] = [] @options[:minTermSize] = 3 @options[:scored] = true @options[:semanticTypes] = [] @options[:stopWords] = [] @options[:wholeWordOnly] = true @options[:withDefaultStopWords] = true @options[:withSynonyms] = true # RI-specific @options[:conceptids] = [] @options[:mode] = :union @options[:elementid] = [] @options[:resourceids] = [] @options[:elementDetails] = false @options[:withContext] = true @options[:offset] = 0 @options[:limit] = 10 @options[:format] = :xml @options[:counts] = false @options[:request_timeout] = 300 @options.merge!(args) @ontologies = nil @options[: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 @options[: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
181 182 183 |
# File 'lib/ncbo_resource_index.rb', line 181 def self.ontologies() new().ontologies end |
.popular_concepts(resources = nil, options = {}) ⇒ Object
159 160 161 |
# File 'lib/ncbo_resource_index.rb', line 159 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
196 197 198 |
# File 'lib/ncbo_resource_index.rb', line 196 def self.resources() new().resources end |
.resources_hash(options) ⇒ Object
211 212 213 |
# File 'lib/ncbo_resource_index.rb', line 211 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) @options[:conceptids] = concepts unless concepts.nil? || concepts.empty? raise ArgumentError, ":conceptids must be included" if @options[:conceptids].nil? || @options[:conceptids].empty? raise ArgumentError, ":resourceids must be an array" unless @options[: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 = @options[: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 = [], = {}) @options[:conceptids] = concepts unless concepts.nil? || concepts.empty? @options.merge!() unless .empty? fix_params raise ArgumentError, ":conceptids must be included" if @options[:conceptids].nil? || @options[: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, = {}) @options[:elementid] = element unless element.nil? || element.empty? @options[:resourceids] = [resource] unless resource.nil? || resource.empty? @options.merge!() unless .empty? fix_params raise ArgumentError, ":elementid must be included" if @options[:elementid].nil? || @options[:elementid].empty? raise ArgumentError, ":resourceids must be included" if @options[:resourceids].nil? || @options[:resourceids].empty? Parser::ResourceIndex.parse_results(resource_index_post) end |
#ontologies(options = {}) ⇒ Object
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/ncbo_resource_index.rb', line 185 def ontologies( = {}) @options.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
223 224 225 |
# File 'lib/ncbo_resource_index.rb', line 223 def @options end |
#popular_concepts(resources = nil, options = {}) ⇒ Object
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/ncbo_resource_index.rb', line 163 def popular_concepts(resources = nil, = {}) @options[:resourceids] = resources @options[:resourceids] = [resources] unless resources.nil? || resources.empty? || resources.kind_of?(Array) @options.merge!() unless .empty? fix_params if @options[:resourceids].nil? || @options[:resourceids].empty? @options[:resourceids] = self.resources.collect {|resource| resource[:resourceId]} end popular_concepts = {} @options[: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 |
# File 'lib/ncbo_resource_index.rb', line 138 def ranked_elements(concepts = [], = {}) @options[:conceptids] = concepts unless concepts.nil? || concepts.empty? @options[:resourceids] ||= [] @options.merge!() unless .empty? fix_params raise ArgumentError, ":conceptids must be included" if @options[:conceptids].nil? || @options[:conceptids].empty? raise ArgumentError, ":resourceids must be an array" unless @options[:resourceids].kind_of? Array result_xml = open(["#{@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("")).read Parser::ResourceIndex.parse_ranked_element_results(result_xml) end |
#resources(options = {}) ⇒ Object
200 201 202 203 204 205 206 207 208 209 |
# File 'lib/ncbo_resource_index.rb', line 200 def resources( = {}) @options.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
215 216 217 218 219 220 221 |
# File 'lib/ncbo_resource_index.rb', line 215 def resources_hash( = {}) @options.merge!() unless .empty? resources = resources() resources_hash = {} resources.each {|res| resources_hash[res[:resourceId].downcase.to_sym] = res} resources_hash end |