bel 0.4.0.beta.4 → 0.4.0.beta.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/bel/resource.rb +3 -0
- data/lib/bel/resource/annotation.rb +122 -0
- data/lib/bel/resource/annotation_value.rb +84 -0
- data/lib/bel/resource/annotations.rb +82 -0
- data/lib/bel/resource/namespace.rb +0 -1
- data/lib/bel/resource/namespace_value.rb +5 -0
- data/lib/bel/resource/namespaces.rb +1 -0
- data/lib/bel/version.rb +1 -1
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6bb79ce88a768f48ee7ed3200ec80552c541165b
|
4
|
+
data.tar.gz: df0d4949c261213198cfdab4d3140dc4040782b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e80a9b4954a24f8e16b816972f67a1ae854d8742d86b3ced5cbb18b481ad29d024377a947b9228bdcdedab20a17cebb22fe81a5541e2acbe3a1300c43f499db9
|
7
|
+
data.tar.gz: 247e7bfba0b685001a3ac4548fdf121eca9761fd5c4de05444c7231e559dc827129931d7b409be144321a936a4f62b063f84b044dda901d0f35bc0c61988f3a6
|
data/lib/bel/resource.rb
CHANGED
@@ -18,6 +18,9 @@ module BEL
|
|
18
18
|
end
|
19
19
|
end
|
20
20
|
|
21
|
+
require_relative 'resource/annotations'
|
22
|
+
require_relative 'resource/annotation'
|
23
|
+
require_relative 'resource/annotation_value'
|
21
24
|
require_relative 'resource/namespaces'
|
22
25
|
require_relative 'resource/namespace'
|
23
26
|
require_relative 'resource/namespace_value'
|
@@ -0,0 +1,122 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
require_relative 'annotation_value'
|
3
|
+
|
4
|
+
module BEL
|
5
|
+
module Resource
|
6
|
+
|
7
|
+
# TODO Document
|
8
|
+
class Annotation
|
9
|
+
|
10
|
+
attr_reader :uri
|
11
|
+
|
12
|
+
# TODO Document
|
13
|
+
def initialize(rdf_repository, uri)
|
14
|
+
@rdf_repository = rdf_repository
|
15
|
+
@uri = RDF::URI(uri.to_s)
|
16
|
+
@uri_hash = @uri.hash
|
17
|
+
@concept_query = [
|
18
|
+
:predicate => RDF::SKOS.inScheme,
|
19
|
+
:object => @uri
|
20
|
+
]
|
21
|
+
@predicates = @rdf_repository.query(:subject => @uri).
|
22
|
+
each.map(&:predicate)
|
23
|
+
end
|
24
|
+
|
25
|
+
# TODO Document
|
26
|
+
def each
|
27
|
+
return to_enum(:each) unless block_given?
|
28
|
+
@rdf_repository.
|
29
|
+
query(@concept_query) { |solution|
|
30
|
+
yield AnnotationValue.new(@rdf_repository, solution.subject)
|
31
|
+
}
|
32
|
+
end
|
33
|
+
|
34
|
+
def find(*values)
|
35
|
+
return to_enum(:find, *values) unless block_given?
|
36
|
+
|
37
|
+
values.flatten.each do |v|
|
38
|
+
yield find_value(v)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def hash
|
43
|
+
@uri_hash
|
44
|
+
end
|
45
|
+
|
46
|
+
def ==(other)
|
47
|
+
return false if other == nil
|
48
|
+
@uri == other.uri
|
49
|
+
end
|
50
|
+
alias_method :eql?, :'=='
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def find_value(value)
|
55
|
+
# nil input always yield nil
|
56
|
+
return nil if value == nil
|
57
|
+
|
58
|
+
# RDF::URI input handled as a special case
|
59
|
+
return find_annotation_value_uri(value) if value.is_a?(RDF::URI)
|
60
|
+
|
61
|
+
# input handled as literal identifier; empty literals match in a
|
62
|
+
# pattern as if it was nil so return nil if empty string
|
63
|
+
vstr = value.to_s
|
64
|
+
return nil if vstr.empty?
|
65
|
+
|
66
|
+
# match input as annotation value prefLabel
|
67
|
+
vlit = RDF::Literal(vstr)
|
68
|
+
label = value_query(
|
69
|
+
:predicate => RDF::SKOS.prefLabel,
|
70
|
+
:object => vlit
|
71
|
+
)
|
72
|
+
return AnnotationValue.new(@rdf_repository, label.subject) if label
|
73
|
+
|
74
|
+
# match input as annotation value identifier
|
75
|
+
ident = value_query(
|
76
|
+
:predicate => RDF::DC.identifier,
|
77
|
+
:object => vlit
|
78
|
+
)
|
79
|
+
return AnnotationValue.new(@rdf_repository, ident.subject) if ident
|
80
|
+
|
81
|
+
# match input as annotation value title
|
82
|
+
title = value_query(
|
83
|
+
:predicate => RDF::DC.title,
|
84
|
+
:object => vlit
|
85
|
+
)
|
86
|
+
return AnnotationValue.new(@rdf_repository, title.subject) if title
|
87
|
+
end
|
88
|
+
|
89
|
+
def find_annotation_value_uri(uri)
|
90
|
+
in_annotation_check = @rdf_repository.has_statement?(
|
91
|
+
RDF::Statement(uri, RDF::SKOS.inScheme, @uri)
|
92
|
+
)
|
93
|
+
return nil if !in_annotation_check
|
94
|
+
|
95
|
+
type_check = RDF::Statement(uri, RDF.type, BELV.AnnotationConcept)
|
96
|
+
if @rdf_repository.has_statement?(type_check)
|
97
|
+
return AnnotationValue.new(@rdf_repository, uri)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
def value_query(pattern)
|
102
|
+
@rdf_repository.query(pattern).find { |solution|
|
103
|
+
@rdf_repository.has_statement?(
|
104
|
+
RDF::Statement(solution.subject, RDF::SKOS.inScheme, @uri)
|
105
|
+
)
|
106
|
+
}
|
107
|
+
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
|
+
end
|
121
|
+
end
|
122
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'rdf'
|
2
|
+
require_relative 'annotation'
|
3
|
+
require_relative 'annotations'
|
4
|
+
|
5
|
+
module BEL
|
6
|
+
module Resource
|
7
|
+
|
8
|
+
# TODO Document
|
9
|
+
class AnnotationValue
|
10
|
+
|
11
|
+
attr_reader :uri
|
12
|
+
|
13
|
+
# TODO Document
|
14
|
+
def initialize(rdf_repository, uri)
|
15
|
+
@rdf_repository = rdf_repository
|
16
|
+
@uri = RDF::URI(uri.to_s)
|
17
|
+
@uri_hash = @uri.hash
|
18
|
+
@eq_query = [
|
19
|
+
:subject => @uri,
|
20
|
+
:predicate => RDF::SKOS.exactMatch
|
21
|
+
]
|
22
|
+
@ortho_query = [
|
23
|
+
:subject => @uri,
|
24
|
+
:predicate => BELV.orthologousMatch
|
25
|
+
]
|
26
|
+
@predicates = @rdf_repository.query(:subject => @uri).
|
27
|
+
each.map(&:predicate).uniq
|
28
|
+
end
|
29
|
+
|
30
|
+
def annotation
|
31
|
+
Annotation.new(@rdf_repository, self.inScheme)
|
32
|
+
end
|
33
|
+
|
34
|
+
def equivalents(target_annotations = :all)
|
35
|
+
return to_enum(:equivalents, target_annotations) unless block_given?
|
36
|
+
if target_annotations == :all
|
37
|
+
@rdf_repository.
|
38
|
+
query(@eq_query) { |solution|
|
39
|
+
yield AnnotationValue.new(@rdf_repository, solution.object)
|
40
|
+
}
|
41
|
+
else
|
42
|
+
target_annotations = Annotations.new(@rdf_repository).
|
43
|
+
find([target_annotations].flatten).to_a
|
44
|
+
target_annotations.compact!
|
45
|
+
target_annotations.map! { |ns| ns.uri }
|
46
|
+
|
47
|
+
@rdf_repository.
|
48
|
+
query(@eq_query).map { |solution|
|
49
|
+
AnnotationValue.new(@rdf_repository, solution.object)
|
50
|
+
}.select { |value|
|
51
|
+
scheme_uri = value.inScheme
|
52
|
+
target_annotations.include?(scheme_uri)
|
53
|
+
}.each { |value|
|
54
|
+
yield value
|
55
|
+
}
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def hash
|
60
|
+
@uri_hash
|
61
|
+
end
|
62
|
+
|
63
|
+
def ==(other)
|
64
|
+
return false if other == nil
|
65
|
+
@uri == other.uri
|
66
|
+
end
|
67
|
+
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
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require_relative 'annotation'
|
2
|
+
|
3
|
+
module BEL
|
4
|
+
module Resource
|
5
|
+
|
6
|
+
# TODO Document
|
7
|
+
class Annotations
|
8
|
+
|
9
|
+
# TODO Document
|
10
|
+
QUERY_ANNOTATIONS = RDF::Query.new do
|
11
|
+
pattern [:uri, RDF.type, BELV.AnnotationConceptScheme]
|
12
|
+
end
|
13
|
+
|
14
|
+
# TODO Document
|
15
|
+
def initialize(rdf_repository)
|
16
|
+
@rdf_repository = rdf_repository
|
17
|
+
end
|
18
|
+
|
19
|
+
# TODO Document
|
20
|
+
def each
|
21
|
+
return to_enum(:each) unless block_given?
|
22
|
+
@rdf_repository.
|
23
|
+
query(QUERY_ANNOTATIONS) { |solution|
|
24
|
+
yield Annotation.new(@rdf_repository, solution.uri)
|
25
|
+
}
|
26
|
+
end
|
27
|
+
|
28
|
+
def find(*annotations)
|
29
|
+
return to_enum(:find, *annotations) unless block_given?
|
30
|
+
|
31
|
+
annotations.flatten.each do |an|
|
32
|
+
yield find_annotation(an)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
protected
|
37
|
+
|
38
|
+
def find_annotation(annotation)
|
39
|
+
# nil input always yield nil
|
40
|
+
return nil if annotation == nil
|
41
|
+
|
42
|
+
# RDF::URI input handled as a special case
|
43
|
+
return find_annotation_uri(annotation) if annotation.is_a?(RDF::URI)
|
44
|
+
|
45
|
+
# input handled as literal identifier; empty literals will match
|
46
|
+
# in a pattern as if it was nil so return nil if empty string
|
47
|
+
nstr = annotation.to_s
|
48
|
+
return nil if nstr.empty?
|
49
|
+
|
50
|
+
# match input as annotation prefix
|
51
|
+
nlit = RDF::Literal(nstr)
|
52
|
+
prefix = annotation_query(
|
53
|
+
:predicate => BELV.prefix,
|
54
|
+
:object => nlit
|
55
|
+
)
|
56
|
+
return Annotation.new(@rdf_repository, prefix.subject) if prefix
|
57
|
+
|
58
|
+
# match input as annotation prefLabel
|
59
|
+
label = annotation_query(
|
60
|
+
:predicate => RDF::SKOS.prefLabel,
|
61
|
+
:object => nlit
|
62
|
+
)
|
63
|
+
return Annotation.new(@rdf_repository, label.subject) if label
|
64
|
+
end
|
65
|
+
|
66
|
+
def find_annotation_uri(uri)
|
67
|
+
type_check = RDF::Statement(uri, RDF.type, BELV.AnnotationConceptScheme)
|
68
|
+
if @rdf_repository.has_statement?(type_check)
|
69
|
+
return Annotation.new(@rdf_repository, uri)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def annotation_query(pattern)
|
74
|
+
@rdf_repository.query(pattern).find { |solution|
|
75
|
+
@rdf_repository.has_statement?(
|
76
|
+
RDF::Statement(solution.subject, RDF.type, BELV.AnnotationConceptScheme)
|
77
|
+
)
|
78
|
+
}
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'rdf'
|
2
|
+
require_relative 'namespace'
|
2
3
|
require_relative 'namespaces'
|
3
4
|
|
4
5
|
module BEL
|
@@ -26,6 +27,10 @@ module BEL
|
|
26
27
|
each.map(&:predicate).uniq
|
27
28
|
end
|
28
29
|
|
30
|
+
def namespace
|
31
|
+
Namespace.new(@rdf_repository, self.inScheme)
|
32
|
+
end
|
33
|
+
|
29
34
|
def equivalents(target_namespaces = :all)
|
30
35
|
return to_enum(:equivalents, target_namespaces) unless block_given?
|
31
36
|
if target_namespaces == :all
|
data/lib/bel/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.0.beta.
|
4
|
+
version: 0.4.0.beta.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Anthony Bargnesi
|
@@ -127,6 +127,9 @@ files:
|
|
127
127
|
- lib/bel/rdf_repository/plugins/memory.rb
|
128
128
|
- lib/bel/rdf_repository/plugins/mongo.rb
|
129
129
|
- lib/bel/resource.rb
|
130
|
+
- lib/bel/resource/annotation.rb
|
131
|
+
- lib/bel/resource/annotation_value.rb
|
132
|
+
- lib/bel/resource/annotations.rb
|
130
133
|
- lib/bel/resource/namespace.rb
|
131
134
|
- lib/bel/resource/namespace_value.rb
|
132
135
|
- lib/bel/resource/namespaces.rb
|