bel_parser 1.0.0.alpha.26 → 1.0.0.alpha.27
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/lib/bel_parser/expression/filter.rb +31 -0
- data/lib/bel_parser/expression/parser.rb +44 -17
- data/lib/bel_parser/expression.rb +3 -0
- data/lib/bel_parser/resource/resource_url_reader.rb +13 -5
- data/lib/bel_parser.rb +3 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 14fda40968c24d90cd1cfa3ea7d07709f6319ab0
|
4
|
+
data.tar.gz: 1285d3eb7fbfdf1ba027557002531d60581bcd1d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c8050d7c6c61eb227b44818518716df1ba9189d848650b7a37f5f8a8eb26b664f0dbec0b6ad3448006d73c031897e4effca36e8ca2f4b28f43a9776aac04ba3f
|
7
|
+
data.tar.gz: bc3a9ba66774a2dedc2ccb1fad3a3e3abce361444587cc16d404aded69a2fba4bf46ee56707844748a16b5e1f11b4c21a9883f7363275c3f4a447269a665f43d
|
data/.gemspec
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.0.alpha.
|
1
|
+
1.0.0.alpha.27
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require_relative '../ast_filter'
|
2
|
+
|
3
|
+
module BELParser
|
4
|
+
module Expression
|
5
|
+
# Filter will enumerate {BELParser::Parsers::AST::Node AST nodes} that make
|
6
|
+
# up BEL expressions. It selects the relevant nodes
|
7
|
+
# from an {BELParser::Parsers::AST::Node AST node} enumerator.
|
8
|
+
class Filter
|
9
|
+
# Represents BEL expression node types.
|
10
|
+
TYPES = [
|
11
|
+
:simple_statement,
|
12
|
+
:observed_term,
|
13
|
+
:nested_statement,
|
14
|
+
:term,
|
15
|
+
:parameter
|
16
|
+
]
|
17
|
+
|
18
|
+
def initialize(ast_enum)
|
19
|
+
@ast_filter = BELParser::ASTFilter.new(ast_enum, *TYPES)
|
20
|
+
end
|
21
|
+
|
22
|
+
def each(&block)
|
23
|
+
if block_given?
|
24
|
+
@ast_filter.each(&block)
|
25
|
+
else
|
26
|
+
enum_for(:each)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -1,34 +1,61 @@
|
|
1
|
-
require_relative '../ast_filter'
|
2
1
|
require_relative '../ast_generator'
|
3
2
|
require_relative '../parsers/common'
|
4
3
|
require_relative '../parsers/expression'
|
5
|
-
require_relative '../mixin/line_mapping'
|
6
4
|
|
7
5
|
module BELParser
|
8
6
|
module Expression
|
9
7
|
# Parser for BEL Expression.
|
10
8
|
class Parser
|
11
|
-
|
12
|
-
|
9
|
+
def parse(input, &block)
|
10
|
+
case input
|
11
|
+
when String
|
12
|
+
parse_string(input, &block)
|
13
|
+
when Array
|
14
|
+
parse_array(input, &block)
|
15
|
+
when IO, StringIO
|
16
|
+
parse_io(input, &block)
|
17
|
+
else
|
18
|
+
raise ArgumentError,
|
19
|
+
%(expected "input" to be one of String, Array, IO: #{input.class})
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
protected
|
13
24
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
25
|
+
def parse_string(string)
|
26
|
+
filter = Filter.new(
|
27
|
+
BELParser::ASTGenerator.new(StringIO.new(string)))
|
28
|
+
num, line, results = filter.each.first
|
29
|
+
if block_given?
|
30
|
+
yield results
|
31
|
+
nil
|
32
|
+
else
|
33
|
+
results
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def parse_array(array)
|
38
|
+
if block_given?
|
39
|
+
array.each do |expression|
|
40
|
+
yield parse_string(expression.to_s)
|
41
|
+
end
|
42
|
+
nil
|
43
|
+
else
|
44
|
+
array.map do |expression|
|
45
|
+
parse_string(expression.to_s)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
21
49
|
|
22
|
-
def
|
50
|
+
def parse_io(io)
|
23
51
|
if block_given?
|
24
|
-
filter = BELParser::
|
25
|
-
|
26
|
-
*TYPES)
|
27
|
-
filter.each do |results|
|
52
|
+
filter = Filter.new(BELParser::ASTGenerator.new(io))
|
53
|
+
filter.each do |(num, line, results)|
|
28
54
|
yield results
|
29
55
|
end
|
56
|
+
nil
|
30
57
|
else
|
31
|
-
enum_for(:
|
58
|
+
enum_for(:parse_io, io)
|
32
59
|
end
|
33
60
|
end
|
34
61
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
require 'base64'
|
2
2
|
require 'digest'
|
3
|
-
require '
|
3
|
+
require 'dbm'
|
4
4
|
require 'net/http'
|
5
5
|
require 'tempfile'
|
6
6
|
require 'uri'
|
@@ -12,26 +12,34 @@ module BELParser
|
|
12
12
|
module Resource
|
13
13
|
# ResourceURLReader retrieves {Dataset datasets} and {Value values} from
|
14
14
|
# Annotation (i.e. belanno extension) and Namespace (i.e. belns extension)
|
15
|
-
# files. Value and encoding are stored in
|
15
|
+
# files. Value and encoding are stored in DBM database files to reduce the
|
16
16
|
# runtime memory usage (22 resources loaded, totaling 100MB memory usage).
|
17
17
|
#
|
18
18
|
# Only supports resource identifiers with an HTTP or HTTPS scheme.
|
19
19
|
class ResourceURLReader
|
20
20
|
include Reader
|
21
21
|
|
22
|
-
# Class ivars for tracking open {
|
22
|
+
# Class ivars for tracking open {DBM} databases.
|
23
23
|
@dataset_file = nil
|
24
24
|
@resource_files = {}
|
25
25
|
|
26
26
|
DEFAULT_RESOURCE_VALUE_DELIMITER = '|'
|
27
27
|
private_constant :DEFAULT_RESOURCE_VALUE_DELIMITER
|
28
28
|
|
29
|
+
# Initializes a {ResourceURLReader}.
|
30
|
+
#
|
31
|
+
# @param [Boolean] reuse_database_files specify +true+ to reuse database
|
32
|
+
# files; +false+ to create new database files (default)
|
29
33
|
def initialize(reuse_database_files = false)
|
30
34
|
@resources = {}
|
31
35
|
@datasets = ResourceURLReader.open_datasets_file
|
32
36
|
@reuse = reuse_database_files
|
33
37
|
end
|
34
38
|
|
39
|
+
# Retrieve the resource identified by +resource_identifier+.
|
40
|
+
#
|
41
|
+
# @param [String] resource_identifier the resource identifier
|
42
|
+
# @return [FileResource] the file resource
|
35
43
|
def retrieve_resource(resource_identifier)
|
36
44
|
read_resource(resource_identifier)[:dataset]
|
37
45
|
end
|
@@ -134,11 +142,11 @@ module BELParser
|
|
134
142
|
end
|
135
143
|
|
136
144
|
def self.open_datasets_file
|
137
|
-
@dataset_file ||= ::
|
145
|
+
@dataset_file ||= ::DBM.open(_temporary_datasets_file)
|
138
146
|
end
|
139
147
|
|
140
148
|
def self.open_resource_file(url)
|
141
|
-
@resource_files[url] ||= ::
|
149
|
+
@resource_files[url] ||= ::DBM.open(_temporary_resource_file(url))
|
142
150
|
end
|
143
151
|
|
144
152
|
def self._temporary_datasets_file
|
data/lib/bel_parser.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bel_parser
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.alpha.
|
4
|
+
version: 1.0.0.alpha.27
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Bargnesi
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-05-
|
12
|
+
date: 2016-05-11 00:00:00.000000000 Z
|
13
13
|
dependencies: []
|
14
14
|
description: Implements language versions 1.0 and 2.0.
|
15
15
|
email: abargnesi@selventa.com
|
@@ -37,6 +37,8 @@ files:
|
|
37
37
|
- lib/bel_parser.rb
|
38
38
|
- lib/bel_parser/ast_filter.rb
|
39
39
|
- lib/bel_parser/ast_generator.rb
|
40
|
+
- lib/bel_parser/expression.rb
|
41
|
+
- lib/bel_parser/expression/filter.rb
|
40
42
|
- lib/bel_parser/expression/parser.rb
|
41
43
|
- lib/bel_parser/expression/validator.rb
|
42
44
|
- lib/bel_parser/language.rb
|