bel_parser 1.0.0.alpha.27-java → 1.0.0.alpha.28-java

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e921d76566be607de95fcb0cc81def38fb66fbc
4
- data.tar.gz: 07403998d6fdaeca6d9a3380a3fc55480470d7f1
3
+ metadata.gz: 13215ac795faa5077028725921572827bb24953b
4
+ data.tar.gz: 94c3c72300afd58322ff396a0ddcb30a8d71109f
5
5
  SHA512:
6
- metadata.gz: 437d7fd653d991fe0e7f3db14e42f210b61744e25f6395b7a673bba701ad43dc5ae920254683916347867402d4c04b3232f518f709ad867cdc3aee0b471338c6
7
- data.tar.gz: 61f465297d02cf000a853f1b1048acd359529b3bdef234aa10f9494c58c51e5b042eab8b0f99a0868bdbb387108fda6b1679cf3edfc972db7539c3ba98cff6a3
6
+ metadata.gz: 68c9dba99dad0c8a19c00dfe78b99d8c882a54c55754f87b421e2353495f42e591e167c0473570ec6df12e76c034f7498c4d4216693e560b9442d1abe61b204d
7
+ data.tar.gz: c490a891dd8cc5bfc2c2abee8d16d49807d19abebb9695ab486059fff6c5b4bd4022c2c489ce0759a1d3c1deb86c10bafa26b14380729dc06527a52ff44ff77d
data/.gemspec-java CHANGED
@@ -27,6 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.required_ruby_version = '>= 2.0.0'
28
28
 
29
29
  spec.platform = 'java'
30
- spec.add_runtime_dependency 'dbm-mapdb3', '~> 0.6.0.beta'
30
+ spec.add_runtime_dependency 'sparql-client', '~> 2.0.0'
31
+ spec.add_runtime_dependency 'dbm-mapdb3', '~> 0.6.0.beta'
31
32
  end
