Class: LD4L::OpenAnnotationRDF::CommentAnnotation

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

Instance Method Summary collapse

Methods inherited from Annotation

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

Constructor Details

#initialize(*args) ⇒ CommentAnnotation

Special processing for new and resumed CommentAnnotations



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

def initialize(*args)
  super(*args)

  # set motivatedBy
  m = get_values(:motivatedBy)
  set_value(:motivatedBy, RDFVocabularies::OA.commenting) unless m.kind_of?(Array) && m.size > 0

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

Instance Method Details

#getCommentObject

Get the value of the comment stored in a comment annotation.

Returns:

  • text value of comment



31
32
33
34
# File 'lib/ld4l/open_annotation_rdf/comment_annotation.rb', line 31

def getComment
  comments = @body.content
  comments && comments.size > 0 ? comments.first : ""
end

#setComment(comment) ⇒ Object

Create a comment annotation body and set the hasBody property to it.

Parameters:

  • (String)

Returns:

  • instance of CommentAnnotation



16
17
18
19
20
21
22
23
24
25
# File 'lib/ld4l/open_annotation_rdf/comment_annotation.rb', line 16

def setComment(comment)
  @body = LD4L::OpenAnnotationRDF::CommentBody.new(
      ActiveTriples::LocalName::Minter.generate_local_name(
          LD4L::OpenAnnotationRDF::CommentBody, 10, @localname_prefix,
          LD4L::OpenAnnotationRDF.configuration.localname_minter ))
  @body.content = comment
  @body.format  = "text/plain"
  set_value(:hasBody, @body)
  @body
end