ncbo_resource_index_client 1.4 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d577d2cbd404bd5442cd4f84f0e58c136b4b07b5
4
+ data.tar.gz: 9b8db209cf08a747a664cf5f3375e86195f327a3
5
+ SHA512:
6
+ metadata.gz: 174c8362112943484444bec3988b77de763a08e8abfcccf6bab0aa05ba81af30c53a48ba8d7bbfed1306fc91448344680979b3d3673787a993262c257299f5ca
7
+ data.tar.gz: 95a149959c6cc5da1e2c683b9a43882d83f261dcb4dbc74f4a520541baa63cd61fc82c946a60c3f43f335abb033cc3b89646bd02624e5d43cc9b67f6070bb9e8
@@ -3,8 +3,8 @@ require 'xml'
3
3
  require 'uri'
4
4
  require 'open-uri'
5
5
  require 'cgi'
6
- require 'ncbo_resource_index/parser'
7
- require 'ncbo_resource_index/data'
6
+ require_relative 'ncbo_resource_index/parser'
7
+ require_relative 'ncbo_resource_index/data'
8
8
 
9
9
 
10
10
  module NCBO
@@ -130,6 +130,27 @@ module NCBO
130
130
  end
131
131
  primary_annotations
132
132
  end
133
+
134
+ def self.element(element_id, resource_id, options = {})
135
+ new(options).element(element_id, resource_id)
136
+ end
137
+
138
+ def element(element_id, resource_id)
139
+ @options.merge!(options) unless options.empty?
140
+
141
+ raise ArugmentError, "element_id must be provided" if element_id.nil?
142
+ raise ArugmentError, "resource_id must be provided" if resource_id.nil?
143
+
144
+ result_url = [
145
+ "#{@options[:resource_index_location]}",
146
+ "elementDetails/#{resource_id}",
147
+ "?elementid=#{element_id}",
148
+ "&apikey=#{@options[:apikey]}"
149
+ ].join("")
150
+
151
+ result_xml = open(result_url).read
152
+ Parser::ResourceIndex.parse_element_results(result_xml)
153
+ end
133
154
 
134
155
  def self.ranked_elements(concepts, options = {})
135
156
  new(options).ranked_elements(concepts)
@@ -12,6 +12,11 @@ module NCBO
12
12
  class RankedElements
13
13
  attr_accessor :concepts, :resources
14
14
  end
15
+
16
+ class Element
17
+ attr_accessor :id, :resource, :text, :weights, :ontoIds
18
+ alias :localElementId :id
19
+ end
15
20
 
16
21
  end
17
22
  end
@@ -51,13 +51,12 @@ module NCBO
51
51
  end
52
52
 
53
53
  def parse_results(options = {})
54
- resource ||= options[:resource]
55
54
  annotation_location ||= options[:annotation_location]
56
55
 
57
56
  results = []
58
57
  @results.find("/success/data/list/*").each do |result|
59
58
  resource_annotations = NCBO::ResourceIndex::Annotations.new
60
- resource_annotations.resource = resource ||= result.find_first("resourceId").content
59
+ resource_annotations.resource = result.find_first("resourceId").content
61
60
 
62
61
  # Check to see if parameters are enabled that will change how we process the output
63
62
  with_context = result.find_first("withContext").content.eql?("true") rescue false
@@ -118,7 +117,22 @@ module NCBO
118
117
  end
119
118
  concepts
120
119
  end
121
-
120
+
121
+ def self.parse_element_results(results)
122
+ new(results).parse_element_results
123
+ end
124
+
125
+ def parse_element_results
126
+ element = parse_element(@results.find_first("/success/data"), "obs.obr.populate.Element")
127
+ new_element = NCBO::ResourceIndex::Element.new
128
+ new_element.id = element[:localElementId]
129
+ new_element.weights = element[:weights]
130
+ new_element.ontoIds = element[:ontoIds]
131
+ new_element.text = element[:text]
132
+ new_element.resource = element[:text].first[0].split("_")[0]
133
+ new_element
134
+ end
135
+
122
136
  def self.parse_element_annotations(results)