32
33
  # vim: ft=ruby
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0.alpha.27
1
+ 1.0.0.alpha.28
@@ -0,0 +1,87 @@
1
+ module BELParser
2
+ module Expression
3
+ module Model
4
+ # Annotation represents a catalog of biological annotation values.
5
+ class Annotation
6
+ include Enumerable
7
+
8
+ attr_reader :keyword
9
+ attr_reader :uri
10
+ attr_reader :url
11
+
12
+ def initialize(keyword, uri = nil, url = nil, options = {})
13
+ raise(ArgumentError, 'keyword is nil') unless keyword
14
+ @keyword = keyword
15
+ @uri = uri
16
+ @url = url
17
+
18
+ # configure reader for URIs (RDF).
19
+ @uri_reader =
20
+ options.fetch(:uri_reader) {
21
+ BELParser::Resource.default_uri_reader
22
+ }
23
+ BELParser::Resource::Reader.assert_reader(@uri_reader, 'uri_reader')
24
+
25
+ # configure reader for URLs (Resource files).
26
+ @url_reader =
27
+ options.fetch(:url_reader) {
28
+ BELParser::Resource.default_url_reader
29
+ }
30
+ BELParser::Resource::Reader.assert_reader(@url_reader, 'url_reader')
31
+ end
32
+
33
+ def uri?
34
+ !@uri.nil?
35
+ end
36
+
37
+ def url?
38
+ !@url.nil?
39
+ end
40
+
41
+ def [](value)
42
+ if uri?
43
+ @uri_reader.retrieve_value_from_resource(@uri, value)
44
+ elsif url?
45
+ @url_reader.retrieve_value_from_resource(@url, value)
46
+ else
47
+ nil
48
+ end
49
+ end
50
+
51
+ def each
52
+ if block_given?
53
+ values =
54
+ if uri?
55
+ @uri_reader.retrieve_values_from_resource(@uri)
56
+ elsif url?
57
+ @url_reader.retrieve_values_from_resource(@url)
58
+ else
59
+ []
60
+ end
61
+ values.each do |value|
62
+ yield value
63
+ end
64
+ else
65
+ to_enum(:each)
66
+ end
67
+ end
68
+
69
+ def hash
70
+ [@keyword, @uri, @url].hash
71
+ end
72
+
73
+ def ==(other)
74
+ return false if other.nil?
75
+ @keyword == other.keyword && @uri == other.uri && @url == other.url
76
+ end
77
+ alias :eql? :'=='
78
+
79
+ def to_s
80
+ @keyword.to_s
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
86
+ # vim: ts=2 sw=2:
87
+ # encoding: utf-8
@@ -0,0 +1,91 @@
1
+ require 'bel_parser/resource'
2
+
3
+ module BELParser
4
+ module Expression
5
+ module Model
6
+ # Namespace represents a catalog of biological identifiers that are to
7
+ # identify parameter values like genes (e.g. _AKT1_),
8
+ # diseases (e.g. _hypertropia_), and processes (e.g. _anaphase_).
9
+ class Namespace
10
+ include Enumerable
11
+
12
+ attr_accessor :keyword
13
+ attr_accessor :uri
14
+ attr_accessor :url
15
+
16
+ def initialize(keyword, uri = nil, url = nil, options = {})
17
+ raise(ArgumentError, 'keyword is nil') unless keyword
18
+ @keyword = keyword
19
+ @uri = uri
20
+ @url = url
21
+
22
+ # configure reader for URIs (RDF).
23
+ @uri_reader =
24
+ options.fetch(:uri_reader) {
25
+ BELParser::Resource.default_uri_reader
26
+ }
27
+ BELParser::Resource::Reader.assert_reader(@uri_reader, 'uri_reader')
28
+
29
+ # configure reader for URLs (Resource files).
30
+ @url_reader =
31
+ options.fetch(:url_reader) {
32
+ BELParser::Resource.default_url_reader
33
+ }
34
+ BELParser::Resource::Reader.assert_reader(@url_reader, 'url_reader')
35
+ end
36
+
37
+ def uri?
38
+ !@uri.nil?
39
+ end
40
+
41
+ def url?
42
+ !@url.nil?
43
+ end
44
+
45
+ def [](value)
46
+ if uri?
47
+ @uri_reader.retrieve_value_from_resource(@uri, value)
48
+ elsif url?
49
+ @url_reader.retrieve_value_from_resource(@url, value)
50
+ else
51
+ nil
52
+ end
53
+ end
54
+
55
+ def each
56
+ if block_given?
57
+ values =
58
+ if uri?
59
+ @uri_reader.retrieve_values_from_resource(@uri)
60
+ elsif url?
61
+ @url_reader.retrieve_values_from_resource(@url)
62
+ else
63
+ []
64
+ end
65
+ values.each do |value|
66
+ yield value
67
+ end
68
+ else
69
+ to_enum(:each)
70
+ end
71
+ end
72
+
73
+ def hash
74
+ [@keyword, @uri, @url].hash
75
+ end
76
+
77
+ def ==(other)
78
+ return false if other.nil?
79
+ @keyword == other.keyword && @uri == other.uri && @url == other.url
80
+ end
81
+ alias :eql? :'=='
82
+
83
+ def to_s
84
+ @keyword.to_s
85
+ end
86
+ end
87
+ end
88
+ end
89
+ end
90
+ # vim: ts=2 sw=2:
91
+ # encoding: utf-8
@@ -0,0 +1,60 @@
1
+ require 'bel_parser/quoting'
2
+
3
+ module BELParser
4
+ module Expression
5
+ module Model
6
+
7
+ class Parameter
8
+ include BELParser::Quoting
9
+ include Comparable
10
+
11
+ attr_accessor :namespace, :value
12
+
13
+ def initialize(namespace, value)
14
+ raise(ArgumentError, 'value is nil') unless value
15
+ unless namespace.nil? || namespace.is_a?(Namespace)
16
+ raise(
17
+ ArgumentError,
18
+ "namespace: expected nil or Namespace, actual #{namespace.class}")
19
+ end
20
+ @namespace = namespace
21
+ @value = value
22
+ end
23
+
24
+ def valid?
25
+ return false unless @value
26
+ return true unless @namespace
27
+ !@namespace[@value].nil?
28
+ end
29
+
30
+ def <=>(other)
31
+ namespace_compare = @namespace <=> other.namespace
32
+ if namespace_compare == 0
33
+ @value <=> other.value
34
+ else
35
+ namespace_compare
36
+ end
37
+ end
38
+
39
+ def hash
40
+ [@namespace, @value].hash
41
+ end
42
+
43
+ def ==(other)
44
+ return false if other == nil
45
+ @namespace == other.namespace && @value == other.value
46
+ end
47
+ alias_method :eql?, :'=='
48
+
49
+ def to_s(_)
50
+ if @namespace
51
+ prefix = "#{@namespace.keyword}:"
52
+ else
53
+ prefix = ''
54
+ end
55
+ %Q{#{prefix}#{quote_if_needed(@value)}}
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,114 @@
1
+ module BELParser
2
+ module Expression
3
+ module Model
4
+
5
+ # A {Statement} captures a BEL statement composed of a subject {Term},
6
+ # +relationship+, and object {Term}. A {Statement} may be one of the
7
+ # following common forms:
8
+ #
9
+ # - SUBJECT
10
+ # - +complex(p(HGNC:F3),p(HGNC:F7))+
11
+ # - SUBJECT RELATIONSHIP OBJECT(Term)
12
+ # - +pep(complex(p(HGNC:F3),p(HGNC:F7))) => pep(p(HGNC:F9))+
13
+ # - SUBJECT RELATIONSHIP OBJECT(Statement)
14
+ # - +p(HGNC:VHL) -> (p(HGNC:TNF) -> bp(GOBP:"cell death"))+
15
+ class Statement
16
+ attr_accessor :subject, :relationship, :object, :comment
17
+
18
+ # Creates a {Statement} with +subject+, +relationship+, +object+, and
19
+ # +comment+.
20
+ #
21
+ # @param [Term] subject
22
+ # @param [BELParser::Language::Relationship] relationship
23
+ # @param [Term, Statement] object
24
+ # @param [String] comment
25
+ def initialize(subject, relationship = nil, object = nil, comment = nil)
26
+ raise(ArgumentError, 'subject is nil') unless subject
27
+ @subject = subject
28
+
29
+ unless relationship.nil? || relationship.is_a?(BELParser::Language::Relationship)
30
+ raise(
31
+ ArgumentError,
32
+ "relationship: expected nil or Relationship, actual #{@relationship.class}")
33
+ end
34
+ @relationship = relationship
35
+
36
+ unless object.nil? || [Term, Statement].any?(&object.method(:is_a?))
37
+ raise(
38
+ ArgumentError,
39
+ "object: expected nil, Term, or Statement, actual #{@object.class}")
40
+ end
41
+ @object = object
42
+ @comment = comment
43
+
44
+ if @relationship && !@object
45
+ raise(
46
+ ArgumentError,
47
+ "object must be set when specifying a relationship")
48
+ end
49
+
50
+ if @object && !@relationship
51
+ raise(
52
+ ArgumentError,
53
+ "relationsihp must be set when specifying an object")
54
+ end
55
+ end
56
+
57
+ def subject_only?
58
+ !@relationship
59
+ end
60
+
61
+ def simple?
62
+ @object && @object.is_a?(Term)
63
+ end
64
+
65
+ def nested?
66
+ @object && @object.is_a?(Statement)
67
+ end
68
+
69
+ def valid?
70
+ # TODO Use expression validator.
71
+ end
72
+
73
+ def hash
74
+ [@subject, @relationship, @object, @comment].hash
75
+ end
76
+
77
+ def ==(other)
78
+ return false if other == nil
79
+ @subject == other.subject &&
80
+ @relationship == other.relationship &&
81
+ @object == other.object &&
82
+ @comment == other.comment
83
+ end
84
+ alias :eql? :'=='
85
+
86
+ def to_s(form = :short)
87
+ rel =
88
+ case form
89
+ when :short
90
+ @relationship && @relationship.short
91
+ when :long
92
+ @relationship && @relationship.long
93
+ else
94
+ nil
95
+ end
96
+
97
+ lbl =
98
+ case
99
+ when subject_only?
100
+ @subject.to_s(form)
101
+ when simple?
102
+ "#{@subject.to_s(form)} #{rel} #{@object.to_s(form)}"
103
+ when nested?
104
+ "#{@subject.to_s(form)} #{rel} (#{@object.to_s(form)})"
105
+ else
106
+ ''
107
+ end
108
+
109
+ comment ? lbl + ' //' + comment : lbl
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
@@ -0,0 +1,52 @@
1
+ module BELParser
2
+ module Expression
3
+ module Model
4
+ class Term
5
+ include Comparable
6
+
7
+ attr_accessor :function, :arguments
8
+
9
+ def initialize(function, *arguments)
10
+ unless function && function.is_a?(BELParser::Language::Function)
11
+ raise(
12
+ ArgumentError,
13
+ %(function: expected Function, actual #{function.class}))
14
+ end
15
+ @function = function
16
+ @arguments = (arguments ||= []).flatten
17
+ end
18
+
19
+ def <<(item)
20
+ @arguments << item
21
+ end
22
+
23
+ def valid?
24
+ # TODO Use expression validator.
25
+ end
26
+
27
+ def hash
28
+ [@function, @arguments].hash
29
+ end
30
+
31
+ def ==(other)
32
+ return false if other == nil
33
+ @function == other.function && @arguments == other.arguments
34
+ end
35
+ alias :eql? :'=='
36
+
37
+ def to_s(form = :short)
38
+ args = [@arguments].flatten.map { |arg| arg.to_s(form) }.join(',')
39
+ case form
40
+ when :short
41
+ "#{@function.short}(#{args})"
42
+ when :long
43
+ "#{@function.long}(#{args})"
44
+ else
45
+ nil
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
52
+
@@ -0,0 +1,5 @@
1
+ require_relative 'model/annotation'
2
+ require_relative 'model/namespace'
3
+ require_relative 'model/parameter'
4
+ require_relative 'model/term'
5
+ require_relative 'model/statement'
@@ -1,3 +1,4 @@
1
1
  require_relative 'expression/filter'
2
+ require_relative 'expression/model'
2
3
  require_relative 'expression/parser'
3
4
  require_relative 'expression/validator'
@@ -2,6 +2,19 @@ module BELParser
2
2
  module Resource
3
3
  # Reader represents the API for a reader of resource data.
4
4
  module Reader
5
+ def self.assert_reader(reader, var_name)
6
+ raise ArgumentError, "#{var_name} is nil" unless reader
7
+ not_impl_methods =
8
+ Reader.instance_methods.reject do |method|
9
+ reader.respond_to?(method)
10
+ end
11
+ unless not_impl_methods.empty?
12
+ raise(
13
+ ArgumentError,
14
+ "#{var_name} does not respond to #{not_impl_methods.join(', ')}.")
15
+ end
16
+ end
17
+
5
18
  def retrieve_resource(resource_identifier)
6
19
  raise NotImplementedError, "#{__method__} is not implemented."
7
20
  end
@@ -60,12 +60,13 @@ module BELParser
60
60
  end
61
61
 
62
62
  def hash_to_concept_scheme(resource_identifier, hash)
63
- return nil if hash[:types].value.empty?
63
+ return nil if hash.empty? or hash[:types].value.empty?
64
64
  ConceptScheme.new(resource_identifier,
65
65
  *hash.values_at(:domain, :prefix, :prefLabel, :types))
66
66
  end
67
67
 
68
68
  def hash_to_concept(concept_scheme, hash)
69
+ return nil if hash.empty?
69
70
  Concept.new(concept_scheme,
70
71
  *hash.values_at(:concept, :prefLabel, :identifier, :title,
71
72
  :altLabels, :types))
@@ -0,0 +1,37 @@
1
+ require_relative 'resource/sparql_reader'
2
+ require_relative 'resource/resource_url_reader'
3
+
4
+ module BELParser
5
+ module Resource
6
+
7
+ # DEFAULT_SPARQL_ENDPOINT = 'http://sparql.openbel.org/identifiers/sparql'
8
+ DEFAULT_SPARQL_ENDPOINT = 'http://localhost:3030/identifiers/sparql'
9
+
10
+ READER_LOCK = Mutex.new
11
+ private_constant :READER_LOCK
12
+
13
+ def self.default_uri_reader
14
+ READER_LOCK.synchronize do
15
+ @default_uri_reader ||= SPARQLReader.new(DEFAULT_SPARQL_ENDPOINT)
16
+ end
17
+ end
18
+
19
+ def self.default_uri_reader=(uri_reader)
20
+ READER_LOCK.synchronize do
21
+ @default_uri_reader ||= uri_reader
22
+ end
23
+ end
24
+
25
+ def self.default_url_reader
26
+ READER_LOCK.synchronize do
27
+ @default_url_reader ||= ResourceURLReader.new
28
+ end
29
+ end
30
+
31
+ def self.default_url_reader=(url_reader)
32
+ READER_LOCK.synchronize do
33
+ @default_url_reader ||= url_reader
34
+ end
35
+ end
36
+ end
37
+ end
data/lib/bel_parser.rb CHANGED
@@ -16,7 +16,7 @@ require 'bel_parser/ast_filter'
16
16
  # Language; version-independent classes
17
17
  require 'bel_parser/language'
18
18
 
19
- # BEL expression support
19
+ # BEL Expression support
20
20
  require 'bel_parser/expression'
21
21
 
22
22
  # BEL Script support
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.27
4
+ version: 1.0.0.alpha.28
5
5
  platform: java
6
6
  authors:
7
7
  - Anthony Bargnesi
@@ -11,6 +11,20 @@ bindir: bin
11
11
  cert_chain: []
12
12
  date: 2016-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.0.0
20
+ name: sparql-client
21
+ prerelease: false
22
+ type: :runtime
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.0.0
14
28
  - !ruby/object:Gem::Dependency
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
@@ -53,6 +67,12 @@ files:
53
67
  - lib/bel_parser/ast_generator.rb
54
68
  - lib/bel_parser/expression.rb
55
69
  - lib/bel_parser/expression/filter.rb
70
+ - lib/bel_parser/expression/model.rb
71
+ - lib/bel_parser/expression/model/annotation.rb
72
+ - lib/bel_parser/expression/model/namespace.rb
73
+ - lib/bel_parser/expression/model/parameter.rb
74
+ - lib/bel_parser/expression/model/statement.rb
75
+ - lib/bel_parser/expression/model/term.rb
56
76
  - lib/bel_parser/expression/parser.rb
57
77
  - lib/bel_parser/expression/validator.rb
58
78
  - lib/bel_parser/language.rb
@@ -323,6 +343,7 @@ files:
323
343
  - lib/bel_parser/parsers/nonblocking_io_wrapper.rb
324
344
  - lib/bel_parser/parsers/serializer.rb
325
345
  - lib/bel_parser/quoting.rb
346
+ - lib/bel_parser/resource.rb
326
347
  - lib/bel_parser/resource/concept.rb
327
348
  - lib/bel_parser/resource/concept_scheme.rb
328
349
  - lib/bel_parser/resource/dataset.rb