Class: LD4L::OpenAnnotationRDF::TagAnnotation
- Inherits:
-
Annotation
- Object
- ActiveTriples::Resource
- Annotation
- LD4L::OpenAnnotationRDF::TagAnnotation
- Defined in:
- lib/ld4l/open_annotation_rdf/tag_annotation.rb
Instance Method Summary collapse
- #destroy ⇒ Object
-
#getTag ⇒ Object
Get the value of the tag stored in a tag annotation.
-
#initialize(*args) ⇒ TagAnnotation
constructor
Special processing for new and resumed TagAnnotations.
-
#setTag(tag) ⇒ Object
Set the hasBody property to the URI of the one and only TagBody holding the tag value.
Methods inherited from Annotation
find_by_target, #getBody, #persist!, resume, #setAnnotatedAtNow
Constructor Details
#initialize(*args) ⇒ TagAnnotation
Special processing for new and resumed TagAnnotations
78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/ld4l/open_annotation_rdf/tag_annotation.rb', line 78 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 TagBody if it exists tag_uri = get_values(:hasBody).first if( tag_uri ) tag_uri = tag_uri.rdf_subject if tag_uri.kind_of?(ActiveTriples::Resource) @body = LD4L::OpenAnnotationRDF::TagBody.new(tag_uri) end end |
Instance Method Details
#destroy ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/ld4l/open_annotation_rdf/tag_annotation.rb', line 93 def destroy # TODO Determine behavior of destroy # Behaviour Options # * Always destroy TagAnnotation # * Handling of TagBody # ** If TagBody is used only by this TagAnnotation, destroy it. # ** Otherwise, do not destroy it. # TODO Write tests for this behaviour. # TODO Write code here to enforce. super end |
#getTag ⇒ Object
Get the value of the tag stored in a tag annotation.
15 16 17 18 |
# File 'lib/ld4l/open_annotation_rdf/tag_annotation.rb', line 15 def getTag = @body.tag && .size > 0 ? .first : "" # TODO What is the appropriate default value for a tag? end |
#setTag(tag) ⇒ Object
Set the hasBody property to the URI of the one and only TagBody holding the tag value. Create a new TagBody if one doesn’t exist with this value.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ld4l/open_annotation_rdf/tag_annotation.rb', line 27 def setTag(tag) raise ArgumentError, 'Argument must be a string with at least one character' unless tag.kind_of?(String) && tag.size > 0 # return existing body if tag value is unchanged old_tag = @body ? @body.tag : nil return @body if old_tag && old_tag.include?(tag) if LD4L::OpenAnnotationRDF.configuration. # when unique_tags = true, try to find an existing TagBody with the tag value before creating a new TagBody # TODO Determine behavior of setTag when unique_tags=true # Behaviour Options: # * Look for an existing TagBody with this value. # ** If none found, create a new TagBody. # ** If one found, set @body to this TagBody # ** If multiple found, use the first one found # ### the same one may not be the first one found each time the query executes @body = LD4L::OpenAnnotationRDF.configuration. ? LD4L::OpenAnnotationRDF::TagBody.fetch_by_tag_value(tag) : nil if @body == nil @body = LD4L::OpenAnnotationRDF::TagBody.new( ActiveTriples::LocalName::Minter.generate_local_name( LD4L::OpenAnnotationRDF::TagBody, 10, @localname_prefix, LD4L::OpenAnnotationRDF.configuration.localname_minter )) @body.tag = tag end else # when unique_tags = false, ??? (see TODO) # TODO Determine behavior of setTag when unique_tags=false # Behaviour Options: # * If this TagAnnotation does not have a TagBody (@body) set, then create a new TagBody. # * If this TagBody is used only by this TagAnnotation, then change the value in the TagBody. # * If this TagBody is used by multiple TagAnnotations, # ** EITHER change the value in the TagBody which changes it for all the TagAnnotations. # ### Likely an undesirable side effect having the value change for all TagAnnotations # ** OR create a new TagBody and update @body to that TagBody # OR # * [CURRENT] Always create a new TagBody each time setTag is called and update @body # ### This last options has the potential for orphaned TagBodys that no TagAnnotation references. # TODO Rethink the current behavior which is always to create a new TagBody potentially leaving around orphans. @body = LD4L::OpenAnnotationRDF::TagBody.new( ActiveTriples::LocalName::Minter.generate_local_name( LD4L::OpenAnnotationRDF::TagBody, 10, @localname_prefix, LD4L::OpenAnnotationRDF.configuration.localname_minter )) @body.tag = tag end set_value(:hasBody, @body) @body end |