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

#root_containerObject

Returns the value of attribute root_container.



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

def root_container
  @root_container
end

Class Method Details

.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(root_container, id) ⇒ Object

Parameters:

  • root_container (String)
    • LDP parent container for annotation

  • id (String)

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



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

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

Instance Method Details

#destroyObject



53
54
55
56
57
# File 'app/models/triannon/annotation.rb', line 53

def destroy
  run_callbacks :destroy do
    Triannon::LdpWriter.delete_anno "#{root_container}/#{id}"
  end
end

#graphObject



63
64
65
66
67
68
# File 'app/models/triannon/annotation.rb', line 63

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



71
72
73
74
75
76
77
# File 'app/models/triannon/annotation.rb', line 71

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



90
91
92
# File 'app/models/triannon/annotation.rb', line 90

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



85
86
87
# File 'app/models/triannon/annotation.rb', line 85

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



80
81
82
# File 'app/models/triannon/annotation.rb', line 80

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



95
96
97
# File 'app/models/triannon/annotation.rb', line 95

def motivated_by
  graph.motivated_by if graph_exists?
end

#persisted?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'app/models/triannon/annotation.rb', line 59

def persisted?
  id.present?
end

#saveObject

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



42
43
44
45
46
47
48
49
50
51
# File 'app/models/triannon/annotation.rb', line 42

def save
  run_callbacks :save do
    # TODO: check if valid anno?
    @id = Triannon::LdpWriter.create_anno(self, root_container) 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(root_container, id)
    id
  end
end