oba-client 1.0.5 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.md CHANGED
@@ -21,4 +21,8 @@
21
21
 
22
22
  ## 1.0.5 / 2010-07-08
23
23
 
24
- * Modify docs slightly.
24
+ * Modify docs slightly.
25
+
26
+ ## 1.1.0 / 2010-07-08
27
+
28
+ * Fully parse MGREP mappings.
data/README.md CHANGED
@@ -1,6 +1,5 @@
1
1
  # oba-client
2
2
 
3
- * http://rubyforge.org/projects/oba-client
4
3
 
5
4
  ## DESCRIPTION:
6
5
 
data/lib/oba_client.rb CHANGED
@@ -5,7 +5,7 @@ require "net/http"
5
5
  require "uri"
6
6
 
7
7
  class OBAClient
8
- VERSION = "1.0.5"
8
+ VERSION = "1.1.0"
9
9
 
10
10
  # A high HTTP read timeout, as the service sometimes takes awhile to respond.
11
11
  DEFAULT_TIMEOUT = 30
@@ -88,6 +88,18 @@ class OBAClient
88
88
  puts "Request for #{text[0..10]}... timed-out at #{@timeout} seconds."
89
89
  end
90
90
  end
91
+
92
+ # Convert a string true/false or 1/0 value to boolean.
93
+ # @param [String] value The value to convert.
94
+ # @return [true, false]
95
+ def self.to_b(value)
96
+ case value
97
+ when "0" then false
98
+ when "1" then true
99
+ when "false" then false
100
+ when "true" then true
101
+ end
102
+ end
91
103
 
92
104
  # Parse the raw XML, returning a Hash with three elements: statistics,
93
105
  # annotations, and ontologies. Respectively, these represent the annotation
@@ -98,20 +110,23 @@ class OBAClient
98
110
  # @return [Hash<Symbol, Object>] A Hash representation of the XML, as
99
111
  # described above.
100
112
  def self.parse(xml)
101
- statistics = []
113
+ statistics = {}
102
114
  annotations = []
103
115
  ontologies = []
104
116
  doc = Nokogiri::XML.parse(xml)
105
117
 
106
118
  doc.xpath("//annotationBean").each do |ann|
107
- parsed = {}
108
- parsed[:score] = ann.xpath("score").text.to_i
109
- parsed[:id] = ann.xpath("concept/id").text.to_i
110
- parsed[:localConceptId] = ann.xpath("concept/localConceptId")
111
- parsed[:localOntologyId] = ann.xpath("concept/localOntologyId").text.to_i
112
- parsed[:isTopLevel] = ann.xpath("concept/isTopLevel").text.to_i
113
- parsed[:fullId] = ann.xpath("concept/fullId").text
114
- parsed[:preferredName] = ann.xpath("concept/preferredName").text
119
+ parsed = {
120
+ :score => ann.xpath("score").text.to_i,
121
+ :id => ann.xpath("concept/id").text.to_i,
122
+ :localConceptId => ann.xpath("concept/localConceptId").text,
123
+ :localOntologyId => ann.xpath("concept/localOntologyId").text.to_i,
124
+ :isTopLevel => to_b(ann.xpath("concept/isTopLevel").text),
125
+ :fullId => ann.xpath("concept/fullId").text,
126
+ :preferredName => ann.xpath("concept/preferredName").text,
127
+ :mappingType => ann.xpath("context/contextName").text,
128
+ :isDirect => to_b(ann.xpath("context/isDirect").text)
129
+ }
115
130
 
116
131
  synonyms = ann.xpath("concept/synonyms/synonym")
117
132
  parsed[:synonyms] = synonyms.map do |synonym|
@@ -38,7 +38,7 @@ class TestOBAClient < Test::Unit::TestCase
38
38
  TEST_TEXTS.each do |text|
39
39
  ann = OBAClient.new :parse_xml => true
40
40
  parsed = ann.execute(text)
41
- assert parsed[:statistics].is_a?(Array)
41
+ assert parsed[:statistics].is_a?(Hash)
42
42
  assert parsed[:annotations].is_a?(Array)
43
43
  assert parsed[:ontologies].is_a?(Array)
44
44
  end
@@ -51,7 +51,7 @@ class TestOBAClient < Test::Unit::TestCase
51
51
  :parse_xml => true
52
52
  )
53
53
  parsed = ann.execute(text)
54
- assert (parsed[:ontologies].all? {|o| o[:localOntologyId] == 42812})
54
+ assert parsed[:ontologies].all? {|o| o[:localOntologyId] == 42812}
55
55
  end
56
56
  end
57
57
 
@@ -64,9 +64,10 @@ class TestOBAClient < Test::Unit::TestCase
64
64
  :hoho => ["merry", "christmas"]
65
65
  )
66
66
  parsed = ann.execute(text)
67
- assert parsed[:statistics].is_a?(Array)
67
+ assert parsed[:statistics].is_a?(Hash)
68
68
  assert parsed[:annotations].is_a?(Array)
69
69
  assert parsed[:ontologies].is_a?(Array)
70
+ p parsed[:annotations].first
70
71
  end
71
72
  end
72
73
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oba-client
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 1
8
+ - 1
8
9
  - 0
9
- - 5
10
- version: 1.0.5
10
+ version: 1.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Rob Tirrell
@@ -87,7 +87,7 @@ files:
87
87
  - lib/oba_client.rb
88
88
  - test/test_oba_client.rb
89
89
  has_rdoc: yard
90
- homepage: http://rubyforge.org/projects/oba-client
90
+ homepage:
91
91
  licenses: []
92
92
 
93
93
  post_install_message: