rdf-resource 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,233 @@
1
+ # -*- encoding: utf-8 -*-
2
+ # This file generated manually from
3
+ # http://iiif.io/model/shared-canvas/1.0/index.html; it's likely incomplete!
4
+ #
5
+ # Note: this class fails to cooperate with:
6
+ # puts RDF::Graph.load( RDF::SC ).to_ttl
7
+ # That should work, e.g. see:
8
+ # puts RDF::Graph.load( RDF::RDFS ).to_ttl
9
+ #
10
+ require 'rdf'
11
+ module RDF
12
+ class SC < RDF::StrictVocabulary("http://www.shared-canvas.org/ns/")
13
+
14
+ # 2. Canvas Model
15
+ # http://iiif.io/model/shared-canvas/1.0/index.html#CanvasIntro
16
+
17
+ # 2.1 Canvas
18
+ # http://iiif.io/model/shared-canvas/1.0/index.html#Canvas
19
+
20
+ term :Canvas,
21
+ label: 'Canvas'.freeze,
22
+ comment: %(The Class for a Canvas, which is the digital surrogate for a physical page within the model.).freeze,
23
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
24
+ type: 'owl:Class'.freeze
25
+
26
+ property :hasAnnotations,
27
+ label: 'hasAnnotations'.freeze,
28
+ comment: %(The relationship between a Canvas and a list of Annotations that target it or part of it. Each Canvas MAY have one or more lists of related annotations.).freeze,
29
+ domain: 'http://www.shared-canvas.org/ns/Canvas'.freeze,
30
+ range: 'http://www.shared-canvas.org/ns/AnnotationList'.freeze,
31
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
32
+ type: 'owl:ObjectProperty'.freeze
33
+
34
+ # 2.2 Zone
35
+ # http://iiif.io/model/shared-canvas/1.0/index.html#Zone
36
+
37
+ term :Zone,
38
+ label: 'Zone'.freeze,
39
+ comment: %(Zones represent part of one or more Canvases).freeze,
40
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
41
+ type: 'owl:Class'.freeze
42
+
43
+ property :naturalAngle,
44
+ label: 'naturalAngle'.freeze,
45
+ comment: %(The relationship between a Canvas and a list of Annotations that target it or part of it. Each Canvas MAY have one or more lists of related annotations.).freeze,
46
+ domain: 'http://www.shared-canvas.org/ns/Zone'.freeze,
47
+ range: 'rdfs:Literal'.freeze,
48
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
49
+ type: 'owl:DatatypeProperty'.freeze
50
+
51
+
52
+ # 3. Annotations
53
+ # http://iiif.io/model/shared-canvas/1.0/index.html#Annotation
54
+ # Modeled by Open Annotations <http://www.w3.org/ns/oa#>
55
+
56
+ # 3.1 Painting Motivation
57
+ # http://iiif.io/model/shared-canvas/1.0/index.html#BasicAnnotation
58
+
59
+ term :painting,
60
+ label: 'painting'.freeze,
61
+ comment: %(The motivation that represents the distinction between resources that should be painted onto the Canvas, rather than resources that are about the Canvas. If the target of the Annotation is not a Canvas or Zone, then the meaning is left to other communities to define.).freeze,
62
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
63
+ type: 'http://www.w3.org/ns/oa#Motivation'.freeze
64
+
65
+
66
+ # 4. Ordering Model
67
+ # http://iiif.io/model/shared-canvas/1.0/index.html#OrderingIntro
68
+ # The Shared Canvas model starts from the Object Reuse and Exchange
69
+ # specification, which provides a method for ordering based on Proxy nodes,
70
+ # however we introduce a simpler method for the most common case of a
71
+ # single, linear order.
72
+
73
+ # 4.1. Ordered Aggregations
74
+ # http://iiif.io/model/shared-canvas/1.0/index.html#OrderedAggregation
75
+ # Nothing to model here; see ore:Aggregation and rdf:List.
76
+
77
+ # 4.2. Sequences
78
+ # http://iiif.io/model/shared-canvas/1.0/index.html#Sequence
79
+
80
+ term :Sequence,
81
+ label: 'Sequence'.freeze,
82
+ comment: %(An ordered aggregation of Canvases for the purpose of rendering them in that order.).freeze,
83
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
84
+ subClassOf: 'http://www.openarchives.org/ore/terms/Aggregation'.freeze,
85
+ type: 'owl:Class'.freeze
86
+
87
+ property :hasContentRange,
88
+ label: 'hasContentRange'.freeze,
89
+ comment: %(A pointer to an sc:Range which contains the content bearing pages of the sequence. If sc:hasContentRange is not supplied, then it defaults to the entire Sequence.).freeze,
90
+ domain: 'http://www.shared-canvas.org/ns/Sequence'.freeze,
91
+ range: 'http://www.shared-canvas.org/ns/Range'.freeze,
92
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
93
+ type: "owl:ObjectProperty".freeze
94
+
95
+ property :readingDirection,
96
+ label: 'readingDirection'.freeze,
97
+ comment: %("Left-to-Right" or "Right-to-Left" for the reading direction of this sequence for animating page viewers.).freeze,
98
+ domain: 'http://www.shared-canvas.org/ns/Sequence'.freeze,
99
+ range: 'rdfs:Literal'.freeze,
100
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
101
+ type: 'owl:DatatypeProperty'.freeze
102
+
103
+ # 4.3. Ranges
104
+ # http://iiif.io/model/shared-canvas/1.0/index.html#Range
105
+
106
+ term :Range,
107
+ label: 'Range'.freeze,
108
+ comment: %(An ordered aggregation of Canvases for the purpose of rendering them in that order.).freeze,
109
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
110
+ subClassOf: 'http://www.openarchives.org/ore/terms/Aggregation'.freeze,
111
+ type: 'owl:Class'.freeze
112
+
113
+
114
+ # 5. Discovery Model
115
+ # http://iiif.io/model/shared-canvas/1.0/index.html#DiscoveryIntro
116
+
117
+ # 5.1. Annotation Lists
118
+
119
+ term :AnnotationList,
120
+ label: 'AnnotationList'.freeze,
121
+ comment: %(An ordered aggregation of Annotations.).freeze,
122
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
123
+ type: 'owl:Class'.freeze
124
+
125
+ property :forCanvas,
126
+ label: 'forCanvas'.freeze,
127
+ comment: %(The relationship between the AnnotationList and any Canvas that are the targets of the included Annotations. Typically this relationship is used to describe the AnnotationList in a Manifest to allow clients to determine which lists should be retrieved.).freeze,
128
+ domain: ['http://www.shared-canvas.org/ns/AnnotationList'.freeze, 'http://www.shared-canvas.org/ns/Layer'.freeze, 'http://www.shared-canvas.org/ns/Manifest'.freeze],
129
+ range: 'http://www.shared-canvas.org/ns/Canvas'.freeze,
130
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
131
+ type: 'owl:ObjectProperty'.freeze
132
+
133
+ property :forMotivation,
134
+ label: 'forMotivation'.freeze,
135
+ comment: %(A shortcut relationship that implies that all of the Annotations in the list have that particular Motivation. ).freeze,
136
+ domain: ['http://www.shared-canvas.org/ns/AnnotationList'.freeze, 'http://www.shared-canvas.org/ns/Layer'.freeze],
137
+ range: 'http://www.w3.org/ns/oa#Motivation'.freeze,
138
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
139
+ type: 'owl:ObjectProperty'.freeze
140
+
141
+
142
+ # 5.2. Layers
143
+ # http://iiif.io/model/shared-canvas/1.0/index.html#Layer
144
+
145
+ term :Layer,
146
+ label: 'Layer'.freeze,
147
+ comment: %(An ordered aggregation of Annotations or Annotation Lists.).freeze,
148
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
149
+ type: 'owl:Class'.freeze
150
+
151
+ # All of the properties of AnnotationList are also useful for Layer:
152
+ # See sc:forCanvas and sc:forMotivation above.
153
+
154
+ # 5.3. Manifests
155
+ # http://iiif.io/model/shared-canvas/1.0/index.html#Manifest
156
+
157
+ term :Manifest,
158
+ label: 'Manifest'.freeze,
159
+ comment: %(The Manifest is what ties everything together. It is an Aggregation of the Layers, AnnotationLists and Sequences that make up the description of the facsimile. As such the Manifest is representative of the Book, Newspaper, Scroll or whatever physical object is being represented in the facsimile. A Manifest MUST have an rdf:label giving a human readable name for it. This label is to be used for rendering purposes to inform the user what they are looking at.).freeze,
160
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
161
+ type: 'owl:Class'.freeze
162
+
163
+ # sc:Manifest shares the sc:forCanvas property with sc:AnnotationList and sc:Layer.
164
+
165
+ # 5.4. Collections
166
+ # http://iiif.io/model/shared-canvas/1.0/index.html#Collection
167
+ # Shared Canvas does not address collections of Manifests (or of other
168
+ # Collections) directly. Ordered or regular ore:Aggregations are recommended
169
+ # as the basis of describing collections in a manner that would be compliant
170
+ # with the Shared Canvas guidelines.
171
+
172
+
173
+ # 5.5. Services and Bibliographic Information
174
+ # http://iiif.io/model/shared-canvas/1.0/index.html#Collection-Info
175
+
176
+ property :hasRelatedService,
177
+ label: 'hasRelatedService'.freeze,
178
+ comment: %(The relationship between a resource in the Shared Canvas model and the endpoint for a related service.).freeze,
179
+ domain: 'owl:Thing'.freeze, # ?
180
+ range: 'owl:Thing'.freeze, # ?
181
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
182
+ type: 'owl:ObjectProperty'.freeze
183
+
184
+ property :hasRelatedDescription,
185
+ label: 'hasRelatedDescription'.freeze,
186
+ comment: %(The relationship between a resource in the Shared Canvas model and a related description of the real world object.).freeze,
187
+ domain: 'owl:Thing'.freeze, # ?
188
+ range: 'owl:Thing'.freeze, # ?
189
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
190
+ type: 'owl:ObjectProperty'.freeze
191
+
192
+ property :agentLabel,
193
+ label: 'agentLabel'.freeze,
194
+ comment: %(A name and possibly role of a person or organization associated with the physical object which is being represented by the Shared Canvas object. For example: "Froissart (author)").freeze,
195
+ domain: 'owl:Thing'.freeze, # ?
196
+ range: 'rdfs:Literal'.freeze,
197
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
198
+ type: 'owl:DatatypeProperty'.freeze
199
+
200
+ property :dateLabel,
201
+ label: 'dateLabel'.freeze,
202
+ comment: %(A date or date range and possiby role associated with the physical object. For example: "Illustrated c. 1200").freeze,
203
+ domain: 'owl:Thing'.freeze, # ?
204
+ range: 'rdfs:Literal'.freeze,
205
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
206
+ type: 'owl:DatatypeProperty'.freeze
207
+
208
+ property :locationLabel,
209
+ label: 'locationLabel'.freeze,
210
+ comment: %(A location and possibly role associated with the physical object. For example: "Paris, France (created)").freeze,
211
+ domain: 'owl:Thing'.freeze, # ?
212
+ range: 'rdfs:Literal'.freeze,
213
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
214
+ type: 'owl:DatatypeProperty'.freeze
215
+
216
+ property :attributionLabel,
217
+ label: 'attributionLabel'.freeze,
218
+ comment: %(An attribution that must be displayed along with the resource. For example: "Held at A Library (NY)").freeze,
219
+ domain: 'owl:Thing'.freeze, # ?
220
+ range: 'rdfs:Literal'.freeze,
221
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
222
+ type: 'owl:DatatypeProperty'.freeze
223
+
224
+ property :rightsLabel,
225
+ label: 'rightsLabel'.freeze,
226
+ comment: %(A rights or license statement, describing how the facsimile may be reused.).freeze,
227
+ domain: 'owl:Thing'.freeze, # ?
228
+ range: 'rdfs:Literal'.freeze,
229
+ 'rdfs:isDefinedBy' => 'http://www.shared-canvas.org/ns/'.freeze,
230
+ type: 'owl:DatatypeProperty'.freeze
231
+
232
+ end
233
+ end
@@ -0,0 +1,39 @@
1
+ require 'dotenv'
2
+ Dotenv.load
3
+
4
+ require 'pry'
5
+ require 'pry-doc'
6
+
7
+ # Using rest-client with options to enable a client HTTP cache
8
+ require 'rest-client'
9
+ RestClient.proxy = ENV['http_proxy'] unless ENV['http_proxy'].nil?
10
+ RestClient.proxy = ENV['HTTP_PROXY'] unless ENV['HTTP_PROXY'].nil?
11
+ if ENV['RDF_CACHE_ENABLED'].to_s.upcase == 'TRUE'
12
+ require 'dalli'
13
+ require 'restclient/components'
14
+ require 'rack/cache'
15
+ # TODO: use RDF_CACHE_LOG_FILE || STDOUT
16
+ RestClient.enable Rack::CommonLogger, STDOUT
17
+ # Enable the HTTP cache to store meta and entity data according
18
+ # to the env config values or the defaults given here. See
19
+ # http://rtomayko.github.io/rack-cache/configuration for available options.
20
+ metastore = ENV['RDF_CACHE_METASTORE'] || 'file:/tmp/cache/rdf_meta'
21
+ entitystore = ENV['RDF_CACHE_ENTITYSTORE'] || 'file:/tmp/cache/rdf_body'
22
+ verbose = ENV['RDF_CACHE_VERBOSE'].to_s.upcase == 'TRUE' || false
23
+ RestClient.enable Rack::Cache,
24
+ :metastore => metastore, :entitystore => entitystore, :verbose => verbose
25
+ end
26
+
27
+ require 'addressable/uri'
28
+ require 'json'
29
+ require 'uuid'
30
+
31
+ require 'linkeddata'
32
+ require 'rdf/iiif'
33
+ require 'rdf-vocab'
34
+ require_relative 'rdf/vocab/Content.rb'
35
+ require_relative 'rdf/vocab/sc.rb'
36
+
37
+ require_relative 'rdf-resource/configuration'
38
+ require_relative 'rdf-resource/resource'
39
+
@@ -0,0 +1,4 @@
1
+ # Ignore everything in this directory
2
+ *
3
+ # Except this file
4
+ !.gitignore
@@ -0,0 +1,54 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'rdf-resource'
5
+ s.version = '0.0.1'
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/rdf-resource'
13
+ s.summary = 'A utility for working with RDF resources and vocabularies.'
14
+ s.description = 'It uses RDF.rb and several RDF::Vocab, with options for caching RDF resources.'
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 'rest-client', '~> 1.0'
32
+ s.add_dependency 'rest-client-components', '~> 1.0'
33
+ s.add_dependency 'rack-cache', '~> 1.2'
34
+ # dalli is a memcached ruby client
35
+ s.add_dependency 'dalli', '~> 2.7.2'
36
+ # Use pry for console and debug config
37
+ s.add_dependency 'pry'
38
+ s.add_dependency 'pry-doc'
39
+
40
+ s.add_development_dependency 'coveralls'
41
+ s.add_development_dependency 'guard'
42
+ s.add_development_dependency 'guard-ctags-bundler'
43
+ s.add_development_dependency 'rake'
44
+ s.add_development_dependency 'rspec'
45
+
46
+ s.files = `git ls-files`.split($/)
47
+ dev_files = %w(.gitignore bin/setup.sh bin/test.sh)
48
+ dev_files.each {|f| s.files.delete f }
49
+
50
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
51
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
52
+
53
+ end
54
+
@@ -0,0 +1,24 @@
1
+ require "spec_helper"
2
+
3
+ module RDFResource
4
+
5
+ describe Configuration do
6
+
7
+ describe '#debug' do
8
+ it 'default value is false' do
9
+ ENV['DEBUG'] = nil
10
+ config = Configuration.new
11
+ expect(config.debug).to be_falsey
12
+ end
13
+ end
14
+
15
+ describe '#debug=' do
16
+ it 'can set value' do
17
+ config = Configuration.new
18
+ config.debug = true
19
+ expect(config.debug).to be_truthy
20
+ end
21
+ end
22
+
23
+ end
24
+ end
@@ -0,0 +1,53 @@
1
+ require "spec_helper"
2
+
3
+ module RDFResource
4
+
5
+ describe Resource do
6
+
7
+ before :all do
8
+ @auth_id = 'no99010609'
9
+ @auth_url = 'http://id.loc.gov/authorities/names/no99010609'
10
+ @auth = Resource.new @auth_url
11
+ end
12
+
13
+ before :each do
14
+ end
15
+
16
+ describe '#initialize' do
17
+ it 'should not raise error for a valid iri' do
18
+ # iri_valid = 'http://id.loc.gov/authorities/names/no99010609'
19
+ expect{Resource.new @auth_url}.not_to raise_error
20
+ end
21
+ it 'should raise error for an invalid iri' do
22
+ expect{Resource.new 'This is not a URL'}.to raise_error(RuntimeError)
23
+ end
24
+ end
25
+
26
+ describe '#id' do
27
+ it 'should equal the url basename' do
28
+ expect(@auth.id).to eq(@auth_id)
29
+ end
30
+ end
31
+
32
+ describe '#iri' do
33
+ it 'should equal the auth url' do
34
+ expect(@auth.iri.to_s).to eq(@auth_url)
35
+ end
36
+ it 'should be an instance of Addressable::URI' do
37
+ expect(@auth.iri.instance_of? Addressable::URI).to be_truthy
38
+ end
39
+ end
40
+
41
+ after :each do
42
+ end
43
+
44
+ after :all do
45
+ @auth_url = nil
46
+ @auth = nil
47
+ end
48
+
49
+ end
50
+
51
+ end
52
+
53
+
@@ -0,0 +1,47 @@
1
+ require 'spec_helper'
2
+
3
+ # ::RDFResource module specs
4
+
5
+ describe ::RDFResource do
6
+
7
+ describe ".configuration" do
8
+ it "should be a configuration object" do
9
+ expect(described_class.configuration).to be_a_kind_of ::RDFResource::Configuration
10
+ end
11
+ end
12
+
13
+ describe "#configure" do
14
+ before :each do
15
+ ::RDFResource.configure do |config|
16
+ config.debug = true
17
+ end
18
+ end
19
+ it "returns a hash of options" do
20
+ config = ::RDFResource.configuration
21
+ expect(config).to be_instance_of ::RDFResource::Configuration
22
+ expect(config.debug).to be_truthy
23
+ end
24
+ after :each do
25
+ ::RDFResource.reset
26
+ end
27
+ end
28
+
29
+ describe ".reset" do
30
+ before :each do
31
+ ::RDFResource.configure do |config|
32
+ config.debug = true
33
+ end
34
+ end
35
+ it "resets the configuration" do
36
+ ::RDFResource.reset
37
+ config = ::RDFResource.configuration
38
+ expect(config).to be_instance_of ::RDFResource::Configuration
39
+ expect(config.debug).to be_falsey
40
+ end
41
+ after :each do
42
+ ::RDFResource.reset
43
+ end
44
+ end
45
+
46
+ end
47
+