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
@@ -24,7 +24,7 @@ module BELRDF
|
|
24
24
|
end
|
25
25
|
|
26
26
|
def read(data, options = {})
|
27
|
-
Reader::
|
27
|
+
Reader::BufferedNanopubYielder.new(data, @format)
|
28
28
|
end
|
29
29
|
|
30
30
|
def write(objects, io = StringIO.new, options = {})
|
@@ -61,10 +61,10 @@ module BELRDF
|
|
61
61
|
yielder << RDF::Statement.new(*schema_statement)
|
62
62
|
end
|
63
63
|
|
64
|
-
# enumerate BEL
|
65
|
-
objects.each do |
|
64
|
+
# enumerate BEL nanopubs
|
65
|
+
objects.each do |nanopub|
|
66
66
|
if void_dataset_uri && !wrote_dataset
|
67
|
-
void_dataset_triples =
|
67
|
+
void_dataset_triples = nanopub.to_void_dataset(void_dataset_uri)
|
68
68
|
if void_dataset_triples && void_dataset_triples.respond_to?(:each)
|
69
69
|
void_dataset_triples.each do |void_triple|
|
70
70
|
yielder << void_triple
|
@@ -73,7 +73,7 @@ module BELRDF
|
|
73
73
|
wrote_dataset = true
|
74
74
|
end
|
75
75
|
|
76
|
-
|
76
|
+
nanopub_uri, statements = nanopub.to_rdf
|
77
77
|
statements.each do |statement|
|
78
78
|
yielder << statement
|
79
79
|
end
|
@@ -82,7 +82,7 @@ module BELRDF
|
|
82
82
|
yielder << RDF::Statement.new(
|
83
83
|
void_dataset_uri,
|
84
84
|
RDF::DC.hasPart,
|
85
|
-
|
85
|
+
nanopub_uri
|
86
86
|
)
|
87
87
|
end
|
88
88
|
end
|
@@ -1,24 +1,25 @@
|
|
1
|
-
require 'bel/
|
1
|
+
require 'bel/nanopub'
|
2
|
+
require_relative 'bel_schema'
|
2
3
|
require_relative 'uuid'
|
3
4
|
|
4
5
|
module BELRDF
|
5
6
|
|
6
|
-
# OpenClass to contribute RDF functionality to BEL
|
7
|
+
# OpenClass to contribute RDF functionality to BEL Nanopub objects.
|
7
8
|
|
8
9
|
class ::BEL::Namespace::NamespaceDefinition
|
9
10
|
|
10
11
|
def to_uri
|
11
|
-
|
12
|
+
rdf_uri
|
12
13
|
end
|
13
14
|
|
14
15
|
def to_rdf_vocabulary
|
15
16
|
uri = @rdf_uri
|
16
|
-
uri << '/'
|
17
|
+
uri << '/' if uri && !uri.end_with?('/')
|
17
18
|
::RDF::Vocabulary.new(uri)
|
18
19
|
end
|
19
20
|
end
|
20
21
|
|
21
|
-
class ::BEL::
|
22
|
+
class ::BEL::Nanopub::Parameter
|
22
23
|
|
23
24
|
CONCEPT_ENCODING = {
|
24
25
|
:G => BELRDF::BELV.GeneConcept,
|
@@ -70,7 +71,7 @@ module BELRDF
|
|
70
71
|
end
|
71
72
|
end
|
72
73
|
|
73
|
-
class ::BEL::
|
74
|
+
class ::BEL::Nanopub::Term
|
74
75
|
|
75
76
|
def to_uri
|
76
77
|
tid = to_s.squeeze(')').gsub(/[")\[\]]/, '').gsub(/[(:, ]/, '_')
|
@@ -82,7 +83,7 @@ module BELRDF
|
|
82
83
|
fx = @fx.respond_to?(:short_form) ? @fx.short_form : @fx.to_s.to_sym
|
83
84
|
if [:p, :proteinAbundance].include?(fx) &&
|
84
85
|
@arguments.find{ |x|
|
85
|
-
if x.is_a? ::BEL::
|
86
|
+
if x.is_a? ::BEL::Nanopub::Term
|
86
87
|
arg_fx = x.fx
|
87
88
|
arg_fx = arg_fx.respond_to?(:short_form) ? arg_fx.short_form : arg_fx.to_s.to_sym
|
88
89
|
[:pmod, :proteinModification].include?(arg_fx)
|
@@ -96,7 +97,7 @@ module BELRDF
|
|
96
97
|
|
97
98
|
if [:p, :proteinAbundance].include?(fx) &&
|
98
99
|
@arguments.find{ |x|
|
99
|
-
if x.is_a? ::BEL::
|
100
|
+
if x.is_a? ::BEL::Nanopub::Term
|
100
101
|
arg_fx = x.fx
|
101
102
|
arg_fx = arg_fx.respond_to?(:short_form) ? arg_fx.short_form : arg_fx.to_s.to_sym
|
102
103
|
BELRDF::PROTEIN_VARIANT.include?(arg_fx)
|
@@ -132,7 +133,7 @@ module BELRDF
|
|
132
133
|
if [:p, :proteinAbundance].include?(fx)
|
133
134
|
pmod =
|
134
135
|
@arguments.find{ |x|
|
135
|
-
if x.is_a? ::BEL::
|
136
|
+
if x.is_a? ::BEL::Nanopub::Term
|
136
137
|
arg_fx = x.fx
|
137
138
|
arg_fx = arg_fx.respond_to?(:short_form) ? arg_fx.short_form : arg_fx.to_s.to_sym
|
138
139
|
[:pmod, :proteinModification].include?(arg_fx)
|
@@ -150,15 +151,15 @@ module BELRDF
|
|
150
151
|
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasModificationPosition, last.to_i, :graph_name => graph_name)
|
151
152
|
end
|
152
153
|
# link root protein abundance as hasChild
|
153
|
-
root_param = @arguments.find{|x| x.is_a? ::BEL::
|
154
|
-
(root_id, root_statements) = ::BEL::
|
154
|
+
root_param = @arguments.find{|x| x.is_a? ::BEL::Nanopub::Parameter}
|
155
|
+
(root_id, root_statements) = ::BEL::Nanopub::Term.new(:p, [root_param]).to_rdf(graph_name, remap)
|
155
156
|
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasChild, root_id, :graph_name => graph_name)
|
156
157
|
statements.concat(root_statements)
|
157
158
|
return [uri, statements]
|
158
|
-
elsif @arguments.find{|x| x.is_a? ::BEL::
|
159
|
+
elsif @arguments.find{|x| x.is_a? ::BEL::Nanopub::Term and BELRDF::PROTEIN_VARIANT.include? x.fx}
|
159
160
|
# link root protein abundance as hasChild
|
160
|
-
root_param = @arguments.find{|x| x.is_a? ::BEL::
|
161
|
-
(root_id, root_statements) = ::BEL::
|
161
|
+
root_param = @arguments.find{|x| x.is_a? ::BEL::Nanopub::Parameter}
|
162
|
+
(root_id, root_statements) = ::BEL::Nanopub::Term.new(:p, [root_param]).to_rdf(graph_name, remap)
|
162
163
|
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasChild, root_id, :graph_name => graph_name)
|
163
164
|
statements.concat(root_statements)
|
164
165
|
return [uri, statements]
|
@@ -167,7 +168,7 @@ module BELRDF
|
|
167
168
|
|
168
169
|
# BELRDF::BELV.hasConcept
|
169
170
|
@arguments.find_all{ |x|
|
170
|
-
x.is_a? ::BEL::
|
171
|
+
x.is_a? ::BEL::Nanopub::Parameter and x.ns != nil
|
171
172
|
}.each do |param|
|
172
173
|
param_uri, encoding_statements = param.to_rdf(graph_name, remap)
|
173
174
|
statements.concat(encoding_statements)
|
@@ -175,7 +176,7 @@ module BELRDF
|
|
175
176
|
end
|
176
177
|
|
177
178
|
# BELRDF::BELV.hasChild]
|
178
|
-
@arguments.find_all{|x| x.is_a? ::BEL::
|
179
|
+
@arguments.find_all{|x| x.is_a? ::BEL::Nanopub::Term}.each do |child|
|
179
180
|
(child_id, child_statements) = child.to_rdf(graph_name, remap)
|
180
181
|
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasChild, child_id, :graph_name => graph_name)
|
181
182
|
statements.concat(child_statements)
|
@@ -185,7 +186,7 @@ module BELRDF
|
|
185
186
|
end
|
186
187
|
end
|
187
188
|
|
188
|
-
class ::BEL::
|
189
|
+
class ::BEL::Nanopub::Statement
|
189
190
|
|
190
191
|
def to_uri
|
191
192
|
case
|
@@ -267,13 +268,13 @@ module BELRDF
|
|
267
268
|
|
268
269
|
# common statement triples
|
269
270
|
statements << ::RDF::Statement.new(uri, BELRDF::RDF.type, BELRDF::BELV.Statement, :graph_name => graph_name)
|
270
|
-
statements << ::RDF::Statement.new(uri, ::
|
271
|
+
statements << ::RDF::Statement.new(uri, BELRDF::RDFS.label, to_s.force_encoding('UTF-8'), :graph_name => graph_name)
|
271
272
|
|
272
|
-
#
|
273
|
-
|
274
|
-
statements << ::RDF::Statement.new(
|
275
|
-
statements << ::RDF::Statement.new(uri, BELRDF::BELV.
|
276
|
-
statements << ::RDF::Statement.new(
|
273
|
+
# nanopub
|
274
|
+
nanopub = BELRDF::BELE[BELRDF.generate_uuid]
|
275
|
+
statements << ::RDF::Statement.new(nanopub, BELRDF::RDF.type, BELRDF::BELV.Nanopub, :graph_name => graph_name)
|
276
|
+
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasNanopub, nanopub, :graph_name => graph_name)
|
277
|
+
statements << ::RDF::Statement.new(nanopub, BELRDF::BELV.hasStatement, uri, :graph_name => graph_name)
|
277
278
|
|
278
279
|
# citation
|
279
280
|
citation = @annotations.delete('Citation')
|
@@ -281,15 +282,15 @@ module BELRDF
|
|
281
282
|
value = citation.value.map{|x| x.gsub('"', '')}
|
282
283
|
if citation and value[0] == 'PubMed'
|
283
284
|
pid = value[2]
|
284
|
-
statements << ::RDF::Statement.new(
|
285
|
+
statements << ::RDF::Statement.new(nanopub, BELRDF::BELV.hasCitation, BELRDF::PUBMED[pid], :graph_name => graph_name)
|
285
286
|
end
|
286
287
|
end
|
287
288
|
|
288
|
-
#
|
289
|
-
|
290
|
-
if
|
291
|
-
value =
|
292
|
-
statements << ::RDF::Statement.new(
|
289
|
+
# nanopub
|
290
|
+
support = @annotations.delete('Support')
|
291
|
+
if support
|
292
|
+
value = support.value.gsub('"', '').force_encoding('UTF-8')
|
293
|
+
statements << ::RDF::Statement.new(nanopub, BELRDF::BELV.hasSupport, value, :graph_name => graph_name)
|
293
294
|
end
|
294
295
|
|
295
296
|
# annotations
|
@@ -317,7 +318,7 @@ module BELRDF
|
|
317
318
|
annotation_scheme = anno_rdf_uri ? anno_rdf_uri : BELRDF::const_get(name)
|
318
319
|
[anno.value].flatten.map{|x| x.gsub('"', '')}.each do |val|
|
319
320
|
value_uri = BELRDF::RDF::URI(URI.encode(annotation_scheme + val.to_s))
|
320
|
-
statements << ::RDF::Statement.new(
|
321
|
+
statements << ::RDF::Statement.new(nanopub, BELRDF::BELV.hasAnnotation, value_uri, :graph_name => graph_name)
|
321
322
|
end
|
322
323
|
end
|
323
324
|
end
|
@@ -336,7 +337,7 @@ module BELRDF
|
|
336
337
|
end
|
337
338
|
end
|
338
339
|
|
339
|
-
class ::BEL::
|
340
|
+
class ::BEL::Nanopub::Nanopub
|
340
341
|
|
341
342
|
def to_uri
|
342
343
|
BELRDF::BELE[BELRDF.generate_uuid]
|
@@ -346,15 +347,15 @@ module BELRDF
|
|
346
347
|
uri = to_uri
|
347
348
|
|
348
349
|
# parse BEL statement if necessary
|
349
|
-
unless self.bel_statement.is_a?(::BEL::
|
350
|
+
unless self.bel_statement.is_a?(::BEL::Nanopub::Statement)
|
350
351
|
self.bel_statement = self.class.parse_statement(self)
|
351
352
|
end
|
352
353
|
|
353
354
|
# convert BEL statement to RDF
|
354
355
|
statement_uri, statements = bel_statement.to_rdf(uri, remap)
|
355
356
|
|
356
|
-
statements << ::RDF::Statement.new(uri, BELRDF::RDF.type, BELRDF::BELV.
|
357
|
-
statements << ::RDF::Statement.new(statement_uri, BELRDF::BELV.
|
357
|
+
statements << ::RDF::Statement.new(uri, BELRDF::RDF.type, BELRDF::BELV.Nanopub, :graph_name => uri)
|
358
|
+
statements << ::RDF::Statement.new(statement_uri, BELRDF::BELV.hasNanopub, uri, :graph_name => uri)
|
358
359
|
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasStatement, statement_uri, :graph_name => uri)
|
359
360
|
|
360
361
|
annotations = bel_statement.annotations
|
@@ -369,11 +370,11 @@ module BELRDF
|
|
369
370
|
end
|
370
371
|
end
|
371
372
|
|
372
|
-
#
|
373
|
-
|
374
|
-
if
|
375
|
-
value =
|
376
|
-
statements << ::RDF::Statement.new(uri, BELRDF::BELV.
|
373
|
+
# support
|
374
|
+
support = annotations.delete('Support')
|
375
|
+
if support
|
376
|
+
value = support.value.gsub('"', '').force_encoding('UTF-8')
|
377
|
+
statements << ::RDF::Statement.new(uri, BELRDF::BELV.hasSupport, value, :graph_name => uri)
|
377
378
|
end
|
378
379
|
|
379
380
|
# annotations
|
@@ -397,16 +398,16 @@ module BELRDF
|
|
397
398
|
return nil if !document_header || !document_header.is_a?(Hash)
|
398
399
|
|
399
400
|
triples = ::RDF::Repository.new
|
400
|
-
triples << ::RDF::Statement.new(void_dataset_uri, ::RDF.type, ::
|
401
|
+
triples << ::RDF::Statement.new(void_dataset_uri, ::RDF.type, BELRDF::VOID.Dataset)
|
401
402
|
|
402
403
|
name = version = nil
|
403
404
|
document_header.each do |property, value|
|
404
405
|
case property
|
405
406
|
when /name/i
|
406
407
|
name = value.to_s
|
407
|
-
triples << ::RDF::Statement.new(void_dataset_uri, ::
|
408
|
+
triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.title, name)
|
408
409
|
when /description/i
|
409
|
-
triples << ::RDF::Statement.new(void_dataset_uri, ::
|
410
|
+
triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.description, value.to_s)
|
410
411
|
when /version/i
|
411
412
|
version = value.to_s
|
412
413
|
when /copyright/i
|
@@ -423,10 +424,10 @@ module BELRDF
|
|
423
424
|
when /authors/i
|
424
425
|
if value.respond_to?(:each)
|
425
426
|
value.each do |v|
|
426
|
-
triples << ::RDF::Statement.new(void_dataset_uri, ::
|
427
|
+
triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.creator, v.to_s)
|
427
428
|
end
|
428
429
|
else
|
429
|
-
triples << ::RDF::Statement.new(void_dataset_uri, ::
|
430
|
+
triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.creator, value.to_s)
|
430
431
|
end
|
431
432
|
when /licenses/i
|
432
433
|
value = value.to_s
|
@@ -436,17 +437,17 @@ module BELRDF
|
|
436
437
|
else
|
437
438
|
value
|
438
439
|
end
|
439
|
-
triples << ::RDF::Statement.new(void_dataset_uri, ::
|
440
|
+
triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.license, value)
|
440
441
|
when /contactinfo/i
|
441
|
-
triples << ::RDF::Statement.new(void_dataset_uri, ::
|
442
|
-
triples << ::RDF::Statement.new(:publisher,
|
443
|
-
triples << ::RDF::Statement.new(:publisher,
|
442
|
+
triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.publisher, :publisher)
|
443
|
+
triples << ::RDF::Statement.new(:publisher, ::RDF.type, BELRDF::FOAF.Person)
|
444
|
+
triples << ::RDF::Statement.new(:publisher, BELRDF::FOAF.mbox, value.to_s)
|
444
445
|
end
|
445
446
|
end
|
446
447
|
|
447
448
|
if name && version
|
448
449
|
identifier = "#{name}/#{version}"
|
449
|
-
triples << ::RDF::Statement.new(void_dataset_uri, ::
|
450
|
+
triples << ::RDF::Statement.new(void_dataset_uri, BELRDF::DC.identifier, identifier)
|
450
451
|
end
|
451
452
|
|
452
453
|
triples
|
@@ -1,11 +1,11 @@
|
|
1
1
|
module BELRDF
|
2
2
|
module Reader
|
3
3
|
|
4
|
-
module
|
4
|
+
module NanopubYielder
|
5
5
|
|
6
6
|
BELV = BELRDF::BELV
|
7
7
|
|
8
|
-
include ::BEL::
|
8
|
+
include ::BEL::Nanopub
|
9
9
|
include ::BEL::Quoting
|
10
10
|
|
11
11
|
# Find described resources by +type+ in +graph+.
|
@@ -36,44 +36,44 @@ module BELRDF
|
|
36
36
|
}
|
37
37
|
end
|
38
38
|
|
39
|
-
# Iterate the {BELV.
|
40
|
-
# {::RDF::Graph graph}, and yield those correspdonding {
|
39
|
+
# Iterate the {BELV.Nanopub} predicated statements, from the
|
40
|
+
# {::RDF::Graph graph}, and yield those correspdonding {Nanopub}
|
41
41
|
# objects.
|
42
42
|
#
|
43
43
|
# @param [::RDF::Graph] graph the RDF graph to query
|
44
|
-
# @yield [
|
45
|
-
def
|
46
|
-
resources_of_type(BELV.
|
44
|
+
# @yield [::BEL::Nanopub::Nanopub] yields a nanopub object
|
45
|
+
def nanopub_yielder(graph)
|
46
|
+
resources_of_type(BELV.Nanopub, graph).each do |nanopub|
|
47
47
|
|
48
|
-
yield
|
48
|
+
yield make_nanopub(nanopub, graph)
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
-
# Create an {
|
52
|
+
# Create an {Nanopub} object from RDF statements found in
|
53
53
|
# the {::RDF::Graph graph}.
|
54
54
|
#
|
55
|
-
# @param [Hash]
|
56
|
-
# representing the described
|
55
|
+
# @param [Hash] nanopub a hash of predicate to object
|
56
|
+
# representing the described nanopub
|
57
57
|
# @param [::RDF::Graph] graph the RDF graph to query
|
58
|
-
# @return [
|
59
|
-
def
|
60
|
-
statement = describe(
|
58
|
+
# @return [Nanopub] the nanopub
|
59
|
+
def make_nanopub(nanopub_hash, graph)
|
60
|
+
statement = describe(nanopub_hash[BELV.hasStatement], graph)
|
61
61
|
|
62
62
|
# values
|
63
63
|
bel_statement = statement[::RDF::RDFS.label].value
|
64
|
-
|
65
|
-
citation =
|
64
|
+
support_text = nanopub_hash[BELV.hasSupport]
|
65
|
+
citation = nanopub_hash[BELV.hasCitation]
|
66
66
|
|
67
67
|
# model
|
68
|
-
|
69
|
-
|
68
|
+
nanopub = Nanopub.new
|
69
|
+
nanopub.bel_statement = ::BEL::Script.parse(bel_statement)
|
70
70
|
.find { |obj|
|
71
71
|
obj.is_a? Statement
|
72
72
|
}
|
73
|
-
|
73
|
+
nanopub.support = Support.new(support_text.value) if support_text
|
74
74
|
|
75
75
|
if citation.respond_to?(:value)
|
76
|
-
|
76
|
+
nanopub.citation =
|
77
77
|
case citation.value
|
78
78
|
when /pubmed:(\d+)$/
|
79
79
|
pubmed_id = $1.to_i
|
@@ -87,13 +87,13 @@ module BELRDF
|
|
87
87
|
end
|
88
88
|
end
|
89
89
|
|
90
|
-
|
90
|
+
nanopub
|
91
91
|
end
|
92
92
|
end
|
93
93
|
|
94
|
-
class
|
94
|
+
class BufferedNanopubYielder
|
95
95
|
|
96
|
-
include
|
96
|
+
include NanopubYielder
|
97
97
|
|
98
98
|
def initialize(data, format = :ntriples)
|
99
99
|
@data = data
|
@@ -108,8 +108,8 @@ module BELRDF
|
|
108
108
|
graph << statement
|
109
109
|
end
|
110
110
|
end
|
111
|
-
|
112
|
-
yield
|
111
|
+
nanopub_yielder(graph) do |nanopub|
|
112
|
+
yield nanopub
|
113
113
|
end
|
114
114
|
else
|
115
115
|
to_enum(:each)
|
@@ -117,9 +117,9 @@ module BELRDF
|
|
117
117
|
end
|
118
118
|
end
|
119
119
|
|
120
|
-
class
|
120
|
+
class UnbufferedNanopubYielder
|
121
121
|
|
122
|
-
include
|
122
|
+
include NanopubYielder
|
123
123
|
|
124
124
|
def initialize(data, format)
|
125
125
|
@data = data
|
@@ -128,27 +128,27 @@ module BELRDF
|
|
128
128
|
|
129
129
|
def each
|
130
130
|
if block_given?
|
131
|
-
graph
|
132
|
-
|
131
|
+
graph = RDF::Graph.new
|
132
|
+
nanopub = nil
|
133
133
|
RDF::Reader.for(@format).new(@data) do |reader|
|
134
134
|
reader.each_statement do |statement|
|
135
135
|
case
|
136
|
-
when statement.object == BELV.
|
136
|
+
when statement.object == BELV.Nanopub &&
|
137
137
|
statement.predicate == RDF.type
|
138
|
-
|
139
|
-
when
|
140
|
-
statement.predicate != BELV.
|
141
|
-
statement.subject !=
|
142
|
-
|
143
|
-
# yield current graph as
|
144
|
-
yield
|
145
|
-
describe(
|
138
|
+
nanopub = statement.subject
|
139
|
+
when nanopub &&
|
140
|
+
statement.predicate != BELV.hasNanopub &&
|
141
|
+
statement.subject != nanopub
|
142
|
+
|
143
|
+
# yield current graph as nanopub
|
144
|
+
yield make_nanopub(
|
145
|
+
describe(nanopub, graph),
|
146
146
|
graph
|
147
147
|
)
|
148
148
|
|
149
149
|
# reset parse state
|
150
150
|
graph.clear
|
151
|
-
|
151
|
+
nanopub = nil
|
152
152
|
|
153
153
|
# insert this RDF statement
|
154
154
|
graph << statement
|
@@ -158,9 +158,9 @@ module BELRDF
|
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|
161
|
-
# yield last graph as
|
162
|
-
yield
|
163
|
-
describe(
|
161
|
+
# yield last graph as nanopub
|
162
|
+
yield make_nanopub(
|
163
|
+
describe(nanopub, graph),
|
164
164
|
graph
|
165
165
|
)
|
166
166
|
else
|