Class: Triannon::Annotation

Inherits:
Object
  • Object
show all
Includes:
ActiveModel::Model
Defined in:
app/models/triannon/annotation.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dataObject

Returns the value of attribute data.



9
10
11
# File 'app/models/triannon/annotation.rb', line 9

def data
  @data
end

#expected_content_typeObject

Returns the value of attribute expected_content_type.



9
10
11
# File 'app/models/triannon/annotation.rb', line 9

def expected_content_type
  @expected_content_type
end

#idObject

Returns the value of attribute id.



9
10
11
# File 'app/models/triannon/annotation.rb', line 9

def id
  @id
end

Class Method Details

.allObject

Deprecated.
  • was used by old annotations#index action, before redirect to search (2015-04)



39
40
41
# File 'app/models/triannon/annotation.rb', line 39

def self.all
  Triannon::LdpLoader.find_all
end

.create(attrs = {}) ⇒ Object

Class Methods —————————————————————-



23
24
25
26
27
# File 'app/models/triannon/annotation.rb', line 23

def self.create(attrs = {})
  a = Triannon::Annotation.new attrs
  a.save
  a
end

.find(id) ⇒ Object

Parameters:

  • id (String)

    the unique id of the annotation. Can include base_uri prefix or omit it.



30
31
32
33
34
35
36
# File 'app/models/triannon/annotation.rb', line 30

def self.find(id)
  oa_graph = Triannon::LdpLoader.load id
  anno = Triannon::Annotation.new
  anno.graph = oa_graph
  anno.id = id
  anno
end

Instance Method Details

#destroyObject



56
57
58
59
60
# File 'app/models/triannon/annotation.rb', line 56

def destroy
  _run_destroy_callbacks do
    Triannon::LdpWriter.delete_anno @id
  end
end

#graphObject



66
67
68
69
70
71
# File 'app/models/triannon/annotation.rb', line 66

def graph
  @graph ||= begin
    g = data_to_graph
    OA::Graph.new g if g.kind_of? RDF::Graph
  end
end

#graph=(g) ⇒ Object

Parameters:

  • g

    either a OA::Graph or RDF::Graph object



74
75
76
77
78
79
80
# File 'app/models/triannon/annotation.rb', line 74

def graph= g
  if g.is_a? OA::Graph
    @graph = g
  elsif g.kind_of? RDF::Graph
    @graph = OA::Graph.new g
  end
end

#id_as_urlString

Returns the id of this annotation as a url or nil if no graph.

Returns:

  • (String)

    the id of this annotation as a url or nil if no graph



93
94
95
# File 'app/models/triannon/annotation.rb', line 93

def id_as_url
  graph.id_as_url if graph_exists?
end

#jsonld_iiifObject

Returns json-ld representation of anno with IIIF context as a url.

Returns:

  • json-ld representation of anno with IIIF context as a url



88
89
90
# File 'app/models/triannon/annotation.rb', line 88

def jsonld_iiif
  graph.jsonld_iiif
end

#jsonld_oaObject

Returns json-ld representation of anno with OpenAnnotation context as a url.

Returns:

  • json-ld representation of anno with OpenAnnotation context as a url



83
84
85
# File 'app/models/triannon/annotation.rb', line 83

def jsonld_oa
  graph.jsonld_oa
end

#motivated_byArray<String>

Returns of urls expressing the OA motivated_by values or nil if no graph.

Returns:

  • (Array<String>)

    of urls expressing the OA motivated_by values or nil if no graph



98
99
100
# File 'app/models/triannon/annotation.rb', line 98

def motivated_by
  graph.motivated_by if graph_exists?
end

#persisted?Boolean

Returns:

  • (Boolean)


62
63
64
# File 'app/models/triannon/annotation.rb', line 62

def persisted?
  id.present?
end

#saveObject

Instance Methods —————————————————————-



45
46
47
48
49
50
51
52
53
54
# File 'app/models/triannon/annotation.rb', line 45

def save
  _run_save_callbacks do
    # TODO: check if valid anno?
    @id = Triannon::LdpWriter.create_anno self if graph && graph.size > 2
    # reload from storage to get the anno id within the graph
    # TODO:  do graph manipulation to add id instead?
    @graph = Triannon::LdpLoader.load id
    id
  end
end