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.
Files changed (67) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +73 -3
  3. data/Rakefile +5 -0
  4. data/html/BioCReader.html +657 -0
  5. data/html/BioCWriter.html +556 -0
  6. data/html/README_md.html +231 -0
  7. data/html/SimpleBioC.html +255 -0
  8. data/html/SimpleBioC/Annotation.html +279 -0
  9. data/html/SimpleBioC/Collection.html +316 -0
  10. data/html/SimpleBioC/Document.html +426 -0
  11. data/html/SimpleBioC/Location.html +288 -0
  12. data/html/SimpleBioC/Node.html +334 -0
  13. data/html/SimpleBioC/NodeBase.html +281 -0
  14. data/html/SimpleBioC/Passage.html +418 -0
  15. data/html/SimpleBioC/Relation.html +301 -0
  16. data/html/SimpleBioC/Sentence.html +399 -0
  17. data/html/created.rid +15 -0
  18. data/html/images/add.png +0 -0
  19. data/html/images/arrow_up.png +0 -0
  20. data/html/images/brick.png +0 -0
  21. data/html/images/brick_link.png +0 -0
  22. data/html/images/bug.png +0 -0
  23. data/html/images/bullet_black.png +0 -0
  24. data/html/images/bullet_toggle_minus.png +0 -0
  25. data/html/images/bullet_toggle_plus.png +0 -0
  26. data/html/images/date.png +0 -0
  27. data/html/images/delete.png +0 -0
  28. data/html/images/find.png +0 -0
  29. data/html/images/loadingAnimation.gif +0 -0
  30. data/html/images/macFFBgHack.png +0 -0
  31. data/html/images/package.png +0 -0
  32. data/html/images/page_green.png +0 -0
  33. data/html/images/page_white_text.png +0 -0
  34. data/html/images/page_white_width.png +0 -0
  35. data/html/images/plugin.png +0 -0
  36. data/html/images/ruby.png +0 -0
  37. data/html/images/tag_blue.png +0 -0
  38. data/html/images/tag_green.png +0 -0
  39. data/html/images/transparent.png +0 -0
  40. data/html/images/wrench.png +0 -0
  41. data/html/images/wrench_orange.png +0 -0
  42. data/html/images/zoom.png +0 -0
  43. data/html/index.html +212 -0
  44. data/html/js/darkfish.js +155 -0
  45. data/html/js/jquery.js +18 -0
  46. data/html/js/navigation.js +142 -0
  47. data/html/js/search.js +94 -0
  48. data/html/js/search_index.js +1 -0
  49. data/html/js/searcher.js +228 -0
  50. data/html/rdoc.css +595 -0
  51. data/html/table_of_contents.html +199 -0
  52. data/lib/simple_bioc.rb +4 -0
  53. data/lib/simple_bioc/annotation.rb +10 -6
  54. data/lib/simple_bioc/bioc_reader.rb +2 -2
  55. data/lib/simple_bioc/collection.rb +13 -11
  56. data/lib/simple_bioc/document.rb +31 -22
  57. data/lib/simple_bioc/location.rb +13 -7
  58. data/lib/simple_bioc/node.rb +14 -8
  59. data/lib/simple_bioc/node_base.rb +13 -10
  60. data/lib/simple_bioc/passage.rb +26 -23
  61. data/lib/simple_bioc/relation.rb +13 -8
  62. data/lib/simple_bioc/sentence.rb +21 -15
  63. data/lib/simple_bioc/version.rb +2 -2
  64. data/samples/print_annotation.rb +18 -0
  65. data/samples/sample1.rb +31 -0
  66. data/simple_bioc.gemspec +1 -1
  67. metadata +52 -2
