bel 0.7.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (105) hide show
  1. checksums.yaml +4 -4
  2. data/{bel.gemspec → .gemspec} +8 -4
  3. data/README.md +3 -3
  4. data/VERSION +1 -0
  5. data/bin/bel +8 -8
  6. data/bin/bel2rdf.rb +1 -1
  7. data/bin/bel_summarize.rb +4 -4
  8. data/bin/bel_upgrade.rb +6 -6
  9. data/lib/bel.rb +3 -2
  10. data/lib/bel/completion.rb +13 -10
  11. data/lib/bel/completion_rule.rb +29 -21
  12. data/lib/bel/dsl.rb +75 -0
  13. data/lib/bel/gen.rb +2 -2
  14. data/lib/bel/gen/annotation.rb +2 -2
  15. data/lib/bel/gen/citation.rb +6 -6
  16. data/lib/bel/gen/document_header.rb +1 -1
  17. data/lib/bel/gen/{evidence.rb → nanopub.rb} +15 -15
  18. data/lib/bel/gen/parameter.rb +6 -6
  19. data/lib/bel/gen/sample_resources.rb +4 -4
  20. data/lib/bel/gen/statement.rb +1 -1
  21. data/lib/bel/gen/term.rb +1 -1
  22. data/lib/bel/language.rb +0 -20
  23. data/lib/bel/namespace.rb +7 -3
  24. data/lib/bel/nanopub.rb +15 -0
  25. data/lib/bel/{evidence_model/buffering_evidence_combiner.rb → nanopub/buffering_nanopub_combiner.rb} +39 -45
  26. data/lib/bel/{evidence_model → nanopub}/citation.rb +2 -2
  27. data/lib/bel/{evidence_model → nanopub}/experiment_context.rb +7 -1
  28. data/lib/bel/{evidence_model → nanopub}/hash_map_references.rb +1 -1
  29. data/lib/bel/{evidence_model → nanopub}/map_references.rb +1 -1
  30. data/lib/bel/nanopub/map_references_combiner.rb +30 -0
  31. data/lib/bel/nanopub/metadata.rb +102 -0
  32. data/lib/bel/nanopub/nanopub.rb +122 -0
  33. data/lib/bel/{evidence_model → nanopub}/references.rb +50 -38
  34. data/lib/bel/{evidence_model/streaming_evidence_combiner.rb → nanopub/streaming_nanopub_combiner.rb} +8 -8
  35. data/lib/bel/{evidence_model/summary_text.rb → nanopub/support.rb} +8 -2
  36. data/lib/bel/{evidence_model → nanopub}/util.rb +10 -10
  37. data/lib/bel/resource/annotation.rb +15 -24
  38. data/lib/bel/resource/annotation_value.rb +24 -20
  39. data/lib/bel/resource/annotations.rb +12 -11
  40. data/lib/bel/resource/concept.rb +62 -0
  41. data/lib/bel/resource/concept_scheme.rb +49 -0
  42. data/lib/bel/resource/namespace.rb +15 -24
  43. data/lib/bel/resource/namespace_value.rb +26 -23
  44. data/lib/bel/resource/namespaces.rb +11 -11
  45. data/lib/bel/script.rb +367 -367
  46. data/lib/bel/translate.rb +7 -7
  47. data/lib/bel/translator.rb +10 -10
  48. data/lib/bel/translator/plugins/bnj.rb +37 -0
  49. data/lib/bel/translator/plugins/{json_evidence → bnj}/translator.rb +17 -34
  50. data/lib/bel/translator/plugins/jgf.rb +1 -1
  51. data/lib/bel/translator/plugins/jgf/translator.rb +10 -10
  52. data/lib/bel/translator/plugins/jsonld.rb +1 -1
  53. data/lib/bel/translator/plugins/nquads.rb +1 -1
  54. data/lib/bel/translator/plugins/ntriples.rb +1 -1
  55. data/lib/bel/translator/plugins/rdf/bel_schema.rb +134 -126
  56. data/lib/bel/translator/plugins/rdf/graph_translator.rb +6 -6
  57. data/lib/bel/translator/plugins/rdf/monkey_patch.rb +50 -49
  58. data/lib/bel/translator/plugins/rdf/reader.rb +42 -42
  59. data/lib/bel/translator/plugins/rdf/translator.rb +6 -6
  60. data/lib/bel/translator/plugins/rdf/writer.rb +4 -4
  61. data/lib/bel/translator/plugins/rdf2/belv2_0.rb +416 -0
  62. data/lib/bel/translator/plugins/rdf2/converter.rb +13 -0
  63. data/lib/bel/translator/plugins/rdf2/namespace_converter.rb +24 -0
  64. data/lib/bel/translator/plugins/rdf2/nanopub_converter.rb +82 -0
  65. data/lib/bel/translator/plugins/rdf2/parameter_converter.rb +50 -0
  66. data/lib/bel/translator/plugins/rdf2/rdf_converter.rb +13 -0
  67. data/lib/bel/translator/plugins/rdf2/rdf_writer.rb +63 -0
  68. data/lib/bel/translator/plugins/rdf2/reader.rb +172 -0
  69. data/lib/bel/translator/plugins/rdf2/relationship_converter.rb +49 -0
  70. data/lib/bel/translator/plugins/rdf2/statement_converter.rb +65 -0
  71. data/lib/bel/translator/plugins/rdf2/term_converter.rb +262 -0
  72. data/lib/bel/translator/plugins/rdf2/translator.rb +51 -0
  73. data/lib/bel/translator/plugins/rdf2/uuid.rb +20 -0
  74. data/lib/bel/translator/plugins/rdf2/writer.rb +53 -0
  75. data/lib/bel/translator/plugins/rdfa.rb +1 -1
  76. data/lib/bel/translator/plugins/rdfxml.rb +1 -1
  77. data/lib/bel/translator/plugins/rj.rb +1 -1
  78. data/lib/bel/translator/plugins/trig.rb +1 -1
  79. data/lib/bel/translator/plugins/trix.rb +1 -1
  80. data/lib/bel/translator/plugins/turtle.rb +3 -6
  81. data/lib/bel/translator/plugins/xbel.rb +5 -6
  82. data/lib/bel/translator/plugins/xbel/nanopub_handler.rb +625 -0
  83. data/lib/bel/translator/plugins/xbel/{evidence_yielder.rb → nanopub_yielder.rb} +3 -3
  84. data/lib/bel/translator/plugins/xbel/translator.rb +2 -5
  85. data/lib/bel/translator/plugins/xbel/xbel_yielder.rb +135 -74
  86. data/lib/bel/version.rb +31 -1
  87. metadata +81 -33
  88. data/lib/bel/evidence_model.rb +0 -15
  89. data/lib/bel/evidence_model/bel_parameter.rb +0 -56
  90. data/lib/bel/evidence_model/bel_statement.rb +0 -97
  91. data/lib/bel/evidence_model/bel_term.rb +0 -87
  92. data/lib/bel/evidence_model/evidence.rb +0 -127
  93. data/lib/bel/evidence_model/map_references_combiner.rb +0 -30
  94. data/lib/bel/evidence_model/metadata.rb +0 -49
  95. data/lib/bel/parser.rb +0 -39
  96. data/lib/bel/translator/plugins/bel_script.rb +0 -36
  97. data/lib/bel/translator/plugins/bel_script/bel_citation_serialization.rb +0 -125
  98. data/lib/bel/translator/plugins/bel_script/bel_discrete_serialization.rb +0 -109
  99. data/lib/bel/translator/plugins/bel_script/bel_top_down_serialization.rb +0 -100
  100. data/lib/bel/translator/plugins/bel_script/bel_yielder.rb +0 -180
  101. data/lib/bel/translator/plugins/bel_script/evidence_serialization.rb +0 -79
  102. data/lib/bel/translator/plugins/bel_script/evidence_yielder.rb +0 -87
  103. data/lib/bel/translator/plugins/bel_script/translator.rb +0 -35
  104. data/lib/bel/translator/plugins/json_evidence.rb +0 -38
  105. data/lib/bel/translator/plugins/xbel/evidence_handler.rb +0 -495
