bel 0.5.0 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +21 -0
  3. data/README.md +4 -2
  4. data/bin/bel +60 -3
  5. data/lib/bel/completion_rule.rb +2 -2
  6. data/lib/bel/evidence_model.rb +5 -0
  7. data/lib/bel/evidence_model/bel_parameter.rb +1 -6
  8. data/lib/bel/evidence_model/buffering_evidence_combiner.rb +182 -0
  9. data/lib/bel/evidence_model/evidence.rb +21 -0
  10. data/lib/bel/evidence_model/hash_map_references.rb +33 -0
  11. data/lib/bel/evidence_model/map_references.rb +30 -0
  12. data/lib/bel/evidence_model/map_references_combiner.rb +30 -0
  13. data/lib/bel/evidence_model/streaming_evidence_combiner.rb +37 -0
  14. data/lib/bel/evidence_model/util.rb +84 -0
  15. data/lib/bel/gen.rb +7 -3
  16. data/lib/bel/gen/annotation.rb +5 -2
  17. data/lib/bel/gen/evidence.rb +10 -4
  18. data/lib/bel/gen/namespace.rb +37 -0
  19. data/lib/bel/gen/parameter.rb +71 -0
  20. data/lib/bel/gen/sample_resources.rb +52 -0
  21. data/lib/bel/gen/statement.rb +33 -0
  22. data/lib/bel/gen/term.rb +33 -0
  23. data/lib/bel/language.rb +4 -4
  24. data/lib/bel/libbel/library_resolver.rb +1 -1
  25. data/lib/bel/namespace.rb +3 -3
  26. data/lib/bel/quoting.rb +218 -14
  27. data/lib/bel/translator.rb +11 -3
  28. data/lib/bel/translator/plugins/bel_script/bel_citation_serialization.rb +2 -2
  29. data/lib/bel/translator/plugins/bel_script/bel_discrete_serialization.rb +1 -1
  30. data/lib/bel/translator/plugins/bel_script/bel_yielder.rb +32 -21
  31. data/lib/bel/translator/plugins/bel_script/evidence_serialization.rb +11 -10
  32. data/lib/bel/translator/plugins/bel_script/evidence_yielder.rb +2 -2
  33. data/lib/bel/translator/plugins/bel_script/translator.rb +1 -1
  34. data/lib/bel/translator/plugins/json_evidence/translator.rb +5 -1
  35. data/lib/bel/translator/plugins/rdf/monkey_patch.rb +4 -0
  36. data/lib/bel/translator/plugins/xbel/evidence_handler.rb +23 -12
  37. data/lib/bel/translator/plugins/xbel/evidence_yielder.rb +1 -1
  38. data/lib/bel/translator/plugins/xbel/translator.rb +4 -4
  39. data/lib/bel/translator/plugins/xbel/xbel_yielder.rb +24 -7
  40. data/lib/bel/util.rb +55 -21
  41. data/lib/bel/version.rb +1 -1
  42. metadata +13 -3
  43. data/lib/bel/gen/bel_expression.rb +0 -128
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9607df657bf0ec8a4e822b371546bbcd36defd49
4
- data.tar.gz: 7db54613d93ad0257a3c6eda5b4d306740e9f78e
3
+ metadata.gz: f162658eee7622744bcf1334c246b34b9178c70f
4
+ data.tar.gz: e13d38c9a6775f28b83bd6803f076dec155feb30
5
5
  SHA512:
6
- metadata.gz: 5f431222a320c0c5b3bc41f7d04ff170b3f87232ed6c9a6d117e824230f42c8b46f032c94fe2ba671feb54048ff0827f2ece436ab4912c577b088b5380fca88a
7
- data.tar.gz: f902f6573d1453029fa927ccb562b621264054db9dae160a78cffebb76419ed14a531e47283f23bc4ada979c68357bb801bb2036bd35fb98298757d8fd907665
6
+ metadata.gz: f40dca2bb377aec1d86066648a0ac51a61f60bc7f12f76cc583b46e5e54367baf018bebe5832451433382ee9bf21eb3e4ce6e7d7deddb0070ec09b7cf15f49ba
7
+ data.tar.gz: 81b35ae4c5c6fcaf6ac81c37731fe5783004ee67b0dd8e5b6253204687eb5db0d63754d1902137223ade06379dea40b403353e176c95b9dc1164c96f6e5cda9e
@@ -3,6 +3,22 @@ All notable changes to bel.rb will be documented in this file. The curated log b
3
3
 