@@ -0,0 +1,199 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html>
4
+ <head>
5
+ <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
6
+
7
+ <title>Table of Contents - 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 class="indexpage">
24
+ <h1>Table of Contents - RDoc Documentation</h1>
25
+
26
+ <h2>Pages</h2>
27
+ <ul>
28
+ <li class="file">
29
+ <a href="README_md.html">README</a>
30
+
31
+ <img class="toc-toggle" src="images/transparent.png" alt="" title="toggle headings">
32
+ <ul class="initially-hidden">
33
+ <li><a href="README_md.html#label-SimpleBioc">SimpleBioc</a>
34
+ <li><a href="README_md.html#label-Feature%3A">Feature:</a>
35
+ <li><a href="README_md.html#label-Installation">Installation</a>
36
+ <li><a href="README_md.html#label-Usages">Usages</a>
37
+ <li><a href="README_md.html#label-Sample">Sample</a>
38
+ <li><a href="README_md.html#label-Contributing">Contributing</a>
39
+ <li><a href="README_md.html#label-LICENSE">LICENSE</a>
40
+ </ul>
41
+ </li>
42
+
43
+ </ul>
44
+
45
+ <h2 id="classes">Classes/Modules</h2>
46
+ <ul>
47
+ <li class="module">
48
+ <a href="BioCReader.html">BioCReader</a>
49
+ </li>
50
+ <li class="module">
51
+ <a href="BioCWriter.html">BioCWriter</a>
52
+ </li>
53
+ <li class="module">
54
+ <a href="SimpleBioC.html">SimpleBioC</a>
55
+ </li>
56
+ <li class="class">
57
+ <a href="SimpleBioC/Annotation.html">SimpleBioC::Annotation</a>
58
+ </li>
59
+ <li class="class">
60
+ <a href="SimpleBioC/Collection.html">SimpleBioC::Collection</a>
61
+ </li>
62
+ <li class="class">
63
+ <a href="SimpleBioC/Document.html">SimpleBioC::Document</a>
64
+ </li>
65
+ <li class="class">
66
+ <a href="SimpleBioC/Location.html">SimpleBioC::Location</a>
67
+ </li>
68
+ <li class="class">
69
+ <a href="SimpleBioC/Node.html">SimpleBioC::Node</a>
70
+ </li>
71
+ <li class="class">
72
+ <a href="SimpleBioC/NodeBase.html">SimpleBioC::NodeBase</a>
73
+ </li>
74
+ <li class="class">
75
+ <a href="SimpleBioC/Passage.html">SimpleBioC::Passage</a>
76
+ </li>
77
+ <li class="class">
78
+ <a href="SimpleBioC/Relation.html">SimpleBioC::Relation</a>
79
+ </li>
80
+ <li class="class">
81
+ <a href="SimpleBioC/Sentence.html">SimpleBioC::Sentence</a>
82
+ </li>
83
+
84
+ </ul>
85
+
86
+ <h2 id="methods">Methods</h2>
87
+ <ul>
88
+
89
+ <li class="method"><a href="SimpleBioC/Annotation.html#method-c-new">::new &mdash; SimpleBioC::Annotation</a>
90
+
91
+ <li class="method"><a href="SimpleBioC/Passage.html#method-c-new">::new &mdash; SimpleBioC::Passage</a>
92
+
93
+ <li class="method"><a href="SimpleBioC/Collection.html#method-c-new">::new &mdash; SimpleBioC::Collection</a>
94
+
95
+ <li class="method"><a href="SimpleBioC/NodeBase.html#method-c-new">::new &mdash; SimpleBioC::NodeBase</a>
96
+
97
+ <li class="method"><a href="SimpleBioC/Document.html#method-c-new">::new &mdash; SimpleBioC::Document</a>
98
+
99
+ <li class="method"><a href="SimpleBioC/Relation.html#method-c-new">::new &mdash; SimpleBioC::Relation</a>
100
+
101
+ <li class="method"><a href="SimpleBioC/Node.html#method-c-new">::new &mdash; SimpleBioC::Node</a>
102
+
103
+ <li class="method"><a href="SimpleBioC/Location.html#method-c-new">::new &mdash; SimpleBioC::Location</a>
104
+
105
+ <li class="method"><a href="SimpleBioC/Sentence.html#method-c-new">::new &mdash; SimpleBioC::Sentence</a>
106
+
107
+ <li class="method"><a href="SimpleBioC/Document.html#method-i-adjust_ref">#adjust_ref &mdash; SimpleBioC::Document</a>
108
+
109
+ <li class="method"><a href="SimpleBioC/Relation.html#method-i-adjust_ref">#adjust_ref &mdash; SimpleBioC::Relation</a>
110
+
111
+ <li class="method"><a href="SimpleBioC/Node.html#method-i-adjust_ref">#adjust_ref &mdash; SimpleBioC::Node</a>
112
+
113
+ <li class="method"><a href="SimpleBioC/Document.html#method-i-each_relation">#each_relation &mdash; SimpleBioC::Document</a>
114
+
115
+ <li class="method"><a href="SimpleBioC/Sentence.html#method-i-each_relation">#each_relation &mdash; SimpleBioC::Sentence</a>
116
+
117
+ <li class="method"><a href="SimpleBioC/Passage.html#method-i-each_relation">#each_relation &mdash; SimpleBioC::Passage</a>
118
+
119
+ <li class="method"><a href="SimpleBioC/Sentence.html#method-i-find_node">#find_node &mdash; SimpleBioC::Sentence</a>
120
+
121
+ <li class="method"><a href="SimpleBioC/Document.html#method-i-find_node">#find_node &mdash; SimpleBioC::Document</a>
122
+
123
+ <li class="method"><a href="SimpleBioC/Passage.html#method-i-find_node">#find_node &mdash; SimpleBioC::Passage</a>
124
+
125
+ <li class="method"><a href="SimpleBioC.html#method-i-from_xml">#from_xml &mdash; SimpleBioC</a>
126
+
127
+ <li class="method"><a href="BioCReader.html#method-i-read">#read &mdash; BioCReader</a>
128
+
129
+ <li class="method"><a href="BioCReader.html#method-i-read_annotation">#read_annotation &mdash; BioCReader</a>
130
+
131
+ <li class="method"><a href="BioCReader.html#method-i-read_collection">#read_collection &mdash; BioCReader</a>
132
+
133
+ <li class="method"><a href="BioCReader.html#method-i-read_document">#read_document &mdash; BioCReader</a>
134
+
135
+ <li class="method"><a href="BioCReader.html#method-i-read_infon">#read_infon &mdash; BioCReader</a>
136
+
137
+ <li class="method"><a href="BioCReader.html#method-i-read_int">#read_int &mdash; BioCReader</a>
138
+
139
+ <li class="method"><a href="BioCReader.html#method-i-read_location">#read_location &mdash; BioCReader</a>
140
+
141
+ <li class="method"><a href="BioCReader.html#method-i-read_node">#read_node &mdash; BioCReader</a>
142
+
143
+ <li class="method"><a href="BioCReader.html#method-i-read_passage">#read_passage &mdash; BioCReader</a>
144
+
145
+ <li class="method"><a href="BioCReader.html#method-i-read_recursive">#read_recursive &mdash; BioCReader</a>
146
+
147
+ <li class="method"><a href="BioCReader.html#method-i-read_relation">#read_relation &mdash; BioCReader</a>
148
+
149
+ <li class="method"><a href="BioCReader.html#method-i-read_sentence">#read_sentence &mdash; BioCReader</a>
150
+
151
+ <li class="method"><a href="BioCReader.html#method-i-read_text">#read_text &mdash; BioCReader</a>
152
+
153
+ <li class="method"><a href="SimpleBioC/Node.html#method-i-to_c">#to_c &mdash; SimpleBioC::Node</a>
154
+
155
+ <li class="method"><a href="SimpleBioC/Collection.html#method-i-to_c">#to_c &mdash; SimpleBioC::Collection</a>
156
+
157
+ <li class="method"><a href="SimpleBioC/Relation.html#method-i-to_c">#to_c &mdash; SimpleBioC::Relation</a>
158
+
159
+ <li class="method"><a href="SimpleBioC/Sentence.html#method-i-to_c">#to_c &mdash; SimpleBioC::Sentence</a>
160
+
161
+ <li class="method"><a href="SimpleBioC/Document.html#method-i-to_s">#to_s &mdash; SimpleBioC::Document</a>
162
+
163
+ <li class="method"><a href="SimpleBioC/Passage.html#method-i-to_s">#to_s &mdash; SimpleBioC::Passage</a>
164
+
165
+ <li class="method"><a href="SimpleBioC/Location.html#method-i-to_s">#to_s &mdash; SimpleBioC::Location</a>
166
+
167
+ <li class="method"><a href="SimpleBioC/Annotation.html#method-i-to_s">#to_s &mdash; SimpleBioC::Annotation</a>
168
+
169
+ <li class="method"><a href="SimpleBioC.html#method-i-to_xml">#to_xml &mdash; SimpleBioC</a>
170
+
171
+ <li class="method"><a href="BioCWriter.html#method-i-write">#write &mdash; BioCWriter</a>
172
+
173
+ <li class="method"><a href="BioCWriter.html#method-i-write_annotation">#write_annotation &mdash; BioCWriter</a>
174
+
175
+ <li class="method"><a href="BioCWriter.html#method-i-write_collection">#write_collection &mdash; BioCWriter</a>
176
+
177
+ <li class="method"><a href="BioCWriter.html#method-i-write_document">#write_document &mdash; BioCWriter</a>
178
+
179
+ <li class="method"><a href="BioCWriter.html#method-i-write_infon">#write_infon &mdash; BioCWriter</a>
180
+
181
+ <li class="method"><a href="BioCWriter.html#method-i-write_location">#write_location &mdash; BioCWriter</a>
182
+
183
+ <li class="method"><a href="BioCWriter.html#method-i-write_node">#write_node &mdash; BioCWriter</a>
184
+
185
+ <li class="method"><a href="BioCWriter.html#method-i-write_passage">#write_passage &mdash; BioCWriter</a>
186
+
187
+ <li class="method"><a href="BioCWriter.html#method-i-write_relation">#write_relation &mdash; BioCWriter</a>
188
+
189
+ <li class="method"><a href="BioCWriter.html#method-i-write_sentence">#write_sentence &mdash; BioCWriter</a>
190
+
191
+ </ul>
192
+
193
+
194
+ <footer id="validator-badges">
195
+ <p><a href="http://validator.w3.org/check/referer">[Validate]</a>
196
+ <p>Generated by <a href="https://github.com/rdoc/rdoc">RDoc</a> 4.0.0.
197
+ <p>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish Rdoc Generator</a> 3.
198
+ </footer>
199
+
data/lib/simple_bioc.rb CHANGED
@@ -2,12 +2,16 @@ require "simple_bioc/version"
2
2
  require "simple_bioc/bioc_reader"