@@ -0,0 +1,65 @@
1
+ require 'rdf'
2
+ require_relative 'rdf_converter'
3
+
4
+ module BEL
5
+ module BELRDF
6
+ class StatementConverter
7
+ include RDFConverter
8
+
9
+ def initialize(term_converter, relationship_converter)
10
+ @term_converter = term_converter
11
+ @rel_converter = relationship_converter
12
+ end
13
+
14
+ # Convert a {BELParser::Expression::Model::Statement} to {RDF::Graph} of
15
+ # RDF statements.
16
+ #
17
+ # @param [BELParser::Expression::Model::Statement] bel_statement
18
+ # @return [RDF::Graph] graph of RDF statements representing the statement
19
+ def convert(bel_statement)
20
+ # Dive into subject
21
+ sub_part, sub_uri, subg = @term_converter.convert(bel_statement.subject)
22
+
23
+ # Dive into object
24
+ case
25
+ when bel_statement.simple?
26
+ obj_part, obj_uri, objg = @term_converter.convert(bel_statement.object)
27
+ rel_part, rel_uri = @rel_converter.convert(bel_statement.relationship)
28
+ path_part = "#{sub_part}_#{rel_part}_#{obj_part}"
29
+ stmt_uri = BELR[URI::encode(path_part)]
30
+
31
+ sg = RDF::Graph.new
32
+ sg << subg
33
+ sg << objg
34
+ sg << s(stmt_uri, RDF.type, BELV2_0.Statement)
35
+ sg << s(stmt_uri, BELV2_0.hasSubject, sub_uri)
36
+ sg << s(stmt_uri, BELV2_0.hasObject, obj_uri)
37
+ sg << s(stmt_uri, BELV2_0.hasRelationship, rel_uri) if rel_uri
38
+ when bel_statement.nested?
39
+ obj_part, obj_uri, objg = convert(bel_statement.object)
40
+ rel_part, rel_uri = @rel_converter.convert(bel_statement.relationship)
41
+ path_part = "#{sub_part}_#{rel_part}_#{obj_part}"
42
+ stmt_uri = BELR[URI::encode(path_part)]
43
+
44
+ sg = RDF::Graph.new
45
+ sg << subg
46
+ sg << objg
47
+ sg << s(stmt_uri, RDF.type, BELV2_0.Statement)
48
+ sg << s(stmt_uri, BELV2_0.hasSubject, sub_uri)
49
+ sg << s(stmt_uri, BELV2_0.hasObject, obj_uri)
50
+ sg << s(stmt_uri, BELV2_0.hasRelationship, rel_uri) if rel_uri
51
+ else
52
+ path_part = sub_part
53
+ stmt_uri = BELR[URI::encode(path_part)]
54
+
55
+ sg = RDF::Graph.new
56
+ sg << subg
57
+ sg << s(stmt_uri, RDF.type, BELV2_0.Statement)
58
+ sg << s(stmt_uri, BELV2_0.hasSubject, sub_uri)
59
+ end
60
+
61
+ [path_part, stmt_uri, sg]
62
+ end
63
+ end
64
+ end
65
+ end
@@ -0,0 +1,262 @@
1
+ require 'rdf'
2
+ require 'bel_parser/language/version2_0'
3
+ require 'bel_parser/quoting'
4
+ require_relative 'belv2_0'
5
+ require_relative 'rdf_converter'
6
+
7
+ module BEL
8
+ module BELRDF
9
+ class TermConverter
10
+ include BELParser::Language::Version2_0::Functions
11
+ include BELParser::Quoting
12
+ include RDFConverter
13
+
14
+ def initialize(parameter_converter)
15
+ @parameter_converter = parameter_converter
16
+ end
17
+
18
+ # Convert a {BELParser::Expression::Model::Term} to {RDF::Graph} of
19
+ # RDF statements.
20
+ #
21
+ # @param [BELParser::Expression::Model::Term] term
22
+ # @return [RDF::Graph] graph of RDF statements representing the term
23
+ def convert(term)
24
+ path_part = to_path_part(term)
25
+ term_uri = to_uri(path_part)
26
+ tg = RDF::Graph.new
27
+ tg << s(term_uri, RDF.type, BELV2_0.Term)
28
+
29
+ term_class = FUNCTION_HASH[term.function]
30
+ if term_class
31
+ tg << s(term_uri, RDF.type, term_class)
32
+ end
33
+
34
+ term.arguments.each do |arg|
35
+ case arg
36
+ when BELParser::Expression::Model::Parameter
37
+ param_uri, paramg = @parameter_converter.convert(arg)
38
+ if param_uri
39
+ tg << paramg
40
+ tg << s(term_uri, BELV2_0.hasConcept, param_uri)
41
+ end
42
+ when BELParser::Expression::Model::Term
43
+ if FUNCTION_HASH.key?(arg.function)
44
+ path_part, iterm_uri, itermg = convert(arg)
45
+ tg << itermg
46
+ tg << s(term_uri, BELV2_0.hasChild, iterm_uri)
47
+ end
48
+ handle_special_inner(term, term_uri, arg, tg)
49
+ end
50
+ end
51
+
52
+ [path_part, term_uri, tg]
53
+ end
54
+
55
+ private
56
+
57
+ def handle_special_inner(outer_term, outer_uri, inner_term, tg)
58
+ inner_function = inner_term.function
59
+ case
60
+ when inner_function.return_type.subtype_of?(BELParser::Language::Version2_0::ReturnTypes::Abundance)
61
+ handle_activity_abundance(outer_term, outer_uri, inner_term, tg)
62
+ when inner_function == Fragment
63
+ handle_fragment(outer_term, outer_uri, inner_term, tg)
64
+ when inner_function == FromLocation
65
+ handle_from_location(outer_term, outer_uri, inner_term, tg)
66
+ when inner_function == Location
67
+ handle_location(outer_term, outer_uri, inner_term, tg)
68
+ when inner_function == MolecularActivity
69
+ handle_molecular_activity(outer_term, outer_uri, inner_term, tg)
70
+ when inner_function == Products
71
+ handle_products(outer_term, outer_uri, inner_term, tg)
72
+ when inner_function == ProteinModification
73
+ handle_pmod(outer_term, outer_uri, inner_term, tg)
74
+ when inner_function == Reactants
75
+ handle_reactants(outer_term, outer_uri, inner_term, tg)
76
+ when inner_function == ToLocation
77
+ handle_to_location(outer_term, outer_uri, inner_term, tg)
78
+ when inner_function == Variant
79
+ handle_variant(outer_term, outer_uri, inner_term, tg)
80
+ end
81
+ end
82
+
83
+ def handle_activity_abundance(outer_term, outer_uri, inner_term, tg)
84
+ if outer_term.function == Activity
85
+ _, inner_uri, _ = convert(inner_term)
86
+ tg << s(outer_uri, BELV2_0.hasActivityAbundance, inner_uri)
87
+ end
88
+ end
89
+
90
+ def handle_fragment(outer_term, outer_uri, inner_term, tg)
91
+ if outer_term.function == ProteinAbundance
92
+ frag_range, frag_desc = inner_term.arguments
93
+ if frag_range.is_a?(BELParser::Expression::Model::Parameter)
94
+ tg << s(outer_uri, BELV2_0.hasFragmentRange, unquote(frag_range.to_s))
95
+ end
96
+ if frag_desc.is_a?(BELParser::Expression::Model::Parameter)
97
+ tg << s(outer_uri, BELV2_0.hasFragmentDescriptor, unquote(frag_desc.to_s))
98
+ end
99
+ end
100
+ end
101
+
102
+ def handle_location(outer_term, outer_uri, inner_term, tg)
103
+ match = LOCATION_ABUNDANCES.any? { |f| outer_term.function == f}
104
+ if match
105
+ location = inner_term.arguments[0]
106
+ if location.is_a?(BELParser::Expression::Model::Parameter)
107
+ param_uri, paramg = @parameter_converter.convert(location)
108
+ if param_uri
109
+ tg << paramg
110
+ tg << s(outer_uri, BELV2_0.hasLocation, param_uri)
111
+ end
112
+ end
113
+ end
114
+ end
115
+
116
+ def handle_from_location(outer_term, outer_uri, inner_term, tg)
117
+ if outer_term.function == Translocation
118
+ location = inner_term.arguments[0]
119
+ if location.is_a?(BELParser::Expression::Model::Parameter)
120
+ param_uri, paramg = @parameter_converter.convert(location)
121
+ if param_uri
122
+ tg << paramg
123
+ tg << s(outer_uri, BELV2_0.hasFromLocation, param_uri)
124
+ end
125
+ end
126
+ end
127
+ end
128
+
129
+ def handle_to_location(outer_term, outer_uri, inner_term, tg)
130
+ if outer_term.function == Translocation
131
+ location = inner_term.arguments[0]
132
+ if location.is_a?(BELParser::Expression::Model::Parameter)
133
+ param_uri, paramg = @parameter_converter.convert(location)
134
+ if param_uri
135
+ tg << paramg
136
+ tg << s(outer_uri, BELV2_0.hasToLocation, param_uri)
137
+ end
138
+ end
139
+ end
140
+ end
141
+
142
+ def handle_molecular_activity(outer_term, outer_uri, inner_term, tg)
143
+ if outer_term.function == Activity
144
+ ma, _ = inner_term.arguments
145
+ if ma.is_a?(BELParser::Expression::Model::Parameter)
146
+ param_uri, paramg = @parameter_converter.convert(ma)
147
+ if param_uri
148
+ tg << paramg
149
+ tg << s(outer_uri, BELV2_0.hasActivityType, param_uri)
150
+ end
151
+ end
152
+ end
153
+ end
154
+
155
+ def handle_products(outer_term, outer_uri, inner_term, tg)
156
+ if outer_term.function == Reaction
157
+ inner_term.arguments.each do |arg|
158
+ if arg.is_a?(BELParser::Expression::Model::Term)
159
+ _, inner_uri, _ = convert(arg)
160
+ tg << s(outer_uri, BELV2_0.hasProduct, inner_uri)
161
+ end
162
+ end
163
+ end
164
+ end
165
+
166
+ def handle_reactants(outer_term, outer_uri, inner_term, tg)
167
+ if outer_term.function == Reaction
168
+ inner_term.arguments.each do |arg|
169
+ if arg.is_a?(BELParser::Expression::Model::Term)
170
+ _, inner_uri, _ = convert(arg)
171
+ tg << s(outer_uri, BELV2_0.hasReactant, inner_uri)
172
+ end
173
+ end
174
+ end
175
+ end
176
+
177
+ def handle_pmod(outer_term, outer_uri, inner_term, tg)
178
+ if outer_term.function == ProteinAbundance
179
+ tg << s(outer_uri, RDF.type, BELV2_0.ModifiedProteinAbundance)
180
+ tg << s(outer_uri, BELV2_0.hasModifiedProteinAbundance, outer_uri)
181
+
182
+ mod_protein_uri = BELR[URI::encode(to_path_part(inner_term))]
183
+ tg << s(outer_uri, BELV2_0.hasProteinModification, mod_protein_uri)
184
+
185
+ modtype, amino_acid, residue = inner_term.arguments
186
+ if modtype && modtype.is_a?(BELParser::Expression::Model::Parameter)
187
+ param_uri, paramg = @parameter_converter.convert(modtype)
188
+ if param_uri
189
+ tg << paramg
190
+ tg << s(mod_protein_uri, BELV2_0.hasProteinModificationType, param_uri)
191
+ end
192
+ end
193
+
194
+ if amino_acid && amino_acid.is_a?(BELParser::Expression::Model::Parameter)
195
+ tg << s(mod_protein_uri, BELV2_0.hasAminoAcid, unquote(amino_acid.to_s))
196
+ end
197
+
198
+ if residue && residue.is_a?(BELParser::Expression::Model::Parameter)
199
+ tg << s(mod_protein_uri, BELV2_0.hasProteinResidue, residue.to_s.to_i)
200
+ end
201
+ end
202
+ end
203
+
204
+ def handle_variant(outer_term, outer_uri, inner_term, tg)
205
+ match = VARIANT_ABUNDANCES.any? { |f| outer_term.function == f}
206
+ if match
207
+ hgvs_descriptor, _ = inner_term.arguments
208
+ if hgvs_descriptor.is_a?(BELParser::Expression::Model::Parameter)
209
+ tg << s(outer_uri, BELV2_0.hasVariant, unquote(hgvs_descriptor.to_s))
210
+ end
211
+ end
212
+ end
213
+
214
+ def to_path_part(term)
215
+ return '' if term.nil?
216
+ term
217
+ .to_s
218
+ .squeeze(')')
219
+ .gsub(/[")\[\]]/, '')
220
+ .gsub(/[(:, ]/, '_')
221
+ end
222
+
223
+ def to_uri(path_part)
224
+ BELR[URI::encode(path_part)]
225
+ end
226
+
227
+ FUNCTION_HASH = {
228
+ Abundance => BELV2_0.Abundance,
229
+ Activity => BELV2_0.Activity,
230
+ BiologicalProcess => BELV2_0.BiologicalProcess,
231
+ CellSecretion => BELV2_0.CellSecretion,
232
+ CellSurfaceExpression => BELV2_0.CellSurfaceExpression,
233
+ ComplexAbundance => BELV2_0.ComplexAbundance,
234
+ CompositeAbundance => BELV2_0.CompositeAbundance,
235
+ Degradation => BELV2_0.Degradation,
236
+ Fusion => BELV2_0.FusionAbundance,
237
+ GeneAbundance => BELV2_0.GeneAbundance,
238
+ MicroRNAAbundance => BELV2_0.MicroRNAAbundance,
239
+ Pathology => BELV2_0.Pathology,
240
+ ProteinAbundance => BELV2_0.ProteinAbundance,
241
+ Reaction => BELV2_0.Reaction,
242
+ RNAAbundance => BELV2_0.RNAAbundance,
243
+ Translocation => BELV2_0.Translocation
244
+ }.freeze
245
+
246
+ LOCATION_ABUNDANCES = [
247
+ ComplexAbundance,
248
+ GeneAbundance,
249
+ MicroRNAAbundance,
250
+ ProteinAbundance,
251
+ RNAAbundance
252
+ ]
253
+
254
+ VARIANT_ABUNDANCES = [
255
+ GeneAbundance,
256
+ MicroRNAAbundance,
257
+ ProteinAbundance,
258
+ RNAAbundance
259
+ ]
260
+ end
261
+ end
262
+ end
@@ -0,0 +1,51 @@
1
+ require 'rdf'
2
+ require 'yaml'
3
+
4
+ require_relative 'belv2_0'
5
+ require_relative 'reader'
6
+ require_relative 'rdf_writer'
7
+
8
+ module BEL
9
+ module BELRDF
10
+ class Translator
11
+ include ::BEL::Translator
12
+
13
+ def initialize(format, write_schema = true)
14
+ @format = format
15
+ write_schema = true if write_schema.nil?
16
+ @rdf_schema =
17
+ if write_schema
18
+ BELV2_0
19
+ else
20
+ []
21
+ end
22
+ end
23
+
24
+ def read(data, options = {})
25
+ Reader::UnbufferedNanopubYielder.new(data, @format)
26
+ end
27
+
28
+ def write(objects, io = StringIO.new, options = {})
29
+ rdfw = Writer::RDFWriter.new(io, @format, options)
30
+ objects.each do |nanopub|
31
+ rdfw << nanopub
32
+ end
33
+
34
+ io.is_a?(StringIO) ? io.string : io
35
+ end
36
+
37
+ def load_prefixes(options)
38
+ prefix_file = options[:rdf_prefix_file] || default_prefix_file
39
+ YAML::load_file(prefix_file)
40
+ end
41
+
42
+ def default_prefix_file
43
+ File.join(
44
+ File.expand_path(File.dirname(__FILE__)),
45
+ 'config',
46
+ 'default_prefixes.yml'
47
+ )
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,20 @@
1
+ module BEL
2
+ module BELRDF
3
+
4
+ unless self.methods.include?(:generate_uuid)
5
+
6
+ # Dynamically defines an efficient UUID method for the current ruby.
7
+ if RUBY_ENGINE =~ /^jruby/i
8
+ java_import 'java.util.UUID'
9
+ define_singleton_method(:generate_uuid) do
10
+ Java::JavaUtil::UUID.random_uuid.to_s
11
+ end
12
+ else
13
+ require 'uuid'
14
+ define_singleton_method(:generate_uuid) do
15
+ UUID.generate
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,53 @@
1
+ require_relative 'statement_converter'
2
+ require_relative 'nanopub_converter'
3
+
4
+ module BEL
5
+ module BELRDF
6
+ module Writer
7
+ class RDFWriter
8
+ attr_reader :writer
9
+
10
+ def initialize(io, format, options = {})
11
+ rdf_writer = RDF::Writer.for(format)
12
+ @writer = rdf_writer.new(io, { :stream => true })
13
+
14
+ if options[:void_dataset_uri]
15
+ void_dataset_uri = options.delete(:void_dataset_uri)
16
+ void_dataset_uri = RDF::URI(void_dataset_uri)
17
+ unless void_dataset_uri.valid?
18
+ raise ArgumentError.new 'void_dataset_uri is not a valid URI'
19
+ end
20
+ @void_dataset_uri = void_dataset_uri
21
+ else
22
+ @void_dataset_uri = nil
23
+ end
24
+
25
+ @writer.write_prologue
26
+ @wrote_dataset = false
27
+ @nanopub_converter = NanopubConverter.new(StatementConverter.new))
28
+ end
29
+
30
+ def <<(nanopub)
31
+ if !@wrote_dataset && @void_dataset_uri
32
+ # TODO Write VoID dataset for document.
33
+ end
34
+
35
+ @writer << @nanopub_converter.nanopub(nanopub)
36
+
37
+ # @nanopub_converter.nanopub(nanopub).each do |statement|
38
+ # @writer.write_statement(statement)
39
+ # end
40
+
41
+ if @void_dataset_uri
42
+ # TODO Include this nanopub in the VoID dataset.
43
+ # @writer.write_statement(RDF::Statement.new(@void_dataset_uri, RDF::DC.hasPart, nanopub_uri))
44
+ end
45
+ end
46
+
47
+ def done
48
+ @writer.write_epilogue
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end