class LD4L::OpenAnnotationRDF::SemanticTagAnnotation

Public Class Methods

new(*args) click to toggle source

Special processing for new and resumed SemanticTagAnnotations

Calls superclass method
# File lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb, line 54
def initialize(*args)
  super(*args)

  # set motivatedBy
  m = get_values(:motivatedBy)
  m = m.to_a if Object::ActiveTriples.const_defined?("Relation") && m.kind_of?(ActiveTriples::Relation)
  set_value(:motivatedBy, RDF::Vocab::OA.tagging) unless m.kind_of?(Array) && m.size > 0

  # resume SemanticTagBody if it exists
  term_uri = get_values(:hasBody).first
  if( term_uri )
    term_uri = term_uri.rdf_subject  if term_uri.kind_of?(ActiveTriples::Resource)
    @body  = LD4L::OpenAnnotationRDF::SemanticTagBody.new(term_uri)
  end
end

Public Instance Methods

destroy() click to toggle source
Calls superclass method
# File lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb, line 70
def destroy
  # TODO Determine behavior of destroy
  #   Behaviour Options
  #     * Always destroy SemanticTagAnnotation
  #     * Handling of SemanticTagBody
  #     **  If SemanticTagBody is used only by this SemanticTagAnnotation, destroy it.
  #     **  Otherwise, do not destroy it.
  # TODO Write tests for this behaviour.
  # TODO Write code here to enforce.
  super
end
getTerm() click to toggle source

Get the term URI of the semantic tag body.

@return the term URI

# File lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb, line 21
def getTerm
  # return existing body if term is unchanged
  @body ? @body.rdf_subject : nil
end
setTerm(term_uri) click to toggle source

Set the hasBody property to the URI of the controlled vocabulary term that is the annotation and create the semantic tag body instance identifying the term as a semantic tag annotation.

@param [String] controlled vocabulary uri for the term

@return instance of SemanticTagBody

# File lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb, line 33
def setTerm(term_uri)
  raise ArgumentError, 'Argument must be a uri string or an instance of RDF::URI'  unless
      term_uri.kind_of?(String) && term_uri.size > 0 || term_uri.kind_of?(RDF::URI)

  # return existing body if term is unchanged
  old_term_uri = @body ? @body.rdf_subject.to_s : nil
  term_uri = RDF::URI(term_uri) unless term_uri.kind_of?(RDF::URI)
  return @body if old_term_uri && old_term_uri == term_uri.to_s

  if self.respond_to? 'persistence_strategy'  # >= ActiveTriples 0.8
    @body = LD4L::OpenAnnotationRDF::SemanticTagBody.new(term_uri,self)
  else # < ActiveTriples 0.8
    @body = LD4L::OpenAnnotationRDF::SemanticTagBody.new(term_uri)
  end
  set_value(:hasBody, @body)
  @body
end