annotations2triannon 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +7 -0
  2. data/.env_example +44 -0
  3. data/.travis.yml +15 -0
  4. data/Gemfile +5 -0
  5. data/LICENSE +202 -0
  6. data/README.md +31 -0
  7. data/Rakefile +50 -0
  8. data/annotations2triannon.gemspec +58 -0
  9. data/bin/console +5 -0
  10. data/bin/ctags.rb +8 -0
  11. data/bin/dms.rb +175 -0
  12. data/bin/revs.rb +17 -0
  13. data/bin/revs_annotations2csv.sh +66 -0
  14. data/lib/annotations2triannon/annotation_list.rb +37 -0
  15. data/lib/annotations2triannon/configuration.rb +52 -0
  16. data/lib/annotations2triannon/iiif_annotation_list.rb +17 -0
  17. data/lib/annotations2triannon/iiif_collection.rb +56 -0
  18. data/lib/annotations2triannon/iiif_manifest.rb +32 -0
  19. data/lib/annotations2triannon/iiif_navigator.rb +172 -0
  20. data/lib/annotations2triannon/manifest.rb +86 -0
  21. data/lib/annotations2triannon/open_annotation.rb +262 -0
  22. data/lib/annotations2triannon/open_annotation_harvest.rb +37 -0
  23. data/lib/annotations2triannon/resource.rb +264 -0
  24. data/lib/annotations2triannon/revs.rb +263 -0
  25. data/lib/annotations2triannon/revs_db.rb +69 -0
  26. data/lib/annotations2triannon/shared_canvas_annotation_list.rb +18 -0
  27. data/lib/annotations2triannon/shared_canvas_manifest.rb +32 -0
  28. data/lib/annotations2triannon.rb +27 -0
  29. data/lib/rdf/vocab/Content.rb +112 -0
  30. data/lib/rdf/vocab/sc.rb +233 -0
  31. data/lib/requires.rb +69 -0
  32. data/log/.gitignore +4 -0
  33. data/spec/lib/annotations2triannon/configuration_spec.rb +24 -0
  34. data/spec/lib/annotations2triannon/open_annotation_spec.rb +176 -0
  35. data/spec/lib/annotations2triannon/resource_spec.rb +53 -0
  36. data/spec/lib/annotations2triannon_spec.rb +45 -0
  37. data/spec/spec_helper.rb +10 -0
  38. metadata +387 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: f33ee86839aa0422e2b9d4f65c3e7d4eb8d43abd
