active_annotations 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_annotations/rdf_annotation.rb +32 -32
- data/lib/active_annotations/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d34f9e85da537d14ac22967ea3592c74810f3fb9
|
4
|
+
data.tar.gz: 96ca561d94834c2d73e938c7347eb091ed605933
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccb6b7fcf53e6ff98b5558c1e2708cddfe460014c801e955c3e498f8ceeec80bc493a252a1ca7ea5b90980aaca4b28cd7d9c1ca2c5c569a8bd2a3d3f9f6093fd
|
7
|
+
data.tar.gz: 32b2d972f14e2ba6ce9c836113b9fc2ddd6768180801df53a7818d3a67f8e3b3e6b242095c50684a865de939812f140a223abeb530464ded1c3feec6e7077391
|
@@ -8,27 +8,27 @@ require 'rdf/vocab/cnt'
|
|
8
8
|
require 'rdf/vocab/dcmitype'
|
9
9
|
require 'rdf/vocab/foaf'
|
10
10
|
|
11
|
-
module ActiveAnnotations
|
11
|
+
module ActiveAnnotations
|
12
12
|
class RDFAnnotation
|
13
13
|
RDF::Vocab::DC = RDF::DC unless defined?(RDF::Vocab::DC)
|
14
14
|
RDF::Vocab::FOAF = RDF::FOAF unless defined?(RDF::Vocab::FOAF)
|
15
|
-
|
15
|
+
|
16
16
|
# Support reading legacy properties
|
17
17
|
RDF::Vocab::OA.property 'annotatedAt'
|
18
18
|
RDF::Vocab::OA.property 'annotatedBy'
|
19
|
-
|
19
|
+
|
20
20
|
attr_reader :graph
|
21
21
|
CONTEXT_URI = 'http://www.w3.org/ns/oa.jsonld'
|
22
|
-
|
22
|
+
|
23
23
|
def self.from_jsonld(json)
|
24
24
|
content = JSON.parse(json)
|
25
25
|
self.new(JSON::LD::API.toRDF(content, documentLoader: DocumentLoader.document_loader))
|
26
26
|
end
|
27
|
-
|
27
|
+
|
28
28
|
def to_jsonld(opts={})
|
29
29
|
input = JSON.parse(graph.dump :jsonld, standard_prefixes: true, prefixes: { oa: RDF::Vocab::OA.to_iri.value })
|
30
30
|
frame = YAML.load(File.read(File.expand_path('../frame.yml',__FILE__)))
|
31
|
-
output = JSON::LD::API.frame(input, frame, omitDefault: true, documentLoader: DocumentLoader.document_loader)
|
31
|
+
output = JSON::LD::API.frame(input, frame, validate: false, omitDefault: true, documentLoader: DocumentLoader.document_loader)
|
32
32
|
output.merge!(output.delete('@graph')[0])
|
33
33
|
if opts[:pretty_json]
|
34
34
|
JSON.pretty_generate output
|
@@ -45,7 +45,7 @@ module ActiveAnnotations
|
|
45
45
|
@graph << content
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
def get_value(s, p)
|
50
50
|
return nil if s.nil?
|
51
51
|
statement = graph.first(subject: s, predicate: p)
|
@@ -57,17 +57,17 @@ module ActiveAnnotations
|
|
57
57
|
statement.object.value
|
58
58
|
end
|
59
59
|
end
|
60
|
-
|
60
|
+
|
61
61
|
def set_value(s, p, value)
|
62
62
|
return nil if s.nil?
|
63
63
|
@graph.delete({ subject: s, predicate: p })
|
64
64
|
@graph << RDF::Statement.new(s, p, value) unless value.nil?
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
def add_statements(*statements)
|
68
68
|
statements.each { |statement| @graph << statement }
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
def add_default_content!
|
72
72
|
aid = new_id
|
73
73
|
add_statements(
|
@@ -86,7 +86,7 @@ module ActiveAnnotations
|
|
86
86
|
)
|
87
87
|
end
|
88
88
|
end
|
89
|
-
|
89
|
+
|
90
90
|
def ensure_target!
|
91
91
|
if target_id.nil?
|
92
92
|
tid = new_id
|
@@ -108,7 +108,7 @@ module ActiveAnnotations
|
|
108
108
|
)
|
109
109
|
end
|
110
110
|
end
|
111
|
-
|
111
|
+
|
112
112
|
def new_id
|
113
113
|
RDF::URI.new("urn:uuid:#{SecureRandom.uuid}")
|
114
114
|
end
|
@@ -117,68 +117,68 @@ module ActiveAnnotations
|
|
117
117
|
statement = @graph.first(predicate: RDF.type, object: type)
|
118
118
|
statement.nil? ? nil : statement.subject
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
def annotation_id
|
122
122
|
find_id(RDF::Vocab::OA.Annotation)
|
123
123
|
end
|
124
|
-
|
124
|
+
|
125
125
|
def body_id
|
126
126
|
statement = @graph.first(subject: annotation_id, predicate: RDF::Vocab::OA.hasBody)
|
127
127
|
statement.nil? ? nil : statement.object
|
128
128
|
end
|
129
|
-
|
129
|
+
|
130
130
|
def target_id
|
131
131
|
find_id(RDF::Vocab::OA.SpecificResource)
|
132
132
|
end
|
133
|
-
|
133
|
+
|
134
134
|
def selector_id
|
135
135
|
find_id(RDF::Vocab::OA.FragmentSelector)
|
136
136
|
end
|
137
|
-
|
137
|
+
|
138
138
|
def fragment_value
|
139
139
|
graph.first(subject: selector_id, predicate: RDF.value)
|
140
140
|
end
|
141
|
-
|
141
|
+
|
142
142
|
def fragment_value=(value)
|
143
143
|
ensure_selector!
|
144
144
|
set_value(selector_id, RDF.value, value)
|
145
145
|
end
|
146
|
-
|
146
|
+
|
147
147
|
def start_time
|
148
148
|
value = fragment_value.nil? ? nil : fragment_value.object.value.scan(/^t=(.*)$/).flatten.first.split(/,/)[0]
|
149
149
|
Float(value)
|
150
150
|
rescue
|
151
151
|
value
|
152
152
|
end
|
153
|
-
|
153
|
+
|
154
154
|
def start_time=(value)
|
155
155
|
self.fragment_value = "t=#{[value, end_time].join(',')}"
|
156
156
|
end
|
157
|
-
|
157
|
+
|
158
158
|
def end_time
|
159
159
|
value = fragment_value.nil? ? nil : fragment_value.object.value.scan(/^t=(.*)$/).flatten.first.split(/,/)[1]
|
160
160
|
Float(value)
|
161
161
|
rescue
|
162
162
|
value
|
163
163
|
end
|
164
|
-
|
164
|
+
|
165
165
|
def end_time=(value)
|
166
166
|
self.fragment_value = "t=#{[start_time, value].join(',')}"
|
167
167
|
end
|
168
|
-
|
168
|
+
|
169
169
|
def content
|
170
170
|
get_value(body_id, RDF::Vocab::CNT.chars)
|
171
171
|
end
|
172
|
-
|
172
|
+
|
173
173
|
def content=(value)
|
174
174
|
ensure_body!
|
175
175
|
set_value(body_id, RDF::Vocab::CNT.chars, value)
|
176
176
|
end
|
177
|
-
|
177
|
+
|
178
178
|
def annotated_by
|
179
179
|
get_value(annotation_id, RDF::Vocab::DC.creator) || get_value(annotation_id, RDF::Vocab::OA.annotatedBy)
|
180
180
|
end
|
181
|
-
|
181
|
+
|
182
182
|
def annotated_by=(value)
|
183
183
|
unless annotated_by.nil?
|
184
184
|
@graph.delete({ subject: RDF::URI(annotated_by) })
|
@@ -188,20 +188,20 @@ module ActiveAnnotations
|
|
188
188
|
set_value(annotation_id, RDF::Vocab::DC.creator, value)
|
189
189
|
set_value(value, RDF.type, RDF::Vocab::FOAF.Person)
|
190
190
|
end
|
191
|
-
|
191
|
+
|
192
192
|
def annotated_at
|
193
193
|
get_value(annotation_id, RDF::Vocab::DC.modified) || get_value(annotation_id, RDF::Vocab::OA.annotatedAt)
|
194
194
|
end
|
195
|
-
|
195
|
+
|
196
196
|
def annotated_at=(value)
|
197
197
|
set_value(annotation_id, RDF::Vocab::DC.modified, value)
|
198
198
|
end
|
199
|
-
|
199
|
+
|
200
200
|
def source
|
201
201
|
# TODO: Replace this with some way of retrieving the actual source
|
202
202
|
get_value(target_id, RDF::Vocab::OA.hasSource)
|
203
203
|
end
|
204
|
-
|
204
|
+
|
205
205
|
def source=(value)
|
206
206
|
unless target_id.nil?
|
207
207
|
statement = @graph.first(subject: target_id, predicate: RDF::Vocab::OA.hasSource)
|
@@ -216,11 +216,11 @@ module ActiveAnnotations
|
|
216
216
|
)
|
217
217
|
end
|
218
218
|
end
|
219
|
-
|
219
|
+
|
220
220
|
def label
|
221
221
|
get_value(annotation_id, RDF::RDFS.label)
|
222
222
|
end
|
223
|
-
|
223
|
+
|
224
224
|
def label=(value)
|
225
225
|
set_value(annotation_id, RDF::RDFS.label, value)
|
226
226
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_annotations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael B. Klein
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json-ld
|