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
@@ -1,8 +1,8 @@
|
|
1
1
|
require 'forwardable'
|
2
2
|
|
3
3
|
module BEL
|
4
|
-
module
|
5
|
-
class
|
4
|
+
module Nanopub
|
5
|
+
class Support
|
6
6
|
extend Forwardable
|
7
7
|
|
8
8
|
attr_accessor :value
|
@@ -11,6 +11,12 @@ module BEL
|
|
11
11
|
@value = value
|
12
12
|
end
|
13
13
|
|
14
|
+
def ==(other)
|
15
|
+
return false if other.nil?
|
16
|
+
@value == other.value
|
17
|
+
end
|
18
|
+
alias eql? ==
|
19
|
+
|
14
20
|
def_delegators :@value, :to_s
|
15
21
|
end
|
16
22
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module BEL
|
2
|
-
module
|
2
|
+
module Nanopub
|
3
3
|
|
4
4
|
def self.union_namespace_references(destination, source, suffix = 'incr')
|
5
|
-
BEL::
|
5
|
+
BEL::Nanopub.union_by_keyword(
|
6
6
|
destination,
|
7
7
|
source,
|
8
8
|
suffix
|
@@ -10,7 +10,7 @@ module BEL
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def self.union_annotation_references(destination, source, suffix = 'incr')
|
13
|
-
BEL::
|
13
|
+
BEL::Nanopub.union_by_keyword(
|
14
14
|
destination,
|
15
15
|
source,
|
16
16
|
suffix
|
@@ -36,21 +36,20 @@ module BEL
|
|
36
36
|
remap_result = {}
|
37
37
|
|
38
38
|
combined = destination + new.map { |new_obj|
|
39
|
-
new_key = new_obj
|
39
|
+
new_key = new_obj.keyword
|
40
40
|
|
41
41
|
# find a match where the keyword differs
|
42
|
-
new_value = new_obj.reject { |key, value| key == :keyword }
|
43
42
|
match_by_value = destination.find { |dest|
|
44
|
-
|
43
|
+
new_obj.domain_equal?(dest)
|
45
44
|
}
|
46
45
|
|
47
46
|
rewrite_key =
|
48
47
|
if match_by_value
|
49
|
-
match_by_value
|
48
|
+
match_by_value.keyword
|
50
49
|
else
|
51
50
|
# find max suffix match
|
52
51
|
max_suffix = destination.map { |dest|
|
53
|
-
key, suffix_number = dest
|
52
|
+
key, suffix_number = dest.keyword.to_s.split(suffix_pattern)
|
54
53
|
if new_key == key
|
55
54
|
suffix_number
|
56
55
|
else
|
@@ -63,7 +62,7 @@ module BEL
|
|
63
62
|
if max_suffix
|
64
63
|
new_key + suffix + max_suffix.next
|
65
64
|
else
|
66
|
-
if destination.any? { |dest| dest
|
65
|
+
if destination.any? { |dest| dest.keyword == new_key }
|
67
66
|
"#{new_key}#{suffix}1"
|
68
67
|
else
|
69
68
|
new_key
|
@@ -71,7 +70,8 @@ module BEL
|
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
74
|
-
rewrite_obj = new_obj.
|
73
|
+
rewrite_obj = new_obj.dup
|
74
|
+
rewrite_obj.keyword = rewrite_key
|
75
75
|
remap_result[new_obj] = rewrite_obj
|
76
76
|
rewrite_obj
|
77
77
|
}
|
@@ -1,28 +1,31 @@
|
|
1
1
|
require 'rdf'
|
2
|
+
require 'rdf/vocab'
|
3
|
+
require_relative 'concept_scheme'
|
2
4
|
require_relative 'annotation_value'
|
3
5
|
|
4
6
|
module BEL
|
5
7
|
module Resource
|
6
|
-
|
7
|
-
#
|
8
|
+
# Annotation represents a AnnotationConceptScheme RDF Resource and
|
9
|
+
# associated properties.
|
8
10
|
class Annotation
|
11
|
+
include ConceptScheme
|
12
|
+
|
13
|
+
DC = RDF::Vocab::DC
|
14
|
+
SKOS = RDF::Vocab::SKOS
|
15
|
+
BELV = RDF::Vocabulary.new('http://www.openbel.org/vocabulary/')
|
9
16
|
|
10
17
|
attr_reader :uri
|
11
18
|
|
12
|
-
# TODO Document
|
13
19
|
def initialize(rdf_repository, uri)
|
14
20
|
@rdf_repository = rdf_repository
|
15
21
|
@uri = RDF::URI(uri.to_s)
|
16
22
|
@uri_hash = @uri.hash
|
17
23
|
@concept_query = [
|
18
|
-
:predicate =>
|
24
|
+
:predicate => SKOS.inScheme,
|
19
25
|
:object => @uri
|
20
26
|
]
|
21
|
-
@predicates = @rdf_repository.query(:subject => @uri).
|
22
|
-
each.map(&:predicate)
|
23
27
|
end
|
24
28
|
|
25
|
-
# TODO Document
|
26
29
|
def each
|
27
30
|
return to_enum(:each) unless block_given?
|
28
31
|
@rdf_repository.
|
@@ -66,21 +69,21 @@ module BEL
|
|
66
69
|
# match input as annotation value prefLabel
|
67
70
|
vlit = RDF::Literal(vstr)
|
68
71
|
label = value_query(
|
69
|
-
:predicate =>
|
72
|
+
:predicate => SKOS.prefLabel,
|
70
73
|
:object => vlit
|
71
74
|
)
|
72
75
|
return AnnotationValue.new(@rdf_repository, label.subject) if label
|
73
76
|
|
74
77
|
# match input as annotation value identifier
|
75
78
|
ident = value_query(
|
76
|
-
:predicate =>
|
79
|
+
:predicate => DC.identifier,
|
77
80
|
:object => vlit
|
78
81
|
)
|
79
82
|
return AnnotationValue.new(@rdf_repository, ident.subject) if ident
|
80
83
|
|
81
84
|
# match input as annotation value title
|
82
85
|
title = value_query(
|
83
|
-
:predicate =>
|
86
|
+
:predicate => DC.title,
|
84
87
|
:object => vlit
|
85
88
|
)
|
86
89
|
return AnnotationValue.new(@rdf_repository, title.subject) if title
|
@@ -88,7 +91,7 @@ module BEL
|
|
88
91
|
|
89
92
|
def find_annotation_value_uri(uri)
|
90
93
|
in_annotation_check = @rdf_repository.has_statement?(
|
91
|
-
RDF::Statement(uri,
|
94
|
+
RDF::Statement(uri, SKOS.inScheme, @uri)
|
92
95
|
)
|
93
96
|
return nil if !in_annotation_check
|
94
97
|
|
@@ -101,22 +104,10 @@ module BEL
|
|
101
104
|
def value_query(pattern)
|
102
105
|
@rdf_repository.query(pattern).find { |solution|
|
103
106
|
@rdf_repository.has_statement?(
|
104
|
-
RDF::Statement(solution.subject,
|
107
|
+
RDF::Statement(solution.subject, SKOS.inScheme, @uri)
|
105
108
|
)
|
106
109
|
}
|
107
110
|
end
|
108
|
-
|
109
|
-
def method_missing(method)
|
110
|
-
method_predicate = @predicates.find { |p|
|
111
|
-
p.qname[1].to_sym == method.to_sym
|
112
|
-
}
|
113
|
-
return nil unless method_predicate
|
114
|
-
objects = @rdf_repository.query(
|
115
|
-
:subject => @uri,
|
116
|
-
:predicate => method_predicate
|
117
|
-
).each.map(&:object)
|
118
|
-
objects.size == 1 ? objects.first : objects.to_a
|
119
|
-
end
|
120
111
|
end
|
121
112
|
end
|
122
113
|
end
|
@@ -1,34 +1,52 @@
|
|
1
1
|
require 'rdf'
|
2
|
+
require 'rdf/vocab'
|
3
|
+
require_relative 'concept'
|
2
4
|
require_relative 'annotation'
|
3
5
|
require_relative 'annotations'
|
4
6
|
|
5
7
|
module BEL
|
6
8
|
module Resource
|
7
9
|
|
8
|
-
#
|
10
|
+
# AnnotationValue represents a AnnotationConcept RDF Resource and
|
11
|
+
# associated properties.
|
9
12
|
class AnnotationValue
|
13
|
+
include Concept
|
14
|
+
|
15
|
+
DC = RDF::Vocab::DC
|
16
|
+
SKOS = RDF::Vocab::SKOS
|
17
|
+
BELV = RDF::Vocabulary.new('http://www.openbel.org/vocabulary/')
|
10
18
|
|
11
19
|
attr_reader :uri
|
12
20
|
|
13
|
-
# TODO Document
|
14
21
|
def initialize(rdf_repository, uri)
|
15
22
|
@rdf_repository = rdf_repository
|
16
23
|
@uri = RDF::URI(uri.to_s)
|
17
24
|
@uri_hash = @uri.hash
|
18
25
|
@eq_query = [
|
19
26
|
:subject => @uri,
|
20
|
-
:predicate =>
|
27
|
+
:predicate => SKOS.exactMatch
|
21
28
|
]
|
22
29
|
@ortho_query = [
|
23
30
|
:subject => @uri,
|
24
31
|
:predicate => BELV.orthologousMatch
|
25
32
|
]
|
26
|
-
@predicates = @rdf_repository.query(:subject => @uri).
|
27
|
-
each.map(&:predicate).uniq
|
28
33
|
end
|
29
34
|
|
30
35
|
def annotation
|
31
|
-
|
36
|
+
schemes = in_scheme
|
37
|
+
return nil if schemes.empty?
|
38
|
+
Annotation.new(@rdf_repository, schemes.first)
|
39
|
+
end
|
40
|
+
|
41
|
+
def in_scheme
|
42
|
+
@rdf_repository
|
43
|
+
.query([:subject => @uri, :predicate => SKOS.inScheme])
|
44
|
+
.select { |solution|
|
45
|
+
scheme_uri = solution.object
|
46
|
+
@rdf_repository.has_statement?(
|
47
|
+
RDF::Statement(scheme_uri, RDF.type, BELV.AnnotationConceptScheme)
|
48
|
+
)
|
49
|
+
}.map { |solution| solution.object.to_s }
|
32
50
|
end
|
33
51
|
|
34
52
|
def equivalents(target_annotations = :all)
|
@@ -65,20 +83,6 @@ module BEL
|
|
65
83
|
@uri == other.uri
|
66
84
|
end
|
67
85
|
alias_method :eql?, :'=='
|
68
|
-
|
69
|
-
protected
|
70
|
-
|
71
|
-
def method_missing(method)
|
72
|
-
method_predicate = @predicates.find { |p|
|
73
|
-
p.qname[1].to_sym == method.to_sym
|
74
|
-
}
|
75
|
-
return nil unless method_predicate
|
76
|
-
objects = @rdf_repository.query(
|
77
|
-
:subject => @uri,
|
78
|
-
:predicate => method_predicate
|
79
|
-
).each.map(&:object)
|
80
|
-
objects.size == 1 ? objects.first : objects.to_a
|
81
|
-
end
|
82
86
|
end
|
83
87
|
end
|
84
88
|
end
|
@@ -1,27 +1,28 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
require 'rdf/vocab'
|
1
3
|
require_relative 'annotation'
|
2
4
|
|
3
5
|
module BEL
|
4
6
|
module Resource
|
5
|
-
|
6
|
-
#
|
7
|
+
# Annotations allows access to all AnnotationConceptScheme RDF Resources
|
8
|
+
# available in the resources dataset.
|
7
9
|
class Annotations
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
pattern [:uri, RDF.type, BELV.AnnotationConceptScheme]
|
12
|
-
end
|
11
|
+
BELV = RDF::Vocabulary.new('http://www.openbel.org/vocabulary/')
|
12
|
+
SKOS = RDF::Vocab::SKOS
|
13
13
|
|
14
|
-
# TODO Document
|
15
14
|
def initialize(rdf_repository)
|
16
15
|
@rdf_repository = rdf_repository
|
17
16
|
end
|
18
17
|
|
19
|
-
# TODO Document
|
20
18
|
def each
|
21
19
|
return to_enum(:each) unless block_given?
|
22
20
|
@rdf_repository.
|
23
|
-
query(
|
24
|
-
|
21
|
+
query(
|
22
|
+
:predicate => RDF.type,
|
23
|
+
:object => BELV.AnnotationConceptScheme) { |solution|
|
24
|
+
|
25
|
+
yield Annotation.new(@rdf_repository, solution.subject)
|
25
26
|
}
|
26
27
|
end
|
27
28
|
|
@@ -57,7 +58,7 @@ module BEL
|
|
57
58
|
|
58
59
|
# match input as annotation prefLabel
|
59
60
|
label = annotation_query(
|
60
|
-
:predicate =>
|
61
|
+
:predicate => SKOS.prefLabel,
|
61
62
|
:object => nlit
|
62
63
|
)
|
63
64
|
return Annotation.new(@rdf_repository, label.subject) if label
|
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
require 'rdf/vocab'
|
3
|
+
|
4
|
+
module BEL
|
5
|
+
module Resource
|
6
|
+
# Concept captures the properties available on an RDF Annotation or
|
7
|
+
# Namespace Concept.
|
8
|
+
module Concept
|
9
|
+
DC = RDF::Vocab::DC
|
10
|
+
SKOS = RDF::Vocab::SKOS
|
11
|
+
BELV = RDF::Vocabulary.new('http://www.openbel.org/vocabulary/')
|
12
|
+
|
13
|
+
def type
|
14
|
+
@rdf_repository
|
15
|
+
.query([:subject => @uri, :predicate => RDF.type])
|
16
|
+
.map do |solution|
|
17
|
+
solution.object.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def pref_label
|
22
|
+
@rdf_repository
|
23
|
+
.query([:subject => @uri, :predicate => SKOS.prefLabel])
|
24
|
+
.map do |solution|
|
25
|
+
solution.object.to_s
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def identifier
|
30
|
+
@rdf_repository
|
31
|
+
.query([:subject => @uri, :predicate => DC.identifier])
|
32
|
+
.map do |solution|
|
33
|
+
solution.object.to_s
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def title
|
38
|
+
@rdf_repository
|
39
|
+
.query([:subject => @uri, :predicate => DC.title])
|
40
|
+
.map do |solution|
|
41
|
+
solution.object.to_s
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def alt_label
|
46
|
+
@rdf_repository
|
47
|
+
.query([:subject => @uri, :predicate => SKOS.altLabel])
|
48
|
+
.map do |solution|
|
49
|
+
solution.object.to_s
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
def from_species
|
54
|
+
@rdf_repository
|
55
|
+
.query([:subject => @uri, :predicate => BELV.fromSpecies])
|
56
|
+
.map do |solution|
|
57
|
+
solution.object.to_s
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
require 'rdf/vocab'
|
3
|
+
|
4
|
+
module BEL
|
5
|
+
module Resource
|
6
|
+
# ConceptScheme captures the properties available on an RDF Annotation or
|
7
|
+
# Namespace ConceptScheme.
|
8
|
+
module ConceptScheme
|
9
|
+
SKOS = RDF::Vocab::SKOS
|
10
|
+
BELV = RDF::Vocabulary.new('http://www.openbel.org/vocabulary/')
|
11
|
+
|
12
|
+
def type
|
13
|
+
solution =
|
14
|
+
@rdf_repository
|
15
|
+
.query([:subject => @uri, :predicate => RDF.type])
|
16
|
+
.map do |solution|
|
17
|
+
solution.object.to_s
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def pref_label
|
22
|
+
solution =
|
23
|
+
@rdf_repository
|
24
|
+
.query([:subject => @uri, :predicate => SKOS.prefLabel])
|
25
|
+
.map do |solution|
|
26
|
+
solution.object.to_s
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def domain
|
31
|
+
solution =
|
32
|
+
@rdf_repository
|
33
|
+
.query([:subject => @uri, :predicate => BELV.domain])
|
34
|
+
.map do |solution|
|
35
|
+
solution.object.to_s
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def prefix
|
40
|
+
solution =
|
41
|
+
@rdf_repository
|
42
|
+
.query([:subject => @uri, :predicate => BELV.prefix])
|
43
|
+
.map do |solution|
|
44
|
+
solution.object.to_s
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -1,28 +1,31 @@
|
|
1
1
|
require 'rdf'
|
2
|
+
require 'rdf/vocab'
|
3
|
+
require_relative 'concept_scheme'
|
2
4
|
require_relative 'namespace_value'
|
3
5
|
|
4
6
|
module BEL
|
5
7
|
module Resource
|
6
|
-
|
7
|
-
#
|
8
|
+
# Namespace represents a NamespaceConceptScheme RDF Resource and
|
9
|
+
# associated properties.
|
8
10
|
class Namespace
|
11
|
+
include ConceptScheme
|
9
12
|
|
10
13
|
attr_reader :uri
|
11
14
|
|
12
|
-
|
15
|
+
DC = RDF::Vocab::DC
|
16
|
+
SKOS = RDF::Vocab::SKOS
|
17
|
+
BELV = RDF::Vocabulary.new('http://www.openbel.org/vocabulary/')
|
18
|
+
|
13
19
|
def initialize(rdf_repository, uri)
|
14
20
|
@rdf_repository = rdf_repository
|
15
21
|
@uri = RDF::URI(uri.to_s)
|
16
22
|
@uri_hash = @uri.hash
|
17
23
|
@concept_query = [
|
18
|
-
:predicate =>
|
24
|
+
:predicate => SKOS.inScheme,
|
19
25
|
:object => @uri
|
20
26
|
]
|
21
|
-
@predicates = @rdf_repository.query(:subject => @uri).
|
22
|
-
each.map(&:predicate)
|
23
27
|
end
|
24
28
|
|
25
|
-
# TODO Document
|
26
29
|
def each
|
27
30
|
return to_enum(:each) unless block_given?
|
28
31
|
@rdf_repository.
|
@@ -66,21 +69,21 @@ module BEL
|
|
66
69
|
# match input as namespace value prefLabel
|
67
70
|
vlit = RDF::Literal(vstr)
|
68
71
|
label = value_query(
|
69
|
-
:predicate =>
|
72
|
+
:predicate => SKOS.prefLabel,
|
70
73
|
:object => vlit
|
71
74
|
)
|
72
75
|
return NamespaceValue.new(@rdf_repository, label.subject) if label
|
73
76
|
|
74
77
|
# match input as namespace value identifier
|
75
78
|
ident = value_query(
|
76
|
-
:predicate =>
|
79
|
+
:predicate => DC.identifier,
|
77
80
|
:object => vlit
|
78
81
|
)
|
79
82
|
return NamespaceValue.new(@rdf_repository, ident.subject) if ident
|
80
83
|
|
81
84
|
# match input as namespace value title
|
82
85
|
title = value_query(
|
83
|
-
:predicate =>
|
86
|
+
:predicate => DC.title,
|
84
87
|
:object => vlit
|
85
88
|
)
|
86
89
|
return NamespaceValue.new(@rdf_repository, title.subject) if title
|
@@ -89,7 +92,7 @@ module BEL
|
|
89
92
|
def find_namespace_value_uri(uri_s)
|
90
93
|
subject = RDF::URI(uri_s)
|
91
94
|
in_namespace_check = @rdf_repository.has_statement?(
|
92
|
-
RDF::Statement(subject,
|
95
|
+
RDF::Statement(subject, SKOS.inScheme, @uri)
|
93
96
|
)
|
94
97
|
return nil if !in_namespace_check
|
95
98
|
|
@@ -102,22 +105,10 @@ module BEL
|
|
102
105
|
def value_query(pattern)
|
103
106
|
@rdf_repository.query(pattern).find { |solution|
|
104
107
|
@rdf_repository.has_statement?(
|
105
|
-
RDF::Statement(solution.subject,
|
108
|
+
RDF::Statement(solution.subject, SKOS.inScheme, @uri)
|
106
109
|
)
|
107
110
|
}
|
108
111
|
end
|
109
|
-
|
110
|
-
def method_missing(method)
|
111
|
-
method_predicate = @predicates.find { |p|
|
112
|
-
p.qname[1].to_sym == method.to_sym
|
113
|
-
}
|
114
|
-
return nil unless method_predicate
|
115
|
-
objects = @rdf_repository.query(
|
116
|
-
:subject => @uri,
|
117
|
-
:predicate => method_predicate
|
118
|
-
).each.map(&:object)
|
119
|
-
objects.size == 1 ? objects.first : objects.to_a
|
120
|
-
end
|
121
112
|
end
|
122
113
|
end
|
123
114
|
end
|