3
3
  require "simple_bioc/bioc_writer"
4
4
 
5
+ # SimpleBioC main library
5
6
  module SimpleBioC
6
7
  module_function
8
+
9
+ # parse a BioC XML file in the given path and convert it into a collection instance
7
10
  def from_xml(file_path)
8
11
  BioCReader.read(file_path)
9
12
  end
10
13
 
14
+ # convert a collection instance to a BioC XML text
11
15
  def to_xml(collection)
12
16
  BioCWriter.write(collection)
13
17
  end
@@ -1,11 +1,15 @@
1
1
  require 'simple_bioc/node_base'
2
+ module SimpleBioC
3
+ class Annotation < NodeBase
4
+ attr_accessor :locations, :text
2
5
 
3
- class Annotation < NodeBase
4
- attr_accessor :locations, :text
6
+ def initialize(parent)
7
+ super(parent)
8
+ @locations = []
9
+ end
5
10
 
6
- def initialize(parent)
7
- super(parent)
8
-
9
- @locations = []
11
+ def to_s
12
+ "Annotation:#{id} #{text}"
13
+ end
10
14
  end
11
15
  end
@@ -14,7 +14,7 @@ module BioCReader
14
14
  if xml.nil?
15
15
  fail 'Wrong format'
16
16
  end
