Class: LD4L::OpenAnnotationRDF::SemanticTagBody

Inherits:
ActiveTriples::Resource
  • Object
show all
Defined in:
lib/ld4l/open_annotation_rdf/semantic_tag_body.rb

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.localname_prefixObject (readonly)

Returns the value of attribute localname_prefix.



5
6
7
# File 'lib/ld4l/open_annotation_rdf/semantic_tag_body.rb', line 5

def localname_prefix
  @localname_prefix
end

Class Method Details

.annotations_using(term_uri) ⇒ Object

Get a list of annotations using a term.

NOTE: This method returns only persisted annotations.

Parameters:

  • controlled (String)

    vocabulary uri for the term

Returns:

  • array of annotation URIs

Raises:

  • (ArgumentError)


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ld4l/open_annotation_rdf/semantic_tag_body.rb', line 23

def self::annotations_using( term_uri )
  raise ArgumentError, 'Argument must be a uri string or an instance of RDF::URI'  unless
      term_uri.kind_of?(String) && term_uri.size > 0 || term_uri.kind_of?(RDF::URI)

  term_uri = RDF::URI(term_uri) unless term_uri.kind_of?(RDF::URI)

  # find usage by Annotations
  repo = ActiveTriples::Repositories.repositories[repository]
  query = RDF::Query.new({
                             :annotation => {
                                 RDF.type =>  RDF::Vocab::OA.Annotation,
                                 RDF::Vocab::OA.hasBody => term_uri,
                             }
                         })
  annotations = []
  results = query.execute(repo)
  results.each { |r| annotations << r.to_hash[:annotation] }
  annotations
end

.destroy_if_unused(term_uri) ⇒ Object

Destroy the SemanticTagBody only if the term is not used by another SemanticAnnotation

NOTE: Use this method after changing the term AND persisting the annotation on which the term was changed.

Parameters:

  • controlled (String)

    vocabulary uri for the term

Returns:

  • true if destroyed; otherwise, false if used by other annotations

Raises:

  • (ArgumentError)


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ld4l/open_annotation_rdf/semantic_tag_body.rb', line 52

def self::destroy_if_unused( term_uri )
  raise ArgumentError, 'Argument must be a uri string or an instance of RDF::URI'  unless
      term_uri.kind_of?(String) && term_uri.size > 0 || term_uri.kind_of?(RDF::URI)

  term_uri = RDF::URI(term_uri) unless term_uri.kind_of?(RDF::URI)

  # find usage by Annotations
  annotations = self::annotations_using( term_uri )
  destroyed = false
  if( annotations.empty? )
    stb = LD4L::OpenAnnotationRDF::SemanticTagBody.new(term_uri)
    destroyed = stb.destroy!
  end
  destroyed
end