4
4
  This project adheres to [Semantic Versioning](http://semver.org/).
5
5
 
6
+ ## [0.6.0][0.6.0] - 2016-03-15
7
+ ### Fixed
8
+ - Serialization of BEL Script / XBEL can produce incorrect annotation and namespaces references ([Issue #111][111]).
9
+
10
+ ### Changed
11
+ - Separate random sampling from random data in BEL generator ([Issue #105][105]).
12
+ - Improved BEL quoting API. **Deprecated previous API methods.** ([Issue #104][104]).
13
+ - BEL and XBEL translators will now buffer on write to account for all annotation/namespace references. Pass the `-t streaming=true` option to `bel translate` to stream data when the references are consistent.
14
+
15
+ ### Added
16
+ - Added translator read/write option passing from the `bel translate` subcommand.
17
+
18
+ ### Development
19
+ - Added *doctest* Rake task to run YARD `@example` tests in method level documentation.
20
+ - Added gosh commands for running unit, integration and doctests ([Issue #85][85]).
21
+
6
22
  ## [0.5.0][0.5.0] - 2016-02-10
7
23
  ### Fixed
8
24
  - Fix missing RDF prefixes when converting BEL Script to RDF ([Issue #71][71]).
@@ -75,6 +91,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
75
91
  ### Added
76
92
  - Development gem dependencies (i.e. byebug, pry, pry-byebug) for debugging.
77
93
 
94
+ [0.6.0]: https://github.com/OpenBEL/bel.rb/compare/0.5.0...0.6.0
78
95
  [0.5.0]: https://github.com/OpenBEL/bel.rb/compare/0.4.2...0.5.0
79
96
  [0.4.2]: https://github.com/OpenBEL/bel.rb/compare/0.4.1...0.4.2
80
97
  [0.4.1]: https://github.com/OpenBEL/bel.rb/compare/0.4.0...0.4.1
@@ -93,6 +110,7 @@ This project adheres to [Semantic Versioning](http://semver.org/).
93
110
  [68]: https://github.com/OpenBEL/bel.rb/issues/68
94
111
  [71]: https://github.com/OpenBEL/bel.rb/issues/71
95
112
  [82]: https://github.com/OpenBEL/bel.rb/issues/82
113
+ [85]: https://github.com/OpenBEL/bel.rb/issues/85
96
114
  [86]: https://github.com/OpenBEL/bel.rb/pull/86
97
115
  [90]: https://github.com/OpenBEL/bel.rb/issues/90
98
116
  [91]: https://github.com/OpenBEL/bel.rb/issues/91
@@ -104,5 +122,8 @@ This project adheres to [Semantic Versioning](http://semver.org/).
104
122
  [98]: https://github.com/OpenBEL/bel.rb/issues/98
105
123
  [100]: https://github.com/OpenBEL/bel.rb/issues/100
106
124
  [102]: https://github.com/OpenBEL/bel.rb/issues/102
125
+ [104]: https://github.com/OpenBEL/bel.rb/issues/104
126
+ [105]: https://github.com/OpenBEL/bel.rb/issues/105
127
+ [111]: https://github.com/OpenBEL/bel.rb/issues/111
107
128
  [20150611]: http://resource.belframework.org/belframework/20150611/
108
129
  [RDF.rb]: https://github.com/ruby-rdf/rdf
data/README.md CHANGED
@@ -75,7 +75,7 @@ the root of the bel.rb tree:
75
75
  ## branches
76
76
 
77
77
  - master branch
78
- - Contains stable code. Releases are created from this branch using a tag (e.g. 0.4.0).
78
+ - Contains stable code. Releases are created from this branch using a tag (e.g. `MAJOR.MINOR.PATCH`).
79
79
  - [![Travis CI Build](https://travis-ci.org/OpenBEL/bel.rb.svg?branch=master)](https://travis-ci.org/OpenBEL/bel.rb)
80
80
 
81
81
  - next branch
@@ -110,7 +110,7 @@ the root of the bel.rb tree:
110
110
  plugins
111
111
 
112
112
 
113
- bel 0.4.3
113
+ bel
114
114
  Copyright (C) 2015 OpenBEL
115
115
  Apache License, Version 2.0, January 2004
116
116
  http://www.apache.org/licenses/
@@ -418,4 +418,6 @@ the root of the bel.rb tree:
418
418
  end
419
419
  ```
420
420
 
421
+ Built with collaboration and a lot of :heart: from the OpenBEL community.
422
+
421
423
  [CHANGELOG]: https://github.com/OpenBEL/bel.rb/blob/master/CHANGELOG.md
data/bin/bel CHANGED
@@ -2,6 +2,7 @@
2
2
  $:.unshift(File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
3
3
  require 'erb'
4
4
  require 'bel'
5
+ require 'bel/util'
5
6
  require 'bel/vendor/trollop'
6
7
 
7
8
  VERSION_BANNER = <<-VERSION
@@ -232,14 +233,28 @@ Subcommands:
232
233
  def run
233
234
  parsed_options =
234
235
  Trollop::options do
235
- synopsis "Translates BEL evidence between file formats."
236
- usage "[OPTIONS]... translate [OPTIONS] FROM_FORMAT TO_FORMAT"
236
+ synopsis "Translates BEL evidence between formats using translator plugins."
237
+ usage "[OPTIONS]... translate [OPTIONS] FROM_TRANSLATOR TO_TRANSLATOR"
237
238
 
238
239
  opt :'input-file', 'The file containing evidence data to translate. If not specified the default is to read from STDIN.',
239
240
  :type => String,
240
241
  :long => :'input-file',
241
242
  :short => :i,
242
243
  :default => nil
244
+
245
+ opt :'from-option', 'A "key=value" option to be sent to the FROM_TRANSLATOR.',
246
+ :type => String,
247
+ :multi => true,
248
+ :long => :'from-option',
249
+ :short => :f,
250
+ :default => nil
251
+
252
+ opt :'to-option', 'A "key=value" option to be sent to the TO_TRANSLATOR.',
253
+ :type => String,
254
+ :multi => true,
255
+ :long => :'to-option',
256
+ :short => :t,
257
+ :default => nil
243
258
  end
244
259
 
245
260
  input_io = which_io(parsed_options[:'input-file'])
@@ -282,12 +297,48 @@ Subcommands:
282
297
  Trollop::educate
283
298
  end
284
299
 
300
+ from_options = map_kv_options(parsed_options, :'from-option')
301
+ to_options = map_kv_options(parsed_options, :'to-option')
302
+
285
303
  begin
286
- BEL.translate(input_io, from_format, to_format, $stdout)
304
+ BEL.translate(
305
+ input_io,
306
+ from_format,
307
+ to_format,
308
+ $stdout,
309
+ from_options.merge(to_options) # XXX Merge conflicts.
310
+ )
287
311
  ensure
288
312
  $stdout.close
289
313
  end
290
314
  end
315
+
316
+ private
317
+
318
+ def map_kv_options(parsed_options, opt)
319
+ BEL.keys_to_symbols(
320
+ Hash[
321
+ parsed_options[opt].map { |opt|
322
+ key, value = opt.split('=')
323
+ if !key || !value
324
+ nil
325
+ else
326
+ value =
327
+ case value
328
+ when "true"
329
+ true
330
+ when "false"
331
+ false
332
+ else
333
+ value
334
+ end
335
+
336
+ [key, value]
337
+ end
338
+ }.compact
339
+ ]
340
+ )
341
+ end
291
342
  end
292
343
 
293
344
  class UpgradeCommand
@@ -405,11 +456,17 @@ Subcommands:
405
456
  :long => :translator,
406
457
  :short => :t,
407
458
  :default => 'bel'
459
+
460
+ opt :sample, 'Sample namespace values and annotations from BEL resources.',
461
+ :long => :sample,
462
+ :short => :s,
463
+ :default => false
408
464
  end
409
465
 
410
466
  # require BEL generator and include in GenerateCommand
411
467
  require 'bel/gen'
412
468
  self.class.include(BEL::Gen::Evidence)
469
+ self.class.include(BEL::Gen::SampleResources) if options[:sample]
413
470
 
414
471
  # create enumerator of random evidence
415
472
  limit = options[:limit].to_i
@@ -234,13 +234,13 @@ module BEL
234
234
  :id => ns_value,
235
235
  :type => :namespace_value,
236
236
  :label => ns_value,
237
- :value => ensure_quotes(ns_value),
237
+ :value => quote_if_needed(ns_value),
238
238
  :offset => 0
239
239
  }
240
240
  end
241
241
 
242
242
  def map_namespace_value_with_prefix(ns, ns_value)
243
- quoted_value = ensure_quotes(ns_value)
243
+ quoted_value = quote_if_needed(ns_value)
244
244
 
245
245
  if ns
246
246
  ns_prefix = ns.prefix.to_s.upcase
@@ -8,3 +8,8 @@ require_relative 'evidence_model/citation'
8
8
  require_relative 'evidence_model/summary_text'
9
9
  require_relative 'evidence_model/experiment_context'
10
10
  require_relative 'evidence_model/metadata'
11
+
12
+ require_relative 'evidence_model/buffering_evidence_combiner'
13
+ require_relative 'evidence_model/map_references_combiner'
14
+ require_relative 'evidence_model/streaming_evidence_combiner'
15
+ require_relative 'evidence_model/util'
@@ -17,11 +17,6 @@ module BEL
17
17
  attr_accessor :ns, :value, :enc
18
18
 
19
19
  def initialize(ns, value, enc=nil)
20
- if !enc && ns.is_a?(BEL::Namespace::NamespaceDefinition)
21
- lookup = ns[value]
22
- enc = lookup && lookup.enc
23
- end
24
-
25
20
  @enc = enc
26
21
  @ns = ns
27
22
  @value = value
@@ -53,7 +48,7 @@ module BEL
53
48
  else
54
49
  prefix = ''
55
50
  end
56
- %Q{#{prefix}#{ensure_quotes(@value)}}
51
+ %Q{#{prefix}#{quote_if_needed(@value)}}
57
52
  end
58
53
  alias_method :to_s, :to_bel
59
54
  end
@@ -0,0 +1,182 @@
1
+ require_relative 'hash_map_references'
2
+
3
+ module BEL
4
+ module Model
5
+
6
+ # EvidenceReferenceCombiner is responsible for disambiguating evidence
7
+ # with overlapping sets of annotation/namespace references. This can occur
8
+ # when documents use the same keyword to refer to more than one reference.
9
+ #
10
+ # For example, evidence A may be annotated with:
11
+ #
12
+ # {
13
+ # :keyword => :Species,
14
+ # :type => :uri,
15
+ # :domain => 'file:///20131211/annotation/species-taxonomy-id.belanno'
16
+ # }
17
+ #
18
+ # while evidence B may be annotated with:
19
+ #
20
+ # {
21
+ # :keyword => :Species,
22
+ # :type => :uri,
23
+ # :domain => 'file:///20150611/annotation/species-taxonomy-id.belanno'
24
+ # }
25
+ #
26
+ # It is the job of this class to remap references to disambiguate the
27
+ # keywords.
28
+ #
29
+ # @abstract Subclass and override {#map_namespace_reference} to implement
30
+ # mapping of namespaces.
31
+ class BufferingEvidenceCombiner
32
+
33
+ attr_reader :annotation_references, :namespace_references
34
+
35
+ def initialize(evidence_collection)
36
+ @evidence_collection = evidence_collection
37
+ end
38
+
39
+ def each
40
+ if block_given?
41
+ evidence_array, map_references =
42
+ combine_references(@evidence_collection)
43
+ @annotation_references = map_references.annotation_references
44
+ @namespace_references = map_references.namespace_references
45
+
46
+ evidence_array.each do |evidence|
47
+ if evidence.bel_statement.is_a?(String)
48
+ evidence.bel_statement = BEL::Model::Evidence.parse_statement(evidence)
49
+ end
50
+ yield rewrite_evidence!(evidence, map_references)
51
+ end
52
+ else
53
+ to_enum(:each)
54
+ end
55
+ end
56
+
57
+ protected
58
+
59
+ def combine_references(evidence_collection)
60
+ annotation_reference_map = {}
61
+ namespace_reference_map = {}
62
+ annotations = []
63
+ namespaces = []
64
+ buffered_evidence = evidence_collection.each.map { |evidence|
65
+ annotations, remap =
66
+ BEL::Model.union_annotation_references(
67
+ annotations,
68
+ evidence.references.annotations,
69
+ 'incr'
70
+ )
71
+ annotation_reference_map.merge!(remap)
72
+
73
+ namespaces, remap =
74
+ BEL::Model.union_namespace_references(
75
+ namespaces,
76
+ evidence.references.namespaces,
77
+ 'incr'
78
+ )
79
+ namespace_reference_map.merge!(remap)
80
+
81
+ evidence
82
+ }.to_a
83
+
84
+ [
85
+ buffered_evidence,
86
+ HashMapReferences.new(
87
+ annotation_reference_map,
88
+ namespace_reference_map
89
+ )
90
+ ]
91
+ end
92
+
93
+ def rewrite_evidence!(evidence, map_references)
94
+ rewrite_experiment_context!(
95
+ evidence.experiment_context,
96
+ evidence.references.annotations,
97
+ map_references
98
+ )
99
+
100
+ rewrite_statement!(
101
+ evidence.bel_statement,
102
+ evidence.references.namespaces,
103
+ map_references
104
+ )
105
+
106
+ evidence
107
+ end
108
+
109
+ def rewrite_statement!(statement, namespace_references, map_references)
110
+ keyword_to_reference = Hash[
111
+ namespace_references.map { |reference|
112
+ [reference[:keyword], reference]
113
+ }
114
+ ]
115
+
116
+ sub = statement.subject
117
+ if sub
118
+ rewrite_term!(sub, keyword_to_reference, map_references)
119
+ end
120
+
121
+ obj = statement.object
122
+ if obj
123
+ case obj
124
+ when ::BEL::Model::Statement
125
+ rewrite_statement!(obj, namespace_references, map_references)
126
+ when ::BEL::Model::Term
127
+ rewrite_term!(obj, keyword_to_reference, map_references)
128
+ end
129
+ end
130
+ end
131
+
132
+ def rewrite_term!(term, keyword_to_reference, map_references)
133
+ return unless term
134
+
135
+ term.arguments.each do |arg|
136
+ case arg
137
+ when ::BEL::Model::Parameter
138
+ if arg.ns
139
+ prefix =
140
+ if arg.ns.respond_to?(:prefix)
141
+ arg.ns.prefix
142
+ else
143
+ arg.ns[:prefix]
144
+ end
145
+ reference = keyword_to_reference[prefix.to_sym]
146
+ new_reference = map_references.map_namespace_reference(reference)
147
+ if new_reference
148
+ arg.ns = BEL::Namespace::NamespaceDefinition.new(
149
+ new_reference[:keyword],
150
+ new_reference[:uri]
151
+ )
152
+ end
153
+ end
154
+ when ::BEL::Model::Term
155
+ rewrite_term!(arg, keyword_to_reference, map_references)
156
+ end
157
+ end
158
+ end
159
+
160
+ def rewrite_experiment_context!(
161
+ experiment_context,
162
+ annotation_references,
163
+ map_references
164
+ )
165
+ references = Hash[
166
+ annotation_references.map { |reference|
167
+ [reference[:keyword], reference]
168
+ }
169
+ ]
170
+ experiment_context.values.each do |annotation|
171
+ new_reference = map_references.map_annotation_reference(
172
+ references[annotation[:name].to_sym]
173
+ )
174
+
175
+ if new_reference
176
+ annotation[:name] = new_reference[:keyword]
177
+ end
178
+ end
179
+ end
180
+ end
181
+ end
182
+ end
@@ -101,6 +101,27 @@ module BEL
101
101
  )
102
102
  hash
103
103
  end
104
+
105
+ private
106
+
107
+ def parse_statement(bel_statement)
108
+ namespaces = self.references.namespaces
109
+ ::BEL::Script.parse(
110
+ "#{bel_statement}\n",
111
+ Hash[
112
+ namespaces.map { |ns|
113
+ keyword, uri = ns.values_at(:keyword, :uri)
114
+ sym = keyword.to_sym
115
+ [
116
+ sym,
117
+ ::BEL::Namespace::NamespaceDefinition.new(sym, uri, uri)
118
+ ]
119
+ }
120
+ ]
121
+ ).select { |obj|
122
+ obj.is_a? ::BEL::Model::Statement
123
+ }.first
124
+ end
104
125
  end
105
126
  end
106
127
  end