bel_parser 1.0.0.alpha.44 → 1.0.0.alpha.45
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gemspec +1 -1
- data/VERSION +1 -1
- data/bin/bel2_validator +68 -12
- data/bin/bel_script_reader +56 -25
- data/lib/bel/translator/plugins/bel_script/reader.rb +2 -1
- data/lib/bel_parser/expression/validator.rb +7 -8
- data/lib/bel_parser/language/apply_namespace_encoding.rb +20 -23
- data/lib/bel_parser/language/expression_validator.rb +2 -2
- data/lib/bel_parser/parsers/ast/node.rb +35 -0
- data/lib/bel_parser/parsers/bel_script/define_annotation.rb +964 -808
- data/lib/bel_parser/parsers/bel_script/define_annotation.rl +24 -4
- data/lib/bel_parser/parsers/bel_script/define_namespace.rb +336 -300
- data/lib/bel_parser/parsers/bel_script/define_namespace.rl +15 -3
- data/lib/bel_parser/parsers/common/common.rl +1 -0
- data/lib/bel_parser/resource/resource_url_reader.rb +2 -2
- data/lib/bel_parser/resource.rb +50 -3
- data/lib/bel_parser/script/apply_resource_uri.rb +30 -0
- data/lib/bel_parser/script/nanopub_mapper.rb +9 -5
- data/lib/bel_parser/script/state/annotation_definition.rb +24 -9
- data/lib/bel_parser/script/state/namespace_definition.rb +22 -8
- data/lib/bel_parser/script/syntax/expression_validation.rb +6 -5
- data/lib/bel_parser/script/syntax/undefined_annotation_value.rb +14 -9
- data/lib/bel_parser/script/syntax/unresolvable_namespace.rb +14 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c22403d119fe61cf2f6171a1ed8edca537030623
|
4
|
+
data.tar.gz: 1334d29e2fd4c03b14853062a581c4a7e2b78381
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34c25add567566fef27c7e309a0bca529292e52e111fa02d98946c0960562f09a0700da777af1999bc5e4b5ed86ba533ba47a0e455ef2efb9417b38558f08d42
|
7
|
+
data.tar.gz: e14ce6412c8a18d579f72c766619430157e860bbe05c76c7e111f66cb16767457bd5e7eddc3064fcad1f81c944fcb93d7b5cdd6e011d9bf02eb1a61be316c06b
|
data/.gemspec
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.0.alpha.
|
1
|
+
1.0.0.alpha.45
|
data/bin/bel2_validator
CHANGED
@@ -2,13 +2,69 @@
|
|
2
2
|
$LOAD_PATH.unshift(
|
3
3
|
File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib'))
|
4
4
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
5
|
+
require 'optparse'
|
6
|
+
require 'bel_parser'
|
7
|
+
|
8
|
+
options = {
|
9
|
+
uri_reader: BELParser::Resource.default_uri_reader,
|
10
|
+
url_reader: BELParser::Resource.default_url_reader,
|
11
|
+
spec: BELParser::Language.specification(
|
12
|
+
BELParser::Language.latest_supported_version)
|
13
|
+
}
|
14
|
+
OptionParser.new do |opts|
|
15
|
+
opts.banner = <<-USAGE.gsub(/^ {4}/, '')
|
16
|
+
Validates BEL 2.0 expressions.
|
17
|
+
|
18
|
+
Read from a BEL file.
|
19
|
+
usage: #$PROGRAM_NAME --file [FILE]
|
20
|
+
|
21
|
+
Read from standard input.
|
22
|
+
usage: #$PROGRAM_NAME
|
9
23
|
USAGE
|
10
|
-
|
11
|
-
|
24
|
+
|
25
|
+
opts.on('-f', '--file FILE', 'BEL script file to read.') do |bel|
|
26
|
+
options[:file] = bel
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on(
|
30
|
+
'-v',
|
31
|
+
'--[no-]verbose',
|
32
|
+
'Enable verbose logging.') do |verbose|
|
33
|
+
options[:verbose] = verbose
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on(
|
37
|
+
'-s',
|
38
|
+
'--specification VERSION',
|
39
|
+
'BEL specification version (e.g. 1.0, 2.0).') do |spec|
|
40
|
+
unless BELParser::Language.defines_version?(spec)
|
41
|
+
$stderr.puts %(Invalid BEL specification "#{spec}")
|
42
|
+
exit 1
|
43
|
+
end
|
44
|
+
|
45
|
+
options[:spec] = BELParser::Language.specification(spec)
|
46
|
+
end
|
47
|
+
|
48
|
+
opts.on(
|
49
|
+
'-q',
|
50
|
+
'--sparql-endpoint URL',
|
51
|
+
'SPARQL endpoint URL containing BEL RDF resources.') do |sparql|
|
52
|
+
|
53
|
+
require 'bel_parser/resource/sparql_reader'
|
54
|
+
options[:uri_reader] = BELParser::Resource::SPARQLReader.new(sparql)
|
55
|
+
end
|
56
|
+
|
57
|
+
if RUBY_ENGINE =~ /^jruby/i
|
58
|
+
opts.on(
|
59
|
+
'-t',
|
60
|
+
'--read-jena-tdb DIRECTORY',
|
61
|
+
'Jena TDB directory containing BEL RDF resources.') do |tdb|
|
62
|
+
|
63
|
+
require 'bel_parser/resource/jena_tdb_reader'
|
64
|
+
options[:uri_reader] = BELParser::Resource::JenaTDBReader.new(tdb)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end.parse!
|
12
68
|
|
13
69
|
def syntax_results(results)
|
14
70
|
results.select do |res|
|
@@ -22,22 +78,22 @@ def semantics_results(results)
|
|
22
78
|
end
|
23
79
|
end
|
24
80
|
|
25
|
-
require 'bel_parser'
|
26
81
|
require 'bel_parser/expression/validator'
|
27
82
|
require 'bel_parser/resource/resource_url_reader'
|
28
83
|
|
29
|
-
|
30
|
-
|
84
|
+
uri_reader, url_reader = options.values_at(:uri_reader, :url_reader)
|
85
|
+
|
86
|
+
namespaces =
|
31
87
|
Hash[
|
32
88
|
ARGV.map do |ns|
|
33
89
|
prefix, identifier = ns.split('=')
|
34
|
-
dataset =
|
35
|
-
dataset ? [prefix, dataset] : nil
|
90
|
+
dataset = uri_reader.retrieve_resource(identifier)
|
91
|
+
dataset ? [prefix, [:uri, dataset]] : nil
|
36
92
|
end.compact
|
37
93
|
]
|
38
94
|
|
39
95
|
BELParser::Expression::Validator
|
40
|
-
.new(
|
96
|
+
.new(options[:spec], namespaces, uri_reader, url_reader)
|
41
97
|
.each($stdin) do |(line_number, line, ast, results)|
|
42
98
|
puts "#{line_number}: #{line}"
|
43
99
|
puts " AST Type: #{ast.type}"
|
data/bin/bel_script_reader
CHANGED
@@ -4,9 +4,10 @@ $LOAD_PATH.unshift(
|
|
4
4
|
|
5
5
|
require 'optparse'
|
6
6
|
require 'bel_parser'
|
7
|
-
require 'bel_parser/resource/resource_url_reader'
|
8
7
|
|
9
8
|
options = {
|
9
|
+
uri_reader: BELParser::Resource.default_uri_reader,
|
10
|
+
url_reader: BELParser::Resource.default_url_reader,
|
10
11
|
spec: BELParser::Language.specification(
|
11
12
|
BELParser::Language.latest_supported_version)
|
12
13
|
}
|
@@ -25,25 +26,43 @@ OptionParser.new do |opts|
|
|
25
26
|
options[:file] = bel
|
26
27
|
end
|
27
28
|
|
29
|
+
opts.on(
|
30
|
+
'-v',
|
31
|
+
'--[no-]verbose',
|
32
|
+
'Enable verbose logging.') do |verbose|
|
33
|
+
options[:verbose] = verbose
|
34
|
+
end
|
35
|
+
|
28
36
|
opts.on(
|
29
37
|
'-s',
|
30
38
|
'--specification VERSION',
|
31
|
-
'BEL specification version (e.g. 1.0, 2.0)') do |spec|
|
39
|
+
'BEL specification version (e.g. 1.0, 2.0).') do |spec|
|
40
|
+
unless BELParser::Language.defines_version?(spec)
|
41
|
+
$stderr.puts %(Invalid BEL specification "#{spec}")
|
42
|
+
exit 1
|
43
|
+
end
|
32
44
|
|
33
|
-
|
34
|
-
$stderr.puts %(Invalid BEL specification "#{spec}")
|
35
|
-
exit 1
|
45
|
+
options[:spec] = BELParser::Language.specification(spec)
|
36
46
|
end
|
37
47
|
|
38
|
-
options[:spec] = BELParser::Language.specification(spec)
|
39
|
-
end
|
40
|
-
|
41
48
|
opts.on(
|
42
|
-
'-
|
43
|
-
'--
|
44
|
-
'
|
49
|
+
'-q',
|
50
|
+
'--sparql-endpoint URL',
|
51
|
+
'SPARQL endpoint URL containing BEL RDF resources.') do |sparql|
|
45
52
|
|
46
|
-
|
53
|
+
require 'bel_parser/resource/sparql_reader'
|
54
|
+
options[:uri_reader] = BELParser::Resource::SPARQLReader.new(sparql)
|
55
|
+
end
|
56
|
+
|
57
|
+
if RUBY_ENGINE =~ /^jruby/i
|
58
|
+
opts.on(
|
59
|
+
'-t',
|
60
|
+
'--read-jena-tdb DIRECTORY',
|
61
|
+
'Jena TDB directory containing BEL RDF resources.') do |tdb|
|
62
|
+
|
63
|
+
require 'bel_parser/resource/jena_tdb_reader'
|
64
|
+
options[:uri_reader] = BELParser::Resource::JenaTDBReader.new(tdb)
|
65
|
+
end
|
47
66
|
end
|
48
67
|
end.parse!
|
49
68
|
|
@@ -55,17 +74,20 @@ io =
|
|
55
74
|
$stdin
|
56
75
|
end
|
57
76
|
|
58
|
-
|
77
|
+
uri_reader = options[:uri_reader]
|
78
|
+
url_reader = options[:url_reader]
|
79
|
+
|
59
80
|
namespaces = Hash[
|
60
81
|
ARGV.map do |ns|
|
61
82
|
prefix, identifier = ns.split('=')
|
62
|
-
dataset =
|
83
|
+
dataset = uri_reader.retrieve_resource(identifier)
|
63
84
|
dataset ? [prefix, dataset] : nil
|
64
85
|
end.compact
|
65
86
|
]
|
66
87
|
|
67
88
|
initial_state = {
|
68
|
-
|
89
|
+
uri_reader: uri_reader,
|
90
|
+
url_reader: url_reader,
|
69
91
|
specification: spec,
|
70
92
|
namespace_definitions: namespaces
|
71
93
|
}
|
@@ -80,7 +102,8 @@ module BELParser
|
|
80
102
|
SYN_WARN = BELParser::Language::Syntax::SyntaxWarning
|
81
103
|
SEM_WARN = BELParser::Language::Semantics::SemanticsWarning
|
82
104
|
|
83
|
-
def initialize(initial_state, io)
|
105
|
+
def initialize(initial_state, io, verbose)
|
106
|
+
@verbose = verbose
|
84
107
|
@validator =
|
85
108
|
Validator.new(
|
86
109
|
StateAggregator.new(
|
@@ -96,7 +119,7 @@ module BELParser
|
|
96
119
|
select(syntax_errors, SYN_WARN) +
|
97
120
|
select(syntax_errors, SEM_WARN)
|
98
121
|
|
99
|
-
report(line_number, ast_node, errors, warnings)
|
122
|
+
report(line_number, line, ast_node, errors, warnings)
|
100
123
|
|
101
124
|
unless errors.empty?
|
102
125
|
puts "Exiting due to error on line #{line_number}: #{line}"
|
@@ -111,22 +134,30 @@ module BELParser
|
|
111
134
|
list.select { |item| item.is_a?(cls) }
|
112
135
|
end
|
113
136
|
|
114
|
-
def report(line_number, ast, errors, warnings)
|
137
|
+
def report(line_number, line, ast, errors, warnings)
|
115
138
|
log = !errors.empty? || !warnings.empty?
|
116
139
|
if log
|
117
140
|
puts "On line #{line_number} for #{ast.type}"
|
118
|
-
puts
|
119
|
-
|
120
|
-
|
141
|
+
puts ' Line:'
|
142
|
+
puts " #{line}"
|
143
|
+
unless errors.empty?
|
144
|
+
puts ' Errors:'
|
145
|
+
errors.each do |err|
|
146
|
+
puts " #{err}"
|
147
|
+
end
|
121
148
|
end
|
122
|
-
|
123
|
-
|
124
|
-
|
149
|
+
unless warnings.empty?
|
150
|
+
puts ' Warnings:'
|
151
|
+
warnings.each do |warn|
|
152
|
+
puts " #{warn}"
|
153
|
+
end
|
125
154
|
end
|
155
|
+
else
|
156
|
+
puts "Line OK: #{line}" if @verbose
|
126
157
|
end
|
127
158
|
end
|
128
159
|
end
|
129
160
|
end
|
130
161
|
end
|
131
162
|
|
132
|
-
BELParser::Script::Reader.new(initial_state, io).read
|
163
|
+
BELParser::Script::Reader.new(initial_state, io, options[:verbose]).read
|
@@ -12,7 +12,8 @@ module BEL::Translator::Plugins
|
|
12
12
|
def initialize(io, options = {})
|
13
13
|
@io = io
|
14
14
|
@state = {
|
15
|
-
|
15
|
+
uri_reader: BELParser::Resource.default_uri_reader,
|
16
|
+
url_reader: BELParser::Resource.default_url_reader,
|
16
17
|
specification: BELParser::Language.specification('2.0'),
|
17
18
|
namespace_definitions: {}
|
18
19
|
}
|
@@ -19,10 +19,10 @@ module BELParser
|
|
19
19
|
:nested_statement
|
20
20
|
]
|
21
21
|
|
22
|
-
def initialize(
|
23
|
-
@spec =
|
22
|
+
def initialize(specification, namespaces, uri_reader, url_reader)
|
23
|
+
@spec = specification
|
24
24
|
@validator = BELParser::Language::ExpressionValidator.new(
|
25
|
-
@spec, namespaces,
|
25
|
+
@spec, namespaces, uri_reader, url_reader)
|
26
26
|
end
|
27
27
|
|
28
28
|
def each(io)
|
@@ -52,19 +52,18 @@ if __FILE__ == $PROGRAM_NAME
|
|
52
52
|
exit 1
|
53
53
|
end
|
54
54
|
|
55
|
-
|
56
|
-
|
57
|
-
resource_reader = BELParser::Resource::ResourceURLReader.new
|
55
|
+
uri_reader = BELParser::Resource.default_uri_reader
|
56
|
+
url_reader = BELParser::Resource.default_url_reader
|
58
57
|
namespaces =
|
59
58
|
Hash[
|
60
59
|
ARGV[1..-1]
|
61
60
|
.map do |ns|
|
62
61
|
prefix, identifier = ns.split('=')
|
63
|
-
[prefix,
|
62
|
+
[prefix, uri_reader.retrieve_resource(identifier)]
|
64
63
|
end
|
65
64
|
]
|
66
65
|
BELParser::Expression::Validator
|
67
|
-
.new(ARGV.first, namespaces,
|
66
|
+
.new(ARGV.first, namespaces, uri_reader, url_reader)
|
68
67
|
.each($stdin) do |(line_number, line, ast, results)|
|
69
68
|
results.select { |res| res.is_a? BELParser::Language::Syntax::SyntaxError }
|
70
69
|
puts "#{line_number}: #{line}"
|
@@ -1,17 +1,15 @@
|
|
1
|
-
require 'bel_parser/quoting'
|
2
|
-
|
3
1
|
module BELParser
|
4
2
|
module Language
|
5
3
|
# ApplyNamespaceEncoding applies _namespace_ and _encoding_ properties to
|
6
4
|
# {BELParser::Parsers::AST::Parameter} child nodes.
|
7
5
|
class ApplyNamespaceEncoding
|
8
6
|
include AST::Processor::Mixin
|
9
|
-
include BELParser::Quoting
|
10
7
|
|
11
|
-
def initialize(language_spec, namespace_hash,
|
12
|
-
@language_spec
|
13
|
-
@namespace_hash
|
14
|
-
@
|
8
|
+
def initialize(language_spec, namespace_hash, uri_reader, url_reader)
|
9
|
+
@language_spec = language_spec
|
10
|
+
@namespace_hash = namespace_hash
|
11
|
+
@uri_reader = uri_reader
|
12
|
+
@url_reader = url_reader
|
15
13
|
end
|
16
14
|
|
17
15
|
def on_observed_term(observed_term_node)
|
@@ -51,8 +49,9 @@ module BELParser
|
|
51
49
|
end
|
52
50
|
|
53
51
|
def on_parameter(parameter_node)
|
54
|
-
@
|
55
|
-
@
|
52
|
+
@type = nil
|
53
|
+
@dataset = nil
|
54
|
+
@prefix = nil
|
56
55
|
process(parameter_node.prefix)
|
57
56
|
process(parameter_node.value)
|
58
57
|
end
|
@@ -60,28 +59,26 @@ module BELParser
|
|
60
59
|
def on_prefix(prefix_node)
|
61
60
|
return prefix_node unless prefix_node.identifier
|
62
61
|
|
63
|
-
@prefix
|
64
|
-
dataset
|
65
|
-
return prefix_node unless dataset
|
66
|
-
|
67
|
-
@resolved_dataset = dataset
|
68
|
-
prefix_node.namespace = dataset
|
62
|
+
@prefix = prefix_node.identifier.string_literal
|
63
|
+
@type, @dataset = @namespace_hash[@prefix]
|
64
|
+
return prefix_node unless @dataset
|
69
65
|
|
66
|
+
prefix_node.namespace = @dataset
|
70
67
|
prefix_node
|
71
68
|
end
|
72
69
|
|
73
70
|
def on_value(value_node)
|
74
|
-
return value_node unless @
|
75
|
-
value_node.namespace = @
|
76
|
-
identifier = @
|
77
|
-
value_literal =
|
71
|
+
return value_node unless @dataset
|
72
|
+
value_node.namespace = @dataset
|
73
|
+
identifier = @dataset.identifier
|
74
|
+
value_literal = value_node.children[0].string_literal
|
78
75
|
|
79
|
-
|
80
|
-
|
81
|
-
.retrieve_value_from_resource(identifier, value_literal)
|
76
|
+
reader = @type == :uri ? @uri_reader : @url_reader
|
77
|
+
values = reader.retrieve_value_from_resource(identifier, value_literal)
|
82
78
|
|
83
79
|
value_node.prefix = @prefix
|
84
|
-
if
|
80
|
+
if values
|
81
|
+
value = values.first
|
85
82
|
value_node.encoding =
|
86
83
|
value
|
87
84
|
.encodings
|
@@ -8,13 +8,13 @@ module BELParser
|
|
8
8
|
# when supplied a {BELParser::Language::Specification} and Hash of
|
9
9
|
# namespaces.
|
10
10
|
class ExpressionValidator
|
11
|
-
def initialize(spec, namespaces,
|
11
|
+
def initialize(spec, namespaces, uri_reader, url_reader)
|
12
12
|
@spec = spec
|
13
13
|
@namespaces = namespaces || {}
|
14
14
|
@syntax_functions = Syntax.syntax_functions
|
15
15
|
@semantics_functions = Semantics.semantics_functions
|
16
16
|
@transform =
|
17
|
-
ApplyNamespaceEncoding.new(@spec, @namespaces,
|
17
|
+
ApplyNamespaceEncoding.new(@spec, @namespaces, uri_reader, url_reader)
|
18
18
|
end
|
19
19
|
|
20
20
|
# Validate the syntax and semantics of
|
@@ -266,6 +266,9 @@ module BELParser
|
|
266
266
|
def domain
|
267
267
|
children[1]
|
268
268
|
end
|
269
|
+
|
270
|
+
# Get/Set the uri property.
|
271
|
+
attr_accessor :uri
|
269
272
|
end
|
270
273
|
|
271
274
|
# AST node representing the function of a BEL term.
|
@@ -317,6 +320,9 @@ module BELParser
|
|
317
320
|
def domain
|
318
321
|
children[1]
|
319
322
|
end
|
323
|
+
|
324
|
+
# Get/Set the uri property.
|
325
|
+
attr_accessor :uri
|
320
326
|
end
|
321
327
|
|
322
328
|
# AST node representing a keyword (e.g. definitions).
|
@@ -363,6 +369,11 @@ module BELParser
|
|
363
369
|
children[0] && children[0].is_a?(Pattern)
|
364
370
|
end
|
365
371
|
|
372
|
+
# Determine if this is a URI domain.
|
373
|
+
def uri?
|
374
|
+
children[0] && children[0].is_a?(Uri)
|
375
|
+
end
|
376
|
+
|
366
377
|
# Determine if this is a URL domain.
|
367
378
|
def url?
|
368
379
|
children[0] && children[0].is_a?(Url)
|
@@ -394,6 +405,26 @@ module BELParser
|
|
394
405
|
end
|
395
406
|
end
|
396
407
|
|
408
|
+
# AST node representing a URI.
|
409
|
+
class Uri < Node
|
410
|
+
# AST node type
|
411
|
+
@ast_type = :uri
|
412
|
+
# Urls have semantic meaning
|
413
|
+
@has_semantics = true
|
414
|
+
|
415
|
+
# New Uri AST node.
|
416
|
+
#
|
417
|
+
# @see Node#initialize Node class for basic properties
|
418
|
+
def initialize(children = [], properties = {})
|
419
|
+
super(Uri.ast_type, children, properties)
|
420
|
+
end
|
421
|
+
|
422
|
+
# Get the uri's string.
|
423
|
+
def string
|
424
|
+
children[0]
|
425
|
+
end
|
426
|
+
end
|
427
|
+
|
397
428
|
# AST node representing a Pattern.
|
398
429
|
class Pattern < Node
|
399
430
|
# AST node type
|
@@ -1029,6 +1060,10 @@ module BELParser
|
|
1029
1060
|
Url.new(children, props)
|
1030
1061
|
end
|
1031
1062
|
|
1063
|
+
def uri(*children, **props)
|
1064
|
+
Uri.new(children, props)
|
1065
|
+
end
|
1066
|
+
|
1032
1067
|
def pattern(*children, **props)
|
1033
1068
|
Pattern.new(children, props)
|
1034
1069
|
end
|