ld4l-open_annotation_rdf 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (33) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +23 -0
  3. data/.ruby-gemset +1 -0
  4. data/.ruby-version +1 -0
  5. data/Gemfile +11 -0
  6. data/LICENSE.txt +14 -0
  7. data/README.md +231 -0
  8. data/Rakefile +2 -0
  9. data/ld4l-open_annotation_rdf.gemspec +46 -0
  10. data/lib/ld4l/open_annotation_rdf.rb +66 -0
  11. data/lib/ld4l/open_annotation_rdf/annotation.rb +82 -0
  12. data/lib/ld4l/open_annotation_rdf/comment_annotation.rb +47 -0
  13. data/lib/ld4l/open_annotation_rdf/comment_body.rb +24 -0
  14. data/lib/ld4l/open_annotation_rdf/configuration.rb +127 -0
  15. data/lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb +66 -0
  16. data/lib/ld4l/open_annotation_rdf/semantic_tag_body.rb +70 -0
  17. data/lib/ld4l/open_annotation_rdf/tag_annotation.rb +98 -0
  18. data/lib/ld4l/open_annotation_rdf/tag_body.rb +83 -0
  19. data/lib/ld4l/open_annotation_rdf/version.rb +5 -0
  20. data/lib/ld4l/open_annotation_rdf/vocab/cnt.rb +6 -0
  21. data/lib/ld4l/open_annotation_rdf/vocab/dctypes.rb +5 -0
  22. data/lib/ld4l/open_annotation_rdf/vocab/oa.rb +23 -0
  23. data/spec/ld4l/open_annotation_rdf/annotation_spec.rb +603 -0
  24. data/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb +559 -0
  25. data/spec/ld4l/open_annotation_rdf/comment_body_spec.rb +371 -0
  26. data/spec/ld4l/open_annotation_rdf/configuration_spec.rb +194 -0
  27. data/spec/ld4l/open_annotation_rdf/semantic_tag_annotation_spec.rb +619 -0
  28. data/spec/ld4l/open_annotation_rdf/semantic_tag_body_spec.rb +412 -0
  29. data/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb +672 -0
  30. data/spec/ld4l/open_annotation_rdf/tag_body_spec.rb +430 -0
  31. data/spec/ld4l/open_annotation_rdf_spec.rb +57 -0
  32. data/spec/spec_helper.rb +21 -0
  33. metadata +201 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3300bb3c1ed7f05ad15bcc48d3db4027138b986c
