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.
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/ld4l/open_annotation_rdf/annotation.rb', line 87 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 => RDFVocabularies::OA.Annotation, RDFVocabularies::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 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# 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) # get motivatedBy m = a.get_values(:motivatedBy) # TODO: Should m's class be validated? I've seen it be RDF::Vocabulary::Term and RDF::URI. For now, removing the validation. return a unless m.kind_of?(Array) && m.size > 0 # return a unless m.kind_of?(Array) && m.size > 0 && (m.first.kind_of?(RDF::Vocabulary::Term) || m.first.kind_of?(RDF::URI) # motivatedBy is set m_uri = m.first # currently only support commenting and tagging return LD4L::OpenAnnotationRDF::CommentAnnotation.new(uri_or_str) if m_uri == RDFVocabularies::OA.commenting return a unless m_uri == RDFVocabularies::OA.tagging # Tagging can be TagAnnotation or SemanticTagAnnotation. Only way to tell is by checking type of body. sta = LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new(uri_or_str) stb = sta.getBody return sta if stb.type.include?(RDFVocabularies::OA.SemanticTag) ta = LD4L::OpenAnnotationRDF::TagAnnotation.new(uri_or_str) tb = ta.getBody return ta if tb.type.include?(RDFVocabularies::OA.Tag) # can't match to a known annotation type, so return as generic annotation return a end |
Instance Method Details
#getBody ⇒ Object
Get the ActiveTriples::Resource
instance holding the body of this annotation.
55 56 57 |
# File 'lib/ld4l/open_annotation_rdf/annotation.rb', line 55 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.
73 74 75 76 77 |
# File 'lib/ld4l/open_annotation_rdf/annotation.rb', line 73 def persist! persisted = super # persist annotation body_persisted = persisted && @body ? @body.persist! : false # persist body persisted end |
#setAnnotatedAtNow ⇒ Object
Set annotatedAt property to now.
63 64 65 |
# File 'lib/ld4l/open_annotation_rdf/annotation.rb', line 63 def setAnnotatedAtNow set_value(:annotatedAt, Time.now.utc.iso8601(0)) end |