bel 0.7.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/{bel.gemspec → .gemspec} +8 -4
- data/README.md +3 -3
- data/VERSION +1 -0
- data/bin/bel +8 -8
- data/bin/bel2rdf.rb +1 -1
- data/bin/bel_summarize.rb +4 -4
- data/bin/bel_upgrade.rb +6 -6
- data/lib/bel.rb +3 -2
- data/lib/bel/completion.rb +13 -10
- data/lib/bel/completion_rule.rb +29 -21
- data/lib/bel/dsl.rb +75 -0
- data/lib/bel/gen.rb +2 -2
- data/lib/bel/gen/annotation.rb +2 -2
- data/lib/bel/gen/citation.rb +6 -6
- data/lib/bel/gen/document_header.rb +1 -1
- data/lib/bel/gen/{evidence.rb → nanopub.rb} +15 -15
- data/lib/bel/gen/parameter.rb +6 -6
- data/lib/bel/gen/sample_resources.rb +4 -4
- data/lib/bel/gen/statement.rb +1 -1
- data/lib/bel/gen/term.rb +1 -1
- data/lib/bel/language.rb +0 -20
- data/lib/bel/namespace.rb +7 -3
- data/lib/bel/nanopub.rb +15 -0
- data/lib/bel/{evidence_model/buffering_evidence_combiner.rb → nanopub/buffering_nanopub_combiner.rb} +39 -45
- data/lib/bel/{evidence_model → nanopub}/citation.rb +2 -2
- data/lib/bel/{evidence_model → nanopub}/experiment_context.rb +7 -1
- data/lib/bel/{evidence_model → nanopub}/hash_map_references.rb +1 -1
- data/lib/bel/{evidence_model → nanopub}/map_references.rb +1 -1
- data/lib/bel/nanopub/map_references_combiner.rb +30 -0
- data/lib/bel/nanopub/metadata.rb +102 -0
- data/lib/bel/nanopub/nanopub.rb +122 -0
- data/lib/bel/{evidence_model → nanopub}/references.rb +50 -38
- data/lib/bel/{evidence_model/streaming_evidence_combiner.rb → nanopub/streaming_nanopub_combiner.rb} +8 -8
- data/lib/bel/{evidence_model/summary_text.rb → nanopub/support.rb} +8 -2
- data/lib/bel/{evidence_model → nanopub}/util.rb +10 -10
- data/lib/bel/resource/annotation.rb +15 -24
- data/lib/bel/resource/annotation_value.rb +24 -20
- data/lib/bel/resource/annotations.rb +12 -11
- data/lib/bel/resource/concept.rb +62 -0
- data/lib/bel/resource/concept_scheme.rb +49 -0
- data/lib/bel/resource/namespace.rb +15 -24
- data/lib/bel/resource/namespace_value.rb +26 -23
- data/lib/bel/resource/namespaces.rb +11 -11
- data/lib/bel/script.rb +367 -367
- data/lib/bel/translate.rb +7 -7
- data/lib/bel/translator.rb +10 -10
- data/lib/bel/translator/plugins/bnj.rb +37 -0
- data/lib/bel/translator/plugins/{json_evidence → bnj}/translator.rb +17 -34
- data/lib/bel/translator/plugins/jgf.rb +1 -1
- data/lib/bel/translator/plugins/jgf/translator.rb +10 -10
- data/lib/bel/translator/plugins/jsonld.rb +1 -1
- data/lib/bel/translator/plugins/nquads.rb +1 -1
- data/lib/bel/translator/plugins/ntriples.rb +1 -1
- data/lib/bel/translator/plugins/rdf/bel_schema.rb +134 -126
- data/lib/bel/translator/plugins/rdf/graph_translator.rb +6 -6
- data/lib/bel/translator/plugins/rdf/monkey_patch.rb +50 -49
- data/lib/bel/translator/plugins/rdf/reader.rb +42 -42
- data/lib/bel/translator/plugins/rdf/translator.rb +6 -6
- data/lib/bel/translator/plugins/rdf/writer.rb +4 -4
- data/lib/bel/translator/plugins/rdf2/belv2_0.rb +416 -0
- data/lib/bel/translator/plugins/rdf2/converter.rb +13 -0
- data/lib/bel/translator/plugins/rdf2/namespace_converter.rb +24 -0
- data/lib/bel/translator/plugins/rdf2/nanopub_converter.rb +82 -0
- data/lib/bel/translator/plugins/rdf2/parameter_converter.rb +50 -0
- data/lib/bel/translator/plugins/rdf2/rdf_converter.rb +13 -0
- data/lib/bel/translator/plugins/rdf2/rdf_writer.rb +63 -0
- data/lib/bel/translator/plugins/rdf2/reader.rb +172 -0
- data/lib/bel/translator/plugins/rdf2/relationship_converter.rb +49 -0
- data/lib/bel/translator/plugins/rdf2/statement_converter.rb +65 -0
- data/lib/bel/translator/plugins/rdf2/term_converter.rb +262 -0
- data/lib/bel/translator/plugins/rdf2/translator.rb +51 -0
- data/lib/bel/translator/plugins/rdf2/uuid.rb +20 -0
- data/lib/bel/translator/plugins/rdf2/writer.rb +53 -0
- data/lib/bel/translator/plugins/rdfa.rb +1 -1
- data/lib/bel/translator/plugins/rdfxml.rb +1 -1
- data/lib/bel/translator/plugins/rj.rb +1 -1
- data/lib/bel/translator/plugins/trig.rb +1 -1
- data/lib/bel/translator/plugins/trix.rb +1 -1
- data/lib/bel/translator/plugins/turtle.rb +3 -6
- data/lib/bel/translator/plugins/xbel.rb +5 -6
- data/lib/bel/translator/plugins/xbel/nanopub_handler.rb +625 -0
- data/lib/bel/translator/plugins/xbel/{evidence_yielder.rb → nanopub_yielder.rb} +3 -3
- data/lib/bel/translator/plugins/xbel/translator.rb +2 -5
- data/lib/bel/translator/plugins/xbel/xbel_yielder.rb +135 -74
- data/lib/bel/version.rb +31 -1
- metadata +81 -33
- data/lib/bel/evidence_model.rb +0 -15
- data/lib/bel/evidence_model/bel_parameter.rb +0 -56
- data/lib/bel/evidence_model/bel_statement.rb +0 -97
- data/lib/bel/evidence_model/bel_term.rb +0 -87
- data/lib/bel/evidence_model/evidence.rb +0 -127
- data/lib/bel/evidence_model/map_references_combiner.rb +0 -30
- data/lib/bel/evidence_model/metadata.rb +0 -49
- data/lib/bel/parser.rb +0 -39
- data/lib/bel/translator/plugins/bel_script.rb +0 -36
- data/lib/bel/translator/plugins/bel_script/bel_citation_serialization.rb +0 -125
- data/lib/bel/translator/plugins/bel_script/bel_discrete_serialization.rb +0 -109
- data/lib/bel/translator/plugins/bel_script/bel_top_down_serialization.rb +0 -100
- data/lib/bel/translator/plugins/bel_script/bel_yielder.rb +0 -180
- data/lib/bel/translator/plugins/bel_script/evidence_serialization.rb +0 -79
- data/lib/bel/translator/plugins/bel_script/evidence_yielder.rb +0 -87
- data/lib/bel/translator/plugins/bel_script/translator.rb +0 -35
- data/lib/bel/translator/plugins/json_evidence.rb +0 -38
- data/lib/bel/translator/plugins/xbel/evidence_handler.rb +0 -495
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
|
3
|
+
module BEL
|
4
|
+
module BELRDF
|
5
|
+
module RDFConverter
|
6
|
+
# Convenience function to create an {RDF::Statement} given a triple
|
7
|
+
# of subject, predicate, and object.
|
8
|
+
def s(subject, predicate, object)
|
9
|
+
RDF::Statement.new(subject, predicate, object)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
module BEL
|
2
|
+
module BELRDF
|
3
|
+
class NamespaceConverter
|
4
|
+
|
5
|
+
PREFIX_TERMINAL = '/'
|
6
|
+
|
7
|
+
# Convert a {BELParser::Expression::Model::Namespace} to {RDF::Graph} of
|
8
|
+
# RDF statements.
|
9
|
+
#
|
10
|
+
# @param [BELParser::Expression::Model::Namespace] namespace
|
11
|
+
# @return [RDF::Graph] graph of RDF statements representing the namespace
|
12
|
+
def convert(namespace)
|
13
|
+
return nil if namespace.nil? || !namespace.uri?
|
14
|
+
NamespaceConverter.resolve_vocabulary(namespace.uri)
|
15
|
+
end
|
16
|
+
|
17
|
+
@namespace_vocabulary_hash = {}
|
18
|
+
def self.resolve_vocabulary(uri)
|
19
|
+
@namespace_vocabulary_hash[uri] ||=
|
20
|
+
RDF::Vocabulary.new("#{uri}#{PREFIX_TERMINAL}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require_relative 'uuid'
|
2
|
+
require_relative 'rdf_converter'
|
3
|
+
|
4
|
+
module BEL
|
5
|
+
module BELRDF
|
6
|
+
class NanopubConverter
|
7
|
+
include RDFConverter
|
8
|
+
|
9
|
+
def initialize(statement_converter)
|
10
|
+
@statement_converter = statement_converter
|
11
|
+
end
|
12
|
+
|
13
|
+
# Convert a {BEL::Nanopub::Nanopub} to {RDF::Graph} of RDF statements.
|
14
|
+
#
|
15
|
+
# @param [BEL::Nanopub::Nanopub] nanopub
|
16
|
+
# @return [RDF::Graph] graph of RDF statements representing the nanopub
|
17
|
+
def convert(nanopub)
|
18
|
+
resource = generate_nanopub_uri
|
19
|
+
graph = RDF::Graph.new
|
20
|
+
graph << s(resource, RDF.type, BELV2_0.Nanopub)
|
21
|
+
|
22
|
+
bel_statement(nanopub.bel_statement, resource, graph)
|
23
|
+
citation(nanopub.citation, resource, graph)
|
24
|
+
support(nanopub.support, resource, graph)
|
25
|
+
experiment_context(nanopub.experiment_context, resource, graph)
|
26
|
+
references(nanopub.references, resource, graph)
|
27
|
+
metadata(nanopub.metadata, resource, graph)
|
28
|
+
|
29
|
+
graph
|
30
|
+
end
|
31
|
+
|
32
|
+
protected
|
33
|
+
|
34
|
+
def bel_statement(statement, nr, ng)
|
35
|
+
path_part, stmt_uri, sg = @statement_converter.convert(statement)
|
36
|
+
ng << sg
|
37
|
+
ng << s(nr, BELV2_0.hasStatement, stmt_uri)
|
38
|
+
end
|
39
|
+
|
40
|
+
def citation(citation, nr, ng)
|
41
|
+
type = citation.type
|
42
|
+
if type && (type.to_s.downcase == 'pubmed')
|
43
|
+
ng << s(nr, BELV2_0.hasCitation, PUBMED[citation.id.to_s])
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
def support(support, nr, ng)
|
48
|
+
unless support.value.nil?
|
49
|
+
ng << s(nr, BELV2_0.hasSupport, support.to_s)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def experiment_context(experiment_context, nr, ng)
|
54
|
+
end
|
55
|
+
|
56
|
+
def references(references, nr, ng)
|
57
|
+
end
|
58
|
+
|
59
|
+
def metadata(metadata, nr, ng)
|
60
|
+
v = metadata.bel_version
|
61
|
+
bel_version(v, nr, ng) if v
|
62
|
+
end
|
63
|
+
|
64
|
+
def bel_version(bel_version, nr, ng)
|
65
|
+
spec = BELParser::Language.specification(bel_version) rescue nil
|
66
|
+
return unless spec
|
67
|
+
|
68
|
+
bel = RDF::URI(spec.uri)
|
69
|
+
ng << s(bel, RDF.type, BELV2_0.BiologicalExpressionLanguage)
|
70
|
+
ng << s(bel, BELV2_0.hasVersion, spec.version.to_s)
|
71
|
+
ng << s(nr, BELV2_0.hasBiologicalExpressionLanguage, bel)
|
72
|
+
end
|
73
|
+
|
74
|
+
private
|
75
|
+
|
76
|
+
# @api private
|
77
|
+
def generate_nanopub_uri
|
78
|
+
BELN[BELRDF.generate_uuid]
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
require_relative 'rdf_converter'
|
3
|
+
require_relative 'belv2_0'
|
4
|
+
|
5
|
+
module BEL
|
6
|
+
module BELRDF
|
7
|
+
class ParameterConverter
|
8
|
+
include RDFConverter
|
9
|
+
|
10
|
+
def initialize(namespace_converter)
|
11
|
+
@namespace_converter = namespace_converter
|
12
|
+
end
|
13
|
+
# Convert a {BELParser::Expression::Model::Parameter} to {RDF::Graph} of
|
14
|
+
# RDF statements.
|
15
|
+
#
|
16
|
+
# @param [BELParser::Expression::Model::Parameter] parameter
|
17
|
+
# @return [RDF::Graph] graph of RDF statements representing the parameter
|
18
|
+
def convert(parameter)
|
19
|
+
namespace_vocab = @namespace_converter.convert(parameter.namespace)
|
20
|
+
return nil unless namespace_vocab
|
21
|
+
|
22
|
+
value_s = parameter.value.to_s
|
23
|
+
param_uri = namespace_vocab[value_s]
|
24
|
+
pg = RDF::Graph.new
|
25
|
+
if parameter.encoding
|
26
|
+
parameter.encoding.each do |enc|
|
27
|
+
concept_type = ENCODING_HASH[enc]
|
28
|
+
next unless concept_type
|
29
|
+
pg << s(param_uri, RDF.type, concept_type)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
[param_uri, pg]
|
33
|
+
end
|
34
|
+
|
35
|
+
ENCODING_HASH = {
|
36
|
+
:A => BELV2_0.AbundanceConcept,
|
37
|
+
:B => BELV2_0.BiologicalProcessConcept,
|
38
|
+
:C => BELV2_0.ComplexConcept,
|
39
|
+
:E => BELV2_0.ProteinModificationConcept,
|
40
|
+
:G => BELV2_0.GeneConcept,
|
41
|
+
:L => BELV2_0.LocationConcept,
|
42
|
+
:M => BELV2_0.MicroRNAConcept,
|
43
|
+
:O => BELV2_0.PathologyConcept,
|
44
|
+
:P => BELV2_0.ProteinConcept,
|
45
|
+
:R => BELV2_0.RNAConcept,
|
46
|
+
:T => BELV2_0.MolecularActivityConcept
|
47
|
+
}.freeze
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
|
3
|
+
module BEL
|
4
|
+
module BELRDF
|
5
|
+
module RDFConverter
|
6
|
+
# Convenience function to create an {RDF::Statement} given a triple
|
7
|
+
# of subject, predicate, and object.
|
8
|
+
def s(subject, predicate, object)
|
9
|
+
RDF::Statement.new(subject, predicate, object)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require_relative 'nanopub_converter'
|
2
|
+
require_relative 'statement_converter'
|
3
|
+
require_relative 'relationship_converter'
|
4
|
+
require_relative 'term_converter'
|
5
|
+
require_relative 'parameter_converter'
|
6
|
+
require_relative 'namespace_converter'
|
7
|
+
|
8
|
+
module BEL
|
9
|
+
module BELRDF
|
10
|
+
module Writer
|
11
|
+
class RDFWriter
|
12
|
+
attr_reader :writer
|
13
|
+
|
14
|
+
def initialize(io, format, options = {})
|
15
|
+
rdf_writer = RDF::Writer.for(format)
|
16
|
+
@writer = rdf_writer.new(io, { :stream => true })
|
17
|
+
|
18
|
+
if options[:void_dataset_uri]
|
19
|
+
void_dataset_uri = options.delete(:void_dataset_uri)
|
20
|
+
void_dataset_uri = RDF::URI(void_dataset_uri)
|
21
|
+
unless void_dataset_uri.valid?
|
22
|
+
raise ArgumentError.new 'void_dataset_uri is not a valid URI'
|
23
|
+
end
|
24
|
+
@void_dataset_uri = void_dataset_uri
|
25
|
+
else
|
26
|
+
@void_dataset_uri = nil
|
27
|
+
end
|
28
|
+
|
29
|
+
@writer.write_prologue
|
30
|
+
@wrote_dataset = false
|
31
|
+
@nanopub_converter =
|
32
|
+
NanopubConverter.new(
|
33
|
+
StatementConverter.new(
|
34
|
+
TermConverter.new(
|
35
|
+
ParameterConverter.new(
|
36
|
+
NamespaceConverter.new)),
|
37
|
+
RelationshipConverter.new))
|
38
|
+
end
|
39
|
+
|
40
|
+
def <<(nanopub)
|
41
|
+
if !@wrote_dataset && @void_dataset_uri
|
42
|
+
# TODO Write VoID dataset for document.
|
43
|
+
end
|
44
|
+
|
45
|
+
@writer << @nanopub_converter.convert(nanopub)
|
46
|
+
|
47
|
+
# @nanopub_converter.nanopub(nanopub).each do |statement|
|
48
|
+
# @writer.write_statement(statement)
|
49
|
+
# end
|
50
|
+
|
51
|
+
if @void_dataset_uri
|
52
|
+
# TODO Include this nanopub in the VoID dataset.
|
53
|
+
# @writer.write_statement(RDF::Statement.new(@void_dataset_uri, RDF::DC.hasPart, nanopub_uri))
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
def done
|
58
|
+
@writer.write_epilogue
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,172 @@
|
|
1
|
+
require_relative 'belv2_0'
|
2
|
+
|
3
|
+
module BEL
|
4
|
+
module BELRDF
|
5
|
+
module Reader
|
6
|
+
module NanopubYielder
|
7
|
+
include ::BEL::Nanopub
|
8
|
+
include ::BEL::Quoting
|
9
|
+
|
10
|
+
# Find described resources by +type+ in +graph+.
|
11
|
+
#
|
12
|
+
# @param [::RDF::Resource] type the RDF type to find instances for
|
13
|
+
# @param [::RDF::Graph] graph the RDF graph to query
|
14
|
+
# @return [Enumerator] an enumerator of described resource instances
|
15
|
+
def resources_of_type(type, graph)
|
16
|
+
graph.query([nil, ::RDF.type, type])
|
17
|
+
.lazy
|
18
|
+
.map { |rdf_statement|
|
19
|
+
describe(rdf_statement.subject, graph)
|
20
|
+
}
|
21
|
+
end
|
22
|
+
|
23
|
+
# Describes an RDF +resource+ contained within +graph+. Describing an RDF
|
24
|
+
# resource will retrieve the neighborhood of RDF statements with
|
25
|
+
# +resource+ in the subject position.
|
26
|
+
#
|
27
|
+
# @param [::RDF::Resource] resource the RDF resource to describe
|
28
|
+
# @param [::RDF::Graph] graph the RDF graph to query
|
29
|
+
# @return [Hash] a hash of predicate to object in the
|
30
|
+
# neighborhood of +resource+
|
31
|
+
def describe(resource, graph)
|
32
|
+
graph.query([resource, nil, nil]).reduce({}) { |hash, statement|
|
33
|
+
hash[statement.predicate] = statement.object
|
34
|
+
hash
|
35
|
+
}
|
36
|
+
end
|
37
|
+
|
38
|
+
# Iterate the {BELV.Nanopub} predicated statements, from the
|
39
|
+
# {::RDF::Graph graph}, and yield those correspdonding {Nanopub}
|
40
|
+
# objects.
|
41
|
+
#
|
42
|
+
# @param [::RDF::Graph] graph the RDF graph to query
|
43
|
+
# @yield [::BEL::Nanopub::Nanopub] yields a nanopub object
|
44
|
+
def nanopub_yielder(graph)
|
45
|
+
resources_of_type(BELV.Nanopub, graph).each do |nanopub|
|
46
|
+
|
47
|
+
yield make_nanopub(nanopub, graph)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
# Create an {Nanopub} object from RDF statements found in
|
52
|
+
# the {::RDF::Graph graph}.
|
53
|
+
#
|
54
|
+
# @param [Hash] nanopub a hash of predicate to object
|
55
|
+
# representing the described nanopub
|
56
|
+
# @param [::RDF::Graph] graph the RDF graph to query
|
57
|
+
# @return [Nanopub] the nanopub
|
58
|
+
def make_nanopub(nanopub_hash, graph)
|
59
|
+
statement = describe(nanopub_hash[BELV.hasStatement], graph)
|
60
|
+
|
61
|
+
# values
|
62
|
+
bel_statement = statement[::RDF::RDFS.label].value
|
63
|
+
support_text = nanopub_hash[BELV.hasSupport]
|
64
|
+
citation = nanopub_hash[BELV.hasCitation]
|
65
|
+
|
66
|
+
# model
|
67
|
+
nanopub = Nanopub.new
|
68
|
+
nanopub.bel_statement = ::BEL::Script.parse(bel_statement)
|
69
|
+
.find { |obj|
|
70
|
+
obj.is_a? Statement
|
71
|
+
}
|
72
|
+
nanopub.support = Support.new(support_text.value) if support_text
|
73
|
+
|
74
|
+
if citation.respond_to?(:value)
|
75
|
+
nanopub.citation =
|
76
|
+
case citation.value
|
77
|
+
when /pubmed:(\d+)$/
|
78
|
+
pubmed_id = $1.to_i
|
79
|
+
Citation.new({
|
80
|
+
:type => 'PubMed',
|
81
|
+
:id => pubmed_id,
|
82
|
+
:name => "PubMed Citation - #{pubmed_id}"
|
83
|
+
})
|
84
|
+
else
|
85
|
+
nil
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
nanopub
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
class BufferedNanopubYielder
|
94
|
+
|
95
|
+
include NanopubYielder
|
96
|
+
|
97
|
+
def initialize(data, format = :ntriples)
|
98
|
+
@data = data
|
99
|
+
@format = format
|
100
|
+
end
|
101
|
+
|
102
|
+
def each
|
103
|
+
if block_given?
|
104
|
+
graph = RDF::Graph.new
|
105
|
+
RDF::Reader.for(@format).new(@data) do |reader|
|
106
|
+
reader.each_statement do |statement|
|
107
|
+
graph << statement
|
108
|
+
end
|
109
|
+
end
|
110
|
+
nanopub_yielder(graph) do |nanopub|
|
111
|
+
yield nanopub
|
112
|
+
end
|
113
|
+
else
|
114
|
+
to_enum(:each)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
class UnbufferedNanopubYielder
|
120
|
+
|
121
|
+
include NanopubYielder
|
122
|
+
|
123
|
+
def initialize(data, format)
|
124
|
+
@data = data
|
125
|
+
@format = format
|
126
|
+
end
|
127
|
+
|
128
|
+
def each
|
129
|
+
if block_given?
|
130
|
+
graph = RDF::Graph.new
|
131
|
+
nanopub = nil
|
132
|
+
RDF::Reader.for(@format).new(@data) do |reader|
|
133
|
+
reader.each_statement do |statement|
|
134
|
+
case
|
135
|
+
when statement.object == BELV.Nanopub &&
|
136
|
+
statement.predicate == RDF.type
|
137
|
+
nanopub = statement.subject
|
138
|
+
when nanopub &&
|
139
|
+
statement.predicate != BELV.hasNanopub &&
|
140
|
+
statement.subject != nanopub
|
141
|
+
|
142
|
+
# yield current graph as nanopub
|
143
|
+
yield make_nanopub(
|
144
|
+
describe(nanopub, graph),
|
145
|
+
graph
|
146
|
+
)
|
147
|
+
|
148
|
+
# reset parse state
|
149
|
+
graph.clear
|
150
|
+
nanopub = nil
|
151
|
+
|
152
|
+
# insert this RDF statement
|
153
|
+
graph << statement
|
154
|
+
else
|
155
|
+
graph << statement
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
# yield last graph as nanopub
|
161
|
+
yield make_nanopub(
|
162
|
+
describe(nanopub, graph),
|
163
|
+
graph
|
164
|
+
)
|
165
|
+
else
|
166
|
+
to_enum(:each)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
end
|
170
|
+
end
|
171
|
+
end
|
172
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
require 'bel_parser/language/version2_0'
|
3
|
+
require_relative 'rdf_converter'
|
4
|
+
|
5
|
+
module BEL
|
6
|
+
module BELRDF
|
7
|
+
class RelationshipConverter
|
8
|
+
include BELParser::Language::Version2_0::Relationships
|
9
|
+
include RDFConverter
|
10
|
+
|
11
|
+
# Convert a version 2.0 {BELParser::Language::Relationship}
|
12
|
+
# to RDF statements.
|
13
|
+
#
|
14
|
+
# @param [BELParser::Language::Relationship] relationship
|
15
|
+
# @return [RDF::Graph] graph of RDF statements representing the relationship
|
16
|
+
def convert(relationship)
|
17
|
+
return nil if relationship.nil?
|
18
|
+
[relationship.long.to_s, RELATIONSHIP_HASH[relationship]]
|
19
|
+
end
|
20
|
+
|
21
|
+
RELATIONSHIP_HASH = {
|
22
|
+
Analogous => BELV2_0.Analogous,
|
23
|
+
Association => BELV2_0.Association,
|
24
|
+
BiomarkerFor => BELV2_0.BiomarkerFor,
|
25
|
+
CausesNoChange => BELV2_0.CausesNoChange,
|
26
|
+
Decreases => BELV2_0.Decreases,
|
27
|
+
DirectlyDecreases => BELV2_0.DirectlyDecreases,
|
28
|
+
DirectlyIncreases => BELV2_0.DirectlyIncreases,
|
29
|
+
HasComponent => BELV2_0.HasComponent,
|
30
|
+
HasMember => BELV2_0.HasMember,
|
31
|
+
Increases => BELV2_0.Increases,
|
32
|
+
IsA => BELV2_0.IsA,
|
33
|
+
NegativeCorrelation => BELV2_0.NegativeCorrelation,
|
34
|
+
Orthologous => BELV2_0.Orthologous,
|
35
|
+
PositiveCorrelation => BELV2_0.PositiveCorrelation,
|
36
|
+
PrognosticBiomarkerFor => BELV2_0.PrognosticBiomarkerFor,
|
37
|
+
RateLimitingStepOf => BELV2_0.RateLimitingStepOf,
|
38
|
+
Regulates => BELV2_0.Regulates,
|
39
|
+
SubProcessOf => BELV2_0.SubProcessOf,
|
40
|
+
TranscribedTo => BELV2_0.TranscribedTo,
|
41
|
+
TranslatedTo => BELV2_0.TranslatedTo
|
42
|
+
}.freeze
|
43
|
+
# Special
|
44
|
+
# HasMembers
|
45
|
+
# HasComponents
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|