17
- collection = Collection.new
17
+ collection = SimpleBioC::Collection.new
18
18
  read_collection(xml, collection)
19
19
  end
20
20
 
@@ -36,7 +36,7 @@ module BioCReader
36
36
  end
37
37
 
38
38
  def read_recursive(xml, obj, name)
39
- target_class = Module.const_get(name.capitalize)
39
+ target_class = SimpleBioC.const_get(name.capitalize)
40
40
  xml.xpath(name).each do |node|
41
41
  instance = target_class.new(obj)
42
42
  send(:"read_#{name}", node, instance)
@@ -1,15 +1,17 @@
1
- class Collection
2
- attr_accessor :documents, :infons, :source, :date, :key
1
+ module SimpleBioC
2
+ class Collection
3
+ attr_accessor :documents, :infons, :source, :date, :key
3
4
 
4
- def initialize
5
- @documents = []
6
- @infons = {}
7
- @source = ""
8
- @date = ""
9
- @key = ""
10
- end
5
+ def initialize
6
+ @documents = []
7
+ @infons = {}
8
+ @source = ""
9
+ @date = ""
10
+ @key = ""
11
+ end
11
12
 
12
- def to_xml
13
-
13
+ def to_c
14
+ "Collection(source: #{source}, date: #{date}, key: #{key})"
15
+ end
14
16
  end
