Class: OpenBEL::Resource::Nanopub::AnnotationTransform

Inherits:
Object
  • Object
show all
Defined in:
app/openbel/api/resources/nanopub_transform.rb

Constant Summary collapse

SERVER_PATTERN =
%r{/api/annotations/([^/]*)/values/([^/]*)/?}
RDFURI_PATTERN =
%r{/bel/namespace/([^/]*)/([^/]*)/?}
URI_PATTERNS =
[
  %r{/api/annotations/([^/]*)/values/([^/]*)/?},
  %r{/bel/namespace/([^/]*)/([^/]*)/?}
]
ANNOTATION_VALUE_URI =
"%s/api/annotations/%s/values/%s"

Instance Method Summary collapse

Constructor Details

#initialize(annotations) ⇒ AnnotationTransform

Returns a new instance of AnnotationTransform.



17
18
19
# File 'app/openbel/api/resources/nanopub_transform.rb', line 17

def initialize(annotations)
  @annotations = annotations
end

Instance Method Details

#transform_annotation(annotation, base_url) ⇒ Object



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/openbel/api/resources/nanopub_transform.rb', line 33

def transform_annotation(annotation, base_url)
  if annotation[:uri]
    transformed = transform_uri(annotation[:uri], base_url)
    return transformed if transformed != nil
  end

  if annotation[:name] && annotation[:value]
    name  = annotation[:name]
    value = annotation[:value]
    transform_name_value(name, value, base_url)
  elsif annotation.respond_to?(:each)
    name  = annotation[0]
    value = annotation[1]
    transform_name_value(name, value, base_url)
  end
end

#transform_nanopub!(nanopub, base_url) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'app/openbel/api/resources/nanopub_transform.rb', line 21

def transform_nanopub!(nanopub, base_url)
  if nanopub
    experiment_context = nanopub.experiment_context
    if experiment_context != nil
      nanopub.experiment_context.values =
        experiment_context.values.flat_map { |annotation|
          transform_annotation(annotation, base_url)
        }
    end
  end
end