bel 0.7.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{bel.gemspec → .gemspec} +8 -4
- data/README.md +3 -3
- data/VERSION +1 -0
- data/bin/bel +8 -8
- data/bin/bel2rdf.rb +1 -1
- data/bin/bel_summarize.rb +4 -4
- data/bin/bel_upgrade.rb +6 -6
- data/lib/bel.rb +3 -2
- data/lib/bel/completion.rb +13 -10
- data/lib/bel/completion_rule.rb +29 -21
- data/lib/bel/dsl.rb +75 -0
- data/lib/bel/gen.rb +2 -2
- data/lib/bel/gen/annotation.rb +2 -2
- data/lib/bel/gen/citation.rb +6 -6
- data/lib/bel/gen/document_header.rb +1 -1
- data/lib/bel/gen/{evidence.rb → nanopub.rb} +15 -15
- data/lib/bel/gen/parameter.rb +6 -6
- data/lib/bel/gen/sample_resources.rb +4 -4
- data/lib/bel/gen/statement.rb +1 -1
- data/lib/bel/gen/term.rb +1 -1
- data/lib/bel/language.rb +0 -20
- data/lib/bel/namespace.rb +7 -3
- data/lib/bel/nanopub.rb +15 -0
- data/lib/bel/{evidence_model/buffering_evidence_combiner.rb → nanopub/buffering_nanopub_combiner.rb} +39 -45
- data/lib/bel/{evidence_model → nanopub}/citation.rb +2 -2
- data/lib/bel/{evidence_model → nanopub}/experiment_context.rb +7 -1
- data/lib/bel/{evidence_model → nanopub}/hash_map_references.rb +1 -1
- data/lib/bel/{evidence_model → nanopub}/map_references.rb +1 -1
- data/lib/bel/nanopub/map_references_combiner.rb +30 -0
- data/lib/bel/nanopub/metadata.rb +102 -0
- data/lib/bel/nanopub/nanopub.rb +122 -0
- data/lib/bel/{evidence_model → nanopub}/references.rb +50 -38
- data/lib/bel/{evidence_model/streaming_evidence_combiner.rb → nanopub/streaming_nanopub_combiner.rb} +8 -8
- data/lib/bel/{evidence_model/summary_text.rb → nanopub/support.rb} +8 -2
- data/lib/bel/{evidence_model → nanopub}/util.rb +10 -10
- data/lib/bel/resource/annotation.rb +15 -24
- data/lib/bel/resource/annotation_value.rb +24 -20
- data/lib/bel/resource/annotations.rb +12 -11
- data/lib/bel/resource/concept.rb +62 -0
- data/lib/bel/resource/concept_scheme.rb +49 -0
- data/lib/bel/resource/namespace.rb +15 -24
- data/lib/bel/resource/namespace_value.rb +26 -23
- data/lib/bel/resource/namespaces.rb +11 -11
- data/lib/bel/script.rb +367 -367
- data/lib/bel/translate.rb +7 -7
- data/lib/bel/translator.rb +10 -10
- data/lib/bel/translator/plugins/bnj.rb +37 -0
- data/lib/bel/translator/plugins/{json_evidence → bnj}/translator.rb +17 -34
- data/lib/bel/translator/plugins/jgf.rb +1 -1
- data/lib/bel/translator/plugins/jgf/translator.rb +10 -10
- data/lib/bel/translator/plugins/jsonld.rb +1 -1
- data/lib/bel/translator/plugins/nquads.rb +1 -1
- data/lib/bel/translator/plugins/ntriples.rb +1 -1
- data/lib/bel/translator/plugins/rdf/bel_schema.rb +134 -126
- data/lib/bel/translator/plugins/rdf/graph_translator.rb +6 -6
- data/lib/bel/translator/plugins/rdf/monkey_patch.rb +50 -49
- data/lib/bel/translator/plugins/rdf/reader.rb +42 -42
- data/lib/bel/translator/plugins/rdf/translator.rb +6 -6
- data/lib/bel/translator/plugins/rdf/writer.rb +4 -4
- data/lib/bel/translator/plugins/rdf2/belv2_0.rb +416 -0
- data/lib/bel/translator/plugins/rdf2/converter.rb +13 -0
- data/lib/bel/translator/plugins/rdf2/namespace_converter.rb +24 -0
- data/lib/bel/translator/plugins/rdf2/nanopub_converter.rb +82 -0
- data/lib/bel/translator/plugins/rdf2/parameter_converter.rb +50 -0
- data/lib/bel/translator/plugins/rdf2/rdf_converter.rb +13 -0
- data/lib/bel/translator/plugins/rdf2/rdf_writer.rb +63 -0
- data/lib/bel/translator/plugins/rdf2/reader.rb +172 -0
- data/lib/bel/translator/plugins/rdf2/relationship_converter.rb +49 -0
- data/lib/bel/translator/plugins/rdf2/statement_converter.rb +65 -0
- data/lib/bel/translator/plugins/rdf2/term_converter.rb +262 -0
- data/lib/bel/translator/plugins/rdf2/translator.rb +51 -0
- data/lib/bel/translator/plugins/rdf2/uuid.rb +20 -0
- data/lib/bel/translator/plugins/rdf2/writer.rb +53 -0
- data/lib/bel/translator/plugins/rdfa.rb +1 -1
- data/lib/bel/translator/plugins/rdfxml.rb +1 -1
- data/lib/bel/translator/plugins/rj.rb +1 -1
- data/lib/bel/translator/plugins/trig.rb +1 -1
- data/lib/bel/translator/plugins/trix.rb +1 -1
- data/lib/bel/translator/plugins/turtle.rb +3 -6
- data/lib/bel/translator/plugins/xbel.rb +5 -6
- data/lib/bel/translator/plugins/xbel/nanopub_handler.rb +625 -0
- data/lib/bel/translator/plugins/xbel/{evidence_yielder.rb → nanopub_yielder.rb} +3 -3
- data/lib/bel/translator/plugins/xbel/translator.rb +2 -5
- data/lib/bel/translator/plugins/xbel/xbel_yielder.rb +135 -74
- data/lib/bel/version.rb +31 -1
- metadata +81 -33
- data/lib/bel/evidence_model.rb +0 -15
- data/lib/bel/evidence_model/bel_parameter.rb +0 -56
- data/lib/bel/evidence_model/bel_statement.rb +0 -97
- data/lib/bel/evidence_model/bel_term.rb +0 -87
- data/lib/bel/evidence_model/evidence.rb +0 -127
- data/lib/bel/evidence_model/map_references_combiner.rb +0 -30
- data/lib/bel/evidence_model/metadata.rb +0 -49
- data/lib/bel/parser.rb +0 -39
- data/lib/bel/translator/plugins/bel_script.rb +0 -36
- data/lib/bel/translator/plugins/bel_script/bel_citation_serialization.rb +0 -125
- data/lib/bel/translator/plugins/bel_script/bel_discrete_serialization.rb +0 -109
- data/lib/bel/translator/plugins/bel_script/bel_top_down_serialization.rb +0 -100
- data/lib/bel/translator/plugins/bel_script/bel_yielder.rb +0 -180
- data/lib/bel/translator/plugins/bel_script/evidence_serialization.rb +0 -79
- data/lib/bel/translator/plugins/bel_script/evidence_yielder.rb +0 -87
- data/lib/bel/translator/plugins/bel_script/translator.rb +0 -35
- data/lib/bel/translator/plugins/json_evidence.rb +0 -38
- data/lib/bel/translator/plugins/xbel/evidence_handler.rb +0 -495
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ee6f5ca76360462e55335f9e1c46479ce56798da
|
4
|
+
data.tar.gz: b0f1a01dddc5d8cccf586b08c957cf153d6d8cfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 86319d2b95fb02b39a18d9f7034adf147ab7e9625dd2915150a91ea7d657de471c7ea7641f8fba5195d6a3dabd421c869331fc68c407a02f03a6783c0d24b74e
|
7
|
+
data.tar.gz: def4cf7f97273305d73d706b7362f14facdfbf9620a82c1b98731dc064e633fd31bf787ae3b225a71d582cf337173f753a5451576a3dc66d691fbf788f69b0cb
|
data/{bel.gemspec → .gemspec}
RENAMED
@@ -1,8 +1,8 @@
|
|
1
|
-
require './lib/bel/version'
|
2
|
-
|
3
1
|
Gem::Specification.new do |spec|
|
4
2
|
spec.name = 'bel'
|
5
|
-
spec.version =
|
3
|
+
spec.version = File.read(File.join(
|
4
|
+
File.expand_path(File.dirname(__FILE__)),
|
5
|
+
'VERSION'))
|
6
6
|
spec.summary = '''
|
7
7
|
Process BEL with ruby.
|
8
8
|
'''.gsub(%r{^\s+}, ' ').gsub(%r{\n}, '')
|
@@ -36,6 +36,7 @@ Gem::Specification.new do |spec|
|
|
36
36
|
'INSTALL_RUBY.md',
|
37
37
|
'LICENSE',
|
38
38
|
'README.md',
|
39
|
+
'VERSION',
|
39
40
|
].flatten!
|
40
41
|
spec.executables = Dir.glob('bin/*').map(&File.method(:basename))
|
41
42
|
spec.homepage = 'https://github.com/OpenBEL/bel.rb'
|
@@ -59,7 +60,10 @@ Gem::Specification.new do |spec|
|
|
59
60
|
spec.extensions << 'ext/mri/extconf.rb'
|
60
61
|
spec.required_ruby_version = '>= 2.0.0'
|
61
62
|
|
62
|
-
spec.add_runtime_dependency '
|
63
|
+
spec.add_runtime_dependency 'bel_parser', '~> 1.0.0'
|
64
|
+
spec.add_runtime_dependency 'rdf', '~> 2.0.0'
|
65
|
+
spec.add_runtime_dependency 'rdf-vocab', '~> 2.0.0'
|
66
|
+
spec.add_runtime_dependency 'ffi', '1.9.8'
|
63
67
|
|
64
68
|
# Example post-install message.
|
65
69
|
#
|
data/README.md
CHANGED
@@ -211,7 +211,7 @@ the root of the bel.rb tree:
|
|
211
211
|
|
212
212
|
# reference namespace value using standard prefixes (HGNC, MGI, RGD, etc.)
|
213
213
|
HGNC['AKT1']
|
214
|
-
=> #<BEL::
|
214
|
+
=> #<BEL::Nanopub::Parameter:0x00000004df5bc0
|
215
215
|
@enc=:GRP,
|
216
216
|
@ns_def="BEL::Namespace::HGNC",
|
217
217
|
@value=:AKT1>
|
@@ -405,14 +405,14 @@ the root of the bel.rb tree:
|
|
405
405
|
|
406
406
|
# parse term
|
407
407
|
parser.parse('p(HGNC:AKT1)') do |obj|
|
408
|
-
if obj.is_a? BEL::
|
408
|
+
if obj.is_a? BEL::Nanopub::Term
|
409
409
|
rdf_statements += obj.to_rdf
|
410
410
|
end
|
411
411
|
end
|
412
412
|
|
413
413
|
# parse statement
|
414
414
|
parser.parse("p(HGNC:AKT1) => tscript(g(HGNC:TNF))\n") do |obj|
|
415
|
-
if obj.is_a? BEL::
|
415
|
+
if obj.is_a? BEL::Nanopub::Statement
|
416
416
|
rdf_statements += obj.to_rdf
|
417
417
|
end
|
418
418
|
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
data/bin/bel
CHANGED
@@ -6,7 +6,7 @@ require 'bel/util'
|
|
6
6
|
require 'bel/vendor/trollop'
|
7
7
|
|
8
8
|
VERSION_BANNER = <<-VERSION
|
9
|
-
bel #{BEL::
|
9
|
+
bel #{BEL::Version}
|
10
10
|
Copyright (C) #{Time.now.year} OpenBEL
|
11
11
|
Apache License, Version 2.0, January 2004
|
12
12
|
http://www.apache.org/licenses/
|
@@ -247,7 +247,7 @@ Subcommands:
|
|
247
247
|
def run
|
248
248
|
parsed_options =
|
249
249
|
Trollop::options do
|
250
|
-
synopsis "Translates BEL
|
250
|
+
synopsis "Translates BEL nanopubs between formats using translator plugins."
|
251
251
|
usage <<-DOC.gsub(/^ {14}/, '')
|
252
252
|
[OPTIONS]... translate [OPTIONS] FROM_TRANSLATOR TO_TRANSLATOR
|
253
253
|
|
@@ -275,7 +275,7 @@ Subcommands:
|
|
275
275
|
Run "bel remapfile" to get an example of the YAML format.
|
276
276
|
DOC
|
277
277
|
|
278
|
-
opt :'input-file', 'The file containing
|
278
|
+
opt :'input-file', 'The file containing nanopubs to translate. If not specified the default is to read from STDIN.',
|
279
279
|
:type => String,
|
280
280
|
:long => :'input-file',
|
281
281
|
:short => :i,
|
@@ -506,21 +506,21 @@ Subcommands:
|
|
506
506
|
|
507
507
|
# require BEL generator and include in GenerateCommand
|
508
508
|
require 'bel/gen'
|
509
|
-
self.class.include(BEL::Gen::
|
509
|
+
self.class.include(BEL::Gen::Nanopub)
|
510
510
|
self.class.include(BEL::Gen::SampleResources) if options[:sample]
|
511
511
|
|
512
|
-
# create enumerator of random
|
512
|
+
# create enumerator of random nanopubs
|
513
513
|
limit = options[:limit].to_i
|
514
514
|
random_data = Enumerator.new do |yielder|
|
515
515
|
count = 0
|
516
516
|
while count != limit do
|
517
|
-
yielder <<
|
517
|
+
yielder << nanopub
|
518
518
|
count += 1
|
519
|
-
$stderr.puts "#{count}
|
519
|
+
$stderr.puts "#{count} nanopubs generated..." if count % 500 == 0
|
520
520
|
end
|
521
521
|
end
|
522
522
|
|
523
|
-
# write random
|
523
|
+
# write random nanopubs to STDOUT through a translator
|
524
524
|
translator_id = options[:translator] || :bel
|
525
525
|
translator = BEL.translator(options[:translator] || :bel)
|
526
526
|
unless translator
|
data/bin/bel2rdf.rb
CHANGED
data/bin/bel_summarize.rb
CHANGED
@@ -31,7 +31,7 @@ CSV do |csv_out|
|
|
31
31
|
statement_group_count: 0,
|
32
32
|
empty_statement_groups: 0,
|
33
33
|
statement_count: 0,
|
34
|
-
|
34
|
+
support_count: 0
|
35
35
|
}
|
36
36
|
|
37
37
|
FUNCTIONS.each do |k, v|
|
@@ -53,7 +53,7 @@ CSV do |csv_out|
|
|
53
53
|
report[:empty_statement_groups] += 1
|
54
54
|
end
|
55
55
|
end
|
56
|
-
if obj.is_a? BEL::
|
56
|
+
if obj.is_a? BEL::Nanopub::Term
|
57
57
|
fx = obj.fx
|
58
58
|
fx = fx.respond_to?(:long_form) ?
|
59
59
|
fx.long_form.to_s :
|
@@ -61,7 +61,7 @@ CSV do |csv_out|
|
|
61
61
|
fx = FUNCTIONS[fx.to_sym][:long_form]
|
62
62
|
report["fx_#{fx}"] += 1
|
63
63
|
end
|
64
|
-
if obj.is_a? BEL::
|
64
|
+
if obj.is_a? BEL::Nanopub::Statement
|
65
65
|
report[:statement_count] += 1
|
66
66
|
obj.relationship = case obj.relationship
|
67
67
|
when :"->"
|
@@ -83,7 +83,7 @@ CSV do |csv_out|
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
if obj.is_a? BEL::Language::Annotation
|
86
|
-
report[:
|
86
|
+
report[:support_count] += 1 if obj.name == 'Support'
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
data/bin/bel_upgrade.rb
CHANGED
@@ -75,7 +75,7 @@ end
|
|
75
75
|
|
76
76
|
class Main
|
77
77
|
|
78
|
-
|
78
|
+
SupportMatcher = Regexp.compile(/SET Support = ([0-9a-zA-Z]+)/)
|
79
79
|
LostReplaceValues = ['unresolved', 'withdrawn']
|
80
80
|
attr_reader :ttl
|
81
81
|
|
@@ -141,11 +141,11 @@ class Main
|
|
141
141
|
end
|
142
142
|
end
|
143
143
|
|
144
|
-
#
|
144
|
+
# support always needs quoting; backwards-compatibility
|
145
145
|
if obj.is_a? BEL::Language::Annotation
|
146
|
-
if obj.name == '
|
146
|
+
if obj.name == 'Support'
|
147
147
|
ev = obj.to_s
|
148
|
-
ev.gsub!(
|
148
|
+
ev.gsub!(SupportMatcher, 'SET Support = "\1"')
|
149
149
|
puts ev.to_s
|
150
150
|
next
|
151
151
|
# look for replacement values for annotations
|
@@ -185,7 +185,7 @@ class Main
|
|
185
185
|
end
|
186
186
|
end
|
187
187
|
|
188
|
-
if obj.is_a? BEL::
|
188
|
+
if obj.is_a? BEL::Nanopub::Parameter and obj.ns
|
189
189
|
# first try replacing by existing namespace prefix...
|
190
190
|
prefix = obj.ns.prefix.to_s
|
191
191
|
replacements = @change_log[prefix]
|
@@ -225,7 +225,7 @@ class Main
|
|
225
225
|
end
|
226
226
|
end
|
227
227
|
# do not print Parameter and Term; they are included in Statement
|
228
|
-
if not obj.is_a? BEL::
|
228
|
+
if not obj.is_a? BEL::Nanopub::Parameter and not obj.is_a? BEL::Nanopub::Term
|
229
229
|
puts obj.to_bel
|
230
230
|
end
|
231
231
|
end
|
data/lib/bel.rb
CHANGED
@@ -5,7 +5,7 @@ require_relative 'bel/annotation'
|
|
5
5
|
require_relative 'bel/namespace'
|
6
6
|
require_relative 'bel/util'
|
7
7
|
|
8
|
-
require_relative 'bel/
|
8
|
+
require_relative 'bel/nanopub'
|
9
9
|
require_relative 'bel/translator'
|
10
10
|
require_relative 'bel/translate'
|
11
11
|
|
@@ -15,9 +15,10 @@ require_relative 'bel/resource'
|
|
15
15
|
require_relative 'bel/script'
|
16
16
|
|
17
17
|
require_relative 'bel/libbel.rb'
|
18
|
-
require_relative 'bel/parser'
|
19
18
|
require_relative 'bel/completion'
|
20
19
|
|
20
|
+
require_relative 'bel/dsl'
|
21
|
+
|
21
22
|
module BEL
|
22
23
|
extend BEL::Translate::ClassMethods
|
23
24
|
end
|
data/lib/bel/completion.rb
CHANGED
@@ -1,11 +1,12 @@
|
|
1
|
+
require 'bel_parser/language'
|
1
2
|
require_relative 'libbel'
|
2
3
|
require_relative 'completion_rule'
|
3
4
|
require_relative 'language'
|
4
5
|
require_relative 'namespace'
|
5
6
|
|
6
7
|
module BEL
|
8
|
+
# Completion defines an API for completing BEL Expressions.
|
7
9
|
module Completion
|
8
|
-
|
9
10
|
# Provides completions on BEL expressions.
|
10
11
|
#
|
11
12
|
# If +bel_expression+ is +nil+ then its assumed to be the empty string
|
@@ -26,17 +27,18 @@ module BEL
|
|
26
27
|
#
|
27
28
|
# @param bel_expression [responds to #to_s] the bel expression to
|
28
29
|
# complete on
|
30
|
+
# @param specification [BELParser::Language::Specification] language specification
|
29
31
|
# @param search [#search_namespace, #search] the search object used to
|
30
32
|
# provide namespace value completions
|
31
33
|
# @param position [responds to #to_i] the position to complete from
|
32
34
|
# @return [Array<Completion>]
|
33
|
-
def self.complete(bel_expression, search, namespaces, position = nil)
|
34
|
-
raise ArgumentError.new(
|
35
|
-
|
36
|
-
) unless search
|
37
|
-
raise ArgumentError.new(
|
38
|
-
|
39
|
-
) unless namespaces
|
35
|
+
def self.complete(bel_expression, specification, search, namespaces, position = nil)
|
36
|
+
#raise ArgumentError.new(
|
37
|
+
# "search should be a BEL::Resource::Search plugin implementation"
|
38
|
+
#) unless search
|
39
|
+
#raise ArgumentError.new(
|
40
|
+
# "namespaces should be a BEL::Resource::Namespaces object"
|
41
|
+
#) unless namespaces
|
40
42
|
|
41
43
|
bel_expression = (bel_expression || '').to_s
|
42
44
|
position = (position || bel_expression.length).to_i
|
@@ -58,8 +60,9 @@ module BEL
|
|
58
60
|
}
|
59
61
|
BEL::Completion::run_rules(
|
60
62
|
tokens, active_index, active_token,
|
61
|
-
:
|
62
|
-
:
|
63
|
+
:specification => specification,
|
64
|
+
:search => search,
|
65
|
+
:namespaces => namespaces
|
63
66
|
)
|
64
67
|
end
|
65
68
|
end
|
data/lib/bel/completion_rule.rb
CHANGED
@@ -1,30 +1,31 @@
|
|
1
|
-
require_relative 'language'
|
2
1
|
require_relative 'namespace'
|
3
2
|
require_relative 'quoting'
|
4
3
|
|
5
4
|
module BEL
|
6
5
|
module Completion
|
7
|
-
|
8
|
-
SORTED_FUNCTIONS = BEL::Language::FUNCTIONS.keys.sort.map(&:to_s)
|
9
6
|
SORTED_NAMESPACES = BEL::Namespace::NAMESPACE_LATEST.keys.sort.map(&:to_s)
|
10
7
|
EMPTY_MATCH = []
|
11
8
|
|
9
|
+
# Run all defined {Rule rules}.
|
12
10
|
def self.run_rules(tokens, active_index, active_token, options = {})
|
13
11
|
self.rules.reduce([]) { |completion_results, rule|
|
14
12
|
completion_results.concat(
|
15
13
|
rule.apply(tokens, active_token, active_index, options)
|
16
14
|
)
|
15
|
+
completion_results
|
17
16
|
}
|
18
17
|
end
|
19
18
|
|
19
|
+
# Retrieve all completion {Rule rules}.
|
20
20
|
def self.rules
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
]
|
21
|
+
constants.map do |const|
|
22
|
+
obj = const_get(const)
|
23
|
+
obj.new if obj.include?(Rule)
|
24
|
+
end.compact
|
26
25
|
end
|
27
26
|
|
27
|
+
# Rule defines the {#apply} API contract and additional helpers to convey
|
28
|
+
# completion actions.
|
28
29
|
module Rule
|
29
30
|
|
30
31
|
def apply(token_list, active_token, active_token_index, options = {})
|
@@ -100,21 +101,22 @@ module BEL
|
|
100
101
|
end
|
101
102
|
end
|
102
103
|
|
104
|
+
# MatchFunctionRule defines a function completion rule. This rule relies on
|
105
|
+
# a {BELParser::Language::Specification} for the available functions.
|
103
106
|
class MatchFunctionRule
|
104
107
|
include Rule
|
105
108
|
|
106
109
|
def _apply(token_list, active_token, active_token_index, options = {})
|
107
110
|
if token_list.empty? or active_token.type == :O_PAREN
|
108
|
-
return
|
109
|
-
fx[:label]
|
110
|
-
}
|
111
|
+
return spec_functions(options[:specification]).map(&method(:map_function))
|
111
112
|
end
|
112
113
|
|
113
114
|
if active_token.type == :IDENT
|
114
|
-
value
|
115
|
-
|
116
|
-
|
117
|
-
|
115
|
+
value = active_token.value.downcase
|
116
|
+
matches = spec_functions(options[:specification]).select do |func|
|
117
|
+
func.short.to_s.include?(value) || func.long.to_s.include?(value)
|
118
|
+
end
|
119
|
+
return matches.map(&method(:map_function))
|
118
120
|
end
|
119
121
|
|
120
122
|
return EMPTY_MATCH
|
@@ -122,14 +124,17 @@ module BEL
|
|
122
124
|
|
123
125
|
protected
|
124
126
|
|
125
|
-
def
|
126
|
-
|
127
|
-
|
127
|
+
def spec_functions(spec)
|
128
|
+
spec.functions.sort_by(&:long)
|
129
|
+
end
|
130
|
+
|
131
|
+
def map_function(function)
|
132
|
+
if function
|
128
133
|
{
|
129
|
-
:id =>
|
134
|
+
:id => function.short,
|
130
135
|
:type => :function,
|
131
|
-
:label =>
|
132
|
-
:value => "#{
|
136
|
+
:label => function.long,
|
137
|
+
:value => "#{function.short}()",
|
133
138
|
:offset => -1
|
134
139
|
}
|
135
140
|
else
|
@@ -138,6 +143,8 @@ module BEL
|
|
138
143
|
end
|
139
144
|
end
|
140
145
|
|
146
|
+
# MatchNamespacePrefixRule defines a namespace completion rule.
|
147
|
+
# TODO Namespces should be passed as state, not hardcoded.
|
141
148
|
class MatchNamespacePrefixRule
|
142
149
|
include Rule
|
143
150
|
|
@@ -176,6 +183,7 @@ module BEL
|
|
176
183
|
end
|
177
184
|
end
|
178
185
|
|
186
|
+
# MatchNamespaceValueRule defines a namespace value completion rule.
|
179
187
|
class MatchNamespaceValueRule
|
180
188
|
include Rule
|
181
189
|
include BEL::Quoting
|
data/lib/bel/dsl.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
require 'bel_parser/expression/model'
|
2
|
+
require 'bel_parser/resources'
|
3
|
+
|
4
|
+
module BEL
|
5
|
+
# DSL adds BEL functions and relationships as Ruby methods that allows
|
6
|
+
# creation of {BELParser::Expression::Model::Term} and
|
7
|
+
# {BELParser::Expression::Model::Statement} objects.
|
8
|
+
#
|
9
|
+
# DSL is an acronym for "Domain-specific language".
|
10
|
+
#
|
11
|
+
# @see https://en.wikipedia.org/wiki/Domain-specific_language
|
12
|
+
module DSL
|
13
|
+
# Defines ruby methods for BEL functions and relationships on
|
14
|
+
# +another_module+. The functions and relationships from the
|
15
|
+
# {BELParser::Language.default_specification default specification}
|
16
|
+
# are included.
|
17
|
+
#
|
18
|
+
# This method is called when {BEL::DSL} is included, as in:
|
19
|
+
#
|
20
|
+
# # calls this method
|
21
|
+
# include BEL::DSL
|
22
|
+
#
|
23
|
+
# # Can access namespace constants.
|
24
|
+
# HGNC
|
25
|
+
#
|
26
|
+
# # Create new terms.
|
27
|
+
# p(HGNC['AKT1'])
|
28
|
+
#
|
29
|
+
# # Create new statements.
|
30
|
+
# p(HGNC['AKT1']).increases bp(GOBP['apoptotic process'])
|
31
|
+
#
|
32
|
+
# @param [Module] another_module the module receiving DSL functionality
|
33
|
+
def self.included(another_module)
|
34
|
+
self.include_in(
|
35
|
+
another_module,
|
36
|
+
BELParser::Language.default_specification)
|
37
|
+
end
|
38
|
+
|
39
|
+
# Defines ruby methods for BEL functions and relationships on _object_. The
|
40
|
+
# functions and relationships from the provided _specification_ are used.
|
41
|
+
#
|
42
|
+
# @param [Object] object the object to include the DSL methods in
|
43
|
+
# @param [BELParser::Language::Specification] spec the BEL specification
|
44
|
+
def self.include_in(object, spec)
|
45
|
+
if [Class, Module].none? { |type| object.is_a?(type) }
|
46
|
+
raise(ArgumentError, "object: expected Class or Module, actual #{object}")
|
47
|
+
end
|
48
|
+
|
49
|
+
BELParser::Resources.included(object)
|
50
|
+
spec.functions.each do |function|
|
51
|
+
self.send(:_define_term_method, object, function.short, function, spec)
|
52
|
+
self.send(:_define_term_method, object, function.long, function, spec)
|
53
|
+
end
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
57
|
+
# @api private
|
58
|
+
def self._define_term_method(object, name, function, spec)
|
59
|
+
object.send(:define_method, name) do |*args|
|
60
|
+
object = BELParser::Expression::Model::Term.new(function, *args)
|
61
|
+
object_class = object.singleton_class
|
62
|
+
spec.relationships.each do |relationship|
|
63
|
+
object_class.send(:define_method, relationship.long) do |another|
|
64
|
+
s = BELParser::Expression::Model::Statement.new self
|
65
|
+
s.relationship = relationship
|
66
|
+
s.object = another
|
67
|
+
s
|
68
|
+
end
|
69
|
+
end
|
70
|
+
object
|
71
|
+
end
|
72
|
+
end
|
73
|
+
private_class_method :_define_term_method
|
74
|
+
end
|
75
|
+
end
|