simple_bioc 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +73 -3
- data/Rakefile +5 -0
- data/html/BioCReader.html +657 -0
- data/html/BioCWriter.html +556 -0
- data/html/README_md.html +231 -0
- data/html/SimpleBioC.html +255 -0
- data/html/SimpleBioC/Annotation.html +279 -0
- data/html/SimpleBioC/Collection.html +316 -0
- data/html/SimpleBioC/Document.html +426 -0
- data/html/SimpleBioC/Location.html +288 -0
- data/html/SimpleBioC/Node.html +334 -0
- data/html/SimpleBioC/NodeBase.html +281 -0
- data/html/SimpleBioC/Passage.html +418 -0
- data/html/SimpleBioC/Relation.html +301 -0
- data/html/SimpleBioC/Sentence.html +399 -0
- data/html/created.rid +15 -0
- data/html/images/add.png +0 -0
- data/html/images/arrow_up.png +0 -0
- data/html/images/brick.png +0 -0
- data/html/images/brick_link.png +0 -0
- data/html/images/bug.png +0 -0
- data/html/images/bullet_black.png +0 -0
- data/html/images/bullet_toggle_minus.png +0 -0
- data/html/images/bullet_toggle_plus.png +0 -0
- data/html/images/date.png +0 -0
- data/html/images/delete.png +0 -0
- data/html/images/find.png +0 -0
- data/html/images/loadingAnimation.gif +0 -0
- data/html/images/macFFBgHack.png +0 -0
- data/html/images/package.png +0 -0
- data/html/images/page_green.png +0 -0
- data/html/images/page_white_text.png +0 -0
- data/html/images/page_white_width.png +0 -0
- data/html/images/plugin.png +0 -0
- data/html/images/ruby.png +0 -0
- data/html/images/tag_blue.png +0 -0
- data/html/images/tag_green.png +0 -0
- data/html/images/transparent.png +0 -0
- data/html/images/wrench.png +0 -0
- data/html/images/wrench_orange.png +0 -0
- data/html/images/zoom.png +0 -0
- data/html/index.html +212 -0
- data/html/js/darkfish.js +155 -0
- data/html/js/jquery.js +18 -0
- data/html/js/navigation.js +142 -0
- data/html/js/search.js +94 -0
- data/html/js/search_index.js +1 -0
- data/html/js/searcher.js +228 -0
- data/html/rdoc.css +595 -0
- data/html/table_of_contents.html +199 -0
- data/lib/simple_bioc.rb +4 -0
- data/lib/simple_bioc/annotation.rb +10 -6
- data/lib/simple_bioc/bioc_reader.rb +2 -2
- data/lib/simple_bioc/collection.rb +13 -11
- data/lib/simple_bioc/document.rb +31 -22
- data/lib/simple_bioc/location.rb +13 -7
- data/lib/simple_bioc/node.rb +14 -8
- data/lib/simple_bioc/node_base.rb +13 -10
- data/lib/simple_bioc/passage.rb +26 -23
- data/lib/simple_bioc/relation.rb +13 -8
- data/lib/simple_bioc/sentence.rb +21 -15
- data/lib/simple_bioc/version.rb +2 -2
- data/samples/print_annotation.rb +18 -0
- data/samples/sample1.rb +31 -0
- data/simple_bioc.gemspec +1 -1
- metadata +52 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7cb0f3556fb61a2f2f802cef37678522bc0195f1
|
4
|
+
data.tar.gz: 9ecd0c5f1ab4fccd5313076f057bf979d192533f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02c83c1d490001ccc56098e6370b74068d6b24e4ed167bad7b474f2d01cdaa605de44593a6c6090141cafefbe442e71203b4dcf0d994f1c8465d4fe97643363f
|
7
|
+
data.tar.gz: 48a386b80cba3bd6fa754592b74d1b83d2e7c15f43b898fc72fda6c7d92f43d61a6576ec4375a928c6237e38495c9e31c3e65542a385c6db4ad6c172ea9302db
|
data/README.md
CHANGED
@@ -1,6 +1,13 @@
|
|
1
1
|
# SimpleBioc
|
2
2
|
|
3
|
-
|
3
|
+
SimpleBioC is a simple parser / builder for BioC data format. BioC is a simple XML format to share text documents and annotations. You can find more information about BioC from the official BioC web site ([http://www.ncbi.nlm.nih.gov/CBBresearch/Dogan/BioC/](http://www.ncbi.nlm.nih.gov/CBBresearch/Dogan/BioC/))
|
4
|
+
|
5
|
+
## Feature:
|
6
|
+
|
7
|
+
* Parse & convert a BioC document to an object instance compatible to BioC DTD
|
8
|
+
* Use plain ruby objects for simplicity
|
9
|
+
* Build a BioC document from an object instance
|
10
|
+
|
4
11
|
|
5
12
|
## Installation
|
6
13
|
|
@@ -16,9 +23,65 @@ Or install it yourself as:
|
|
16
23
|
|
17
24
|
$ gem install simple_bioc
|
18
25
|
|
19
|
-
## Usage
|
20
26
|
|
21
|
-
|
27
|
+
## Usages
|
28
|
+
|
29
|
+
Include library
|
30
|
+
|
31
|
+
require 'simple_bioc'
|
32
|
+
|
33
|
+
|
34
|
+
Parse with a file name (path)
|
35
|
+
|
36
|
+
collection = SimpleBioC::from_xml(filename)
|
37
|
+
|
38
|
+
Traverse & Manipulate Data. Data structure are almost the same as the DTD. Please refer [library documents](https://github.com/dongseop/simple_bioc/blob/master/html/index.html) and [the BioC DTD](http://www.ncbi.nlm.nih.gov/CBBresearch/Dogan/BioC/BioCDTD.html).
|
39
|
+
|
40
|
+
puts collection.documents[2].passages[0].text
|
41
|
+
|
42
|
+
Build XML text from data
|
43
|
+
|
44
|
+
puts SimpleBioC::to_xml(collection)
|
45
|
+
|
46
|
+
|
47
|
+
## Sample
|
48
|
+
|
49
|
+
More samples can be found in Samples directory
|
50
|
+
|
51
|
+
require 'simple_bioc'
|
52
|
+
|
53
|
+
# Sample1: parse, traverse, manipulate, and build BioC data
|
54
|
+
require 'simple_bioc'
|
55
|
+
|
56
|
+
# parse BioC file
|
57
|
+
collection = SimpleBioC.from_xml("../xml/everything.xml")
|
58
|
+
|
59
|
+
# the returned object contains all the information in the BioC file
|
60
|
+
# traverse & read information
|
61
|
+
collection.documents.each do |document|
|
62
|
+
puts document
|
63
|
+
document.passages.each do |passage|
|
64
|
+
puts passage
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# manipulate
|
69
|
+
doc = SimpleBioC::Document.new(collection)
|
70
|
+
doc.id = "23071747"
|
71
|
+
doc.infons["journal"] = "PLoS One"
|
72
|
+
collection.documents << doc
|
73
|
+
|
74
|
+
p = SimpleBioC::Passage.new(doc)
|
75
|
+
p.offset = 0
|
76
|
+
p.text = "TRIP database 2.0: a manually curated information hub for accessing TRP channel interaction network."
|
77
|
+
p.infons["type"] = "title"
|
78
|
+
doc.passages << p
|
79
|
+
|
80
|
+
|
81
|
+
# build BioC document from data
|
82
|
+
xml = SimpleBioC.to_xml(collection)
|
83
|
+
puts xml
|
84
|
+
|
22
85
|
|
23
86
|
## Contributing
|
24
87
|
|
@@ -27,3 +90,10 @@ TODO: Write usage instructions here
|
|
27
90
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
91
|
4. Push to the branch (`git push origin my-new-feature`)
|
29
92
|
5. Create new Pull Request
|
93
|
+
|
94
|
+
|
95
|
+
## LICENSE
|
96
|
+
|
97
|
+
Copyright © 2013, Dongseop Kwon
|
98
|
+
|
99
|
+
Released under the MIT License.
|
data/Rakefile
CHANGED
@@ -0,0 +1,657 @@
|
|
1
|
+
<!DOCTYPE html>
|
2
|
+
|
3
|
+
<html>
|
4
|
+
<head>
|
5
|
+
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
|
6
|
+
|
7
|
+
<title>module BioCReader - RDoc Documentation</title>
|
8
|
+
|
9
|
+
<link type="text/css" media="screen" href="./rdoc.css" rel="stylesheet">
|
10
|
+
|
11
|
+
<script type="text/javascript">
|
12
|
+
var rdoc_rel_prefix = "./";
|
13
|
+
</script>
|
14
|
+
|
15
|
+
<script type="text/javascript" charset="utf-8" src="./js/jquery.js"></script>
|
16
|
+
<script type="text/javascript" charset="utf-8" src="./js/navigation.js"></script>
|
17
|
+
<script type="text/javascript" charset="utf-8" src="./js/search_index.js"></script>
|
18
|
+
<script type="text/javascript" charset="utf-8" src="./js/search.js"></script>
|
19
|
+
<script type="text/javascript" charset="utf-8" src="./js/searcher.js"></script>
|
20
|
+
<script type="text/javascript" charset="utf-8" src="./js/darkfish.js"></script>
|
21
|
+
|
22
|
+
|
23
|
+
<body id="top" class="module">
|
24
|
+
<nav id="metadata">
|
25
|
+
<nav id="home-section" class="section">
|
26
|
+
<h3 class="section-header">
|
27
|
+
<a href="./index.html">Home</a>
|
28
|
+
<a href="./table_of_contents.html#classes">Classes</a>
|
29
|
+
<a href="./table_of_contents.html#methods">Methods</a>
|
30
|
+
</h3>
|
31
|
+
</nav>
|
32
|
+
|
33
|
+
|
34
|
+
<nav id="search-section" class="section project-section" class="initially-hidden">
|
35
|
+
<form action="#" method="get" accept-charset="utf-8">
|
36
|
+
<h3 class="section-header">
|
37
|
+
<input type="text" name="search" placeholder="Search" id="search-field"
|
38
|
+
title="Type to search, Up and Down to navigate, Enter to load">
|
39
|
+
</h3>
|
40
|
+
</form>
|
41
|
+
|
42
|
+
<ul id="search-results" class="initially-hidden"></ul>
|
43
|
+
</nav>
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
<div id="file-metadata">
|
49
|
+
<nav id="file-list-section" class="section">
|
50
|
+
<h3 class="section-header">Defined In</h3>
|
51
|
+
<ul>
|
52
|
+
<li>lib/simple_bioc/bioc_reader.rb
|
53
|
+
</ul>
|
54
|
+
</nav>
|
55
|
+
|
56
|
+
|
57
|
+
</div>
|
58
|
+
|
59
|
+
<div id="class-metadata">
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
|
64
|
+
<!-- Method Quickref -->
|
65
|
+
<nav id="method-list-section" class="section">
|
66
|
+
<h3 class="section-header">Methods</h3>
|
67
|
+
|
68
|
+
<ul class="link-list">
|
69
|
+
|
70
|
+
<li ><a href="#method-i-read">#read</a>
|
71
|
+
|
72
|
+
<li ><a href="#method-i-read_annotation">#read_annotation</a>
|
73
|
+
|
74
|
+
<li ><a href="#method-i-read_collection">#read_collection</a>
|
75
|
+
|
76
|
+
<li ><a href="#method-i-read_document">#read_document</a>
|
77
|
+
|
78
|
+
<li ><a href="#method-i-read_infon">#read_infon</a>
|
79
|
+
|
80
|
+
<li ><a href="#method-i-read_int">#read_int</a>
|
81
|
+
|
82
|
+
<li ><a href="#method-i-read_location">#read_location</a>
|
83
|
+
|
84
|
+
<li ><a href="#method-i-read_node">#read_node</a>
|
85
|
+
|
86
|
+
<li ><a href="#method-i-read_passage">#read_passage</a>
|
87
|
+
|
88
|
+
<li ><a href="#method-i-read_recursive">#read_recursive</a>
|
89
|
+
|
90
|
+
<li ><a href="#method-i-read_relation">#read_relation</a>
|
91
|
+
|
92
|
+
<li ><a href="#method-i-read_sentence">#read_sentence</a>
|
93
|
+
|
94
|
+
<li ><a href="#method-i-read_text">#read_text</a>
|
95
|
+
|
96
|
+
</ul>
|
97
|
+
</nav>
|
98
|
+
|
99
|
+
</div>
|
100
|
+
|
101
|
+
<div id="project-metadata">
|
102
|
+
<nav id="fileindex-section" class="section project-section">
|
103
|
+
<h3 class="section-header">Pages</h3>
|
104
|
+
|
105
|
+
<ul>
|
106
|
+
|
107
|
+
<li class="file"><a href="./README_md.html">README</a>
|
108
|
+
|
109
|
+
</ul>
|
110
|
+
</nav>
|
111
|
+
|
112
|
+
<nav id="classindex-section" class="section project-section">
|
113
|
+
<h3 class="section-header">Class and Module Index</h3>
|
114
|
+
|
115
|
+
<ul class="link-list">
|
116
|
+
|
117
|
+
<li><a href="./BioCReader.html">BioCReader</a>
|
118
|
+
|
119
|
+
<li><a href="./BioCWriter.html">BioCWriter</a>
|
120
|
+
|
121
|
+
<li><a href="./SimpleBioC.html">SimpleBioC</a>
|
122
|
+
|
123
|
+
<li><a href="./SimpleBioC/Annotation.html">SimpleBioC::Annotation</a>
|
124
|
+
|
125
|
+
<li><a href="./SimpleBioC/Collection.html">SimpleBioC::Collection</a>
|
126
|
+
|
127
|
+
<li><a href="./SimpleBioC/Document.html">SimpleBioC::Document</a>
|
128
|
+
|
129
|
+
<li><a href="./SimpleBioC/Location.html">SimpleBioC::Location</a>
|
130
|
+
|
131
|
+
<li><a href="./SimpleBioC/Node.html">SimpleBioC::Node</a>
|
132
|
+
|
133
|
+
<li><a href="./SimpleBioC/NodeBase.html">SimpleBioC::NodeBase</a>
|
134
|
+
|
135
|
+
<li><a href="./SimpleBioC/Passage.html">SimpleBioC::Passage</a>
|
136
|
+
|
137
|
+
<li><a href="./SimpleBioC/Relation.html">SimpleBioC::Relation</a>
|
138
|
+
|
139
|
+
<li><a href="./SimpleBioC/Sentence.html">SimpleBioC::Sentence</a>
|
140
|
+
|
141
|
+
</ul>
|
142
|
+
</nav>
|
143
|
+
|
144
|
+
</div>
|
145
|
+
</nav>
|
146
|
+
|
147
|
+
<div id="documentation">
|
148
|
+
<h1 class="module">module BioCReader</h1>
|
149
|
+
|
150
|
+
<div id="description" class="description">
|
151
|
+
|
152
|
+
</div><!-- description -->
|
153
|
+
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
<section id="5Buntitled-5D" class="documentation-section">
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
|
166
|
+
<!-- Methods -->
|
167
|
+
|
168
|
+
<section id="public-instance-5Buntitled-5D-method-details" class="method-section section">
|
169
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
170
|
+
|
171
|
+
|
172
|
+
<div id="method-i-read" class="method-detail ">
|
173
|
+
|
174
|
+
<div class="method-heading">
|
175
|
+
<span class="method-name">read</span><span
|
176
|
+
class="method-args">(path)</span>
|
177
|
+
|
178
|
+
<span class="method-click-advice">click to toggle source</span>
|
179
|
+
|
180
|
+
</div>
|
181
|
+
|
182
|
+
|
183
|
+
<div class="method-description">
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
|
190
|
+
<div class="method-source-code" id="read-source">
|
191
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 7</span>
|
192
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>)
|
193
|
+
<span class="ruby-identifier">collection</span> = <span class="ruby-keyword">nil</span>
|
194
|
+
<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">path</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">file</span><span class="ruby-operator">|</span>
|
195
|
+
<span class="ruby-identifier">xml_doc</span> = <span class="ruby-constant">Nokogiri</span><span class="ruby-operator">::</span><span class="ruby-constant">XML</span>(<span class="ruby-identifier">file</span>) <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">config</span><span class="ruby-operator">|</span>
|
196
|
+
<span class="ruby-identifier">config</span>.<span class="ruby-identifier">noent</span>.<span class="ruby-identifier">strict</span>.<span class="ruby-identifier">noblanks</span>
|
197
|
+
<span class="ruby-keyword">end</span>
|
198
|
+
<span class="ruby-identifier">xml</span> = <span class="ruby-identifier">xml_doc</span>.<span class="ruby-identifier">at_xpath</span>(<span class="ruby-string">"//collection"</span>)
|
199
|
+
<span class="ruby-keyword">if</span> <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">nil?</span>
|
200
|
+
<span class="ruby-identifier">fail</span> <span class="ruby-string">'Wrong format'</span>
|
201
|
+
<span class="ruby-keyword">end</span>
|
202
|
+
<span class="ruby-identifier">collection</span> = <span class="ruby-constant">SimpleBioC</span><span class="ruby-operator">::</span><span class="ruby-constant">Collection</span>.<span class="ruby-identifier">new</span>
|
203
|
+
<span class="ruby-identifier">read_collection</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">collection</span>)
|
204
|
+
<span class="ruby-keyword">end</span>
|
205
|
+
|
206
|
+
<span class="ruby-identifier">collection</span>
|
207
|
+
<span class="ruby-keyword">end</span></pre>
|
208
|
+
</div><!-- read-source -->
|
209
|
+
|
210
|
+
</div>
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
</div><!-- read-method -->
|
216
|
+
|
217
|
+
|
218
|
+
<div id="method-i-read_annotation" class="method-detail ">
|
219
|
+
|
220
|
+
<div class="method-heading">
|
221
|
+
<span class="method-name">read_annotation</span><span
|
222
|
+
class="method-args">(xml, annotation)</span>
|
223
|
+
|
224
|
+
<span class="method-click-advice">click to toggle source</span>
|
225
|
+
|
226
|
+
</div>
|
227
|
+
|
228
|
+
|
229
|
+
<div class="method-description">
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
|
236
|
+
<div class="method-source-code" id="read_annotation-source">
|
237
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 80</span>
|
238
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_annotation</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">annotation</span>)
|
239
|
+
<span class="ruby-identifier">annotation</span>.<span class="ruby-identifier">id</span> = <span class="ruby-identifier">xml</span>[<span class="ruby-string">"id"</span>]
|
240
|
+
<span class="ruby-identifier">annotation</span>.<span class="ruby-identifier">text</span> = <span class="ruby-identifier">read_text</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-string">"text"</span>)
|
241
|
+
<span class="ruby-identifier">read_infon</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">annotation</span>)
|
242
|
+
<span class="ruby-identifier">read_recursive</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">annotation</span>, <span class="ruby-string">"location"</span>)
|
243
|
+
<span class="ruby-keyword">end</span></pre>
|
244
|
+
</div><!-- read_annotation-source -->
|
245
|
+
|
246
|
+
</div>
|
247
|
+
|
248
|
+
|
249
|
+
|
250
|
+
|
251
|
+
</div><!-- read_annotation-method -->
|
252
|
+
|
253
|
+
|
254
|
+
<div id="method-i-read_collection" class="method-detail ">
|
255
|
+
|
256
|
+
<div class="method-heading">
|
257
|
+
<span class="method-name">read_collection</span><span
|
258
|
+
class="method-args">(xml, collection)</span>
|
259
|
+
|
260
|
+
<span class="method-click-advice">click to toggle source</span>
|
261
|
+
|
262
|
+
</div>
|
263
|
+
|
264
|
+
|
265
|
+
<div class="method-description">
|
266
|
+
|
267
|
+
|
268
|
+
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
<div class="method-source-code" id="read_collection-source">
|
273
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 47</span>
|
274
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_collection</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">collection</span>)
|
275
|
+
<span class="ruby-identifier">collection</span>.<span class="ruby-identifier">source</span> = <span class="ruby-identifier">read_text</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-string">"source"</span>)
|
276
|
+
<span class="ruby-identifier">collection</span>.<span class="ruby-identifier">date</span> = <span class="ruby-identifier">read_text</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-string">"date"</span>)
|
277
|
+
<span class="ruby-identifier">collection</span>.<span class="ruby-identifier">key</span> = <span class="ruby-identifier">read_text</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-string">"key"</span>)
|
278
|
+
<span class="ruby-identifier">read_infon</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">collection</span>)
|
279
|
+
<span class="ruby-identifier">read_recursive</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">collection</span>, <span class="ruby-string">"document"</span>)
|
280
|
+
<span class="ruby-keyword">end</span></pre>
|
281
|
+
</div><!-- read_collection-source -->
|
282
|
+
|
283
|
+
</div>
|
284
|
+
|
285
|
+
|
286
|
+
|
287
|
+
|
288
|
+
</div><!-- read_collection-method -->
|
289
|
+
|
290
|
+
|
291
|
+
<div id="method-i-read_document" class="method-detail ">
|
292
|
+
|
293
|
+
<div class="method-heading">
|
294
|
+
<span class="method-name">read_document</span><span
|
295
|
+
class="method-args">(xml, document)</span>
|
296
|
+
|
297
|
+
<span class="method-click-advice">click to toggle source</span>
|
298
|
+
|
299
|
+
</div>
|
300
|
+
|
301
|
+
|
302
|
+
<div class="method-description">
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
|
307
|
+
|
308
|
+
|
309
|
+
<div class="method-source-code" id="read_document-source">
|
310
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 55</span>
|
311
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_document</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">document</span>)
|
312
|
+
<span class="ruby-identifier">document</span>.<span class="ruby-identifier">id</span> = <span class="ruby-identifier">read_text</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-string">"id"</span>)
|
313
|
+
<span class="ruby-identifier">read_infon</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">document</span>)
|
314
|
+
<span class="ruby-identifier">read_recursive</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">document</span>, <span class="ruby-string">"passage"</span>)
|
315
|
+
<span class="ruby-identifier">read_recursive</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">document</span>, <span class="ruby-string">"relation"</span>)
|
316
|
+
<span class="ruby-identifier">document</span>.<span class="ruby-identifier">adjust_ref</span>
|
317
|
+
<span class="ruby-keyword">end</span></pre>
|
318
|
+
</div><!-- read_document-source -->
|
319
|
+
|
320
|
+
</div>
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
|
325
|
+
</div><!-- read_document-method -->
|
326
|
+
|
327
|
+
|
328
|
+
<div id="method-i-read_infon" class="method-detail ">
|
329
|
+
|
330
|
+
<div class="method-heading">
|
331
|
+
<span class="method-name">read_infon</span><span
|
332
|
+
class="method-args">(xml, obj)</span>
|
333
|
+
|
334
|
+
<span class="method-click-advice">click to toggle source</span>
|
335
|
+
|
336
|
+
</div>
|
337
|
+
|
338
|
+
|
339
|
+
<div class="method-description">
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
|
344
|
+
|
345
|
+
|
346
|
+
<div class="method-source-code" id="read_infon-source">
|
347
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 34</span>
|
348
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_infon</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">obj</span>)
|
349
|
+
<span class="ruby-identifier">xml</span>.<span class="ruby-identifier">xpath</span>(<span class="ruby-string">"infon"</span>).<span class="ruby-identifier">each</span>{ <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span> <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">infons</span>[<span class="ruby-identifier">i</span>[<span class="ruby-string">"key"</span>]] = <span class="ruby-identifier">i</span>.<span class="ruby-identifier">content</span>}
|
350
|
+
<span class="ruby-keyword">end</span></pre>
|
351
|
+
</div><!-- read_infon-source -->
|
352
|
+
|
353
|
+
</div>
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
|
358
|
+
</div><!-- read_infon-method -->
|
359
|
+
|
360
|
+
|
361
|
+
<div id="method-i-read_int" class="method-detail ">
|
362
|
+
|
363
|
+
<div class="method-heading">
|
364
|
+
<span class="method-name">read_int</span><span
|
365
|
+
class="method-args">(xml, name)</span>
|
366
|
+
|
367
|
+
<span class="method-click-advice">click to toggle source</span>
|
368
|
+
|
369
|
+
</div>
|
370
|
+
|
371
|
+
|
372
|
+
<div class="method-description">
|
373
|
+
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
|
378
|
+
|
379
|
+
<div class="method-source-code" id="read_int-source">
|
380
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 29</span>
|
381
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_int</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">name</span>)
|
382
|
+
<span class="ruby-identifier">val</span> = <span class="ruby-identifier">read_text</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">name</span>)
|
383
|
+
<span class="ruby-identifier">val</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">to_i</span>
|
384
|
+
<span class="ruby-keyword">end</span></pre>
|
385
|
+
</div><!-- read_int-source -->
|
386
|
+
|
387
|
+
</div>
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
|
392
|
+
</div><!-- read_int-method -->
|
393
|
+
|
394
|
+
|
395
|
+
<div id="method-i-read_location" class="method-detail ">
|
396
|
+
|
397
|
+
<div class="method-heading">
|
398
|
+
<span class="method-name">read_location</span><span
|
399
|
+
class="method-args">(xml, location)</span>
|
400
|
+
|
401
|
+
<span class="method-click-advice">click to toggle source</span>
|
402
|
+
|
403
|
+
</div>
|
404
|
+
|
405
|
+
|
406
|
+
<div class="method-description">
|
407
|
+
|
408
|
+
|
409
|
+
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
<div class="method-source-code" id="read_location-source">
|
414
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 93</span>
|
415
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_location</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">location</span>)
|
416
|
+
<span class="ruby-identifier">location</span>.<span class="ruby-identifier">offset</span> = <span class="ruby-identifier">xml</span>[<span class="ruby-string">"offset"</span>]
|
417
|
+
<span class="ruby-identifier">location</span>.<span class="ruby-identifier">length</span> = <span class="ruby-identifier">xml</span>[<span class="ruby-string">"length"</span>]
|
418
|
+
<span class="ruby-keyword">end</span></pre>
|
419
|
+
</div><!-- read_location-source -->
|
420
|
+
|
421
|
+
</div>
|
422
|
+
|
423
|
+
|
424
|
+
|
425
|
+
|
426
|
+
</div><!-- read_location-method -->
|
427
|
+
|
428
|
+
|
429
|
+
<div id="method-i-read_node" class="method-detail ">
|
430
|
+
|
431
|
+
<div class="method-heading">
|
432
|
+
<span class="method-name">read_node</span><span
|
433
|
+
class="method-args">(xml, node)</span>
|
434
|
+
|
435
|
+
<span class="method-click-advice">click to toggle source</span>
|
436
|
+
|
437
|
+
</div>
|
438
|
+
|
439
|
+
|
440
|
+
<div class="method-description">
|
441
|
+
|
442
|
+
|
443
|
+
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
<div class="method-source-code" id="read_node-source">
|
448
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 98</span>
|
449
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_node</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">node</span>)
|
450
|
+
<span class="ruby-identifier">node</span>.<span class="ruby-identifier">refid</span> = <span class="ruby-identifier">xml</span>[<span class="ruby-string">"refid"</span>]
|
451
|
+
<span class="ruby-identifier">node</span>.<span class="ruby-identifier">role</span> = <span class="ruby-identifier">xml</span>[<span class="ruby-string">"role"</span>]
|
452
|
+
<span class="ruby-keyword">end</span></pre>
|
453
|
+
</div><!-- read_node-source -->
|
454
|
+
|
455
|
+
</div>
|
456
|
+
|
457
|
+
|
458
|
+
|
459
|
+
|
460
|
+
</div><!-- read_node-method -->
|
461
|
+
|
462
|
+
|
463
|
+
<div id="method-i-read_passage" class="method-detail ">
|
464
|
+
|
465
|
+
<div class="method-heading">
|
466
|
+
<span class="method-name">read_passage</span><span
|
467
|
+
class="method-args">(xml, passage)</span>
|
468
|
+
|
469
|
+
<span class="method-click-advice">click to toggle source</span>
|
470
|
+
|
471
|
+
</div>
|
472
|
+
|
473
|
+
|
474
|
+
<div class="method-description">
|
475
|
+
|
476
|
+
|
477
|
+
|
478
|
+
|
479
|
+
|
480
|
+
|
481
|
+
<div class="method-source-code" id="read_passage-source">
|
482
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 63</span>
|
483
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_passage</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">passage</span>)
|
484
|
+
<span class="ruby-identifier">passage</span>.<span class="ruby-identifier">text</span> = <span class="ruby-identifier">read_text</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-string">"text"</span>)
|
485
|
+
<span class="ruby-identifier">passage</span>.<span class="ruby-identifier">offset</span> = <span class="ruby-identifier">read_int</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-string">"offset"</span>)
|
486
|
+
<span class="ruby-identifier">read_infon</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">passage</span>)
|
487
|
+
<span class="ruby-identifier">read_recursive</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">passage</span>, <span class="ruby-string">"sentence"</span>)
|
488
|
+
<span class="ruby-identifier">read_recursive</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">passage</span>, <span class="ruby-string">"annotation"</span>)
|
489
|
+
<span class="ruby-identifier">read_recursive</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">passage</span>, <span class="ruby-string">"relation"</span>)
|
490
|
+
<span class="ruby-keyword">end</span></pre>
|
491
|
+
</div><!-- read_passage-source -->
|
492
|
+
|
493
|
+
</div>
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
|
498
|
+
</div><!-- read_passage-method -->
|
499
|
+
|
500
|
+
|
501
|
+
<div id="method-i-read_recursive" class="method-detail ">
|
502
|
+
|
503
|
+
<div class="method-heading">
|
504
|
+
<span class="method-name">read_recursive</span><span
|
505
|
+
class="method-args">(xml, obj, name)</span>
|
506
|
+
|
507
|
+
<span class="method-click-advice">click to toggle source</span>
|
508
|
+
|
509
|
+
</div>
|
510
|
+
|
511
|
+
|
512
|
+
<div class="method-description">
|
513
|
+
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
<div class="method-source-code" id="read_recursive-source">
|
520
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 38</span>
|
521
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_recursive</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">obj</span>, <span class="ruby-identifier">name</span>)
|
522
|
+
<span class="ruby-identifier">target_class</span> = <span class="ruby-constant">SimpleBioC</span>.<span class="ruby-identifier">const_get</span>(<span class="ruby-identifier">name</span>.<span class="ruby-identifier">capitalize</span>)
|
523
|
+
<span class="ruby-identifier">xml</span>.<span class="ruby-identifier">xpath</span>(<span class="ruby-identifier">name</span>).<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">node</span><span class="ruby-operator">|</span>
|
524
|
+
<span class="ruby-identifier">instance</span> = <span class="ruby-identifier">target_class</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">obj</span>)
|
525
|
+
<span class="ruby-identifier">send</span>(<span class="ruby-value">:"read_#{name}"</span>, <span class="ruby-identifier">node</span>, <span class="ruby-identifier">instance</span>)
|
526
|
+
<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">instance_variable_get</span>(<span class="ruby-value">:"@#{name}s"</span>) <span class="ruby-operator"><<</span> <span class="ruby-identifier">instance</span>
|
527
|
+
<span class="ruby-keyword">end</span>
|
528
|
+
<span class="ruby-keyword">end</span></pre>
|
529
|
+
</div><!-- read_recursive-source -->
|
530
|
+
|
531
|
+
</div>
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
|
536
|
+
</div><!-- read_recursive-method -->
|
537
|
+
|
538
|
+
|
539
|
+
<div id="method-i-read_relation" class="method-detail ">
|
540
|
+
|
541
|
+
<div class="method-heading">
|
542
|
+
<span class="method-name">read_relation</span><span
|
543
|
+
class="method-args">(xml, relation)</span>
|
544
|
+
|
545
|
+
<span class="method-click-advice">click to toggle source</span>
|
546
|
+
|
547
|
+
</div>
|
548
|
+
|
549
|
+
|
550
|
+
<div class="method-description">
|
551
|
+
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
|
556
|
+
|
557
|
+
<div class="method-source-code" id="read_relation-source">
|
558
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 87</span>
|
559
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_relation</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">relation</span>)
|
560
|
+
<span class="ruby-identifier">relation</span>.<span class="ruby-identifier">id</span> = <span class="ruby-identifier">xml</span>[<span class="ruby-string">"id"</span>]
|
561
|
+
<span class="ruby-identifier">read_infon</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">relation</span>)
|
562
|
+
<span class="ruby-identifier">read_recursive</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">relation</span>, <span class="ruby-string">"node"</span>)
|
563
|
+
<span class="ruby-keyword">end</span></pre>
|
564
|
+
</div><!-- read_relation-source -->
|
565
|
+
|
566
|
+
</div>
|
567
|
+
|
568
|
+
|
569
|
+
|
570
|
+
|
571
|
+
</div><!-- read_relation-method -->
|
572
|
+
|
573
|
+
|
574
|
+
<div id="method-i-read_sentence" class="method-detail ">
|
575
|
+
|
576
|
+
<div class="method-heading">
|
577
|
+
<span class="method-name">read_sentence</span><span
|
578
|
+
class="method-args">(xml, sentence)</span>
|
579
|
+
|
580
|
+
<span class="method-click-advice">click to toggle source</span>
|
581
|
+
|
582
|
+
</div>
|
583
|
+
|
584
|
+
|
585
|
+
<div class="method-description">
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
|
590
|
+
|
591
|
+
|
592
|
+
<div class="method-source-code" id="read_sentence-source">
|
593
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 72</span>
|
594
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_sentence</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">sentence</span>)
|
595
|
+
<span class="ruby-identifier">sentence</span>.<span class="ruby-identifier">text</span> = <span class="ruby-identifier">read_text</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-string">"text"</span>)
|
596
|
+
<span class="ruby-identifier">sentence</span>.<span class="ruby-identifier">offset</span> = <span class="ruby-identifier">read_int</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-string">"offset"</span>)
|
597
|
+
<span class="ruby-identifier">read_infon</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">sentence</span>)
|
598
|
+
<span class="ruby-identifier">read_recursive</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">sentence</span>, <span class="ruby-string">"annotation"</span>)
|
599
|
+
<span class="ruby-identifier">read_recursive</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">sentence</span>, <span class="ruby-string">"relation"</span>)
|
600
|
+
<span class="ruby-keyword">end</span></pre>
|
601
|
+
</div><!-- read_sentence-source -->
|
602
|
+
|
603
|
+
</div>
|
604
|
+
|
605
|
+
|
606
|
+
|
607
|
+
|
608
|
+
</div><!-- read_sentence-method -->
|
609
|
+
|
610
|
+
|
611
|
+
<div id="method-i-read_text" class="method-detail ">
|
612
|
+
|
613
|
+
<div class="method-heading">
|
614
|
+
<span class="method-name">read_text</span><span
|
615
|
+
class="method-args">(xml, name)</span>
|
616
|
+
|
617
|
+
<span class="method-click-advice">click to toggle source</span>
|
618
|
+
|
619
|
+
</div>
|
620
|
+
|
621
|
+
|
622
|
+
<div class="method-description">
|
623
|
+
|
624
|
+
|
625
|
+
|
626
|
+
|
627
|
+
|
628
|
+
|
629
|
+
<div class="method-source-code" id="read_text-source">
|
630
|
+
<pre><span class="ruby-comment"># File lib/simple_bioc/bioc_reader.rb, line 24</span>
|
631
|
+
<span class="ruby-keyword">def</span> <span class="ruby-identifier">read_text</span>(<span class="ruby-identifier">xml</span>, <span class="ruby-identifier">name</span>)
|
632
|
+
<span class="ruby-identifier">node</span> = <span class="ruby-identifier">xml</span>.<span class="ruby-identifier">at_xpath</span>(<span class="ruby-identifier">name</span>)
|
633
|
+
<span class="ruby-identifier">node</span> <span class="ruby-operator">&&</span> <span class="ruby-identifier">node</span>.<span class="ruby-identifier">content</span>
|
634
|
+
<span class="ruby-keyword">end</span></pre>
|
635
|
+
</div><!-- read_text-source -->
|
636
|
+
|
637
|
+
</div>
|
638
|
+
|
639
|
+
|
640
|
+
|
641
|
+
|
642
|
+
</div><!-- read_text-method -->
|
643
|
+
|
644
|
+
|
645
|
+
</section><!-- public-instance-method-details -->
|
646
|
+
|
647
|
+
</section><!-- 5Buntitled-5D -->
|
648
|
+
|
649
|
+
</div><!-- documentation -->
|
650
|
+
|
651
|
+
|
652
|
+
<footer id="validator-badges">
|
653
|
+
<p><a href="http://validator.w3.org/check/referer">[Validate]</a>
|
654
|
+
<p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.0.
|
655
|
+
<p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
|
656
|
+
</footer>
|
657
|
+
|