Skip to content

Commit

Permalink
add convenience method getTerm
Browse files Browse the repository at this point in the history
also, add examples of resuming and get values from body
  • Loading branch information
elrayle committed Feb 18, 2015
1 parent ed07a4f commit c5d6676
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 1 deletion.
37 changes: 37 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,42 +122,79 @@ puts stb.dump :ttl
<http://example.org/term/engineering> a <http://www.w3.org/ns/oa#SemanticTag> .
```

*Resume annotation of known type.*
This is the more efficient approach and should be used if the type of the annotation is known.
```
a1 = LD4L::OpenAnnotationRDF::CommentAnnotation.resume(RDF::URI('http://localhost/c10'))
# => #<LD4L::OpenAnnotationRDF::CommentAnnotation:0x3fdd8267adc8(default)>
comment = a1.getComment
# => "This book is a good resource on archery technique."
a2 = LD4L::OpenAnnotationRDF::TagAnnotation.resume(RDF::URI('http://localhost/t10'))
# => #<LD4L::OpenAnnotationRDF::TagAnnotation:0x3fdd826073f0(default)>
tag = a2.getTag
# => "archery"
a3 = LD4L::OpenAnnotationRDF::SemanticTagAnnotation.resume(RDF::URI('http://localhost/st10'))
# => #<LD4L::OpenAnnotationRDF::SemanticTagAnnotation:0x3fdd8259c7a8(default)>
term = a2.getTerm
# => #<RDF::URI:0x3fdbb4f37300 URI:http://example.org/term/engineering>
```

*Resume annotation of unknown type.*
```
## Using RDF::URI
# Create the annotations first using previous examples.
a1 = LD4L::OpenAnnotationRDF::Annotation.resume(RDF::URI('http://localhost/c10'))
# => #<LD4L::OpenAnnotationRDF::CommentAnnotation:0x3fdd8267adc8(default)>
comment = a1.getComment
# => "This book is a good resource on archery technique."
a2 = LD4L::OpenAnnotationRDF::Annotation.resume(RDF::URI('http://localhost/t10'))
# => #<LD4L::OpenAnnotationRDF::TagAnnotation:0x3fdd826073f0(default)>
tag = a2.getTag
# => "archery"
a3 = LD4L::OpenAnnotationRDF::Annotation.resume(RDF::URI('http://localhost/st10'))
# => #<LD4L::OpenAnnotationRDF::SemanticTagAnnotation:0x3fdd8259c7a8(default)>
term = a2.getTerm
# => #<RDF::URI:0x3fdbb4f37300 URI:http://example.org/term/engineering>
## Using string URI
# Create the annotations first using previous examples.
a1 = LD4L::OpenAnnotationRDF::Annotation.resume('http://localhost/c10')
# => #<LD4L::OpenAnnotationRDF::CommentAnnotation:0x3fdd8267adc8(default)>
# => #<LD4L::OpenAnnotationRDF::CommentAnnotation:0x3fdd8267adc8(default)>
comment = a1.getComment
a2 = LD4L::OpenAnnotationRDF::Annotation.resume('http://localhost/t10')
# => #<LD4L::OpenAnnotationRDF::TagAnnotation:0x3fdd826073f0(default)>
tag = a2.getTag
# => "archery"
a3 = LD4L::OpenAnnotationRDF::Annotation.resume('http://localhost/st10')
# => #<LD4L::OpenAnnotationRDF::SemanticTagAnnotation:0x3fdd8259c7a8(default)>
term = a2.getTerm
# => #<RDF::URI:0x3fdbb4f37300 URI:http://example.org/term/engineering>
## Using localname expanded using configured base_uri
# Create the annotations first using previous examples.
a1 = LD4L::OpenAnnotationRDF::Annotation.resume('c10')
# => #<LD4L::OpenAnnotationRDF::CommentAnnotation:0x3fdd8267adc8(default)>
comment = a1.getComment
# => "This book is a good resource on archery technique."
a2 = LD4L::OpenAnnotationRDF::Annotation.resume('t10')
# => #<LD4L::OpenAnnotationRDF::TagAnnotation:0x3fdd826073f0(default)>
tag = a2.getTag
# => "archery"
a3 = LD4L::OpenAnnotationRDF::Annotation.resume('st10')
# => #<LD4L::OpenAnnotationRDF::SemanticTagAnnotation:0x3fdd8259c7a8(default)>
term = a2.getTerm
# => #<RDF::URI:0x3fdbb4f37300 URI:http://example.org/term/engineering>
```

### Configurations
Expand Down
9 changes: 9 additions & 0 deletions lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,15 @@ class SemanticTagAnnotation < LD4L::OpenAnnotationRDF::Annotation
# TODO: Should a semantic tag be destroyed when the last annotation referencing the term is destroyed?
# TODO: What if other triples have been attached beyond the type?

##
# Get the term URI of the semantic tag body.
#
# @return the term URI
def getTerm
# return existing body if term is unchanged
@body ? @body.rdf_subject : nil
end

##
# Set the hasBody property to the URI of the controlled vocabulary term that is the annotation and
# create the semantic tag body instance identifying the term as a semantic tag annotation.
Expand Down
2 changes: 1 addition & 1 deletion lib/ld4l/open_annotation_rdf/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module LD4L
module OpenAnnotationRDF
VERSION = "0.0.11"
VERSION = "0.0.12"
end
end

0 comments on commit c5d6676

Please sign in to comment.