123
137
  new(results).parse_element_annotations
124
138
  end
@@ -209,18 +223,18 @@ module NCBO
209
223
  a
210
224
  end
211
225
 
212
- def parse_element(annotation)
226
+ def parse_element(annotation, element_location = "element")
213
227
  a = {}
214
- a[:localElementId] = annotation.find_first("element/localElementId").content unless annotation.find_first("element/localElementId").nil?
228
+ a[:localElementId] = annotation.find_first("#{element_location}/localElementId").content unless annotation.find_first("#{element_location}/localElementId").nil?
215
229
  # element text
216
230
  a[:text] = {}
217
- annotation.find("element/elementStructure/contexts/*").each {|context| a[:text][context.children[0].content] = context.children[1].content}
231
+ annotation.find("#{element_location}/elementStructure/contexts/*").each {|context| a[:text][context.children[0].content] = context.children[1].content}
218
232
  # element weights
219
233
  a[:weights] = []
220
- annotation.find("element/elementStructure/weights/*").each {|weight| a[:weights] << {:name => weight.children[0].content, :weight => weight.children[1].content.to_f} }
234
+ annotation.find("#{element_location}/elementStructure/weights/*").each {|weight| a[:weights] << {:name => weight.children[0].content, :weight => weight.children[1].content.to_f} }
221
235
  # which element portions are associated with an ontology
222
236
  a[:ontoIds] = {}
223
- annotation.find("element/elementStructure/ontoIds/*").each {|ont_id| a[:ontoIds][ont_id.children[0].content] = ont_id.children[1].content.to_i}
237
+ annotation.find("#{element_location}/elementStructure/ontoIds/*").each {|ont_id| a[:ontoIds][ont_id.children[0].content] = ont_id.children[1].content.to_i}
224
238
  return a
225
239
  end
226
240
  end
metadata CHANGED
@@ -1,8 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ncbo_resource_index_client
3
3
  version: !ruby/object:Gem::Version
4
- prerelease:
5
- version: '1.4'
4
+ version: 1.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Paul R Alexander
@@ -13,16 +12,14 @@ date: 2013-04-02 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: libxml-ruby
16
- type: :runtime
17
15
  requirement: !ruby/object:Gem::Requirement
18
- none: false
19
16
  requirements:
20
17
  - - ~>
21
18
  - !ruby/object:Gem::Version
22
19
  version: 2.2.0
20
+ type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
24
  - - ~>
28
25
  - !ruby/object:Gem::Version
@@ -46,27 +43,26 @@ files:
46
43
  - lib/ncbo_resource_index.rb
47
44
  homepage: http://github.com/ncbo/resource_index_ruby_client
48
45
  licenses: []
46
+ metadata: {}
49
47
  post_install_message:
50
48
  rdoc_options: []
51
49
  require_paths:
52
50
  - lib
53
51
  required_ruby_version: !ruby/object:Gem::Requirement
54
- none: false
55
52
  requirements:
56
- - - ! '>='
53
+ - - '>='
57
54
  - !ruby/object:Gem::Version
58
55
  version: '0'
59
56
  required_rubygems_version: !ruby/object:Gem::Requirement
60
- none: false
61
57
  requirements:
62
- - - ! '>='
58
+ - - '>='
63
59
  - !ruby/object:Gem::Version
64
60
  version: '0'
65
61
  requirements: []
66
62
  rubyforge_project:
67
- rubygems_version: 1.8.23
63
+ rubygems_version: 2.0.0
68
64
  signing_key:
69
- specification_version: 3
65
+ specification_version: 4
70
66
  summary: The NCBO Resource Index Gem is a Ruby client for NCBO's Resource Index Web
71
67
  service
72
68
  test_files: []