triannon 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9061e8fc2e0127540ae750118289a5f79a7f6969
4
- data.tar.gz: 2785857023cdd9a5a2e5caa3ecb7810f613430cb
3
+ metadata.gz: 38673b232f1a66c6710ed058242fcd79fb49ec92
4
+ data.tar.gz: eedb16b6f71893c5a8559d3f45628790392eaf61
5
5
  SHA512:
6
- metadata.gz: e149fc61982e7323f0a2401a316737f0dc0132fc2f3374f167317b149c0ec9541c47e5ec5364596c977c3d55f96bb006b213d5c78e966d091b770098d18fd5d4
7
- data.tar.gz: edac1a83ba367c2064a0ba1c17662948531634873924c0740a947e272bf90004a8d2128edc9b2e73589fae1522b3d24dcedccec458459a7ee3d062de860d974d
6
+ metadata.gz: d4791ad9be0bb23424dfdfe2de1e63249a527d30aa8c908f5b2718a4c166c0d9f8a013271f7a349ba0d6d1c250675782bacd27975dfd14d9d57b15ce0919e342
7
+ data.tar.gz: dc163e2632dfb58b34f4bd07517e04701fc05ce8a54f8c047b3829289f575b00c3de726d993d6e734decc0c997ed55cb0990f7c696b9a5e642d83f2b520c853e
@@ -26,11 +26,12 @@ module Triannon
26
26
  a
27
27
  end
28
28
 
29
- def self.find(key)
30
- oa_graph = Triannon::LdpLoader.load key
29
+ # @param [String] id the unique id of the annotation. Can include base_uri prefix or omit it.
30
+ def self.find(id)
31
+ oa_graph = Triannon::LdpLoader.load id
31
32
  anno = Triannon::Annotation.new
32
33
  anno.graph = oa_graph
33
- anno.id = key
34
+ anno.id = id
34
35
  anno
35
36
  end
36
37
 
@@ -65,9 +66,13 @@ module Triannon
65
66
  end
66
67
  end
67
68
 
68
- # @param [RDF::Graph]
69
+ # @param either a Triannon::Graph or RDF::Graph object
69
70
  def graph= g
70
- @graph = Triannon::Graph.new g if g.kind_of? RDF::Graph
71
+ if g.is_a? Triannon::Graph
72
+ @graph = g
73
+ elsif g.kind_of? RDF::Graph
74
+ @graph = Triannon::Graph.new g
75
+ end
71
76
  end
72
77
 
73
78
  # @return json-ld representation of anno with OpenAnnotation context as a url
@@ -94,8 +99,10 @@ protected
94
99
 
95
100
  # Add annotation to Solr as a Solr document
96
101
  def solr_save
97
- # pass in id we got from LDP Store
98
- solr_writer.add(graph.solr_hash(id))
102
+ # to be certain we are in sync, and to get the anno id within the graph, reload
103
+ # the graph from Trianon storage
104
+ graph_from_storage = Triannon::LdpLoader.load id
105
+ solr_writer.add(graph_from_storage.solr_hash)
99
106
  end
100
107
 
101
108
  # Delete annotation from Solr
@@ -4,8 +4,10 @@ module Triannon
4
4
  # Loads an existing Annotation from the LDP server
5
5
  class LdpLoader
6
6
 
7
- def self.load key
8
- l = Triannon::LdpLoader.new key
7
+
8
+ # @param [String] id the unique id of the annotation. Can include base_uri prefix or omit it.
9
+ def self.load id
10
+ l = Triannon::LdpLoader.new id
9
11
  l.load_anno_container
10
12
  l.load_bodies
11
13
  l.load_targets
@@ -21,15 +23,16 @@ module Triannon
21
23
 
22
24
  attr_accessor :ldp_annotation
23
25
 
24
- def initialize key = nil
25
- @key = key
26
+ # @param [String] id the unique id of the annotation. Can include base_uri prefix or omit it.
27
+ def initialize id = nil
28
+ @id = id
26
29
  @base_uri = Triannon.config[:ldp_url]
27
30
  @ldp_annotation = Triannon::AnnotationLdp.new
28
31
  end
29
32
 
30
33
  # load annotation container object into @ldp_annotation's (our Triannon::AnnotationLdp object) graph
31
34
  def load_anno_container
32
- load_object_into_annotation_graph(@key)
35
+ load_object_into_annotation_graph(@id)
33
36
  end
34
37
 
35
38
  # load body objects into @ldp_annotation's (our Triannon::AnnotationLdp object) graph
@@ -15,14 +15,22 @@ module Triannon
15
15
  def initialize ldp_anno
16
16
  @ldp_anno = ldp_anno