4
+ data.tar.gz: 6d82cae01c405f875e77033a1884633ae1aa9a6b
5
+ SHA512:
6
+ metadata.gz: b7e45edc10a479132f70c450330643cfc2bda517961cd6a24d3e49df2324624db5e8d7968a1b21afed4a1c9d1b74be6b41b8aec2e8795722989aae47880a3eca
7
+ data.tar.gz: c0d61fc82b296dd164bbd31fd81184212fc9be9493b65158949ac390e80b816a9ca530b928a05e569751c11de5bd61125836ea5050443d8bda4a99a35bdcacd1
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ *.bundle
19
+ *.so
20
+ *.o
21
+ *.a
22
+ mkmf.log
23
+ .idea
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ ld4l-oa-gem_no-rails
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.2
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ # GETTING FROM GEMFILE UNTIL ActiveTriples master CODE IS RELEASED (>0.4.0), THEN MOVE THIS BACK TO *.gemspec FILE
6
+ # Use active-triples for handling of triple persistence
7
+ gem 'active-triples', :git => 'git@github.com:ActiveTriples/ActiveTriples.git', :branch => 'master'
8
+
9
+ # GETTING FROM GEMFILE UNTIL LD4L::FoafRDF GEM IS RELEASED, THEN MOVE TO *.gemspec FILE
10
+ # Use LD4L::FoafRDF Gem
11
+ gem 'ld4l-foaf_rdf', :git => 'git@github.com:ld4l/foaf_rdf.git', :branch => 'master'
data/LICENSE.txt ADDED
@@ -0,0 +1,14 @@
1
+ Copyright (c) 2014 Cornell University
2
+
3
+ ##########################################################################
4
+ # Licensed under the Apache License, Version 2.0 (the "License");
5
+ # you may not use this file except in compliance with the License.
6
+ # You may obtain a copy of the License at
7
+ #
8
+ # http://www.apache.org/licenses/LICENSE-2.0
9
+ #
10
+ # Unless required by applicable law or agreed to in writing, software
11
+ # distributed under the License is distributed on an "AS IS" BASIS,
12
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ # See the License for the specific language governing permissions and
14
+ # limitations under the License.
data/README.md ADDED
@@ -0,0 +1,231 @@
1
+ #LD4L::OpenAnnotationRDF
2
+
3
+ LD4L Open Annotation RDF provides tools for modeling annotations based on the Open Annotation ontology and persisting to a triplestore.
4
+
5
+
6
+ ## Installation
7
+
8
+ Temporary get the gem from github until the gem is released publicly.
9
+
10
+ Add this line to your application's Gemfile:
11
+
12
+ <!-- gem 'ld4l-open_annotation_rdf' -->
13
+ gem 'ld4l-open_annotation_rdf', '~> 0.0.3', :git => 'git@github.com:ld4l/open_annotation_rdf.git'
14
+
15
+
16
+ And then execute:
17
+
18
+ $ bundle install
19
+
20
+ <!--
21
+ Or install it yourself as:
22
+
23
+ $ gem install ld4l-open_annotation_rdf
24
+ -->
25
+
26
+
27
+ ## Usage
28
+
29
+ **Caveat:** This gem is part of the LD4L Project and is being used in that context. There is no guarantee that the
30
+ code will work in a usable way outside of its use in LD4L Use Cases.
31
+
32
+ ### Examples
33
+
34
+ *Setup required for all examples.*
35
+ ```
36
+ require 'ld4l/open_annotation_rdf'
37
+
38
+ # create an in-memory repository
39
+ ActiveTriples::Repositories.add_repository :default, RDF::Repository.new
40
+
41
+ p = LD4L::FoafRDF::Person.new('p4')
42
+ ```
43
+
44
+ *Example creating a comment annotation.*
45
+ ```
46
+ ca = LD4L::OpenAnnotationRDF::CommentAnnotation.new('c10')
47
+ ca.hasTarget = RDF::URI("http://example.org/bibref/br3")
48
+ cb = ca.setComment("This book is a good resource on archery technique.")
49
+ ca.annotatedBy = p
50
+ ca.setAnnotatedAtNow
51
+ ca.persist!
52
+
53
+ puts ca.dump :ttl
54
+ puts cb.dump :ttl
55
+ ```
56
+
57
+ *Example triples created for a comment annotation.*
58
+ ```
59
+ <http://localhost/c10> a <http://www.w3.org/ns/oa#Annotation>;
60
+ <http://www.w3.org/ns/oa#annotatedAt> "2014-11-26T15:53:49Z";
61
+ <http://www.w3.org/ns/oa#annotatedBy> <http://localhost/p4>;
62
+ <http://www.w3.org/ns/oa#hasBody> <http://localhost/9c8c8126-2d31-48be-81d8-3cd4748a3351>;
63
+ <http://www.w3.org/ns/oa#hasTarget> <http://example.org/bibref/br3>;
64
+ <http://www.w3.org/ns/oa#motivatedBy> <http://www.w3.org/ns/oa#commenting> .
65
+
66
+ <http://localhost/9c8c8126-2d31-48be-81d8-3cd4748a3351> a <http://www.w3.org/2011/content#ContentAsText>,
67
+ <http://purl.org/dc/dcmitype/Text>;
68
+ <http://purl.org/dc/terms/format> "text/plain";
69
+ <http://www.w3.org/2011/content#chars> "This book is a good resource on archery technique." .
70
+ ```
71
+
72
+ *Example creating a tag annotation.*
73
+ ```
74
+ ta = LD4L::OpenAnnotationRDF::TagAnnotation.new('t10')
75
+ ta.hasTarget = RDF::URI("http://example.org/bibref/br3")
76
+ tb = ta.setTag("archery")
77
+ ta.annotatedBy = p
78
+ ta.setAnnotatedAtNow
79
+ ta.persist!
80
+
81
+ puts ta.dump :ttl
82
+ puts tb.dump :ttl
83
+ ```
84
+
85
+ *Example triples created for a tag annotation.*
86
+ ```
87
+ <http://localhost/t10> a <http://www.w3.org/ns/oa#Annotation>;
88
+ <http://www.w3.org/ns/oa#annotatedAt> "2014-11-26T15:56:32Z";
89
+ <http://www.w3.org/ns/oa#annotatedBy> <http://localhost/p4>;
90
+ <http://www.w3.org/ns/oa#hasBody> <http://localhost/88db4b38-8b99-4939-b376-1392019aa30c>;
91
+ <http://www.w3.org/ns/oa#hasTarget> <http://example.org/bibref/br3>;
92
+ <http://www.w3.org/ns/oa#motivatedBy> <http://www.w3.org/ns/oa#tagging> .
93
+
94
+ <http://localhost/88db4b38-8b99-4939-b376-1392019aa30c> a <http://www.w3.org/ns/oa#Tag>,
95
+ <http://www.w3.org/2011/content#ContentAsText>;
96
+ <http://www.w3.org/2011/content#chars> "archery" .
97
+ ```
98
+
99
+ *Example creating a semantic tag annotation.*
100
+ ```
101
+ sta = LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new('st10')
102
+ sta.hasTarget = RDF::URI("http://example.org/bibref/br3")
103
+ stb = sta.setTerm(RDF::URI("http://example.org/term/engineering"))
104
+ sta.annotatedBy = p
105
+ sta.setAnnotatedAtNow
106
+ sta.persist!
107
+
108
+ puts sta.dump :ttl
109
+ puts stb.dump :ttl
110
+ ```
111
+
112
+ *Example triples created for a semantic tag annotation.*
113
+ ```
114
+ <http://localhost/st10> a <http://www.w3.org/ns/oa#Annotation>;
115
+ <http://www.w3.org/ns/oa#annotatedAt> "2014-11-26T15:59:01Z";
116
+ <http://www.w3.org/ns/oa#annotatedBy> <http://localhost/p4>;
117
+ <http://www.w3.org/ns/oa#hasBody> <http://example.org/term/engineering>;
118
+ <http://www.w3.org/ns/oa#hasTarget> <http://example.org/bibref/br3>;
119
+ <http://www.w3.org/ns/oa#motivatedBy> <http://www.w3.org/ns/oa#tagging> .
120
+
121
+ <http://example.org/term/engineering> a <http://www.w3.org/ns/oa#SemanticTag> .
122
+ ```
123
+
124
+
125
+ ### Configurations
126
+
127
+ * base_uri - base URI used when new resources are created (default="http://localhost/")
128
+ * localname_minter - minter function to use for creating unique local names (default=nil which uses default minter in active_triples-local_name gem)
129
+ * unique_tags - if true, re-use existing TagBodies only creating a new TagBody if one doesn't exist with the tag value being set; otherwise, if false, create new TagBody when tag value is updated (default=true)
130
+
131
+ *Setup for all examples.*
132
+
133
+ * Restart your interactive session (e.g. irb, pry).
134
+ * Use the Setup for all examples in main Examples section above.
135
+
136
+ #### Example usage using **configured base_uri** and default localname_minter.
137
+ ```
138
+ LD4L::OpenAnnotationRDF.reset
139
+ LD4L::OpenAnnotationRDF.configure do |config|
140
+ config.base_uri = "http://example.org/"
141
+ end
142
+
143
+ ca = LD4L::OpenAnnotationRDF::CommentAnnotation.new(ActiveTriples::LocalName::Minter.generate_local_name(
144
+ LD4L::OpenAnnotationRDF::CommentAnnotation, 10, {:prefix=>'ca'} ))
145
+
146
+ puts ca.dump :ttl
147
+
148
+ ca = LD4L::OpenAnnotationRDF::CommentAnnotation.new(ActiveTriples::LocalName::Minter.generate_local_name(
149
+ LD4L::OpenAnnotationRDF::CommentAnnotation, 10, {:prefix=>'ca'},
150
+ &LD4L::OpenAnnotationRDF.configuration.localname_minter ))
151
+
152
+ puts ca.dump :ttl
153
+ ```
154
+ NOTE: If base_uri is not used, you need to restart your interactive environment (e.g. irb, pry). Once the
155
+ CommentAnnotation class is instantiated the first time, the base_uri for the class is set. If you ran
156
+ through the main Examples, the base_uri was set to the default base_uri.
157
+
158
+
159
+ **Example triples created for a person with configured base_uri and default minter.**
160
+ ```
161
+ <http://example.org/ca45c9c85b-25af-4c52-96a4-cf0d8b70a768> a <http://www.w3.org/ns/oa#Annotation>;
162
+ <http://www.w3.org/ns/oa#motivatedBy> <http://www.w3.org/ns/oa#commenting> .
163
+ ```
164
+
165
+ #### Example usage using **configured base_uri** and **configured localname_minter**.
166
+ ```
167
+ LD4L::OpenAnnotationRDF.configure do |config|
168
+ config.base_uri = "http://example.org/"
169
+ config.localname_minter = lambda { |prefix=""| prefix+'_configured_'+SecureRandom.uuid }
170
+ end
171
+
172
+ ca = LD4L::OpenAnnotationRDF::CommentAnnotation.new(ActiveTriples::LocalName::Minter.generate_local_name(
173
+ LD4L::OpenAnnotationRDF::CommentAnnotation, 10, 'ca',
174
+ &LD4L::OpenAnnotationRDF.configuration.localname_minter ))
175
+
176
+ puts ca.dump :ttl
177
+ ```
178
+ NOTE: If base_uri is not used, you need to restart your interactive environment (e.g. irb, pry). Once the
179
+ CommentAnnotation class is instantiated the first time, the base_uri for the class is set. If you ran
180
+ through the main Examples, the base_uri was set to the default base_uri.
181
+
182
+
183
+ **Example triples created for a person with configured base_uri and configured minter.**
184
+ ```
185
+ <http://example.org/ca_configured_6498ba05-8b21-4e8c-b9d4-a6d5d2180966> a <http://www.w3.org/ns/oa#Annotation>;
186
+ <http://www.w3.org/ns/oa#motivatedBy> <http://www.w3.org/ns/oa#commenting> .
187
+ ```
188
+
189
+ #### Example configuring unique_tags
190
+ ```
191
+ # Any of these are valid and will change the configuration of unique_tags
192
+ LD4L::OpenAnnotationRDF.configuration.unique_tags = true
193
+ LD4L::OpenAnnotationRDF.configuration.unique_tags = false
194
+ LD4L::OpenAnnotationRDF.configuration.reset_unique_tags
195
+ ```
196
+
197
+ ### Models
198
+
199
+ The LD4L::OpenAnnotationRDF gem provides model definitions using the
200
+ [ActiveTriples](https://github.com/ActiveTriples/ActiveTriples) framework extension of
201
+ [ruby-rdf/rdf](https://github.com/ruby-rdf/rdf). The following models are provided:
202
+
203
+ 1. LD4L::OpenAnnotationRDF::Annotation - Implements an open annotation.
204
+ 1. LD4L::OpenAnnotationRDF::CommentAnnotation - Extends Annotation to implement a comment annotation of free-form text.
205
+ 1. LD4L::OpenAnnotationRDF::CommentBody - Implements a body holding free-form text.
206
+ 1. LD4L::OpenAnnotationRDF::TagAnnotation - Extends Annotation to implement a tag annotation of user specified short phrase tag.
207
+ 1. LD4L::OpenAnnotationRDF::TagBody - Implements a body holding the short phrase tag.
208
+ 1. LD4L::OpenAnnotationRDF::SemanticTagAnnotation - Extends Annotation to implement a semantic tag annotation with values limited to a controlled vocabulary.
209
+ 1. LD4L::OpenAnnotationRDF::SemanticTagBody - Implements a body with rdf_subject equal to the URI of the controlled vocabulary term
210
+ .
211
+
212
+ ### Ontologies
213
+
214
+ The listed ontologies are used to represent the primary metadata about the annotations.
215
+ Other ontologies may also be used that aren't listed.
216
+
217
+ * [OA](http://www.openannotation.org/spec/core/)
218
+ * [FOAF](http://xmlns.com/foaf/spec/)
219
+ * [RDF](http://www.w3.org/TR/rdf-syntax-grammar/)
220
+ * [Dublin Core (DC)](http://dublincore.org/documents/dces/)
221
+ * [Dublin Core Terms (DCTERMS)](http://dublincore.org/documents/dcmi-terms/)
222
+
223
+
224
+
225
+ ## Contributing
226
+
227
+ 1. Fork it ( https://github.com/[my-github-username]/ld4l-open_annotation_rdf/fork )
228
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
229
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
230
+ 4. Push to the branch (`git push origin my-new-feature`)
231
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ld4l/open_annotation_rdf/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ld4l-open_annotation_rdf"
8
+ spec.version = LD4L::OpenAnnotationRDF::VERSION
9
+ spec.authors = ["E. Lynette Rayle"]
10
+ spec.email = ["elr37@cornell.edu"]
11
+ spec.platform = Gem::Platform::RUBY
12
+ spec.summary = %q{OpenAnnotation RDF models.}
13
+ spec.description = %q{LD4L Open Annotation RDF provides tools for modeling a annotations based on the Open Annotation ontology and persisting to a triplestore.}
14
+ spec.homepage = "https://github.com/ld4l/open_annotation_rdf"
15
+ spec.license = "APACHE2"
16
+ spec.required_ruby_version = '>= 2.1.2'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0")
19
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
20
+ # spec.test_files = `git ls-files -- {spec}/*`.split("\n") # FROM ActiveTriples gemspec file
21
+ # spec.require_paths = ["lib"] # NOT IN ActiveTriples gemspec file
22
+
23
+ # spec.add_dependency('ffi', '~> 1.9.5')
24
+ spec.add_dependency('rdf', '~> 1.1')
25
+
26
+ # GETTING FROM GEMFILE UNTIL ActiveTriples master CODE IS RELEASED (>0.4.0), THEN MOVE THIS BACK TO *.gemspec FILE
27
+ # spec.add_dependency('active-triples', '~> 0.4')
28
+
29
+ spec.add_dependency('active_triples-local_name', '~> 0.1')
30
+
31
+ # GETTING FROM GEMFILE UNTIL ld4l-foaf_rdf GEM IS RELEASED
32
+ # spec.add_dependency('ld4l-foaf_rdf', '~> 0.0')
33
+
34
+ spec.add_development_dependency('pry')
35
+ spec.add_development_dependency('pry-byebug')
36
+ spec.add_development_dependency('rdoc')
37
+ spec.add_development_dependency('rspec')
38
+ spec.add_development_dependency('guard-rspec')
39
+ spec.add_development_dependency('webmock')
40
+
41
+ spec.extra_rdoc_files = [
42
+ "LICENSE.txt",
43
+ "README.md"
44
+ ]
45
+ end
46
+
@@ -0,0 +1,66 @@
1
+ require 'rdf'
2
+ require 'active_triples'
3
+ require 'active_triples/local_name'
4
+ require 'linkeddata'
5
+ require 'ld4l/foaf_rdf'
6
+ require 'ld4l/open_annotation_rdf/version'
7
+ require 'ld4l/open_annotation_rdf/vocab/oa'
8
+ require 'ld4l/open_annotation_rdf/vocab/cnt'
9
+ require 'ld4l/open_annotation_rdf/vocab/dctypes'
10
+
11
+
12
+ module LD4L
13
+ module OpenAnnotationRDF
14
+
15
+ # Methods for configuring the GEM
16
+ class << self
17
+ attr_accessor :configuration
18
+ end
19
+
20
+ def self.configuration
21
+ @configuration ||= Configuration.new
22
+ end
23
+
24
+ def self.reset
25
+ @configuration = Configuration.new
26
+ end
27
+
28
+ def self.configure
29
+ yield(configuration)
30
+ end
31
+
32
+
33
+ # RDF vocabularies
34
+ autoload :OA, 'ld4l/open_annotation_rdf/vocab/oa'
35
+ autoload :CNT, 'ld4l/open_annotation_rdf/vocab/cnt'
36
+ autoload :DCTYPES, 'ld4l/open_annotation_rdf/vocab/dctypes'
37
+
38
+
39
+ # autoload classes
40
+ autoload :Configuration, 'ld4l/open_annotation_rdf/configuration'
41
+ autoload :Annotation, 'ld4l/open_annotation_rdf/annotation'
42
+ autoload :CommentAnnotation, 'ld4l/open_annotation_rdf/comment_annotation'
43
+ autoload :CommentBody, 'ld4l/open_annotation_rdf/comment_body'
44
+ autoload :TagAnnotation, 'ld4l/open_annotation_rdf/tag_annotation'
45
+ autoload :TagBody, 'ld4l/open_annotation_rdf/tag_body'
46
+ autoload :SemanticTagAnnotation, 'ld4l/open_annotation_rdf/semantic_tag_annotation'
47
+ autoload :SemanticTagBody, 'ld4l/open_annotation_rdf/semantic_tag_body'
48
+
49
+ def self.class_from_string(class_name, container_class=Kernel)
50
+ container_class = container_class.name if container_class.is_a? Module
51
+ container_parts = container_class.split('::')
52
+ (container_parts + class_name.split('::')).flatten.inject(Kernel) do |mod, class_name|
53
+ if mod == Kernel
54
+ Object.const_get(class_name)
55
+ elsif mod.const_defined? class_name.to_sym
56
+ mod.const_get(class_name)
57
+ else
58
+ container_parts.pop
59
+ class_from_string(class_name, container_parts.join('::'))
60
+ end
61
+ end
62
+ end
63
+
64
+ end
65
+ end
66
+
@@ -0,0 +1,82 @@
1
+ module LD4L
2
+ module OpenAnnotationRDF
3
+ class Annotation < ActiveTriples::Resource
4
+
5
+ class << self; attr_reader :localname_prefix end
6
+ @localname_prefix="oa"
7
+
8
+ @body = nil
9
+
10
+ configure :type => RDFVocabularies::OA.Annotation,
11
+ :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri,
12
+ :repository => :default
13
+
14
+ property :hasTarget, :predicate => RDFVocabularies::OA.hasTarget # :type => URI
15
+ property :hasBody, :predicate => RDFVocabularies::OA.hasBody
16
+ property :annotatedBy, :predicate => RDFVocabularies::OA.annotatedBy, :class_name => LD4L::FoafRDF::Person
17
+ property :annotatedAt, :predicate => RDFVocabularies::OA.annotatedAt # :type => xsd:dateTime # the time Annotation was created
18
+ property :motivatedBy, :predicate => RDFVocabularies::OA.motivatedBy # comes from RDFVocabularies::OA ontology
19
+
20
+ def self.resume(*args)
21
+ return nil unless args.kind_of?(Array) && args.size > 0 && args.first.kind_of?(RDF::URI)
22
+
23
+ rdf_subject = args.first
24
+ a = new(rdf_subject)
25
+
26
+ # get motivatedBy
27
+ m = a.get_values(:motivatedBy)
28
+ return a unless m.kind_of?(Array) && m.size > 0 && m.first.kind_of?(ActiveTriples::Resource)
29
+
30
+ # motivatedBy is set
31
+ m_uri = m.first.rdf_subject
32
+
33
+ # currently only support commenting and tagging
34
+ return LD4L::OpenAnnotationRDF::CommentAnnotation.new(rdf_subject) if m_uri == RDFVocabularies::OA.commenting
35
+ return a unless m_uri == RDFVocabularies::OA.tagging
36
+
37
+ # Tagging can be TagAnnotation or SemanticTagAnnotation. Only way to tell is by checking type of body.
38
+ sta = LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new(rdf_subject)
39
+ stb = sta.getBody
40
+ return sta if stb.type.include?(RDFVocabularies::OA.SemanticTag)
41
+
42
+ ta = LD4L::OpenAnnotationRDF::TagAnnotation.new(rdf_subject)
43
+ tb = ta.getBody
44
+ return ta if tb.type.include?(RDFVocabularies::OA.Tag)
45
+
46
+ # can't match to a known annotation type, so return as generic annotation
47
+ return a
48
+ end
49
+
50
+ ##
51
+ # Get the <tt>ActiveTriples::Resource</tt> instance holding the body of this annotation.
52
+ #
53
+ # @param [String] tag value
54
+ #
55
+ # @return instance of an annotation body if one is set; otherwise, nil
56
+ def getBody
57
+ @body
58
+ end
59
+
60
+ ##
61
+ # Set annotatedAt property to now.
62
+ #
63
+ # @return the value of annotatedAt property
64
+ def setAnnotatedAtNow
65
+ set_value(:annotatedAt, Time.now.utc.iso8601(0))
66
+ end
67
+
68
+ ##
69
+ # Save all annotation and annotation body triples to the triple store.
70
+ #
71
+ # @return true if annotation successfully persisted; otherwise, false
72
+ #
73
+ # @todo What to return if annotation persists fine, but body fails to persist?
74
+ def persist!
75
+ persisted = super # persist annotation
76
+ body_persisted = persisted && @body ? @body.persist! : false # persist body
77
+ persisted
78
+ end
79
+ end
80
+ end
81
+ end
82
+