bel_parser 1.0.0.alpha.47-java → 1.0.0.alpha.48-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/bel_parser/expression/model/namespace.rb +60 -20
- data/lib/bel_parser/expression/model/parameter.rb +30 -36
- data/lib/bel_parser/expression/model/statement.rb +28 -3
- data/lib/bel_parser/expression/model/term.rb +46 -7
- data/lib/bel_parser/expression/parser.rb +15 -3
- data/lib/bel_parser/expression/validator.rb +13 -15
- data/lib/bel_parser/language/apply_namespace_encoding.rb +14 -18
- data/lib/bel_parser/language/expression_validator.rb +398 -23
- data/lib/bel_parser/language/semantics_ast_warnings.rb +1 -1
- data/lib/bel_parser/language/specification.rb +4 -0
- data/lib/bel_parser/language/syntax/undefined_namespace.rb +1 -1
- data/lib/bel_parser/language/syntax/undefined_namespace_value.rb +2 -1
- data/lib/bel_parser/language/version2_0/functions/activity.rb +2 -2
- data/lib/bel_parser/language/version2_0/functions/biological_process.rb +1 -2
- data/lib/bel_parser/language/version2_0/functions/cell_secretion.rb +2 -2
- data/lib/bel_parser/language/version2_0/functions/cell_surface_expression.rb +2 -2
- data/lib/bel_parser/language/version2_0/functions/complex_abundance.rb +1 -1
- data/lib/bel_parser/language/version2_0/functions/composite_abundance.rb +1 -1
- data/lib/bel_parser/language/version2_0/functions/degradation.rb +2 -2
- data/lib/bel_parser/language/version2_0/functions/fragment.rb +1 -1
- data/lib/bel_parser/language/version2_0/functions/from_location.rb +1 -1
- data/lib/bel_parser/language/version2_0/functions/fusion.rb +1 -1
- data/lib/bel_parser/language/version2_0/functions/micro_rna_abundance.rb +1 -1
- data/lib/bel_parser/language/version2_0/functions/molecular_activity.rb +1 -1
- data/lib/bel_parser/language/version2_0/functions/protein_modification.rb +1 -1
- data/lib/bel_parser/language/version2_0/functions/reaction.rb +1 -1
- data/lib/bel_parser/language/version2_0/functions/to_location.rb +1 -1
- data/lib/bel_parser/language/version2_0/functions/translocation.rb +1 -1
- data/lib/bel_parser/language/version2_0/functions/variant.rb +1 -1
- data/lib/bel_parser/resource.rb +8 -6
- data/lib/bel_parser/resource/concept_scheme.rb +8 -0
- data/lib/bel_parser/resource/dataset.rb +24 -0
- data/lib/bel_parser/resource/file_resource.rb +8 -0
- data/lib/bel_parser/resource/file_resource_value.rb +1 -0
- data/lib/bel_parser/resource/sparql_reader.rb +3 -1
- data/lib/bel_parser/resource/value.rb +20 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea63f6fcf85946d6713d061c08d7413da2f35300
|
4
|
+
data.tar.gz: 884d2ad127e8a8f6b4f6ce84519eb432605c39a9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d93b622bc38d63de8f7a13c77a6f871ea84635014b6ea8db6e513e65db5df11f0da8f6cb02f937e96b0a86c5377490bf676cba0c1419682f1ab5fbdf0fc97a64
|
7
|
+
data.tar.gz: 3b10d096fb15423b9419714dbec613fec3e839c930e89ebec940dc633ba1149362913450725d198edf09786bfaaf6ce3c225c7662b4ebb901ee6c1e95928b620
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.0.alpha.
|
1
|
+
1.0.0.alpha.48
|
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'bel_parser/quoting'
|
2
1
|
require 'bel_parser/resource'
|
3
2
|
|
4
3
|
module BELParser
|
@@ -8,8 +7,6 @@ module BELParser
|
|
8
7
|
# identify parameter values like genes (e.g. _AKT1_),
|
9
8
|
# diseases (e.g. _hypertropia_), and processes (e.g. _anaphase_).
|
10
9
|
class Namespace
|
11
|
-
include Enumerable
|
12
|
-
|
13
10
|
attr_accessor :keyword
|
14
11
|
attr_accessor :uri
|
15
12
|
attr_accessor :url
|
@@ -23,11 +20,11 @@ module BELParser
|
|
23
20
|
@url = url
|
24
21
|
|
25
22
|
# configure reader for URIs (RDF).
|
26
|
-
@uri_reader = options.fetch(:uri_reader,
|
23
|
+
@uri_reader = options.fetch(:uri_reader, BELParser::Resource.default_uri_reader)
|
27
24
|
BELParser::Resource::Reader.assert_reader(@uri_reader, 'uri_reader')
|
28
25
|
|
29
26
|
# configure reader for URLs (Resource files).
|
30
|
-
@url_reader = options.fetch(:url_reader,
|
27
|
+
@url_reader = options.fetch(:url_reader, BELParser::Resource.default_url_reader)
|
31
28
|
BELParser::Resource::Reader.assert_reader(@url_reader, 'url_reader')
|
32
29
|
end
|
33
30
|
|
@@ -47,13 +44,33 @@ module BELParser
|
|
47
44
|
!@url.nil?
|
48
45
|
end
|
49
46
|
|
47
|
+
def include?(value)
|
48
|
+
resolved_value =
|
49
|
+
if uri? && @uri_reader
|
50
|
+
@uri_reader.retrieve_value_from_resource(@uri, value)
|
51
|
+
elsif url? && @url_reader
|
52
|
+
@url_reader.retrieve_value_from_resource(@url, value)
|
53
|
+
else
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
!resolved_value.nil?
|
57
|
+
end
|
58
|
+
|
50
59
|
def [](value)
|
51
|
-
|
52
|
-
@uri_reader
|
53
|
-
|
54
|
-
@url_reader
|
60
|
+
resolved_value =
|
61
|
+
if uri? && @uri_reader
|
62
|
+
@uri_reader.retrieve_value_from_resource(@uri, value)
|
63
|
+
elsif url? && @url_reader
|
64
|
+
@url_reader.retrieve_value_from_resource(@url, value)
|
65
|
+
else
|
66
|
+
nil
|
67
|
+
end
|
68
|
+
|
69
|
+
if resolved_value
|
70
|
+
value = resolved_value.first
|
71
|
+
Parameter.new(self, value.name, value.encodings)
|
55
72
|
else
|
56
|
-
nil
|
73
|
+
Parameter.new(self, value, nil)
|
57
74
|
end
|
58
75
|
end
|
59
76
|
|
@@ -68,7 +85,7 @@ module BELParser
|
|
68
85
|
[]
|
69
86
|
end
|
70
87
|
values.each do |value|
|
71
|
-
yield value
|
88
|
+
yield Parameter.new(self, value.name, value.encodings)
|
72
89
|
end
|
73
90
|
else
|
74
91
|
to_enum(:each)
|
@@ -96,15 +113,38 @@ module BELParser
|
|
96
113
|
end
|
97
114
|
|
98
115
|
module Converters
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
116
|
+
def ast_to_namespace(ast, namespace_hash = {})
|
117
|
+
return nil if ast.nil?
|
118
|
+
|
119
|
+
case ast
|
120
|
+
when BELParser::Parsers::AST::Prefix
|
121
|
+
if ast.namespace
|
122
|
+
dataset = ast.namespace
|
123
|
+
case
|
124
|
+
when dataset.uri?
|
125
|
+
Namespace.new(dataset.keyword, dataset.identifier, nil)
|
126
|
+
when dataset.url?
|
127
|
+
Namespace.new(dataset.keyword, nil, dataset.identifier)
|
128
|
+
else
|
129
|
+
Namespace.new(dataset.keyword, nil, nil)
|
130
|
+
end
|
131
|
+
else
|
132
|
+
return nil unless ast.identifier
|
133
|
+
prefix_s = ast.identifier.string_literal
|
134
|
+
namespace_hash[prefix_s]
|
135
|
+
end
|
136
|
+
when BELParser::Parsers::AST::NamespaceDefinition
|
137
|
+
keyword, domain = ast.children
|
138
|
+
keyword_s = keyword.identifier.string_literal
|
139
|
+
case
|
140
|
+
when domain.uri?
|
141
|
+
uri = domain.child.string_literal
|
142
|
+
Namespace.new(keyword_s, uri, nil)
|
143
|
+
when domain.url?
|
144
|
+
url = domain.child.string_literal
|
145
|
+
Namespace.new(keyword_s, ast.uri, url)
|
146
|
+
end
|
147
|
+
end
|
108
148
|
end
|
109
149
|
end
|
110
150
|
end
|
@@ -8,45 +8,33 @@ module BELParser
|
|
8
8
|
include BELParser::Quoting
|
9
9
|
include Comparable
|
10
10
|
|
11
|
-
attr_reader :namespace, :value
|
11
|
+
attr_reader :namespace, :value, :encoding
|
12
12
|
|
13
|
-
def initialize(namespace, value)
|
14
|
-
|
15
|
-
|
16
|
-
raise(
|
17
|
-
ArgumentError,
|
18
|
-
"namespace: expected nil or Namespace, actual #{namespace.class}")
|
19
|
-
end
|
13
|
+
def initialize(namespace, value, encoding = nil)
|
14
|
+
assert_namespace_type(namespace)
|
15
|
+
assert_value_type(value)
|
20
16
|
@namespace = namespace
|
21
17
|
@value = value
|
18
|
+
@encoding = encoding
|
22
19
|
end
|
23
20
|
|
24
21
|
def namespace=(namespace)
|
25
|
-
|
26
|
-
raise(
|
27
|
-
ArgumentError,
|
28
|
-
"namespace: expected nil or Namespace, actual #{namespace.class}")
|
29
|
-
end
|
30
|
-
|
22
|
+
assert_namespace_type(namespace)
|
31
23
|
@namespace = namespace
|
32
24
|
end
|
33
25
|
|
34
26
|
def value=(value)
|
35
|
-
|
36
|
-
|
27
|
+
assert_value_type(value)
|
37
28
|
@value = value
|
38
29
|
end
|
39
30
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
nsv.first.encodings
|
31
|
+
def valid?
|
32
|
+
return true if @namespace.nil?
|
33
|
+
@namespace.include?(@value)
|
44
34
|
end
|
45
35
|
|
46
|
-
def
|
47
|
-
|
48
|
-
return true unless @namespace
|
49
|
-
!@namespace[@value].nil?
|
36
|
+
def invalid?
|
37
|
+
!valid?
|
50
38
|
end
|
51
39
|
|
52
40
|
def <=>(other)
|
@@ -76,24 +64,30 @@ module BELParser
|
|
76
64
|
end
|
77
65
|
%Q{#{prefix}#{quote_if_needed(@value)}}
|
78
66
|
end
|
67
|
+
|
68
|
+
private
|
69
|
+
|
70
|
+
def assert_namespace_type(namespace)
|
71
|
+
unless namespace.nil? || namespace.is_a?(Namespace)
|
72
|
+
msg = "namespace: expected nil or Namespace, actual #{namespace.class}"
|
73
|
+
raise(ArgumentError, msg)
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def assert_value_type(value)
|
78
|
+
unless value.is_a?(String)
|
79
|
+
msg = "value: expected String, actual #{value.class}"
|
80
|
+
raise(ArgumentError, msg)
|
81
|
+
end
|
82
|
+
end
|
79
83
|
end
|
80
84
|
|
81
85
|
module Converters
|
82
|
-
include BELParser::Quoting
|
83
|
-
|
84
86
|
def ast_to_parameter(ast, namespace_hash = {})
|
85
87
|
return nil if ast.nil? ||
|
86
88
|
!ast.is_a?(BELParser::Parsers::AST::Parameter)
|
87
|
-
|
88
|
-
namespace
|
89
|
-
if prefix.identifier
|
90
|
-
namespace_hash[prefix.identifier.string_literal]
|
91
|
-
else
|
92
|
-
nil
|
93
|
-
end
|
94
|
-
Parameter.new(
|
95
|
-
namespace,
|
96
|
-
value.children[0].string_literal)
|
89
|
+
namespace = ast_to_namespace(ast.prefix, namespace_hash)
|
90
|
+
namespace[ast.value.children[0].string_literal]
|
97
91
|
end
|
98
92
|
end
|
99
93
|
end
|
@@ -25,8 +25,12 @@ module BELParser
|
|
25
25
|
# @param [Term, Statement] object
|
26
26
|
# @param [String] comment
|
27
27
|
def initialize(subject, relationship = nil, object = nil, comment = nil)
|
28
|
-
|
29
|
-
|
28
|
+
if subject.nil? || !subject.is_a?(Term)
|
29
|
+
raise(
|
30
|
+
ArgumentError,
|
31
|
+
"subject: expected Term, actual #{subject.class}")
|
32
|
+
end
|
33
|
+
@subject = subject
|
30
34
|
|
31
35
|
unless relationship.nil? || relationship.is_a?(BELParser::Language::Relationship)
|
32
36
|
raise(
|
@@ -68,8 +72,29 @@ module BELParser
|
|
68
72
|
@object && @object.is_a?(Statement)
|
69
73
|
end
|
70
74
|
|
75
|
+
def namespaces
|
76
|
+
ns = @subject.namespaces
|
77
|
+
ns.concat(@object.namespaces) unless @object.nil?
|
78
|
+
ns
|
79
|
+
end
|
80
|
+
|
81
|
+
def validation(
|
82
|
+
spec = BELParser::Language.latest_supported_specification,
|
83
|
+
uri_reader = BELParser::Resource.default_uri_reader,
|
84
|
+
url_reader = BELParser::Resource.default_url_reader)
|
85
|
+
|
86
|
+
validator =
|
87
|
+
BELParser::Expression::Validator.new(
|
88
|
+
spec,
|
89
|
+
Hash[namespaces.map { |ns| [ns.keyword, ns] }],
|
90
|
+
uri_reader,
|
91
|
+
url_reader)
|
92
|
+
_, _, _, result = validator.each(StringIO.new("#{to_s}\n")).first
|
93
|
+
result
|
94
|
+
end
|
95
|
+
|
71
96
|
def valid?
|
72
|
-
|
97
|
+
@subject.valid? && @object.valid?
|
73
98
|
end
|
74
99
|
|
75
100
|
def hash
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require_relative '../validator'
|
2
|
+
|
1
3
|
module BELParser
|
2
4
|
module Expression
|
3
5
|
module Model
|
@@ -17,7 +19,7 @@ module BELParser
|
|
17
19
|
ArgumentError,
|
18
20
|
%(function: expected Function, actual #{function.class}))
|
19
21
|
end
|
20
|
-
@function
|
22
|
+
@function = function
|
21
23
|
end
|
22
24
|
|
23
25
|
def arguments=(*args)
|
@@ -25,7 +27,7 @@ module BELParser
|
|
25
27
|
invalid = args.any?(&method(:invalid_argument?))
|
26
28
|
raise(
|
27
29
|
ArgumentError,
|
28
|
-
|
30
|
+
"args: expected Parameter or Term objects") if invalid
|
29
31
|
|
30
32
|
@arguments = args
|
31
33
|
end
|
@@ -33,12 +35,50 @@ module BELParser
|
|
33
35
|
def <<(arg)
|
34
36
|
raise(
|
35
37
|
ArgumentError,
|
36
|
-
'
|
38
|
+
'arg: expected Parameter or Term') if invalid_argument?(arg)
|
37
39
|
@arguments << item
|
38
40
|
end
|
39
41
|
|
40
|
-
def
|
41
|
-
|
42
|
+
def namespaces
|
43
|
+
@arguments.flat_map do |arg|
|
44
|
+
case arg
|
45
|
+
when Term
|
46
|
+
arg.namespaces
|
47
|
+
when Parameter
|
48
|
+
arg.namespace
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def validation(
|
54
|
+
spec = BELParser::Language.latest_supported_specification,
|
55
|
+
uri_reader = BELParser::Resource.default_uri_reader,
|
56
|
+
url_reader = BELParser::Resource.default_url_reader)
|
57
|
+
|
58
|
+
validator =
|
59
|
+
BELParser::Expression::Validator.new(
|
60
|
+
spec,
|
61
|
+
Hash[namespaces.map { |ns| [ns.keyword, ns] }],
|
62
|
+
uri_reader,
|
63
|
+
url_reader)
|
64
|
+
_, _, _, result = validator.each(StringIO.new("#{to_s}\n")).first
|
65
|
+
result
|
66
|
+
end
|
67
|
+
|
68
|
+
def valid?(
|
69
|
+
spec = BELParser::Language.latest_supported_specification,
|
70
|
+
uri_reader = BELParser::Resource.default_uri_reader,
|
71
|
+
url_reader = BELParser::Resource.default_url_reader)
|
72
|
+
|
73
|
+
validation(spec, uri_reader, url_reader).valid?
|
74
|
+
end
|
75
|
+
|
76
|
+
def invalid?(
|
77
|
+
spec = BELParser::Language.latest_supported_specification,
|
78
|
+
uri_reader = BELParser::Resource.default_uri_reader,
|
79
|
+
url_reader = BELParser::Resource.default_url_reader)
|
80
|
+
|
81
|
+
!validation(spec, uri_reader, url_reader).valid?
|
42
82
|
end
|
43
83
|
|
44
84
|
def hash
|
@@ -66,8 +106,7 @@ module BELParser
|
|
66
106
|
private
|
67
107
|
|
68
108
|
def invalid_argument?(arg)
|
69
|
-
|
70
|
-
!arg.is_a?(BELParser::Expression::Model::Term)
|
109
|
+
arg.nil? || [Parameter, Term].none? { |type| arg.is_a?(type) }
|
71
110
|
end
|
72
111
|
end
|
73
112
|
|
@@ -165,7 +165,19 @@ module BELParser
|
|
165
165
|
end
|
166
166
|
|
167
167
|
if __FILE__ == $PROGRAM_NAME
|
168
|
-
|
169
|
-
|
170
|
-
|
168
|
+
namespaces =
|
169
|
+
Hash[
|
170
|
+
ARGV.map do |ns|
|
171
|
+
keyword, uri = ns.split('=')
|
172
|
+
[keyword, BELParser::Expression::Model::Namespace.new(keyword, uri, nil)]
|
173
|
+
end.compact
|
174
|
+
]
|
175
|
+
|
176
|
+
BELParser::Expression.parse(
|
177
|
+
$stdin,
|
178
|
+
BELParser::Language.latest_supported_specification,
|
179
|
+
namespaces
|
180
|
+
).each do |obj|
|
181
|
+
puts " #{obj.class.name.split('::')[-1]}: #{obj}"
|
182
|
+
end
|
171
183
|
end
|
@@ -3,6 +3,7 @@ require_relative '../ast_generator'
|
|
3
3
|
require_relative '../parsers/expression'
|
4
4
|
require_relative '../language'
|
5
5
|
require_relative '../language/expression_validator'
|
6
|
+
require_relative 'model'
|
6
7
|
|
7
8
|
module BELParser
|
8
9
|
module Expression
|
@@ -52,27 +53,24 @@ if __FILE__ == $PROGRAM_NAME
|
|
52
53
|
exit 1
|
53
54
|
end
|
54
55
|
|
55
|
-
|
56
|
-
url_reader = BELParser::Resource.default_url_reader
|
57
|
-
namespaces =
|
56
|
+
namespaces =
|
58
57
|
Hash[
|
59
58
|
ARGV[1..-1]
|
60
59
|
.map do |ns|
|
61
|
-
|
62
|
-
[
|
60
|
+
keyword, identifier = ns.split('=')
|
61
|
+
[keyword, BELParser::Expression::Model::Namespace.new(keyword, identifier, nil)]
|
63
62
|
end
|
64
63
|
]
|
64
|
+
|
65
65
|
BELParser::Expression::Validator
|
66
|
-
.new(
|
67
|
-
|
68
|
-
|
66
|
+
.new(
|
67
|
+
BELParser::Language.specification(ARGV.first),
|
68
|
+
namespaces,
|
69
|
+
BELParser::Resource.default_uri_reader,
|
70
|
+
BELParser::Resource.default_url_reader)
|
71
|
+
.each($stdin) do |(line_number, line, ast, result)|
|
69
72
|
puts "#{line_number}: #{line}"
|
70
|
-
puts "
|
71
|
-
puts
|
72
|
-
.map { |r| "#{r}\n" }
|
73
|
-
.join
|
74
|
-
.each_line
|
75
|
-
.map { |l| " #{l}" }
|
76
|
-
.join
|
73
|
+
puts "AST Type: #{ast.type}"
|
74
|
+
puts result
|
77
75
|
end
|
78
76
|
end
|
@@ -49,9 +49,9 @@ module BELParser
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def on_parameter(parameter_node)
|
52
|
-
@type
|
53
|
-
@
|
54
|
-
@prefix
|
52
|
+
@type = nil
|
53
|
+
@namespace = nil
|
54
|
+
@prefix = nil
|
55
55
|
process(parameter_node.prefix)
|
56
56
|
process(parameter_node.value)
|
57
57
|
end
|
@@ -60,29 +60,25 @@ module BELParser
|
|
60
60
|
return prefix_node unless prefix_node.identifier
|
61
61
|
|
62
62
|
@prefix = prefix_node.identifier.string_literal
|
63
|
-
@
|
64
|
-
return prefix_node unless @
|
63
|
+
@namespace = @namespace_hash[@prefix]
|
64
|
+
return prefix_node unless @namespace
|
65
65
|
|
66
|
-
prefix_node.namespace = @
|
66
|
+
prefix_node.namespace = @namespace
|
67
67
|
prefix_node
|
68
68
|
end
|
69
69
|
|
70
70
|
def on_value(value_node)
|
71
|
-
return value_node unless @
|
72
|
-
value_node.
|
73
|
-
|
74
|
-
value_literal = value_node.children[0].string_literal
|
71
|
+
return value_node unless @namespace
|
72
|
+
value_node.prefix = @prefix
|
73
|
+
value_node.namespace = @namespace
|
75
74
|
|
76
|
-
|
77
|
-
|
75
|
+
value_literal = value_node.children[0].string_literal
|
76
|
+
value = @namespace[value_literal]
|
78
77
|
|
79
|
-
|
80
|
-
if values
|
81
|
-
value = values.first
|
78
|
+
if value
|
82
79
|
value_node.encoding =
|
83
|
-
value
|
84
|
-
.
|
85
|
-
.map(&@language_spec.method(:value_encoding))
|
80
|
+
value.encoding &&
|
81
|
+
value.encoding.map(&@language_spec.method(:value_encoding))
|
86
82
|
value_node.namespace_value = value
|
87
83
|
else
|
88
84
|
value_node.encoding = nil
|