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
@@ -1,7 +1,7 @@
1
1
  module BEL
2
- module Model
2
+ module Nanopub
3
3
 
4
- # A Citation describes a cited reference which {Evidence} is derived from.
4
+ # A Citation describes a cited reference which {Nanopub} is derived from.
5
5
  #
6
6
  # @attr [String] type the type of resource the cited material appears in
7
7
  # (e.g. PubMed, Journal, Book, Online Resource, etc...)
@@ -1,7 +1,7 @@
1
1
  require 'forwardable'
2
2
 
3
3
  module BEL
4
- module Model
4
+ module Nanopub
5
5
  class ExperimentContext
6
6
 
7
7
  attr_reader :values
@@ -21,6 +21,12 @@ module BEL
21
21
  @values.sort_by! { |item| item[:name] }
22
22
  end
23
23
 
24
+ def ==(other)
25
+ return false if other.nil?
26
+ @values == other.values
27
+ end
28
+ alias eql? ==
29
+
24
30
  def_delegators :@values, :<<, :[], :"[]=",
25
31
  :each, :size, :sort
26
32
  end
@@ -1,7 +1,7 @@
1
1
  require_relative 'map_references'
2
2
 
3
3
  module BEL
4
- module Model
4
+ module Nanopub
5
5
  class HashMapReferences
6
6
  include MapReferences
7
7
 
@@ -1,5 +1,5 @@
1
1
  module BEL
2
- module Model
2
+ module Nanopub
3
3
  module MapReferences
4
4
 
5
5
  def annotation_references
