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



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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

Instance Method Details

#destroyObject



70
71
72
73
74
75
76
77
78
79
80
# 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

#getTermObject

Get the term URI of the semantic tag body.

Returns:

  • the term URI



21
22
23
24
# 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) ⇒ 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)


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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