From 192e6ec872bbc4f830c3513eb266707fe9200b3e Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Tue, 13 Jan 2015 09:13:36 -0500 Subject: [PATCH 1/2] add casting restrictions Add casting restrictions to... * motivatedBy * annotatedAt * content * format Update tests to changes references in the form motivatedBy.first.rdf_subject to motivatedBy.first --- lib/ld4l/open_annotation_rdf/annotation.rb | 9 ++++----- lib/ld4l/open_annotation_rdf/comment_body.rb | 4 ++-- lib/ld4l/open_annotation_rdf/tag_body.rb | 2 +- lib/ld4l/open_annotation_rdf/version.rb | 2 +- spec/ld4l/open_annotation_rdf/annotation_spec.rb | 16 ++++++++-------- .../comment_annotation_spec.rb | 10 +++++----- .../semantic_tag_annotation_spec.rb | 10 +++++----- .../open_annotation_rdf/tag_annotation_spec.rb | 10 +++++----- 8 files changed, 31 insertions(+), 32 deletions(-) diff --git a/lib/ld4l/open_annotation_rdf/annotation.rb b/lib/ld4l/open_annotation_rdf/annotation.rb index d76d7c5..9d3ee73 100644 --- a/lib/ld4l/open_annotation_rdf/annotation.rb +++ b/lib/ld4l/open_annotation_rdf/annotation.rb @@ -14,8 +14,8 @@ class << self; attr_reader :localname_prefix end property :hasTarget, :predicate => RDFVocabularies::OA.hasTarget # :type => URI property :hasBody, :predicate => RDFVocabularies::OA.hasBody property :annotatedBy, :predicate => RDFVocabularies::OA.annotatedBy, :class_name => LD4L::FoafRDF::Person - property :annotatedAt, :predicate => RDFVocabularies::OA.annotatedAt # :type => xsd:dateTime # the time Annotation was created - property :motivatedBy, :predicate => RDFVocabularies::OA.motivatedBy # comes from RDFVocabularies::OA ontology + property :annotatedAt, :predicate => RDFVocabularies::OA.annotatedAt, :cast => false # :type => xsd:dateTime # the time Annotation was created + property :motivatedBy, :predicate => RDFVocabularies::OA.motivatedBy, :cast => false # comes from RDFVocabularies::OA ontology def self.resume(*args) return nil unless args.kind_of?(Array) && args.size > 0 && args.first.kind_of?(RDF::URI) @@ -25,11 +25,10 @@ def self.resume(*args) # get motivatedBy m = a.get_values(:motivatedBy) - return a unless m.kind_of?(Array) && m.size > 0 && m.first.kind_of?(ActiveTriples::Resource) + return a unless m.kind_of?(Array) && m.size > 0 && m.first.kind_of?(RDF::Vocabulary::Term) # motivatedBy is set - m_uri = m.first.rdf_subject - + m_uri = m.first # currently only support commenting and tagging return LD4L::OpenAnnotationRDF::CommentAnnotation.new(rdf_subject) if m_uri == RDFVocabularies::OA.commenting return a unless m_uri == RDFVocabularies::OA.tagging diff --git a/lib/ld4l/open_annotation_rdf/comment_body.rb b/lib/ld4l/open_annotation_rdf/comment_body.rb index cd22d2c..fe2354e 100644 --- a/lib/ld4l/open_annotation_rdf/comment_body.rb +++ b/lib/ld4l/open_annotation_rdf/comment_body.rb @@ -9,8 +9,8 @@ class << self; attr_reader :localname_prefix end :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default - property :content, :predicate => RDFVocabularies::CNT.chars # :type => XSD.string - property :format, :predicate => RDF::DC.format # :type => XSD.string + property :content, :predicate => RDFVocabularies::CNT.chars, :cast => true # :type => XSD.string + property :format, :predicate => RDF::DC.format, :cast => true # :type => XSD.string def initialize(*args) super(*args) diff --git a/lib/ld4l/open_annotation_rdf/tag_body.rb b/lib/ld4l/open_annotation_rdf/tag_body.rb index 15fe880..860f86d 100644 --- a/lib/ld4l/open_annotation_rdf/tag_body.rb +++ b/lib/ld4l/open_annotation_rdf/tag_body.rb @@ -9,7 +9,7 @@ class << self; attr_reader :localname_prefix end :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default - property :tag, :predicate => RDFVocabularies::CNT.chars # :type => XSD.string + property :tag, :predicate => RDFVocabularies::CNT.chars, :cast => false # :type => XSD.string ## # Get a list of annotations using the tag value. diff --git a/lib/ld4l/open_annotation_rdf/version.rb b/lib/ld4l/open_annotation_rdf/version.rb index 0e4ad0d..0f10555 100644 --- a/lib/ld4l/open_annotation_rdf/version.rb +++ b/lib/ld4l/open_annotation_rdf/version.rb @@ -1,5 +1,5 @@ module LD4L module OpenAnnotationRDF - VERSION = "0.0.7" + VERSION = "0.0.8" end end diff --git a/spec/ld4l/open_annotation_rdf/annotation_spec.rb b/spec/ld4l/open_annotation_rdf/annotation_spec.rb index a499eaf..071462b 100644 --- a/spec/ld4l/open_annotation_rdf/annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/annotation_spec.rb @@ -151,13 +151,13 @@ it "should be settable" do subject.motivatedBy = RDFVocabularies::OA.describing - expect(subject.motivatedBy.first.rdf_subject).to eq RDFVocabularies::OA.describing + expect(subject.motivatedBy.first).to eq RDFVocabularies::OA.describing end it "should be changeable" do subject.motivatedBy = RDFVocabularies::OA.describing subject.motivatedBy = RDFVocabularies::OA.classifying - expect(subject.motivatedBy.first.rdf_subject).to eq RDFVocabularies::OA.classifying + expect(subject.motivatedBy.first).to eq RDFVocabularies::OA.classifying end end @@ -183,13 +183,13 @@ ca.persist! expect(ca).to be_persisted uri = ca.rdf_subject - + a = LD4L::OpenAnnotationRDF::Annotation.resume(uri) expect(a).to be_a_kind_of(LD4L::OpenAnnotationRDF::CommentAnnotation) expect(a.hasTarget.first.rdf_subject.to_s).to eq "http://example.org/bibref/br3" expect(a.annotatedBy.first).to eq a_person expect(a.annotatedAt.first).to eq a_time - expect(a.motivatedBy.first.rdf_subject).to eq RDFVocabularies::OA.commenting + expect(a.motivatedBy.first).to eq RDFVocabularies::OA.commenting b = a.getBody expect(b).to be_a_kind_of(LD4L::OpenAnnotationRDF::CommentBody) @@ -215,7 +215,7 @@ expect(a.hasTarget.first.rdf_subject.to_s).to eq "http://example.org/bibref/br3" expect(a.annotatedBy.first).to eq a_person expect(a.annotatedAt.first).to eq a_time - expect(a.motivatedBy.first.rdf_subject).to eq RDFVocabularies::OA.tagging + expect(a.motivatedBy.first).to eq RDFVocabularies::OA.tagging b = a.getBody expect(b).to be_a_kind_of(LD4L::OpenAnnotationRDF::TagBody) @@ -240,7 +240,7 @@ expect(a.hasTarget.first.rdf_subject.to_s).to eq "http://example.org/bibref/br3" expect(a.annotatedBy.first).to eq a_person expect(a.annotatedAt.first).to eq a_time - expect(a.motivatedBy.first.rdf_subject).to eq RDFVocabularies::OA.tagging + expect(a.motivatedBy.first).to eq RDFVocabularies::OA.tagging b = a.getBody expect(b).to be_a_kind_of(LD4L::OpenAnnotationRDF::SemanticTagBody) @@ -293,7 +293,7 @@ end it "should reset the motivatedBy" do - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s end it "should be persisted" do @@ -325,7 +325,7 @@ it "should delete from the repository" do subject.reload - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s subject.motivatedBy = [] expect(subject.motivatedBy).to eq [] subject.persist! diff --git a/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb b/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb index 9c9c2ad..1945fad 100644 --- a/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb @@ -154,18 +154,18 @@ describe 'motivatedBy' do it "should be OA.commenting if we haven't set it" do - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.commenting + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting end it "should be settable" do subject.motivatedBy = RDFVocabularies::OA.describing - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.describing + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.describing end it "should be changeable" do subject.motivatedBy = RDFVocabularies::OA.describing subject.motivatedBy = RDFVocabularies::OA.classifying - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.classifying + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.classifying end end @@ -220,7 +220,7 @@ end it "should reset the motivatedBy" do - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s end it "should be persisted" do @@ -252,7 +252,7 @@ it "should delete from the repository" do subject.reload - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s subject.motivatedBy = [] expect(subject.motivatedBy).to eq [] subject.persist! diff --git a/spec/ld4l/open_annotation_rdf/semantic_tag_annotation_spec.rb b/spec/ld4l/open_annotation_rdf/semantic_tag_annotation_spec.rb index 950b7b8..3717eea 100644 --- a/spec/ld4l/open_annotation_rdf/semantic_tag_annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/semantic_tag_annotation_spec.rb @@ -212,18 +212,18 @@ describe 'motivatedBy' do it "should be OA.tagging if we haven't set it" do - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.tagging + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.tagging end it "should be settable" do subject.motivatedBy = RDFVocabularies::OA.describing - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.describing + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.describing end it "should be changeable" do subject.motivatedBy = RDFVocabularies::OA.describing subject.motivatedBy = RDFVocabularies::OA.classifying - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.classifying + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.classifying end end @@ -278,7 +278,7 @@ end it "should reset the motivatedBy" do - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s end it "should be persisted" do @@ -310,7 +310,7 @@ it "should delete from the repository" do subject.reload - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s subject.motivatedBy = [] expect(subject.motivatedBy).to eq [] subject.persist! diff --git a/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb b/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb index 1fbb305..76b4df1 100644 --- a/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb @@ -264,18 +264,18 @@ describe 'motivatedBy' do it "should be OA.tagging if we haven't set it" do - expect(subject.motivatedBy.first.rdf_subject).to eq RDFVocabularies::OA.tagging + expect(subject.motivatedBy.first).to eq RDFVocabularies::OA.tagging end it "should be settable" do subject.motivatedBy = RDFVocabularies::OA.describing - expect(subject.motivatedBy.first.rdf_subject).to eq RDFVocabularies::OA.describing + expect(subject.motivatedBy.first).to eq RDFVocabularies::OA.describing end it "should be changeable" do subject.motivatedBy = RDFVocabularies::OA.describing subject.motivatedBy = RDFVocabularies::OA.classifying - expect(subject.motivatedBy.first.rdf_subject).to eq RDFVocabularies::OA.classifying + expect(subject.motivatedBy.first).to eq RDFVocabularies::OA.classifying end end @@ -330,7 +330,7 @@ end it "should reset the motivatedBy" do - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s end it "should be persisted" do @@ -362,7 +362,7 @@ it "should delete from the repository" do subject.reload - expect(subject.motivatedBy.first.rdf_subject.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s subject.motivatedBy = [] expect(subject.motivatedBy).to eq [] subject.persist! From a5ccca5c7aa389579570eb441ff9f81414b0cc71 Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Tue, 13 Jan 2015 12:23:57 -0500 Subject: [PATCH 2/2] Allow URI or string URI to be passed to Annotation.resume --- README.md | 37 +++++++++++++++++++ lib/ld4l/open_annotation_rdf/annotation.rb | 18 ++++----- .../open_annotation_rdf/annotation_spec.rb | 2 +- 3 files changed, 46 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0f2d3fb..29339ae 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,43 @@ puts stb.dump :ttl a . ``` +*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')) +# => # + +a2 = LD4L::OpenAnnotationRDF::Annotation.resume(RDF::URI('http://localhost/t10')) +# => # + +a3 = LD4L::OpenAnnotationRDF::Annotation.resume(RDF::URI('http://localhost/st10')) +# => # + + +## Using string URI +# Create the annotations first using previous examples. +a1 = LD4L::OpenAnnotationRDF::Annotation.resume('http://localhost/c10') +# => # + +a2 = LD4L::OpenAnnotationRDF::Annotation.resume('http://localhost/t10') +# => # + +a3 = LD4L::OpenAnnotationRDF::Annotation.resume('http://localhost/st10') +# => # + + +## Using localname expanded using configured base_uri +# Create the annotations first using previous examples. +a1 = LD4L::OpenAnnotationRDF::Annotation.resume('c10') +# => # + +a2 = LD4L::OpenAnnotationRDF::Annotation.resume('t10') +# => # + +a3 = LD4L::OpenAnnotationRDF::Annotation.resume('st10') +# => # +``` ### Configurations diff --git a/lib/ld4l/open_annotation_rdf/annotation.rb b/lib/ld4l/open_annotation_rdf/annotation.rb index 9d3ee73..9477b47 100644 --- a/lib/ld4l/open_annotation_rdf/annotation.rb +++ b/lib/ld4l/open_annotation_rdf/annotation.rb @@ -17,11 +17,9 @@ class << self; attr_reader :localname_prefix end property :annotatedAt, :predicate => RDFVocabularies::OA.annotatedAt, :cast => false # :type => xsd:dateTime # the time Annotation was created property :motivatedBy, :predicate => RDFVocabularies::OA.motivatedBy, :cast => false # comes from RDFVocabularies::OA ontology - def self.resume(*args) - return nil unless args.kind_of?(Array) && args.size > 0 && args.first.kind_of?(RDF::URI) - - rdf_subject = args.first - a = new(rdf_subject) + def self.resume(uri_or_str) + # Let ActiveTriples::Resource validate uri_or_str when creating new Annotation + a = new(uri_or_str) # get motivatedBy m = a.get_values(:motivatedBy) @@ -30,17 +28,17 @@ def self.resume(*args) # motivatedBy is set m_uri = m.first # currently only support commenting and tagging - return LD4L::OpenAnnotationRDF::CommentAnnotation.new(rdf_subject) if m_uri == RDFVocabularies::OA.commenting + return LD4L::OpenAnnotationRDF::CommentAnnotation.new(uri_or_str) if m_uri == RDFVocabularies::OA.commenting return a unless m_uri == RDFVocabularies::OA.tagging # Tagging can be TagAnnotation or SemanticTagAnnotation. Only way to tell is by checking type of body. - sta = LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new(rdf_subject) + sta = LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new(uri_or_str) stb = sta.getBody - return sta if stb.type.include?(RDFVocabularies::OA.SemanticTag) + return sta if stb.type.include?(RDFVocabularies::OA.SemanticTag) - ta = LD4L::OpenAnnotationRDF::TagAnnotation.new(rdf_subject) + ta = LD4L::OpenAnnotationRDF::TagAnnotation.new(uri_or_str) tb = ta.getBody - return ta if tb.type.include?(RDFVocabularies::OA.Tag) + return ta if tb.type.include?(RDFVocabularies::OA.Tag) # can't match to a known annotation type, so return as generic annotation return a diff --git a/spec/ld4l/open_annotation_rdf/annotation_spec.rb b/spec/ld4l/open_annotation_rdf/annotation_spec.rb index 071462b..e8c50fc 100644 --- a/spec/ld4l/open_annotation_rdf/annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/annotation_spec.rb @@ -183,7 +183,7 @@ ca.persist! expect(ca).to be_persisted uri = ca.rdf_subject - + a = LD4L::OpenAnnotationRDF::Annotation.resume(uri) expect(a).to be_a_kind_of(LD4L::OpenAnnotationRDF::CommentAnnotation) expect(a.hasTarget.first.rdf_subject.to_s).to eq "http://example.org/bibref/br3"