@@ -0,0 +1,30 @@
1
+ module BEL
2
+ module Nanopub
3
+
4
+ class MapReferencesCombiner < BufferingNanopubCombiner
5
+
6
+ def initialize(nanopub_collection, map_references)
7
+ @nanopub_collection = nanopub_collection
8
+ @map_references = map_references
9
+ end
10
+
11
+ def annotation_references
12
+ @map_references.annotation_references
13
+ end
14
+
15
+ def namespace_references
16
+ @map_references.namespace_references
17
+ end
18
+
19
+ def each
20
+ if block_given?
21
+ @nanopub_collection.each do |nanopub|
22
+ yield rewrite_nanopub!(nanopub, @map_references)
23
+ end
24
+ else
25
+ to_enum(:each)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,102 @@
1
+ require 'forwardable'
2
+
3
+ module BEL
4
+ module Nanopub
5
+ class Metadata
6
+
7
+ attr_reader :values
8
+
9
+ extend Forwardable
10
+ include Enumerable
11
+
12
+ BEL_VERSION = :bel_version
13
+ DOCUMENT_HEADER = :document_header
14
+
15
+ def initialize(values = {})
16
+ if values.is_a? Array
17
+ @values = Hash[
18
+ values.map { |item|
19
+ name = item[:name] || item['name']
20
+ value = item[:value] || item['value']
21
+ [name.to_sym, value]
22
+ }
23
+ ]
24
+ else
25
+ @values = values
26
+ end
27
+
28
+ doc_hdr = @values[:document_header]
29
+ unless doc_hdr.nil?
30
+ @values[:document_header] = Hash[
31
+ doc_hdr.map { |item|
32
+ [item[0].to_sym, item[1]]
33
+ }
34
+ ]
35
+ end
36
+
37
+ unless @values.key?(:bel_version)
38
+ @values[:bel_version] = BELParser::Language.default_version
39
+ end
40
+
41
+ header = @values[:document_header]
42
+ unless header.nil?
43
+ authors = header[:Authors]
44
+ unless authors.is_a? Array
45
+ authors = [authors]
46
+ header[:Authors] = authors
47
+ end
48
+
49
+ licenses = header[:Licenses]
50
+ unless licenses.is_a? Array
51
+ licenses = [licenses]
52
+ header[:Licenses] = licenses
53
+ end
54
+ end
55
+ end
56
+
57
+ def bel_version
58
+ @values[BEL_VERSION]
59
+ end
60
+
61
+ def bel_version=(bel_version)
62
+ @values[BEL_VERSION] =
63
+ case bel_version
64
+ when BELParser::Language::Specification
65
+ bel_version.version.to_s
66
+ when String
67
+ bel_version
68
+ else
69
+ raise(
70
+ ArgumentError,
71
+ %(expected String, Specification; actual #{bel_version.class}))
72
+ end
73
+ end
74
+
75
+ def document_header
76
+ @values[DOCUMENT_HEADER] ||= {}
77
+ end
78
+
79
+ def document_header=(document_header)
80
+ @values[DOCUMENT_HEADER] = document_header
81
+ end
82
+
83
+ def ==(other)
84
+ return false if other.nil?
85
+ @values == other.values
86
+ end
87
+ alias eql? ==
88
+
89
+ def to_a
90
+ @values.each_pair.map { |key, value|
91
+ {
92
+ name: key,
93
+ value: value
94
+ }
95
+ }
96
+ end
97
+
98
+ def_delegators :@values, :[], :"[]=", :delete_if, :each, :each_pair,
99
+ :fetch, :keys, :size, :sort, :store
100
+ end
101
+ end
102
+ end
@@ -0,0 +1,122 @@
1
+ require 'bel'
2
+ require 'bel_parser/expression'
3
+
4
+ require_relative 'citation'
5
+ require_relative 'support'
6
+ require_relative 'experiment_context'
7
+ require_relative 'references'
8
+ require_relative 'metadata'
9
+
10
+ module BEL
11
+ module Nanopub
12
+ # Nanopub represents an asserted biological interaction with associated
13
+ # constituents:
14
+ #
15
+ # - BEL Statement
16
+ # - Citation
17
+ # - Support
18
+ # - Experiment Context
19
+ # - References
20
+ # - Metadata
21
+ class Nanopub
22
+
23
+ def self.create(hash)
24
+ nanopub = Nanopub.new
25
+ # Order-dependent; metadata/references must be set first in order for
26
+ # _parse_statement to reference specification and namespaces.
27
+ nanopub.metadata = Metadata.new(hash[:metadata] || {})
28
+ nanopub.references = References.new(hash[:references] || {})
29
+ nanopub.bel_statement = hash[:bel_statement] || nil
30
+ nanopub.citation = Citation.new(hash[:citation] || {})
31
+ nanopub.support.value = hash[:support] || nil
32
+ nanopub.experiment_context = ExperimentContext.new(hash[:experiment_context] || [])
33
+ nanopub
34
+ end
35
+
36
+ def bel_statement
37
+ @bel_statement
38
+ end
39
+
40
+ def bel_statement=(bel_statement)
41
+ @bel_statement =
42
+ case bel_statement
43
+ when String
44
+ _parse_statement(bel_statement)
45
+ when BELParser::Expression::Model::Statement
46
+ bel_statement
47
+ when nil
48
+ nil
49
+ else
50
+ raise ArgumentError, %(expected String, Statement, actual: #{bel_statement.class})
51
+ end
52
+ end
53
+
54
+ def citation
55
+ (@citation ||= Citation.new)
56
+ end
57
+
58
+ def citation=(citation)
59
+ @citation = citation
60
+ end
61
+
62
+ def support
63
+ (@support ||= Support.new)
64
+ end
65
+
66
+ def support=(support)
67
+ @support = support
68
+ end
69
+
70
+ def experiment_context
71
+ (@experiment_context ||= ExperimentContext.new)
72
+ end
73
+
74
+ def experiment_context=(experiment_context)
75
+ @experiment_context = experiment_context
76
+ end
77
+
78
+ def references
79
+ (@references ||= References.new)
80
+ end
81
+
82
+ def references=(references)
83
+ @references = references
84
+ end
85
+
86
+ def metadata
87
+ (@metadata ||= Metadata.new)
88
+ end
89
+
90
+ def metadata=(metadata)
91
+ @metadata = metadata
92
+ end
93
+
94
+ def to_h(hash = {})
95
+ hash.merge!(
96
+ {
97
+ :bel_statement => bel_statement,
98
+ :citation => citation.to_h,
99
+ :support => support.value,
100
+ :experiment_context => experiment_context.values,
101
+ :references => references.to_h,
102
+ :metadata => metadata.to_a
103
+ }
104
+ )
105
+ hash
106
+ end
107
+
108
+ private
109
+
110
+ def _parse_statement(bel_statement)
111
+ bel_version =
112
+ metadata[:bel_version] || BELParser::Language.default_version
113
+ spec = BELParser::Language.specification(bel_version)
114
+ BELParser::Expression.parse_statements(
115
+ bel_statement,
116
+ spec,
117
+ references.namespaces_hash
118
+ )
119
+ end
120
+ end
121
+ end
122
+ end
@@ -1,8 +1,9 @@
1
1
  require 'forwardable'
2
2
  require 'set'
3
+ require 'bel_parser/expression/model/namespace'
3
4
 
4
5
  module BEL
5
- module Model
6
+ module Nanopub
6
7
  class References
7
8
 
8
9
  attr_reader :values
@@ -17,7 +18,6 @@ module BEL
17
18
  @values = {}
18
19
 
19
20
  values.fetch(ANNOTATIONS, []).each do |annotation|
20
-
21
21
  add_annotation(
22
22
  annotation[:keyword],
23
23
  annotation[:type],
@@ -26,10 +26,10 @@ module BEL
26
26
  end
27
27
 
28
28
  values.fetch(NAMESPACES, []).each do |namespace|
29
-
30
29
  add_namespace(
31
30
  namespace[:keyword],
32
- namespace[:uri]
31
+ namespace[:type],
32
+ namespace[:domain]
33
33
  )
34
34
  end
35
35
  end
@@ -38,6 +38,10 @@ module BEL
38
38
  @values[ANNOTATIONS] ||= []
39
39
  end
40
40
 
41
+ def annotations_hash
42
+ Hash[annotations.map { |ns| ns.values_at(:keyword, :domain) }]
43
+ end
44
+
41
45
  def annotations=(annotations)
42
46
  @values[ANNOTATIONS] = annotations
43
47
  end
@@ -46,56 +50,64 @@ module BEL
46
50
  @values[NAMESPACES] ||= []
47
51
  end
48
52
 
53
+ def namespaces_hash
54
+ Hash[ namespaces.map { |n| [n.keyword, n] } ]
55
+ end
56
+
49
57
  def namespaces=(namespaces)
50
58
  @values[NAMESPACES] = namespaces
51
59
  end
52
60
 
53
61
  def add_annotation(keyword, type, domain)
54
- if type == :pattern
55
- domain = case domain
56
- when Regexp
57
- domain
58
- else
59
- Regexp.new(domain.to_s)
60
- end
61
- end
62
-
63
- annotations << {
64
- :keyword => keyword.to_sym,
65
- :type => type.to_sym,
66
- :domain => domain
67
- }
68
- annotations.sort_by! { |anno| anno[:keyword] }
62
+ annotation =
63
+ BELParser::Expression::Model::Annotation.new(
64
+ keyword,
65
+ type.to_sym,
66
+ domain)
67
+ annotations << annotation
68
+ annotations.sort_by! { |a| a.keyword }
69
69
  end
70
70
 
71
- def add_namespace(keyword, uri)
72
- namespaces << {
73
- :keyword => keyword.to_sym,
74
- :uri => uri
75
- }
76
- namespaces.sort_by! { |ns| ns[:keyword] }
71
+ def add_namespace(keyword, type, domain)
72
+ case type
73
+ when :uri
74
+ uri = domain
75
+ url = nil
76
+ when :url
77
+ url = domain
78
+ uri = nil
79
+ end
80
+
81
+ namespace =
82
+ BELParser::Expression::Model::Namespace.new(
83
+ keyword.to_s,
84
+ uri,
85
+ url)
86
+ namespaces << namespace
87
+ namespaces.sort_by! { |n| n.keyword }
77
88
  end
78
89
 
79
90
  def to_h(hash = {})
80
91
  hash[ANNOTATIONS] = annotations.map { |anno|
81
- keyword, type, domain = anno.values_at(:keyword, :type, :domain)
82
-
83
- domain = case domain
84
- when Regexp
85
- domain.source
86
- else
87
- domain
88
- end
89
-
90
92
  {
91
- :keyword => keyword,
92
- :type => type,
93
- :domain => domain
93
+ :keyword => anno.keyword,
94
+ :type => anno.type,
95
+ :domain =>
96
+ case anno.domain
97
+ when Regexp
98
+ anno.domain.source
99
+ else
100
+ anno.domain
101
+ end
94
102
  }
95
103
  }
96
104
 
97
105
  hash[NAMESPACES] = namespaces.map { |ns|
98
- ns.dup
106
+ {
107
+ :keyword => ns.keyword,
108
+ :type => ns.type,
109
+ :domain => ns.domain
110
+ }
99
111
  }
100
112
 
101
113
  hash
@@ -1,23 +1,23 @@
1
1
  module BEL
2
- module Model
2
+ module Nanopub
3
3
 
4
- class StreamingEvidenceCombiner
4
+ class StreamingNanopubCombiner
5
5
 
6
6
  attr_reader :annotation_references, :namespace_references
7
7
 
8
- def initialize(evidence_collection)
9
- @evidence_collection = evidence_collection
8
+ def initialize(nanopub_collection)
9
+ @nanopub_collection = nanopub_collection
10
10
  end
11
11
 
12
12
  def each
13
13
  if block_given?
14
- @evidence_collection.each do |evidence|
14
+ @nanopub_collection.each do |nanopub|
15
15
  once {
16
- @annotation_references = evidence.references.annotations
17
- @namespace_references = evidence.references.namespaces
16
+ @annotation_references = nanopub.references.annotations
17
+ @namespace_references = nanopub.references.namespaces
18
18
  }
19
19
 
20
- yield evidence
20
+ yield nanopub
21
21
  end
22
22
  else
23
23
  to_enum(:each)