17
17
  @ldp_anno_graph = ldp_anno.stripped_graph
18
- @oa_graph = RDF::Graph.new
18
+ g = RDF::Graph.new
19
+ @oa_graph = Triannon::Graph.new g
19
20
  end
20
21
 
21
22
  def extract_base
23
+ root_subject_solns = @ldp_anno_graph.query Triannon::Graph.anno_query
24
+ if root_subject_solns.count == 1
25
+ @id = root_subject_solns[0].s.to_s.split('/').last
26
+ base_url = Triannon.config[:triannon_base_url]
27
+ base_url.strip!
28
+ base_url.chop! if base_url[-1] == '/'
29
+ @root_uri = RDF::URI.new(base_url + "/#{@id}")
30
+ end
31
+
22
32
  @ldp_anno_graph.each_statement do |stmnt|
23
33
  if stmnt.predicate == RDF.type && stmnt.object == RDF::OpenAnnotation.Annotation
24
- @id = stmnt.subject.to_s.split('/').last
25
- @root_uri = RDF::URI.new(Triannon.config[:triannon_base_url] + "/#{@id}")
26
34
  @oa_graph << [@root_uri, RDF.type, RDF::OpenAnnotation.Annotation]
27
35
  elsif stmnt.predicate == RDF::OpenAnnotation.motivatedBy
28
36
  @oa_graph << [@root_uri, stmnt.predicate, stmnt.object]
@@ -49,17 +49,15 @@ module Triannon
49
49
  hash_from_json.to_json
50
50
  end
51
51
 
52
- # NOTE: NEVER get here before anno is stored
53
- # the graph should have an assigned url for the @id of the root; it shouldn't be a blank node
54
- # @param [String] the Triannon id for this anno. Defaults to nil, in which case id_as_url will be used.
52
+ # DO NOT CALL before anno is stored.
53
+ # The graph should have an assigned url for the @id of the root; it shouldn't be a blank node
55
54
  # @return [Hash] a hash to be written to Solr, populated appropriately
56
- def solr_hash(triannon_id=nil)
55
+ def solr_hash
57
56
  doc_hash = {}
58
57
  # chars in Solr/Lucene query syntax are a big pain in Solr id fields, so we only use
59
58
  # the uuid portion of the Triannon anno id, not the full url
60
- triannon_id ||= id_as_url
61
- solr_id = triannon_id.sub(Triannon.config[:ldp_url], "")
62
- doc_hash[:id] = solr_id.sub(/^\//, "")
59
+ solr_id = id_as_url.sub(Triannon.config[:triannon_base_url], "")
60
+ doc_hash[:id] = solr_id.sub(/^\//, "") # remove first char slash if it is there
63
61
 
64
62
  # use short strings for motivation field
65
63
  doc_hash[:motivation] = motivated_by.map { |m| m.sub(RDF::OpenAnnotation.to_s, "") }
@@ -1,3 +1,3 @@
1
1
  module Triannon
2
- VERSION = "0.5.0"
2
+ VERSION = "0.5.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: triannon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Beer
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2015-01-31 00:00:00.000000000 Z
13
+ date: 2015-02-04 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - "~>"
20
20
  - !ruby/object:Gem::Version
21
- version: 4.2.0.rc1
21
+ version: 4.2.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - "~>"
27
27
  - !ruby/object:Gem::Version
28
- version: 4.2.0.rc1
28
+ version: 4.2.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: linkeddata
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -158,28 +158,28 @@ dependencies:
158
158
  requirements:
159
159
  - - "~>"
160
160
  - !ruby/object:Gem::Version
161
- version: '3.0'
161
+ version: 3.1.0
162
162
  type: :development
163
163
  prerelease: false
164
164
  version_requirements: !ruby/object:Gem::Requirement
165
165
  requirements:
166
166
  - - "~>"
167
167
  - !ruby/object:Gem::Version
168
- version: '3.0'
168
+ version: 3.1.0
169
169
  - !ruby/object:Gem::Dependency
170
170
  name: rspec-rails
171
171
  requirement: !ruby/object:Gem::Requirement
172
172
  requirements:
173
173
  - - "~>"
174
174
  - !ruby/object:Gem::Version
175
- version: '3.0'
175
+ version: 3.1.0
176
176
  type: :development
177
177
  prerelease: false
178
178
  version_requirements: !ruby/object:Gem::Requirement
179
179
  requirements:
180
180
  - - "~>"
181
181
  - !ruby/object:Gem::Version
182
- version: '3.0'
182
+ version: 3.1.0
183
183
  - !ruby/object:Gem::Dependency
184
184
  name: engine_cart
185
185
  requirement: !ruby/object:Gem::Requirement