bel 0.3.3 → 0.4.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +53 -8
- data/bel.gemspec +10 -15
- data/bin/bel +63 -4
- data/bin/bel2rdf.rb +1 -1
- data/bin/bel_compare.rb +1 -1
- data/bin/bel_parse.rb +1 -1
- data/bin/bel_rdfschema.rb +1 -1
- data/bin/bel_summarize.rb +1 -1
- data/bin/bel_upgrade.rb +1 -1
- data/lib/bel.rb +8 -10
- data/lib/bel/completion.rb +3 -2
- data/lib/bel/completion/value_match_rule.rb +10 -0
- data/lib/bel/evidence_model/citation.rb +101 -43
- data/lib/bel/evidence_model/evidence.rb +2 -2
- data/lib/bel/evidence_model/experiment_context.rb +1 -0
- data/lib/bel/evidence_model/metadata.rb +15 -2
- data/lib/bel/evidence_model/references.rb +10 -10
- data/lib/bel/json.rb +63 -0
- data/lib/bel/json/adapter/multi_json.rb +36 -0
- data/lib/bel/json/adapter/oj.rb +65 -0
- data/lib/bel/json/adapter/ruby_json.rb +28 -0
- data/lib/bel/json/reader.rb +9 -0
- data/lib/bel/json/writer.rb +9 -0
- data/lib/bel/libbel.rb +1 -4
- data/lib/bel/parser.rb +2 -2
- data/lib/bel/rdf_repository.rb +18 -0
- data/lib/bel/rdf_repository/plugins/memory.rb +28 -0
- data/lib/bel/rdf_repository/plugins/mongo.rb +28 -0
- data/lib/bel/resource.rb +24 -0
- data/lib/bel/resource/namespace.rb +122 -0
- data/lib/bel/resource/namespace_value.rb +69 -0
- data/lib/bel/resource/namespaces.rb +83 -0
- data/lib/bel/resource/search.rb +26 -0
- data/lib/bel/resource/search/api.rb +36 -0
- data/lib/bel/resource/search/search_result.rb +32 -0
- data/lib/bel/translate.rb +108 -0
- data/lib/bel/translator.rb +69 -0
- data/lib/bel/translator/plugins/bel_script.rb +36 -0
- data/lib/bel/translator/plugins/bel_script/bel_yielder.rb +144 -0
- data/lib/bel/translator/plugins/bel_script/evidence_yielder.rb +95 -0
- data/lib/bel/translator/plugins/bel_script/translator.rb +24 -0
- data/lib/bel/translator/plugins/jgf.rb +37 -0
- data/lib/bel/translator/plugins/jgf/translator.rb +160 -0
- data/lib/bel/translator/plugins/json_evidence.rb +38 -0
- data/lib/bel/translator/plugins/json_evidence/translator.rb +90 -0
- data/lib/bel/translator/plugins/rdf.rb +48 -0
- data/lib/bel/translator/plugins/rdf/bel_schema.rb +339 -0
- data/lib/bel/translator/plugins/rdf/monkey_patch.rb +310 -0
- data/lib/bel/translator/plugins/rdf/reader.rb +173 -0
- data/lib/bel/translator/plugins/rdf/translator.rb +40 -0
- data/lib/bel/translator/plugins/rdf/writer.rb +45 -0
- data/lib/bel/translator/plugins/xbel.rb +36 -0
- data/lib/bel/translator/plugins/xbel/evidence_handler.rb +468 -0
- data/lib/bel/translator/plugins/xbel/evidence_yielder.rb +24 -0
- data/lib/bel/translator/plugins/xbel/translator.rb +24 -0
- data/lib/bel/translator/plugins/xbel/xbel_yielder.rb +414 -0
- data/lib/bel/vendor/little-plugger.rb +323 -0
- data/lib/bel/version.rb +1 -1
- metadata +44 -158
- data/lib/bel/extension.rb +0 -37
- data/lib/bel/extension_format.rb +0 -207
- data/lib/bel/extensions/bel.rb +0 -258
- data/lib/bel/extensions/jgf.rb +0 -219
- data/lib/bel/extensions/json/jrjackson.rb +0 -31
- data/lib/bel/extensions/json/json.rb +0 -133
- data/lib/bel/extensions/json/multi_json.rb +0 -29
- data/lib/bel/extensions/json/oj.rb +0 -68
- data/lib/bel/extensions/json/ruby_json.rb +0 -29
- data/lib/bel/extensions/rdf/bel_rdf.rb +0 -338
- data/lib/bel/extensions/rdf/rdf.rb +0 -584
- data/lib/bel/extensions/xbel.rb +0 -923
- data/lib/bel/format.rb +0 -58
@@ -13,7 +13,7 @@ module BEL
|
|
13
13
|
def self.create(hash)
|
14
14
|
ev = Evidence.new
|
15
15
|
ev.bel_statement = hash[:bel_statement] || nil
|
16
|
-
ev.citation = Citation.
|
16
|
+
ev.citation = Citation.new(hash[:citation] || {})
|
17
17
|
ev.summary_text.value = hash[:summary_text] || nil
|
18
18
|
ev.experiment_context = ExperimentContext.new(hash[:experiment_context] || [])
|
19
19
|
ev.references = References.new(hash[:references] || {})
|
@@ -77,7 +77,7 @@ module BEL
|
|
77
77
|
:summary_text => @summary_text.value,
|
78
78
|
:experiment_context => @experiment_context.values,
|
79
79
|
:references => @references.values,
|
80
|
-
:metadata => @metadata.
|
80
|
+
:metadata => @metadata.to_a
|
81
81
|
}
|
82
82
|
)
|
83
83
|
hash
|
@@ -9,10 +9,14 @@ module BEL
|
|
9
9
|
extend Forwardable
|
10
10
|
include Enumerable
|
11
11
|
|
12
|
-
DOCUMENT_HEADER
|
12
|
+
DOCUMENT_HEADER = :document_header
|
13
13
|
|
14
14
|
def initialize(values = {})
|
15
|
-
|
15
|
+
if values.is_a? Array
|
16
|
+
@values = Hash[values.map { |item| item.values_at(:name, :value) }]
|
17
|
+
else
|
18
|
+
@values = values
|
19
|
+
end
|
16
20
|
end
|
17
21
|
|
18
22
|
def document_header
|
@@ -23,6 +27,15 @@ module BEL
|
|
23
27
|
@values[DOCUMENT_HEADER] = document_header
|
24
28
|
end
|
25
29
|
|
30
|
+
def to_a
|
31
|
+
@values.each_pair.map { |key, value|
|
32
|
+
{
|
33
|
+
name: key,
|
34
|
+
value: value
|
35
|
+
}
|
36
|
+
}
|
37
|
+
end
|
38
|
+
|
26
39
|
def_delegators :@values, :[], :"[]=", :delete_if, :each, :each_pair,
|
27
40
|
:fetch, :keys, :size, :sort, :store
|
28
41
|
end
|
@@ -9,27 +9,27 @@ module BEL
|
|
9
9
|
extend Forwardable
|
10
10
|
include Enumerable
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
ANNOTATIONS = :annotations
|
13
|
+
NAMESPACES = :namespaces
|
14
14
|
|
15
15
|
def initialize(values = {})
|
16
16
|
@values = values
|
17
17
|
end
|
18
18
|
|
19
|
-
def
|
20
|
-
@values[
|
19
|
+
def annotations
|
20
|
+
@values[ANNOTATIONS] ||= {}
|
21
21
|
end
|
22
22
|
|
23
|
-
def
|
24
|
-
@values[
|
23
|
+
def annotations=(annotations)
|
24
|
+
@values[ANNOTATIONS] = annotations
|
25
25
|
end
|
26
26
|
|
27
|
-
def
|
28
|
-
@values[
|
27
|
+
def namespaces
|
28
|
+
@values[NAMESPACES] ||= {}
|
29
29
|
end
|
30
30
|
|
31
|
-
def
|
32
|
-
@values[
|
31
|
+
def namespaces=(namespaces)
|
32
|
+
@values[NAMESPACES] = namespaces
|
33
33
|
end
|
34
34
|
|
35
35
|
def_delegators :@values, :[], :"[]=", :delete_if, :each, :each_pair,
|
data/lib/bel/json.rb
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
# TODO Document.
|
2
|
+
#
|
3
|
+
# What does this abstraction provide?
|
4
|
+
# Why is it here?
|
5
|
+
#
|
6
|
+
module BEL::JSON
|
7
|
+
|
8
|
+
# TODO Document.
|
9
|
+
#
|
10
|
+
# Reads JSON data. Leverages JSON adapters which implement the same signature.
|
11
|
+
def self.read(data, options = {})
|
12
|
+
@adapter ||= self.adapter
|
13
|
+
instance = @adapter.new
|
14
|
+
|
15
|
+
if block_given?
|
16
|
+
instance.read(data, options) { |obj|
|
17
|
+
yield obj
|
18
|
+
}
|
19
|
+
else
|
20
|
+
instance.read(data, options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# TODO Document.
|
25
|
+
#
|
26
|
+
# Writes JSON data. Leverages JSON adapters which implement the same signature.
|
27
|
+
def self.write(data, output_io, options = {})
|
28
|
+
@adapter ||= self.adapter
|
29
|
+
instance = @adapter.new
|
30
|
+
instance.write(data, output_io, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
# Load the most suitable JSON implementation available within ruby.
|
34
|
+
# The load order attempted is:
|
35
|
+
# - oj (provides stream parsing utilizing event callbacks)
|
36
|
+
# - multi_json (simple buffering abstraction over multiple ruby libraries)
|
37
|
+
# - json (stock ruby implementation)
|
38
|
+
def self.adapter
|
39
|
+
implementations = [
|
40
|
+
'json/adapter/oj',
|
41
|
+
'json/adapter/multi_json',
|
42
|
+
'json/adapter/ruby_json'
|
43
|
+
]
|
44
|
+
|
45
|
+
load_success = implementations.any? { |impl|
|
46
|
+
begin
|
47
|
+
require_relative impl
|
48
|
+
true
|
49
|
+
rescue LoadError
|
50
|
+
# Could not load +impl_module+; try the next one
|
51
|
+
false
|
52
|
+
end
|
53
|
+
}
|
54
|
+
|
55
|
+
if load_success
|
56
|
+
BEL::JSON::Implementation
|
57
|
+
else
|
58
|
+
mod_s = impl_modules.join(', ')
|
59
|
+
msg = "Could not load any JSON implementation (tried: #{mod_s})."
|
60
|
+
raise LoadError.new(msg)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'multi_json'
|
2
|
+
|
3
|
+
require_relative '../reader'
|
4
|
+
require_relative '../writer'
|
5
|
+
|
6
|
+
module BEL::JSON
|
7
|
+
|
8
|
+
class Implementation
|
9
|
+
|
10
|
+
include Reader
|
11
|
+
include Writer
|
12
|
+
|
13
|
+
def read(data, options = {})
|
14
|
+
if block_given?
|
15
|
+
options = { :symbolize_keys => true }.merge!(options)
|
16
|
+
MultiJson.load(data, options).each do |obj|
|
17
|
+
yield obj
|
18
|
+
end
|
19
|
+
else
|
20
|
+
to_enum(:read, data, options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def write(data, output_io, options = {})
|
25
|
+
json = MultiJson.dump(json_object)
|
26
|
+
if output_io
|
27
|
+
# write json and return IO
|
28
|
+
output_io.write json
|
29
|
+
output_io
|
30
|
+
else
|
31
|
+
# return json string
|
32
|
+
json
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'oj'
|
2
|
+
|
3
|
+
require_relative '../reader'
|
4
|
+
require_relative '../writer'
|
5
|
+
|
6
|
+
module BEL::JSON
|
7
|
+
|
8
|
+
class Implementation
|
9
|
+
|
10
|
+
include Reader
|
11
|
+
include Writer
|
12
|
+
|
13
|
+
def read(data, options = {}, &block)
|
14
|
+
if block_given?
|
15
|
+
options = { :symbol_keys => true }.merge!(options)
|
16
|
+
Oj.sc_parse(StreamHandler.new(block), data, options)
|
17
|
+
else
|
18
|
+
to_enum(:read, data, options)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def write(data, output_io, options = {})
|
23
|
+
Oj.to_stream(output_io, data)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
class StreamHandler < Oj::ScHandler
|
28
|
+
|
29
|
+
def initialize(callable)
|
30
|
+
@callable = callable
|
31
|
+
end
|
32
|
+
|
33
|
+
def hash_start
|
34
|
+
{}
|
35
|
+
end
|
36
|
+
|
37
|
+
def hash_end
|
38
|
+
@callable.call @hash
|
39
|
+
end
|
40
|
+
|
41
|
+
def hash_set(hash, key, value)
|
42
|
+
hash[key] = value
|
43
|
+
@hash = hash
|
44
|
+
end
|
45
|
+
|
46
|
+
def array_start
|
47
|
+
@array = []
|
48
|
+
@array
|
49
|
+
end
|
50
|
+
|
51
|
+
def array_append(array, value)
|
52
|
+
array << value
|
53
|
+
@array = array
|
54
|
+
end
|
55
|
+
|
56
|
+
def array_end()
|
57
|
+
@callable.call @array
|
58
|
+
end
|
59
|
+
|
60
|
+
def error(message, line, column)
|
61
|
+
msg = "Parse error at line #{line}, column #{column}: #{message}"
|
62
|
+
raise Oj::ParseError.new(msg)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
require_relative '../reader'
|
4
|
+
require_relative '../writer'
|
5
|
+
|
6
|
+
module BEL::JSON
|
7
|
+
|
8
|
+
class Implementation
|
9
|
+
|
10
|
+
include Reader
|
11
|
+
include Writer
|
12
|
+
|
13
|
+
def read(data, options = {})
|
14
|
+
if block_given?
|
15
|
+
options = { :symbolize_names => true }.merge!(options)
|
16
|
+
JSON.load(data, nil, options).each do |obj|
|
17
|
+
yield obj
|
18
|
+
end
|
19
|
+
else
|
20
|
+
to_enum(:read, data, options)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def write(data, output_io, options = {})
|
25
|
+
JSON.dump(data, output_io)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/bel/libbel.rb
CHANGED
@@ -12,7 +12,6 @@ module BEL
|
|
12
12
|
defined?(RUBY_ENGINE) && ("rbx" == RUBY_ENGINE)
|
13
13
|
end
|
14
14
|
|
15
|
-
# @api_private
|
16
15
|
# Determine FFI constant for this ruby engine.
|
17
16
|
def find_ffi
|
18
17
|
if rubinius?
|
@@ -26,7 +25,6 @@ module BEL
|
|
26
25
|
end
|
27
26
|
end
|
28
27
|
|
29
|
-
# @api_private
|
30
28
|
# Extend with the correct ffi implementation.
|
31
29
|
def load_ffi
|
32
30
|
ffi_module = BEL::LibBEL::find_ffi
|
@@ -34,7 +32,6 @@ module BEL
|
|
34
32
|
ffi_module
|
35
33
|
end
|
36
34
|
|
37
|
-
# @api_private
|
38
35
|
# Loads the libbel shared library.
|
39
36
|
def load_libBEL
|
40
37
|
ffi_module = find_ffi
|
@@ -123,7 +120,7 @@ module BEL
|
|
123
120
|
attach_function :bel_tokenize_term, [:string ], :pointer
|
124
121
|
|
125
122
|
# parse
|
126
|
-
attach_function :bel_parse_statement, [:string ], :pointer
|
123
|
+
#attach_function :bel_parse_statement, [:string ], :pointer
|
127
124
|
attach_function :bel_parse_term, [:string ], :pointer
|
128
125
|
|
129
126
|
def self.parse_statement(bel_string)
|
data/lib/bel/parser.rb
CHANGED
@@ -3,12 +3,12 @@ require_relative 'libbel'
|
|
3
3
|
module BEL
|
4
4
|
module Parser
|
5
5
|
|
6
|
-
# Parses BEL expressions to a {BelAst}.
|
6
|
+
# Parses BEL expressions to a {BEL::LibBEL::BelAst}.
|
7
7
|
#
|
8
8
|
# If +bel_expression+ is +nil+ then +nil+ is returned.
|
9
9
|
#
|
10
10
|
# @param bel_expression [responds to #to_s] the bel expression to parse
|
11
|
-
# @return [BelAst]
|
11
|
+
# @return [BEL::LibBEL::BelAst]
|
12
12
|
def self.parse(bel_expression, options = {})
|
13
13
|
if !bel_expression
|
14
14
|
return nil
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module BEL
|
2
|
+
module RdfRepository
|
3
|
+
|
4
|
+
module Plugins; end
|
5
|
+
|
6
|
+
extend LittlePlugger(
|
7
|
+
:path => 'bel/rdf_repository/plugins',
|
8
|
+
:module => BEL::RdfRepository::Plugins
|
9
|
+
)
|
10
|
+
|
11
|
+
module ClassMethods
|
12
|
+
|
13
|
+
def create_repository(options = {})
|
14
|
+
raise NotImplementedError.new("#{__method__} is not implemented.")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Load RDF library dependencies
|
2
|
+
require 'rdf'
|
3
|
+
require 'rdf/mongo'
|
4
|
+
require 'addressable/uri'
|
5
|
+
require 'uuid'
|
6
|
+
|
7
|
+
module BEL::RdfRepository::Plugins
|
8
|
+
|
9
|
+
module Memory
|
10
|
+
|
11
|
+
extend ::BEL::RdfRepository::ClassMethods
|
12
|
+
|
13
|
+
NAME = 'In-memory RDF Repository'
|
14
|
+
DESCRIPTION = 'An in-memory repository provided by default in RDF.rb.'
|
15
|
+
|
16
|
+
def self.create_repository(options = {})
|
17
|
+
RDF::Repository.new(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.name
|
21
|
+
NAME
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.description
|
25
|
+
DESCRIPTION
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# Load RDF library dependencies
|
2
|
+
require 'rdf'
|
3
|
+
require 'rdf/mongo'
|
4
|
+
require 'addressable/uri'
|
5
|
+
require 'uuid'
|
6
|
+
|
7
|
+
module BEL::RdfRepository::Plugins
|
8
|
+
|
9
|
+
module Mongo
|
10
|
+
|
11
|
+
extend ::BEL::RdfRepository::ClassMethods
|
12
|
+
|
13
|
+
NAME = 'Mongo RDF Repository'
|
14
|
+
DESCRIPTION = 'A repository of RDF data on MongoDB.'
|
15
|
+
|
16
|
+
def self.create_repository(options = {})
|
17
|
+
RDF::Mongo::Repository.new(options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.name
|
21
|
+
NAME
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.description
|
25
|
+
DESCRIPTION
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/lib/bel/resource.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
|
3
|
+
module BEL
|
4
|
+
module Resource
|
5
|
+
|
6
|
+
class BELV < RDF::StrictVocabulary('http://www.openbel.org/vocabulary/')
|
7
|
+
term :AnnotationConcept
|
8
|
+
term :AnnotationConceptScheme
|
9
|
+
term :NamespaceConcept
|
10
|
+
term :NamespaceConceptScheme
|
11
|
+
|
12
|
+
property :prefix
|
13
|
+
property :domain
|
14
|
+
property :species
|
15
|
+
property :inScheme
|
16
|
+
property :orthologousMatch
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
require_relative 'resource/namespaces'
|
22
|
+
require_relative 'resource/namespace'
|
23
|
+
require_relative 'resource/namespace_value'
|
24
|
+
require_relative 'resource/search'
|