bel_parser 1.0.5 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +61 -8
- data/VERSION +1 -1
- data/lib/bel/translator/plugins/bel_script/nanopub_serialization.rb +7 -5
- data/lib/bel/translator/plugins/bel_script/writer.rb +37 -26
- data/lib/bel_parser/expression/model/annotation.rb +7 -2
- data/lib/bel_parser/expression/model/statement.rb +30 -16
- data/lib/bel_parser/language/function.rb +1 -3
- data/lib/bel_parser/language/relationship.rb +1 -3
- data/lib/bel_parser/mixin/line_mapping.rb +1 -1
- data/lib/bel_parser/script/state/set.rb +6 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 00ba70f47d103eaab5ad68d6db8dd094fc55e271
|
4
|
+
data.tar.gz: 00e019c029ec1d32afa440906c40ef4693a326a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 656dd3a2604eff139230936f5e6bb773faa32d11237c58fa6bd5cde018a5c8c4b98c9219887d001264e25f39e90bde4dd3891920d606697253b11cfa547b67ce
|
7
|
+
data.tar.gz: 66ae46288d5eaa28ae988c2fbb404948852b4a56c043ce8cf5556c7d9f5d1fab0f8c0e5263d30ee0cf06f6b27caa3e700e636fe6e75b264346e4ff0db3852bab
|
data/README.md
CHANGED
@@ -1,20 +1,73 @@
|
|
1
1
|
# bel_parser
|
2
2
|
|
3
|
-
|
3
|
+
The bel_parser gem implements BEL specifications (currently 1.0 and 2.0) and BEL Script nanopub format.
|
4
4
|
|
5
5
|
### Installation
|
6
6
|
|
7
|
-
gem install bel_parser
|
7
|
+
gem install bel_parser
|
8
|
+
|
9
|
+
### Motivation
|
10
|
+
|
11
|
+
The motivation for this library is to provide the building blocks to implement BEL specifications more easily. This includes:
|
12
|
+
|
13
|
+
- Recognizing input to Abstract Syntax Trees
|
14
|
+
- Applying syntax validation relative to a BEL specification.
|
15
|
+
- Applying signature validation relative to a BEL specification.
|
16
|
+
- Conversion of Abstract Syntax Trees to a Nanopub object model.
|
17
|
+
|
18
|
+
Currently BEL 1.0 and 2.0 specifications are implemented.
|
8
19
|
|
9
20
|
### Getting Started
|
10
21
|
|
11
|
-
|
12
|
-
|
22
|
+
bel_parser provides a Ruby library and a set of command-line tools.
|
23
|
+
|
24
|
+
Command-line tools:
|
25
|
+
|
26
|
+
1. *bel2_debug_ast*
|
27
|
+
|
28
|
+
Writes the AST output recognized from the input.
|
29
|
+
|
30
|
+
usage: `bel2_debug_ast` (Then enter a line at a time)
|
31
|
+
|
32
|
+
usage: `bel2_debug_ast --file file.bel`
|
33
|
+
|
34
|
+
2. *bel2_validator*
|
35
|
+
|
36
|
+
Validate the syntax and semantics of the AST recognized from the input.
|
37
|
+
|
38
|
+
usage: `bel2_validator` (Then enter a line at a time)
|
39
|
+
|
40
|
+
usage: `bel2_validator --file file.bel --specification 2.0`
|
41
|
+
|
42
|
+
3. *bel2_upgrade*
|
43
|
+
|
44
|
+
Upgrades BEL statements from 1.0 to 2.0.
|
45
|
+
|
46
|
+
usage: `bel2_upgrade` (Then enter a line at a time)
|
47
|
+
|
48
|
+
usage: `bel2_upgrade --file file.bel`
|
49
|
+
|
50
|
+
### Development / Deployment
|
51
|
+
|
52
|
+
Development for the next release should be performed on the *next* branch. When the new changes are complete, functional, and tested they should be merged over to the *master* branch.
|
53
|
+
|
54
|
+
To make a release, perform the following steps:
|
55
|
+
|
56
|
+
- Update the version in the `VERSION` file.
|
57
|
+
|
58
|
+
- Add a new version with list of changes in the `CHANGELOG` file. This file is modelled after http://keepachangelog.com/.
|
59
|
+
|
60
|
+
- Build the Ruby and Java versions of the gem:
|
61
|
+
|
62
|
+
Ruby: `gem build .gemspec`
|
63
|
+
|
64
|
+
Java: `gem build .gemspec-java`
|
65
|
+
|
66
|
+
- Create a release on GitHub with both gems and a summary of the changes in this version.
|
13
67
|
|
14
|
-
|
68
|
+
- Push both gems to RubyGems:
|
15
69
|
|
16
|
-
|
70
|
+
`gem push bel_parser-VERSION.gem`
|
17
71
|
|
18
|
-
|
72
|
+
`gem push bel_parser-VERSION-java.gem`
|
19
73
|
|
20
|
-
### Design
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.6
|
@@ -1,11 +1,11 @@
|
|
1
|
-
require '
|
1
|
+
require 'bel_parser/quoting'
|
2
2
|
|
3
3
|
# Serializing of common {BEL::Nanopub::Nanopub nanopub} components to BEL
|
4
4
|
# Script syntax.
|
5
5
|
#
|
6
6
|
# @abstract
|
7
7
|
module BEL::Translator::Plugins::BelScript::NanopubSerialization
|
8
|
-
include
|
8
|
+
include BELParser::Quoting
|
9
9
|
|
10
10
|
# Serialize the {BEL::Nanopub::Nanopub nanopub} to a BEL Script string.
|
11
11
|
#
|
@@ -32,11 +32,13 @@ module BEL::Translator::Plugins::BelScript::NanopubSerialization
|
|
32
32
|
|
33
33
|
values = citation.to_a
|
34
34
|
values.map! { |v|
|
35
|
-
v
|
35
|
+
v = %("") if v.nil? || v.empty?
|
36
36
|
if v.respond_to?(:each)
|
37
|
-
|
37
|
+
v.map! { |item| item.delete("\r\n") }
|
38
|
+
quote(v.join('|'))
|
38
39
|
else
|
39
|
-
|
40
|
+
v.delete!("\r\n")
|
41
|
+
quote(v)
|
40
42
|
end
|
41
43
|
}
|
42
44
|
values.join(', ')
|
@@ -45,7 +45,7 @@ module BEL::Translator::Plugins
|
|
45
45
|
}
|
46
46
|
serialization_module = serialization_refs[serialization.to_sym]
|
47
47
|
unless serialization_module
|
48
|
-
raise %
|
48
|
+
raise %(No BEL serialization strategy for "#{serialization}")
|
49
49
|
end
|
50
50
|
serialization_module
|
51
51
|
else
|
@@ -81,7 +81,7 @@ module BEL::Translator::Plugins
|
|
81
81
|
bel = to_bel(nanopub)
|
82
82
|
|
83
83
|
if @write_header && header_flag
|
84
|
-
yield document_header(nanopub.metadata
|
84
|
+
yield document_header(nanopub.metadata)
|
85
85
|
yield namespaces(combiner.namespace_references)
|
86
86
|
yield annotations(combiner.annotation_references)
|
87
87
|
|
@@ -103,30 +103,35 @@ module BEL::Translator::Plugins
|
|
103
103
|
|
104
104
|
private
|
105
105
|
|
106
|
-
def document_header(
|
107
|
-
return "" unless header
|
108
|
-
|
106
|
+
def document_header(metadata)
|
109
107
|
bel = <<-COMMENT.gsub(/^\s+/, '')
|
110
108
|
###############################################
|
111
109
|
# Document Properties Section
|
112
110
|
COMMENT
|
113
111
|
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
112
|
+
bel_version =
|
113
|
+
metadata.bel_version || BELParser::Language.default_version
|
114
|
+
bel << %(SET DOCUMENT BELVersion = "#{bel_version}"\n)
|
115
|
+
|
116
|
+
if metadata.document_header
|
117
|
+
header = metadata.document_header
|
118
|
+
header.each do |name, value|
|
119
|
+
name_s = name.to_s
|
120
|
+
value_s =
|
121
|
+
if value.respond_to?(:each)
|
122
|
+
value.join('|')
|
123
|
+
else
|
124
|
+
value.to_s
|
125
|
+
end
|
126
|
+
|
127
|
+
# handle casing for document properties (special case, contactinfo)
|
128
|
+
name_s = (name_s.downcase == 'contactinfo') ?
|
129
|
+
'ContactInfo' :
|
130
|
+
name_s.capitalize
|
131
|
+
|
132
|
+
bel << %(SET DOCUMENT #{name_s} = "#{value_s}"\n)
|
133
|
+
end
|
134
|
+
end
|
130
135
|
|
131
136
|
bel << "\n"
|
132
137
|
bel
|
@@ -145,14 +150,14 @@ module BEL::Translator::Plugins
|
|
145
150
|
|
146
151
|
case ref.type.to_sym
|
147
152
|
when :url
|
148
|
-
bel << %
|
153
|
+
bel << %(URL "#{ref.domain}"\n)
|
149
154
|
when :uri
|
150
|
-
bel << %
|
155
|
+
bel << %(URI "#{ref.domain}"\n)
|
151
156
|
when :pattern
|
152
157
|
regex = ref.domain.respond_to?(:source) ? ref.domain.source : ref.domain
|
153
|
-
bel << %
|
158
|
+
bel << %(PATTERN "#{regex}"\n)
|
154
159
|
when :list
|
155
|
-
bel << %
|
160
|
+
bel << %(LIST {#{ref.domain.inspect[1...-1]}}\n)
|
156
161
|
end
|
157
162
|
bel
|
158
163
|
}
|
@@ -169,7 +174,13 @@ module BEL::Translator::Plugins
|
|
169
174
|
return bel unless namespace_references
|
170
175
|
|
171
176
|
namespace_references.reduce(bel) { |bel, ref|
|
172
|
-
|
177
|
+
case
|
178
|
+
when ref.uri?
|
179
|
+
bel << %(DEFINE NAMESPACE #{ref.keyword} AS URI "#{ref.uri}"\n)
|
180
|
+
when ref.url?
|
181
|
+
bel << %(DEFINE NAMESPACE #{ref.keyword} AS URL "#{ref.url}"\n)
|
182
|
+
end
|
183
|
+
|
173
184
|
bel
|
174
185
|
}
|
175
186
|
bel << "\n"
|
@@ -20,8 +20,13 @@ module BELParser
|
|
20
20
|
@type = type.to_sym
|
21
21
|
@domain = domain
|
22
22
|
|
23
|
-
|
24
|
-
|
23
|
+
# configure reader for URIs (RDF).
|
24
|
+
@uri_reader = options.fetch(:uri_reader, BELParser::Resource.default_uri_reader)
|
25
|
+
BELParser::Resource::Reader.assert_reader(@uri_reader, 'uri_reader')
|
26
|
+
|
27
|
+
# configure reader for URLs (Resource files).
|
28
|
+
@url_reader = options.fetch(:url_reader, BELParser::Resource.default_url_reader)
|
29
|
+
BELParser::Resource::Reader.assert_reader(@url_reader, 'url_reader')
|
25
30
|
end
|
26
31
|
|
27
32
|
def initialize_copy(original)
|
@@ -16,7 +16,7 @@ module BELParser
|
|
16
16
|
# - SUBJECT RELATIONSHIP OBJECT(Statement)
|
17
17
|
# - +p(HGNC:VHL) -> (p(HGNC:TNF) -> bp(GOBP:"cell death"))+
|
18
18
|
class Statement
|
19
|
-
|
19
|
+
attr_reader :subject, :relationship, :object, :comment, :type
|
20
20
|
|
21
21
|
# Creates a {Statement} with +subject+, +relationship+, +object+, and
|
22
22
|
# +comment+.
|
@@ -33,44 +33,58 @@ module BELParser
|
|
33
33
|
end
|
34
34
|
@subject = subject
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
case relationship
|
37
|
+
when nil
|
38
|
+
@type = :observed_term
|
39
|
+
@relationship = nil
|
40
|
+
when BELParser::Language::Relationship
|
41
|
+
@type = :simple_statement
|
42
|
+
@relationship = relationship
|
43
|
+
else
|
44
|
+
raise(ArgumentError,
|
39
45
|
"relationship: expected nil or Relationship, actual #{relationship.class}")
|
40
46
|
end
|
41
|
-
@relationship = relationship
|
42
47
|
|
43
|
-
|
44
|
-
|
45
|
-
|
48
|
+
case object
|
49
|
+
when nil
|
50
|
+
@type = :observed_term
|
51
|
+
@object = nil
|
52
|
+
when BELParser::Expression::Model::Term
|
53
|
+
@type = :simple_statement
|
54
|
+
@object = object
|
55
|
+
when BELParser::Expression::Model::Statement
|
56
|
+
@type = :nested_statement
|
57
|
+
@object = object
|
58
|
+
else
|
59
|
+
raise(ArgumentError,
|
46
60
|
"object: expected nil, Term, or Statement, actual #{object.class}")
|
47
61
|
end
|
48
|
-
@object = object
|
49
|
-
@comment = comment
|
50
62
|
|
51
|
-
|
63
|
+
@comment = comment
|
64
|
+
|
65
|
+
if @relationship && @object.nil?
|
52
66
|
raise(
|
53
67
|
ArgumentError,
|
54
68
|
"object must be set when specifying a relationship")
|
55
69
|
end
|
56
70
|
|
57
|
-
if @object &&
|
71
|
+
if @object && @relationship.nil?
|
58
72
|
raise(
|
59
73
|
ArgumentError,
|
60
|
-
"
|
74
|
+
"relationship must be set when specifying an object")
|
61
75
|
end
|
62
76
|
end
|
63
77
|
|
64
78
|
def subject_only?
|
65
|
-
|
79
|
+
@type == :observed_term
|
66
80
|
end
|
67
81
|
|
68
82
|
def simple?
|
69
|
-
@
|
83
|
+
@type == :simple_statement
|
70
84
|
end
|
71
85
|
|
72
86
|
def nested?
|
73
|
-
@
|
87
|
+
@type == :nested_statement
|
74
88
|
end
|
75
89
|
|
76
90
|
def namespaces
|
@@ -60,7 +60,12 @@ module BELParser
|
|
60
60
|
def self.handle_annotation(name_string, value_node, script_context)
|
61
61
|
# add to annotation state
|
62
62
|
script_context[:annotations] ||= Concurrent::Hash.new
|
63
|
-
|
63
|
+
if value_node.children[0].respond_to?(:string_literal)
|
64
|
+
namestr = value_node.children[0].string_literal
|
65
|
+
else
|
66
|
+
namestr = value_node.children[0].to_s
|
67
|
+
end
|
68
|
+
script_context[:annotations][name_string] = namestr
|
64
69
|
end
|
65
70
|
private_class_method :handle_annotation
|
66
71
|
|
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.
|
4
|
+
version: 1.0.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Bargnesi
|
@@ -28,11 +28,11 @@ dependencies:
|
|
28
28
|
description: Implements language versions 1.0 and 2.0.
|
29
29
|
email: abargnesi@selventa.com
|
30
30
|
executables:
|
31
|
-
-
|
31
|
+
- bel2_compatibility
|
32
32
|
- bel2_debug_ast
|
33
|
+
- bel2_upgrade
|
33
34
|
- bel2_validator
|
34
35
|
- bel_script_reader
|
35
|
-
- bel2_compatibility
|
36
36
|
extensions: []
|
37
37
|
extra_rdoc_files: []
|
38
38
|
files:
|