Skip to content

Commit a5ccca5

Browse files
committed
Allow URI or string URI to be passed to Annotation.resume
1 parent 192e6ec commit a5ccca5

File tree

3 files changed

+46
-11
lines changed

3 files changed

+46
-11
lines changed

README.md

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,43 @@ puts stb.dump :ttl
122122
<http://example.org/term/engineering> a <http://www.w3.org/ns/oa#SemanticTag> .
123123
```
124124

125+
*Resume annotation of unknown type.*
126+
```
127+
## Using RDF::URI
128+
# Create the annotations first using previous examples.
129+
a1 = LD4L::OpenAnnotationRDF::Annotation.resume(RDF::URI('http://localhost/c10'))
130+
# => #<LD4L::OpenAnnotationRDF::CommentAnnotation:0x3fdd8267adc8(default)>
131+
132+
a2 = LD4L::OpenAnnotationRDF::Annotation.resume(RDF::URI('http://localhost/t10'))
133+
# => #<LD4L::OpenAnnotationRDF::TagAnnotation:0x3fdd826073f0(default)>
134+
135+
a3 = LD4L::OpenAnnotationRDF::Annotation.resume(RDF::URI('http://localhost/st10'))
136+
# => #<LD4L::OpenAnnotationRDF::SemanticTagAnnotation:0x3fdd8259c7a8(default)>
137+
138+
139+
## Using string URI
140+
# Create the annotations first using previous examples.
141+
a1 = LD4L::OpenAnnotationRDF::Annotation.resume('http://localhost/c10')
142+
# => #<LD4L::OpenAnnotationRDF::CommentAnnotation:0x3fdd8267adc8(default)>
143+
144+
a2 = LD4L::OpenAnnotationRDF::Annotation.resume('http://localhost/t10')
145+
# => #<LD4L::OpenAnnotationRDF::TagAnnotation:0x3fdd826073f0(default)>
146+
147+
a3 = LD4L::OpenAnnotationRDF::Annotation.resume('http://localhost/st10')
148+
# => #<LD4L::OpenAnnotationRDF::SemanticTagAnnotation:0x3fdd8259c7a8(default)>
149+
150+
151+
## Using localname expanded using configured base_uri
152+
# Create the annotations first using previous examples.
153+
a1 = LD4L::OpenAnnotationRDF::Annotation.resume('c10')
154+
# => #<LD4L::OpenAnnotationRDF::CommentAnnotation:0x3fdd8267adc8(default)>
155+
156+
a2 = LD4L::OpenAnnotationRDF::Annotation.resume('t10')
157+
# => #<LD4L::OpenAnnotationRDF::TagAnnotation:0x3fdd826073f0(default)>
158+
159+
a3 = LD4L::OpenAnnotationRDF::Annotation.resume('st10')
160+
# => #<LD4L::OpenAnnotationRDF::SemanticTagAnnotation:0x3fdd8259c7a8(default)>
161+
```
125162

126163
### Configurations
127164

lib/ld4l/open_annotation_rdf/annotation.rb

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@ class << self; attr_reader :localname_prefix end
1717
property :annotatedAt, :predicate => RDFVocabularies::OA.annotatedAt, :cast => false # :type => xsd:dateTime # the time Annotation was created
1818
property :motivatedBy, :predicate => RDFVocabularies::OA.motivatedBy, :cast => false # comes from RDFVocabularies::OA ontology
1919

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)
20+
def self.resume(uri_or_str)
21+
# Let ActiveTriples::Resource validate uri_or_str when creating new Annotation
22+
a = new(uri_or_str)
2523

2624
# get motivatedBy
2725
m = a.get_values(:motivatedBy)
@@ -30,17 +28,17 @@ def self.resume(*args)
3028
# motivatedBy is set
3129
m_uri = m.first
3230
# currently only support commenting and tagging
33-
return LD4L::OpenAnnotationRDF::CommentAnnotation.new(rdf_subject) if m_uri == RDFVocabularies::OA.commenting
31+
return LD4L::OpenAnnotationRDF::CommentAnnotation.new(uri_or_str) if m_uri == RDFVocabularies::OA.commenting
3432
return a unless m_uri == RDFVocabularies::OA.tagging
3533

3634
# Tagging can be TagAnnotation or SemanticTagAnnotation. Only way to tell is by checking type of body.
37-
sta = LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new(rdf_subject)
35+
sta = LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new(uri_or_str)
3836
stb = sta.getBody
39-
return sta if stb.type.include?(RDFVocabularies::OA.SemanticTag)
37+
return sta if stb.type.include?(RDFVocabularies::OA.SemanticTag)
4038

41-
ta = LD4L::OpenAnnotationRDF::TagAnnotation.new(rdf_subject)
39+
ta = LD4L::OpenAnnotationRDF::TagAnnotation.new(uri_or_str)
4240
tb = ta.getBody
43-
return ta if tb.type.include?(RDFVocabularies::OA.Tag)
41+
return ta if tb.type.include?(RDFVocabularies::OA.Tag)
4442

4543
# can't match to a known annotation type, so return as generic annotation
4644
return a

spec/ld4l/open_annotation_rdf/annotation_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@
183183
ca.persist!
184184
expect(ca).to be_persisted
185185
uri = ca.rdf_subject
186-
186+
187187
a = LD4L::OpenAnnotationRDF::Annotation.resume(uri)
188188
expect(a).to be_a_kind_of(LD4L::OpenAnnotationRDF::CommentAnnotation)
189189
expect(a.hasTarget.first.rdf_subject.to_s).to eq "http://example.org/bibref/br3"

0 commit comments

Comments
 (0)