Class: LD4L::OpenAnnotationRDF::TagBody
- Inherits:
-
ActiveTriples::Resource
- Object
- ActiveTriples::Resource
- LD4L::OpenAnnotationRDF::TagBody
- Defined in:
- lib/ld4l/open_annotation_rdf/tag_body.rb
Class Attribute Summary collapse
-
.localname_prefix ⇒ Object
readonly
Returns the value of attribute localname_prefix.
Class Method Summary collapse
-
.annotations_using(tag_value) ⇒ Object
Get a list of annotations using the tag value.
-
.fetch_by_tag_value(tag_value, parent_annotation = nil) ⇒ Object
Search the configured repository for a TagBody triple that has the tag value for the tag property.
Instance Method Summary collapse
-
#initialize(*args) ⇒ TagBody
constructor
A new instance of TagBody.
Constructor Details
#initialize(*args) ⇒ TagBody
Returns a new instance of TagBody.
75 76 77 78 79 80 81 |
# File 'lib/ld4l/open_annotation_rdf/tag_body.rb', line 75 def initialize(*args) super(*args) t = get_values(:type) t << RDF::Vocab::CNT.ContentAsText set_value(:type,t) end |
Class Attribute Details
.localname_prefix ⇒ Object (readonly)
Returns the value of attribute localname_prefix.
5 6 7 |
# File 'lib/ld4l/open_annotation_rdf/tag_body.rb', line 5 def localname_prefix @localname_prefix end |
Class Method Details
.annotations_using(tag_value) ⇒ Object
Get a list of annotations using the tag value.
NOTE: This method returns only persisted annotations.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/ld4l/open_annotation_rdf/tag_body.rb', line 22 def self::annotations_using( tag_value ) raise ArgumentError, 'Argument must be a string with at least one character' unless tag_value.kind_of?(String) && tag_value.size > 0 tb = self::fetch_by_tag_value( tag_value ) return [] unless tb tag_uri = tb.rdf_subject # find usage by Annotations repo = ActiveTriples::Repositories.repositories[repository] query = RDF::Query.new({ :annotation => { RDF.type => RDF::Vocab::OA.Annotation, RDF::Vocab::OA.hasBody => tag_uri, } }) results = query.execute(repo) # process results annotations = [] results.each { |r| annotations << r.to_hash[:annotation] } annotations end |
.fetch_by_tag_value(tag_value, parent_annotation = nil) ⇒ Object
Search the configured repository for a TagBody triple that has the tag value for the tag property.
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_body.rb', line 53 def self::fetch_by_tag_value( tag_value, parent_annotation=nil ) raise ArgumentError, 'Argument must be a string with at least one character' unless tag_value.kind_of?(String) && tag_value.size > 0 repo = ActiveTriples::Repositories.repositories[repository] query = RDF::Query.new({ :tagbody => { RDF.type => RDF::Vocab::OA.Tag, RDF::Vocab::CNT.chars => tag_value, } }) tagbody = nil results = query.execute(repo) unless( results.empty? ) tagbody_uri = results[0].to_hash[:tagbody] tagbody = LD4L::OpenAnnotationRDF::TagBody.new(tagbody_uri) if parent_annotation.nil? tagbody = LD4L::OpenAnnotationRDF::TagBody.new(tagbody_uri,parent_annotation) unless parent_annotation.nil? end tagbody end |