4
+ data.tar.gz: 3734d6618c18d16162ef9d547f477181cd8093cd
5
+ SHA512:
6
+ metadata.gz: 6fdaa5ff288ba974553e1888cd0d9ae1217aa47f0b2e53880977d9c1155b85f1fb1ad90caeed670ec10168acec7fe2db31b39653969632465992b593d86504ea
7
+ data.tar.gz: 7efdb3d2eae0d633a61a1238de7a996edb66251fccc6ecbe446ad24dd422f2875d87c038fd09fa71e1fe9f90116d037550b3421a577907b4962be2de4246f035
data/.env_example ADDED
@@ -0,0 +1,44 @@
1
+ # https://github.com/bkeepers/dotenv is used for
2
+ # default configuration options. The values in
3
+ # this file do not replace existing values in
4
+ # the shell ENV.
5
+
6
+ # Uncomment and set values as required. See used settings in
7
+ # lib/marc2linkeddata/configuration.rb
8
+
9
+ export DEBUG=false
10
+
11
+ # limit the depth of IIIF navigation; useful for development
12
+ # or testing a new data source.
13
+ export ANNO_LIMIT_MANIFESTS=0 # 0 is all of them
14
+ export ANNO_LIMIT_ANNOLISTS=0 # 0 is all of them
15
+ export ANNO_LIMIT_OPENANNOS=0 # 0 is all of them
16
+
17
+ export ANNO_LOG_FILE='log/annotations2triannon.log'
18
+
19
+ # RestClient/Rack-Cache configs, see
20
+ # http://rtomayko.github.io/rack-cache/configuration
21
+ # http://rtomayko.github.io/rack-cache/storage
22
+ export RACK_CACHE_ENABLED=true
23
+ export RACK_CACHE_VERBOSE=false
24
+ export RACK_CACHE_METASTORE='memcached://localhost:11211/anno_meta'
25
+ #export RACK_CACHE_METASTORE='file:/tmp/cache/anno_meta'
26
+ export RACK_CACHE_ENTITYSTORE='file:/tmp/cache/anno_body'
27
+
28
+ # Configure the triannon service
29
+ export TRIANNON_LOG_FILE='log/triannon_client.log'
30
+ export TRIANNON_HOST='triannon.example.org'
31
+ export TRIANNON_USER=''
32
+ export TRIANNON_PASS=''
33
+
34
+ # Configure the revs database for annotations and users
35
+ export REVS_ENABLED=false
36
+ export REVS_SRC_USER='libuser'
37
+ export REVS_SRC_HOST='revs.example.org'
38
+ export REVS_DB_HOST='localhost'
39
+ export REVS_DB_PORT='3306'
40
+ export REVS_DB_USER='revs'
41
+ export REVS_DB_PASSWORD=''
42
+ export REVS_DB_DATABASE='revs'
43
+
44
+
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ install: ./bin/setup.sh
4
+
5
+ script: ./bin/test.sh
6
+
7
+ notifications:
8
+ email: false
9
+
10
+ rvm:
11
+ - 1.9.3
12
+ - 2.0.0
13
+ - 2.1.5
14
+ - 2.2.0
15
+
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Dependencies are defined in *.gemspec
4
+ gemspec
5
+
data/LICENSE ADDED
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
data/README.md ADDED
@@ -0,0 +1,31 @@
1
+ # Utilities for Bulk Loading Open Annotations into Triannon and Fedora4
2
+
3
+ [![Build Status](https://travis-ci.org/sul-dlss/annotations2triannon.svg?branch=master)](https://travis-ci.org/sul-dlss/annotations2triannon)
4
+
5
+ ## A work in progress
6
+
7
+ - rapidly evolving code (as of early 2015)
8
+ - no gems published yet
9
+ - no stable API
10
+
11
+ ## Open Annotation Resources
12
+
13
+ - http://www.openannotation.org/spec/core/
14
+ - http://austese.net/lorestore/validate.html
15
+
16
+ ## Triannon Resources
17
+
18
+ - https://github.com/sul-dlss/triannon-service
19
+ - README has useful info
20
+
21
+ - Triannon gem
22
+ - https://github.com/sul-dlss/triannon
23
+ - has annotation specific graph manipulations:
24
+ - https://github.com/sul-dlss/triannon/blob/master/lib/triannon/graph.rb
25
+ - also RDF vocabs, four small gems for easy ruby RDF vocabulary access:
26
+ - https://github.com/sul-dlss?query=rdf
27
+ - also has specs that show posting annos and looking at http return codes, etc
28
+ - https://github.com/sul-dlss/triannon/blob/master/spec/integration
29
+ - http status codes:
30
+ - https://github.com/sul-dlss/triannon/search?utf8=%E2%9C%93&q=status
31
+
data/Rakefile ADDED
@@ -0,0 +1,50 @@
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+
5
+ require 'rdf'
6
+ require 'linkeddata'
7
+ require 'rdf/cli/vocab-loader'
8
+
9
+ desc 'Default: run specs.'
10
+ task :default => :spec
11
+ task :specs => :spec
12
+
13
+ # Derived from https://raw.githubusercontent.com/ruby-rdf/rdf/develop/Rakefile
14
+ desc "Generate Vocabularies"
15
+ vocab_sources = {
16
+ #oa: {
17
+ # uri: 'http://www.w3.org/ns/oa#',
18
+ # source: 'http://www.openannotation.org/spec/core/20130208/oa.owl',
19
+ # strict: true
20
+ #},
21
+ Content: {
22
+ uri: 'http://www.w3.org/2011/content#',
23
+ source: 'http://www.w3.org/2011/content',
24
+ strict: true
25
+ },
26
+ }
27
+
28
+ task :gen_vocabs => vocab_sources.keys.map {|v| "lib/rdf/vocab/#{v}.rb"}
29
+
30
+ vocab_sources.each do |id, v|
31
+ file "lib/rdf/vocab/#{id}.rb" => :do_build do
32
+ puts "Generate lib/rdf/vocab/#{id}.rb"
33
+ begin
34
+ out = StringIO.new
35
+ loader = RDF::VocabularyLoader.new(id.to_s.upcase)
36
+ loader.uri = v[:uri]
37
+ loader.source = v[:source] if v[:source]
38
+ loader.extra = v[:extra] if v[:extra]
39
+ loader.strict = v.fetch(:strict, true)
40
+ loader.output = out
41
+ loader.run
42
+ out.rewind
43
+ File.open("lib/rdf/vocab/#{id}.rb", "w") {|f| f.write out.read}
44
+ rescue
45
+ puts "Failed to load #{id}: #{$!.message}"
46
+ end
47
+ end
48
+ end
49
+
50
+ task :do_build
@@ -0,0 +1,58 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'annotations2triannon'
5
+ s.version = '0.1.0'
6
+ s.licenses = ['Apache-2.0']
7
+ s.platform = Gem::Platform::RUBY
8
+
9
+ s.authors = ['Darren Weber',]
10
+ s.email = ['darren.weber@stanford.edu']
11
+
12
+ s.homepage = 'https://github.com/sul-dlss/triannon'
13
+ s.summary = 'bulk load annotations into triannon'
14
+ s.description = 'Utilities for bulk loading annotations into triannon'
15
+
16
+ s.required_rubygems_version = '>= 1.3.6'
17
+
18
+ s.extra_rdoc_files = ['README.md', 'LICENSE']
19
+
20
+ # general utils
21
+ s.add_dependency 'json'
22
+ s.add_dependency 'uuid'
23
+ # Use ENV for config
24
+ s.add_dependency 'dotenv'
25
+ # RDF linked data
26
+ s.add_dependency 'addressable', '~> 2.3'
27
+ s.add_dependency 'linkeddata', '~> 1.0'
28
+ s.add_dependency 'rdf-iiif'
29
+ s.add_dependency 'rdf-vocab', '~> 0.5'
30
+ # HTTP client and rack cache components
31
+ s.add_dependency 'triannon-client'
32
+ s.add_dependency 'rest-client', '~> 1.7.0'
33
+ s.add_dependency 'rest-client-components', '~> 1.3.0'
34
+ s.add_dependency 'rack-cache', '~> 1.2'
35
+ # dalli is a memcached ruby client
36
+ s.add_dependency 'dalli', '~> 2.7.2'
37
+ # Use pry for console and debug config
38
+ s.add_dependency 'pry'
39
+ s.add_dependency 'pry-doc'
40
+ # database gems
41
+ s.add_dependency 'mysql2'
42
+ s.add_dependency 'sequel'
43
+
44
+ s.add_development_dependency 'coveralls'
45
+ s.add_development_dependency 'guard'
46
+ s.add_development_dependency 'guard-ctags-bundler'
47
+ s.add_development_dependency 'rake'
48
+ s.add_development_dependency 'rspec'
49
+
50
+ s.files = `git ls-files`.split($/)
51
+ dev_files = %w(.gitignore bin/setup.sh bin/test.sh)
52
+ dev_files.each {|f| s.files.delete f }
53
+
54
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
55
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
56
+
57
+ end
58
+
data/bin/console ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ require 'annotations2triannon'
3
+ CONFIG = Annotations2triannon.configuration
4
+ binding.pry
5
+
data/bin/ctags.rb ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+ system "find . -name '*.rb' | ctags -f .tags --languages=Ruby -L -"
3
+
4
+ if File.exist? './Gemfile'
5
+ require 'bundler'
6
+ paths = Bundler.load.specs.map(&:full_gem_path).join(' ')
7
+ system "ctags -R -f .gemtags --languages=Ruby #{paths}"
8
+ end
data/bin/dms.rb ADDED
@@ -0,0 +1,175 @@
1
+ #!/usr/bin/env ruby
2
+ require 'annotations2triannon'
3
+ CONFIG = Annotations2triannon.configuration
4
+
5
+
6
+ # https://jirasul.stanford.edu/jira/browse/DT-5
7
+ # Annotation lists:
8
+ # 1) http://dms-data.stanford.edu/data/manifests/BnF/jr903ng8662/list/
9
+ # 2) http://dms-data.stanford.edu/data/manifests/Stanford/kq131cs7229/list/
10
+
11
+ # 3) http://dms-data.stanford.edu/data/data/yale/yale_cs_annotations_for_stanford.json
12
+
13
+ # Stanford manifests associated with 1) and 2)
14
+ # 1) http://dms-data.stanford.edu/data/manifests/BnF/jr903ng8662/manifest.json
15
+ # 2) http://dms-data.stanford.edu/data/manifests/Stanford/kq131cs7229/manifest.json
16
+
17
+ # Additional PURL manifest
18
+ # http://purl.stanford.edu/jr903ng8662/iiif/manifest.json
19
+
20
+ # Mirador viewer
21
+ # http://sul-reader-test.stanford.edu/m2/#6c45932d-2276-4699-9203-a9133181c2a1
22
+
23
+
24
+
25
+ IIIF_COLLECTION='http://dms-data.stanford.edu/data/manifests/collections/collection.json'
26
+ puts "\nCollection:\n#{IIIF_COLLECTION}"
27
+
28
+ iiif_navigator = Annotations2triannon::IIIFNavigator.new(IIIF_COLLECTION);
29
+
30
+ puts "\nManifests:"
31
+ manifests = iiif_navigator.manifests;
32
+ manifests.each {|m| puts m.iri}
33
+
34
+ puts "\nAnnotation List counts:"
35
+ annotation_lists = iiif_navigator.annotation_lists;
36
+ annotation_lists.each_pair {|m,alist| puts "#{m} => #{alist.length}"}
37
+
38
+ puts "\nOpen Annotation counts:"
39
+ open_annotations = iiif_navigator.open_annotations;
40
+ open_annotations.each_pair do |m,alists|
41
+ puts "\n#{m}"
42
+ alists.each_pair do |alist, oa_arr|
43
+ puts "\t#{alist}\t=> #{oa_arr.length}"
44
+ end
45
+ end
46
+
47
+ # Find all annotations where the body is text
48
+ text_annotations = {}
49
+ manifest_keys = open_annotations.keys
50
+ manifest_keys.each do |mk|
51
+ text_annotations[mk] = {}
52
+ anno_list_keys = open_annotations[mk].keys
53
+ anno_list_keys.each do |ak|
54
+ anno_list = open_annotations[mk][ak]
55
+ anno_text_list = anno_list.select {|oa| oa if oa.body_contentAsText? }
56
+ text_annotations[mk][ak] = anno_text_list
57
+ end
58
+ end
59
+
60
+ # text_anno_list = text_annotations.values.first.values.first
61
+ # oa = text_anno_list.sample(1).first
62
+ # puts oa.body_contentChars
63
+ # puts oa.to_jsonld_iiif
64
+ # puts oa.to_jsonld_oa
65
+ # binding.pry
66
+
67
+
68
+ # -----------------------------------------------------------------------
69
+ # POST annotations to triannon and track the triannon URIs
70
+
71
+ tc = TriannonClient::TriannonClient.new
72
+
73
+ # cleanup any prior annotations in triannon
74
+ puts "\nText Annotation cleanup:"
75
+ anno_tracking_file = File.join(CONFIG.log_path, 'dms_annotation_tracking.json')
76
+ if File.exists? anno_tracking_file
77
+ if File.size(anno_tracking_file).to_i > 0
78
+ anno_tracking = JSON.parse( File.read(anno_tracking_file) )
79
+ anno_tracking.each_pair do |manifest_uri,anno_lists|
80
+ puts "\n#{manifest_uri}"
81
+ anno_lists.each_pair do |anno_list_uri, anno_list|
82
+ puts "Removing:\t#{anno_list_uri}\t=> #{anno_list.length}"
83
+ anno_list.each do |anno_data|
84
+ success = tc.delete_annotation(anno_data['uri'])
85
+ CONFIG.logger.error("FAILURE to delete #{anno_data['uri']}") unless success
86
+ end
87
+ end
88
+ end
89
+ else
90
+ puts "Nothing to delete."
91
+ end
92
+ else
93
+ puts "Nothing to delete."
94
+ end
95
+
96
+
97
+ puts "\nText Annotation posts:"
98
+ anno_tracking = {}
99
+ text_annotations.each_pair do |m,anno_lists|
100
+ puts "\n#{m}"
101
+ anno_tracking[m] = {}
102
+ anno_lists.each_pair do |anno_list_uri, anno_list|
103
+ puts "Posting:\t#{anno_list_uri}\t=> #{anno_list.length}"
104
+ anno_tracking[m][anno_list_uri] = []
105
+ anno_list.each do |oa|
106
+ response = tc.post_annotation(oa.to_jsonld_oa)
107
+ # parse the response into an RDF::Graph
108
+ g = RDF::Graph.new
109
+ RDF::Reader.for(:rdfxml).new(response) do |reader|
110
+ reader.each_statement {|s| g << s }
111
+ end
112
+ # query the graph to extract the annotation URI
113
+ q = [:s, RDF.type, RDF::Vocab::OA.Annotation]
114
+ uris = g.query(q).collect {|s| s.subject }
115
+ if uris.length != 1
116
+ #TODO issue an error
117
+ else
118
+ anno_data = {
119
+ uri: uris.first,
120
+ chars: oa.body_contentChars.first
121
+ }
122
+ anno_tracking[m][anno_list_uri].push(anno_data)
123
+ end
124
+ end
125
+ end
126
+ end
127
+
128
+ # persist the anno_tracking data
129
+ File.open(anno_tracking_file,'w') do |f|
130
+ f.write(JSON.pretty_generate(anno_tracking))
131
+ end
132
+ puts "Annotation records saved to: #{anno_tracking_file}"
133
+
134
+
135
+ # For conversion of IIIF to OA context, see
136
+ # https://github.com/sul-dlss/triannon/blob/master/lib/triannon/graph.rb#L36-50
137
+ # https://jirasul.stanford.edu/jira/browse/DT-6
138
+
139
+
140
+ # These notes below are left here to document code that filters manifests and
141
+ # based on the RDF type of the manifest (vs. the RDF type for the manifest in
142
+ # the parent collection, which can differ from the manifest itself).
143
+
144
+ # # Explore the collection to resolve IIIF and Shared Canvas (SC) manifests.
145
+ # iiif_manifests = []
146
+ # sc_manifests = []
147
+
148
+ # # Examine IIIF manifests in the collection
149
+ # iiif_manifests.push(* iiif_navigator.iiif_manifests)
150
+ # # A IIIF collection might contain a IIIF manifest that itself
151
+ # # could be typed as an SC manifest.
152
+ # tmp = iiif_manifests.select {|m| m if m.sc_manifest? }
153
+ # tmp.each do |m|
154
+ # sc_manifests << Annotations2triannon::SharedCanvasManifest.new(m.iri.to_s)
155
+ # end
156
+ # iiif_manifests = iiif_manifests.select {|m| m if m.iiif_manifest? }
157
+
158
+ # # Examine SC manifests in the collection
159
+ # sc_manifests.push(* iiif_navigator.sc_manifests)
160
+ # # A IIIF collection might contain an SC manifest that itself
161
+ # # could be typed as a IIIF manifest.
162
+ # iiif_manifests.push(* sc_manifests.select {|m| m if m.iiif_manifest? } )
163
+ # tmp = sc_manifests.select {|m| m if m.iiif_manifest? }
164
+ # tmp.each do |m|
165
+ # iiif_manifests << Annotations2triannon::IIIFManifest.new(m.iri.to_s)
166
+ # end
167
+ # sc_manifests = sc_manifests.select {|m| m if m.sc_manifest? }
168
+
169
+ # # The collection should be now resolved into IIIF and SC manifests.
170
+
171
+ # # Looking at examples of IIIF and SC manifests:
172
+ # sc_manifest = sc_manifests.sample(1).first rescue nil
173
+ # # iiif_manifest = iiif_manifests.sample(1).first rescue nil
174
+ # # There are no IIIF manifests in this data?
175
+
data/bin/revs.rb ADDED
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ENV['REVS_ENABLED'] = 'true'
4
+
5
+ require 'annotations2triannon'
6
+ CONFIG = Annotations2triannon.configuration
7
+
8
+ revs = Annotations2triannon::Revs.new
9
+
10
+ tc = TriannonClient::TriannonClient.new
11
+ puts "\nRevs open annotation posts:"
12
+ revs.open_annotations.each do |oa|
13
+ binding.pry
14
+ tc.post_annotation(oa.to_jsonld_oa)
15
+ end
16
+
17
+