Class: LD4L::OpenAnnotationRDF::Annotation
- Inherits:
-
ActiveTriples::Resource
- Object
- ActiveTriples::Resource
- LD4L::OpenAnnotationRDF::Annotation
- Defined in:
- lib/ld4l/open_annotation_rdf/annotation.rb
Direct Known Subclasses
Class Attribute Summary collapse
-
.localname_prefix ⇒ Object
readonly
Returns the value of attribute localname_prefix.
Class Method Summary collapse
-
.find_by_target(target_uri) ⇒ Object
Find annotation by target.
- .resume(uri_or_str) ⇒ Object
Instance Method Summary collapse
-
#getBody ⇒ Object
Get the
ActiveTriples::Resource
instance holding the body of this annotation. -
#persist! ⇒ Object
Save all annotation and annotation body triples to the triple store.
-
#setAnnotatedAtNow ⇒ Object
Set annotatedAt property to now.
Class Attribute Details
.localname_prefix ⇒ Object (readonly)
Returns the value of attribute localname_prefix.
5 6 7 |
# File 'lib/ld4l/open_annotation_rdf/annotation.rb', line 5 def localname_prefix @localname_prefix end |
Class Method Details
.find_by_target(target_uri) ⇒ Object
TODO:
What to return if annotation persists fine, but body fails to persist?
Find annotation by target.
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/ld4l/open_annotation_rdf/annotation.rb', line 74 def self::find_by_target(target_uri) raise ArgumentError, 'target_uri argument must be a uri string or an instance of RDF::URI' unless target_uri.kind_of?(String) && target_uri.size > 0 || target_uri.kind_of?(RDF::URI) # raise ArgumentError, 'repository argument must be an instance of RDF::Repository' unless # repository.kind_of?(RDF::Repository) target_uri = RDF::URI(target_uri) unless target_uri.kind_of?(RDF::URI) repo = ActiveTriples::Repositories.repositories[repository] query = RDF::Query.new({ :annotation => { RDF.type => RDF::Vocab::OA.Annotation, RDF::Vocab::OA.hasTarget => target_uri, } }) annotations = [] results = query.execute(repo) results.each { |r| annotations << r.to_hash[:annotation] } annotations end |
.resume(uri_or_str) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/ld4l/open_annotation_rdf/annotation.rb', line 20 def self.resume(uri_or_str) # Let ActiveTriples::Resource validate uri_or_str when creating new Annotation a = new(uri_or_str) return nil if a.nil? # currently only support commenting and tagging m = motivated_by a return LD4L::OpenAnnotationRDF::CommentAnnotation.new(uri_or_str) if m.include? RDF::Vocab::OA.commenting # Tagging can be TagAnnotation or SemanticTagAnnotation. Only way to tell is by checking type of body. return a unless m.include? RDF::Vocab::OA.tagging b = body_resource a return LD4L::OpenAnnotationRDF::TagAnnotation.new(uri_or_str) if b.type.include? RDF::Vocab::OA.Tag LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new(uri_or_str) end |
Instance Method Details
#getBody ⇒ Object
Get the ActiveTriples::Resource
instance holding the body of this annotation.
42 43 44 |
# File 'lib/ld4l/open_annotation_rdf/annotation.rb', line 42 def getBody @body end |
#persist! ⇒ Object
TODO:
What to return if annotation persists fine, but body fails to persist?
Save all annotation and annotation body triples to the triple store.
60 61 62 63 64 |
# File 'lib/ld4l/open_annotation_rdf/annotation.rb', line 60 def persist! persisted = super # persist annotation body_persisted = persisted && @body ? @body.persist! : false # persist body persisted end |
#setAnnotatedAtNow ⇒ Object
Set annotatedAt property to now.
50 51 52 |
# File 'lib/ld4l/open_annotation_rdf/annotation.rb', line 50 def setAnnotatedAtNow set_value(:annotatedAt, Time.now.utc.iso8601(0)) end |