15
17
  end
@@ -1,29 +1,38 @@
1
- class Document
2
- attr_accessor :id, :infons, :passages, :relations
3
- attr_reader :collection
1
+ module SimpleBioC
2
+ class Document
3
+ # attribute
4
+ attr_accessor :id, :infons, :passages, :relations
4
5
 
5
- def initialize(parent)
6
- @infons = {}
7
- @passages = []
8
- @relations = []
9
- @collection = parent
10
- end
6
+ # parent
7
+ attr_reader :collection
11
8
 
12
- def find_node(id)
13
- relations.each{|r| return r if r.id == id}
14
- passages.each do |p|
15
- ret = p.find_node(id)
16
- return ret unless ret.nil?
9
+ def initialize(parent)
10
+ @infons = {}
11
+ @passages = []
12
+ @relations = []
13
+ @collection = parent
17
14
  end
18
- nil
19
- end
20
15
 
21
- def adjust_ref
22
- each_relation{|r| r.adjust_ref}
23
- end
16
+ def find_node(id)
17
+ relations.each{|r| return r if r.id == id}
18
+ passages.each do |p|
19
+ ret = p.find_node(id)
20
+ return ret unless ret.nil?
21
+ end
22
+ nil
23
+ end
24
24
 
25
- def each_relation
26
- relations.each{|r| yield r}
27
- passages.each{|p| p.each_relation{|r| yield r}}
25
+ def adjust_ref
26
+ each_relation{|r| r.adjust_ref}
27
+ end
28
+
29
+ def each_relation
30
+ relations.each{|r| yield r}
31
+ passages.each{|p| p.each_relation{|r| yield r}}
32
+ end
33
+
34
+ def to_s
35
+ "Document:#{id}"
36
+ end
28
37
  end
29
38
  end
@@ -1,10 +1,16 @@
1
- class Location
2
- attr_accessor :offset, :length
3
- attr_reader :annotation
1
+ module SimpleBioC
2
+ class Location
3
+ attr_accessor :offset, :length
4
+ attr_reader :annotation
4
5
 
