Class: LD4L::OpenAnnotationRDF::SemanticTagAnnotation

Inherits:
Annotation
  • Object
show all
Defined in:
lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb

Instance Method Summary collapse

Methods inherited from Annotation

#getBody, #persist!, resume, #setAnnotatedAtNow

Constructor Details

#initialize(*args) ⇒ SemanticTagAnnotation

Special processing for new and resumed SemanticTagAnnotations



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb', line 40

def initialize(*args)
  super(*args)

  # set motivatedBy
  m = get_values(:motivatedBy)
  set_value(:motivatedBy, RDFVocabularies::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

Instance Method Details

#destroyObject



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb', line 55

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

#setTerm(term_uri) ⇒ Object

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.

Parameters:

  • controlled (String)

    vocabulary uri for the term

Returns:

  • instance of SemanticTagBody

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb', line 23

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

  @body = LD4L::OpenAnnotationRDF::SemanticTagBody.new(term_uri)
  set_value(:hasBody, @body)
  @body
end