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

find_by_target, #getBody, #persist!, resume, #setAnnotatedAtNow

Constructor Details

#initialize(*args) ⇒ SemanticTagAnnotation

Special processing for new and resumed SemanticTagAnnotations



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb', line 49

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



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb', line 64

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

#getTermObject

Get the term URI of the semantic tag body.

Returns:

  • the term URI



20
21
22
23
# File 'lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb', line 20

def getTerm
  # return existing body if term is unchanged
  @body ? @body.rdf_subject : nil
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)


32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb', line 32

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