5
- def initialize(parent)
6
- @infons = {}
7
- @locations = []
8
- @annotation = parent
6
+ def initialize(parent)
7
+ @infons = {}
8
+ @locations = []
9
+ @annotation = parent
10
+ end
11
+
12
+ def to_s
13
+ "Location @#{offset}:#{length}"
14
+ end
9
15
  end
10
16
  end
@@ -1,12 +1,18 @@
1
- class Node
2
- attr_accessor :refid, :role
3
- attr_reader :ref, :relation
1
+ module SimpleBioC
2
+ class Node
3
+ attr_accessor :refid, :role
4
+ attr_reader :ref, :relation
4
5
 
5
- def initialize(parent)
6
- @relation = parent
7
- end
6
+ def initialize(parent)
7
+ @relation = parent
8
+ end
9
+
10
+ def adjust_ref
11
+ @ref = relation.document.find_node(refid)
12
+ end
8
13
 
9
- def adjust_ref
10
- @ref = relation.document.find_node(refid)
14
+ def to_c
15
+ "Node @#{refid}: #{role})"
16
+ end
11
17
  end
12
18
  end
@@ -1,14 +1,17 @@
1
- class NodeBase
2
- attr_accessor :id, :infons
3
- attr_reader :document, :passage, :sentence
1
+ module SimpleBioC
2
+ # NodeBase is not a BioC DTD entity. This is a super class of Annotation & Relation.
3
+ class NodeBase
4
+ attr_accessor :id, :infons
5
+ attr_reader :document, :passage, :sentence
4
6
 
5
- def initialize(parent)
6
- @infons = {}
7
- @document = parent if parent.is_a? Document
8
- @passage = parent if parent.is_a? Passage
9
- @sentence = parent if parent.is_a? Sentence
7
+ def initialize(parent)
8
+ @infons = {}
9
+ @document = parent if parent.is_a? Document
10
+ @passage = parent if parent.is_a? Passage
11
+ @sentence = parent if parent.is_a? Sentence
10
12
 
11
- @passage = @sentence.passage unless @sentence.nil?
12
- @document = @passage.document unless @passage.nil?
13
+ @passage = @sentence.passage unless @sentence.nil?
14
+ @document = @passage.document unless @passage.nil?
15
+ end
13
16
  end
14
17
  end
@@ -1,29 +1,32 @@
1
- class Passage
2
- attr_accessor :offset, :text, :infons, :sentences, :annotations, :relations
3
- attr_reader :document
1
+ module SimpleBioC
2
+ class Passage
3
+ attr_accessor :offset, :text, :infons, :sentences, :annotations, :relations
4
+ attr_reader :document
4
5
 
5
- def initialize(parent)
6
- @infons = {}
7
- @sentences = []
8
- @annotations = []
9
- @relations = []
10
- @document = parent
11
- end
6
+ def initialize(parent)
7
+ @infons = {}
8
+ @sentences = []
9
+ @annotations = []
10
+ @relations = []
11
+ @document = parent
12
+ end
12
13
 
13
- def to_s
14
- "#{offset}:#{text}"
15
- end
16
- def find_node(id)
17
- (relations+annotations).each{|n| return n if n.id == id}
18
- sentences.each do |s|
19
- ret = s.find_node(id)
20
- return ret unless ret.nil?
14
+ def to_s
15
+ "Passage @#{offset}: #{text}"
21
16
  end
22
- nil
23
- end
24
17
 
25
- def each_relation
26
- relations.each{|r| yield r}
27
- sentences.each{|s| s.each_relation{|r| yield r}}
18
+ def find_node(id)
19
+ (relations+annotations).each{|n| return n if n.id == id}
20
+ sentences.each do |s|
21
+ ret = s.find_node(id)
22
+ return ret unless ret.nil?
23
+ end
24
+ nil
25
+ end
26
+
27
+ def each_relation
28
+ relations.each{|r| yield r}
29
+ sentences.each{|s| s.each_relation{|r| yield r}}
30
+ end
28
31
  end
29
32
  end