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 +5 -1
- data/README.md +0 -1
- data/lib/oba_client.rb +25 -10
- data/test/test_oba_client.rb +4 -3
- metadata +4 -4
data/History.md
CHANGED
data/README.md
CHANGED
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
|
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
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
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|
|
data/test/test_oba_client.rb
CHANGED
@@ -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?(
|
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
|
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?(
|
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:
|
4
|
+
hash: 19
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 1
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
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:
|
90
|
+
homepage:
|
91
91
|
licenses: []
|
92
92
|
|
93
93
|
post_install_message:
|