Class: BEL::Resource::AnnotationValue

Inherits:
Object
  • Object
show all
Includes:
Concept
Defined in:
lib/bel/resource/annotation_value.rb

Overview

AnnotationValue represents a AnnotationConcept RDF Resource and associated properties.

Constant Summary collapse

DC =
RDF::Vocab::DC
SKOS =
RDF::Vocab::SKOS
BELV =
RDF::Vocabulary.new('http://www.openbel.org/vocabulary/')

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Concept

#alt_label, #from_species, #identifier, #pref_label, #title, #type

Constructor Details

#initialize(rdf_repository, uri) ⇒ AnnotationValue

Returns a new instance of AnnotationValue.



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/bel/resource/annotation_value.rb', line 21

def initialize(rdf_repository, uri)
  @rdf_repository = rdf_repository
  @uri            = RDF::URI(uri.to_s)
  @uri_hash       = @uri.hash
  @eq_query       = [
    :subject   => @uri,
    :predicate => SKOS.exactMatch
  ]
  @ortho_query    = [
    :subject   => @uri,
    :predicate => BELV.orthologousMatch
  ]
end

Instance Attribute Details

#uriObject (readonly)

Returns the value of attribute uri.



19
20
21
# File 'lib/bel/resource/annotation_value.rb', line 19

def uri
  @uri
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



81
82
83
84
# File 'lib/bel/resource/annotation_value.rb', line 81

def ==(other)
  return false if other == nil
  @uri == other.uri
end

#annotationObject



35
36
37
38
39
# File 'lib/bel/resource/annotation_value.rb', line 35

def annotation
  schemes = in_scheme
  return nil if schemes.empty?
  Annotation.new(@rdf_repository, schemes.first)
end

#equivalents(target_annotations = :all) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/bel/resource/annotation_value.rb', line 52

def equivalents(target_annotations = :all)
     return to_enum(:equivalents, target_annotations) unless block_given?
     if target_annotations == :all
       @rdf_repository.
         query(@eq_query) { |solution|
           yield AnnotationValue.new(@rdf_repository, solution.object)
         }
     else
       target_annotations = Annotations.new(@rdf_repository).
         find([target_annotations].flatten).to_a
       target_annotations.compact!
       target_annotations.map! { |ns| ns.uri }

       @rdf_repository.
         query(@eq_query).map { |solution|
           AnnotationValue.new(@rdf_repository, solution.object)
         }.select { |value|
           scheme_uri = value.inScheme
           target_annotations.include?(scheme_uri)
         }.each { |value|
           yield value
         }
     end
end

#hashObject



77
78
79
# File 'lib/bel/resource/annotation_value.rb', line 77

def hash
  @uri_hash
end

#in_schemeObject



41
42
43
44
45
46
47
48
49
50
# File 'lib/bel/resource/annotation_value.rb', line 41

def in_scheme
  @rdf_repository
  .query([:subject => @uri, :predicate => SKOS.inScheme])
  .select { |solution|
    scheme_uri = solution.object
    @rdf_repository.has_statement?(
      RDF::Statement(scheme_uri, RDF.type, BELV.AnnotationConceptScheme)
    )
  }.map { |solution| solution.object.to_s }
end