bel_parser 1.0.5-java → 1.0.6-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{.gemspec-java → .gemspec} +1 -3
- 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 +6 -20
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0c9868e3746d9e87d07fa0998aab114ff4fcd0ec
|
4
|
+
data.tar.gz: f352bc984914515f5f25fcc703572e0cb86c5b47
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 79994e64bc3aa53b99f8267d1e39a23fd1a8d7f0570f0421b53af480de35409eda1a1856dd6365f0cdb00adfae1e9dea05471815b30dba1325bc3426391b4341
|
7
|
+
data.tar.gz: 8de33aae5e099d77f448677e7e5b52017cdd3e73f63e0f41c37642e5a4204212c04e8d96f87836c83ba39ed334dfd558bfd38c349246dd61694fb8ba46d60fe0
|
data/{.gemspec-java → .gemspec}
RENAMED
@@ -5,6 +5,7 @@ Gem::Specification.new do |spec|
|
|
5
5
|
File.expand_path(File.dirname(__FILE__)),
|
6
6
|
'VERSION'))
|
7
7
|
spec.summary = %q{Parser for Biolgical Expression Language.}
|
8
|
+
spec.platform = 'java'
|
8
9
|
spec.description = %q{Implements language versions 1.0 and 2.0.}
|
9
10
|
spec.license = 'Apache-2.0'
|
10
11
|
spec.authors = [
|
@@ -26,8 +27,5 @@ Gem::Specification.new do |spec|
|
|
26
27
|
spec.require_paths = ['lib']
|
27
28
|
spec.required_ruby_version = '>= 2.0.0'
|
28
29
|
|
29
|
-
spec.platform = 'java'
|
30
30
|
spec.add_runtime_dependency 'sparql-client', '~> 2.0.0'
|
31
|
-
spec.add_runtime_dependency 'dbm-mapdb3', '~> 0.6.0.beta'
|
32
31
|
end
|
33
|
-
# vim: ft=ruby
|
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: java
|
6
6
|
authors:
|
7
7
|
- Anthony Bargnesi
|
@@ -25,32 +25,18 @@ dependencies:
|
|
25
25
|
- - "~>"
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 2.0.0
|
28
|
-
- !ruby/object:Gem::Dependency
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: 0.6.0.beta
|
34
|
-
name: dbm-mapdb3
|
35
|
-
prerelease: false
|
36
|
-
type: :runtime
|
37
|
-
version_requirements: !ruby/object:Gem::Requirement
|
38
|
-
requirements:
|
39
|
-
- - "~>"
|
40
|
-
- !ruby/object:Gem::Version
|
41
|
-
version: 0.6.0.beta
|
42
28
|
description: Implements language versions 1.0 and 2.0.
|
43
29
|
email: abargnesi@selventa.com
|
44
30
|
executables:
|
45
|
-
- bel2_upgrade
|
46
|
-
- bel2_debug_ast
|
47
|
-
- bel2_validator
|
48
|
-
- bel_script_reader
|
49
31
|
- bel2_compatibility
|
32
|
+
- bel_script_reader
|
33
|
+
- bel2_validator
|
34
|
+
- bel2_debug_ast
|
35
|
+
- bel2_upgrade
|
50
36
|
extensions: []
|
51
37
|
extra_rdoc_files: []
|
52
38
|
files:
|
53
|
-
- ".gemspec
|
39
|
+
- ".gemspec"
|
54
40
|
- CHANGELOG.md
|
55
41
|
- LICENSE
|
56
42
|
- README.md
|