From 2af84fdd3074a825f24ae415b75e85d0b03a4f5f Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Sat, 30 Jul 2016 06:48:43 -0400 Subject: [PATCH 1/2] Update to ActiveTriples 0.10.0 and RDF 2.0.2 --- .travis.yml | 8 +- Gemfile | 3 + README.md | 5 + ld4l-open_annotation_rdf.gemspec | 7 +- lib/ld4l/open_annotation_rdf.rb | 26 ---- lib/ld4l/open_annotation_rdf/annotation.rb | 24 ++-- .../open_annotation_rdf/comment_annotation.rb | 6 +- lib/ld4l/open_annotation_rdf/comment_body.rb | 8 +- .../semantic_tag_annotation.rb | 6 +- .../open_annotation_rdf/semantic_tag_body.rb | 6 +- .../open_annotation_rdf/tag_annotation.rb | 6 +- lib/ld4l/open_annotation_rdf/tag_body.rb | 14 +- lib/ld4l/open_annotation_rdf/version.rb | 2 +- lib/ld4l/open_annotation_rdf/vocab/cnt.rb | 6 - lib/ld4l/open_annotation_rdf/vocab/dctypes.rb | 5 - lib/ld4l/open_annotation_rdf/vocab/oa.rb | 23 --- .../open_annotation_rdf/annotation_spec.rb | 136 +++++++++--------- .../comment_annotation_spec.rb | 82 +++++------ .../open_annotation_rdf/comment_body_spec.rb | 73 +++++----- .../open_annotation_rdf/configuration_spec.rb | 10 +- .../semantic_tag_annotation_spec.rb | 82 +++++------ .../semantic_tag_body_spec.rb | 35 +++-- .../tag_annotation_spec.rb | 82 +++++------ .../ld4l/open_annotation_rdf/tag_body_spec.rb | 43 +++--- spec/ld4l/open_annotation_rdf_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 26 files changed, 326 insertions(+), 376 deletions(-) delete mode 100644 lib/ld4l/open_annotation_rdf/vocab/cnt.rb delete mode 100644 lib/ld4l/open_annotation_rdf/vocab/dctypes.rb delete mode 100644 lib/ld4l/open_annotation_rdf/vocab/oa.rb diff --git a/.travis.yml b/.travis.yml index e5284f3..59caf09 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,13 +4,13 @@ script: "bundle exec rspec spec" sudo: false cache: bundler rvm: - - 2.0 - 2.1 + - 2.2.2 - 2.2.4 - - 2.3.0 + - 2.3.1 - jruby-9.0.4.0 - - rbx-2 + - rbx matrix: allow_failures: - rvm: jruby-9.0.4.0 - - rvm: rbx-2 + - rvm: rbx diff --git a/Gemfile b/Gemfile index fa75df1..338f1e7 100644 --- a/Gemfile +++ b/Gemfile @@ -1,3 +1,6 @@ source 'https://rubygems.org' gemspec + +gem 'activesupport', '< 5.0.0' if RUBY_VERSION =~ /2\.1\..*/ +gem 'pry-byebug' unless ENV["CI"] diff --git a/README.md b/README.md index 116e25f..52d2599 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,11 @@ Or install it yourself as: $ gem install ld4l-open_annotation_rdf +## Primary Dependencies + +* [ActiveTriples 0.10.0](https://github.com/ActiveTriples/ActiveTriples/tree/v0.10.0) +* [RDF 2.0.2](https://github.com/ruby-rdf/rdf/tree/2.0.2) + ## Usage **Caveat:** This gem is part of the LD4L Project and is being used in that context. There is no guarantee that the diff --git a/ld4l-open_annotation_rdf.gemspec b/ld4l-open_annotation_rdf.gemspec index 095855d..e7c799b 100644 --- a/ld4l-open_annotation_rdf.gemspec +++ b/ld4l-open_annotation_rdf.gemspec @@ -13,22 +13,19 @@ Gem::Specification.new do |spec| spec.description = %q{LD4L Open Annotation RDF provides tools for modeling a annotations based on the Open Annotation ontology and persisting to a triplestore.} spec.homepage = "https://github.com/ld4l/open_annotation_rdf" spec.license = "APACHE2" - spec.required_ruby_version = '>= 1.9.3' + spec.required_ruby_version = '>= 2.2.2' spec.files = `git ls-files -z`.split("\x0") spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) - spec.add_dependency('rdf', '= 1.99.0') + spec.add_dependency('rdf') spec.add_dependency('active-triples') spec.add_dependency('active_triples-local_name') spec.add_dependency('ld4l-foaf_rdf') - spec.add_development_dependency('pry') - spec.add_development_dependency('pry-byebug') spec.add_development_dependency('rdoc') spec.add_development_dependency('rspec') spec.add_development_dependency('coveralls') - spec.add_development_dependency('guard-rspec') spec.add_development_dependency('webmock') spec.extra_rdoc_files = [ diff --git a/lib/ld4l/open_annotation_rdf.rb b/lib/ld4l/open_annotation_rdf.rb index 078f7a6..124758e 100644 --- a/lib/ld4l/open_annotation_rdf.rb +++ b/lib/ld4l/open_annotation_rdf.rb @@ -4,9 +4,6 @@ require 'linkeddata' require 'ld4l/foaf_rdf' require 'ld4l/open_annotation_rdf/version' -require 'ld4l/open_annotation_rdf/vocab/oa' -require 'ld4l/open_annotation_rdf/vocab/cnt' -require 'ld4l/open_annotation_rdf/vocab/dctypes' module LD4L @@ -29,13 +26,6 @@ def self.configure yield(configuration) end - - # RDF vocabularies - autoload :OA, 'ld4l/open_annotation_rdf/vocab/oa' - autoload :CNT, 'ld4l/open_annotation_rdf/vocab/cnt' - autoload :DCTYPES, 'ld4l/open_annotation_rdf/vocab/dctypes' - - # autoload classes autoload :Configuration, 'ld4l/open_annotation_rdf/configuration' autoload :Annotation, 'ld4l/open_annotation_rdf/annotation' @@ -45,22 +35,6 @@ def self.configure autoload :TagBody, 'ld4l/open_annotation_rdf/tag_body' autoload :SemanticTagAnnotation, 'ld4l/open_annotation_rdf/semantic_tag_annotation' autoload :SemanticTagBody, 'ld4l/open_annotation_rdf/semantic_tag_body' - - def self.class_from_string(class_name, container_class=Kernel) - container_class = container_class.name if container_class.is_a? Module - container_parts = container_class.split('::') - (container_parts + class_name.split('::')).flatten.inject(Kernel) do |mod, class_name| - if mod == Kernel - Object.const_get(class_name) - elsif mod.const_defined? class_name.to_sym - mod.const_get(class_name) - else - container_parts.pop - class_from_string(class_name, container_parts.join('::')) - end - end - end - end end diff --git a/lib/ld4l/open_annotation_rdf/annotation.rb b/lib/ld4l/open_annotation_rdf/annotation.rb index 5d91102..de0ff22 100644 --- a/lib/ld4l/open_annotation_rdf/annotation.rb +++ b/lib/ld4l/open_annotation_rdf/annotation.rb @@ -7,15 +7,15 @@ class << self; attr_reader :localname_prefix end @body = nil - configure :type => RDFVocabularies::OA.Annotation, + configure :type => RDF::Vocab::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default - 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, :cast => false # :type => xsd:dateTime # the time Annotation was created - property :motivatedBy, :predicate => RDFVocabularies::OA.motivatedBy, :cast => false # comes from RDFVocabularies::OA ontology + property :hasTarget, :predicate => RDF::Vocab::OA.hasTarget # :type => URI + property :hasBody, :predicate => RDF::Vocab::OA.hasBody + property :annotatedBy, :predicate => RDF::Vocab::OA.annotatedBy, :class_name => LD4L::FoafRDF::Person + property :annotatedAt, :predicate => RDF::Vocab::OA.annotatedAt, :cast => false # :type => xsd:dateTime # the time Annotation was created + property :motivatedBy, :predicate => RDF::Vocab::OA.motivatedBy, :cast => false # comes from RDF::Vocab::OA ontology def self.resume(uri_or_str) # Let ActiveTriples::Resource validate uri_or_str when creating new Annotation @@ -32,17 +32,17 @@ def self.resume(uri_or_str) # motivatedBy is set m_uri = m.first # currently only support commenting and tagging - return LD4L::OpenAnnotationRDF::CommentAnnotation.new(uri_or_str) if m_uri == RDFVocabularies::OA.commenting - return a unless m_uri == RDFVocabularies::OA.tagging + return LD4L::OpenAnnotationRDF::CommentAnnotation.new(uri_or_str) if m_uri == RDF::Vocab::OA.commenting + return a unless m_uri == RDF::Vocab::OA.tagging # Tagging can be TagAnnotation or SemanticTagAnnotation. Only way to tell is by checking type of body. sta = LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new(uri_or_str) stb = sta.getBody - return sta unless stb.type.include?(RDFVocabularies::OA.Tag) || !stb.type.include?(RDFVocabularies::OA.SemanticTag) + return sta unless stb.type.include?(RDF::Vocab::OA.Tag) || !stb.type.include?(RDF::Vocab::OA.SemanticTag) 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?(RDF::Vocab::OA.Tag) # can't match to a known annotation type, so return as generic annotation return a @@ -98,8 +98,8 @@ def self::find_by_target(target_uri) repo = ActiveTriples::Repositories.repositories[repository] query = RDF::Query.new({ :annotation => { - RDF.type => RDFVocabularies::OA.Annotation, - RDFVocabularies::OA.hasTarget => target_uri, + RDF.type => RDF::Vocab::OA.Annotation, + RDF::Vocab::OA.hasTarget => target_uri, } }) annotations = [] diff --git a/lib/ld4l/open_annotation_rdf/comment_annotation.rb b/lib/ld4l/open_annotation_rdf/comment_annotation.rb index 23ab15f..ff04b08 100644 --- a/lib/ld4l/open_annotation_rdf/comment_annotation.rb +++ b/lib/ld4l/open_annotation_rdf/comment_annotation.rb @@ -4,11 +4,11 @@ class CommentAnnotation < LD4L::OpenAnnotationRDF::Annotation @localname_prefix="ca" - configure :type => RDFVocabularies::OA.Annotation, + configure :type => RDF::Vocab::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default - property :hasBody, :predicate => RDFVocabularies::OA.hasBody, :class_name => LD4L::OpenAnnotationRDF::CommentBody + property :hasBody, :predicate => RDF::Vocab::OA.hasBody, :class_name => LD4L::OpenAnnotationRDF::CommentBody ## @@ -54,7 +54,7 @@ def initialize(*args) # set motivatedBy m = get_values(:motivatedBy) m = m.to_a if Object::ActiveTriples.const_defined?("Relation") && m.kind_of?(ActiveTriples::Relation) - set_value(:motivatedBy, RDFVocabularies::OA.commenting) unless m.kind_of?(Array) && m.size > 0 + set_value(:motivatedBy, RDF::Vocab::OA.commenting) unless m.kind_of?(Array) && m.size > 0 # resume CommentBody if it exists comment_uri = get_values(:hasBody).first diff --git a/lib/ld4l/open_annotation_rdf/comment_body.rb b/lib/ld4l/open_annotation_rdf/comment_body.rb index 65ac125..9877ec8 100644 --- a/lib/ld4l/open_annotation_rdf/comment_body.rb +++ b/lib/ld4l/open_annotation_rdf/comment_body.rb @@ -5,18 +5,18 @@ class CommentBody < ActiveTriples::Resource class << self; attr_reader :localname_prefix end @localname_prefix="cb" - configure :type => RDFVocabularies::CNT.ContentAsText, + configure :type => RDF::Vocab::CNT.ContentAsText, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default - property :content, :predicate => RDFVocabularies::CNT.chars, :cast => false # :type => XSD.string - property :format, :predicate => RDF::DC.format, :cast => false # :type => XSD.string + property :content, :predicate => RDF::Vocab::CNT.chars, :cast => false # :type => XSD.string + property :format, :predicate => RDF::Vocab::DC.format, :cast => false # :type => XSD.string def initialize(*args) super(*args) t = get_values(:type) - t << RDFVocabularies::DCTYPES.Text + t << RDF::Vocab::DCMIType.Text set_value(:type,t) end end diff --git a/lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb b/lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb index 6ab7ab0..8d56748 100644 --- a/lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb +++ b/lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb @@ -4,11 +4,11 @@ class SemanticTagAnnotation < LD4L::OpenAnnotationRDF::Annotation @localname_prefix = "sta" - configure :type => RDFVocabularies::OA.Annotation, + configure :type => RDF::Vocab::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default - property :hasBody, :predicate => RDFVocabularies::OA.hasBody, :class_name => LD4L::OpenAnnotationRDF::SemanticTagBody + property :hasBody, :predicate => RDF::Vocab::OA.hasBody, :class_name => LD4L::OpenAnnotationRDF::SemanticTagBody # USAGE: Use setTerm to set the hasBody property to be the URI of the controlled vocabulary term that @@ -60,7 +60,7 @@ def initialize(*args) # set motivatedBy m = get_values(:motivatedBy) m = m.to_a if Object::ActiveTriples.const_defined?("Relation") && m.kind_of?(ActiveTriples::Relation) - set_value(:motivatedBy, RDFVocabularies::OA.tagging) unless m.kind_of?(Array) && m.size > 0 + set_value(:motivatedBy, RDF::Vocab::OA.tagging) unless m.kind_of?(Array) && m.size > 0 # resume SemanticTagBody if it exists term_uri = get_values(:hasBody).first diff --git a/lib/ld4l/open_annotation_rdf/semantic_tag_body.rb b/lib/ld4l/open_annotation_rdf/semantic_tag_body.rb index 44236ce..eadfa7b 100644 --- a/lib/ld4l/open_annotation_rdf/semantic_tag_body.rb +++ b/lib/ld4l/open_annotation_rdf/semantic_tag_body.rb @@ -8,7 +8,7 @@ class << self; attr_reader :localname_prefix end # USAGE: When creating a semantic tag body, use the URI of the controlled vocabulary term as the RDF Subject URI # for an instance of this class. - configure :type => RDFVocabularies::OA.SemanticTag, + configure :type => RDF::Vocab::OA.SemanticTag, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default @@ -30,8 +30,8 @@ def self::annotations_using( term_uri ) repo = ActiveTriples::Repositories.repositories[repository] query = RDF::Query.new({ :annotation => { - RDF.type => RDFVocabularies::OA.Annotation, - RDFVocabularies::OA.hasBody => term_uri, + RDF.type => RDF::Vocab::OA.Annotation, + RDF::Vocab::OA.hasBody => term_uri, } }) annotations = [] diff --git a/lib/ld4l/open_annotation_rdf/tag_annotation.rb b/lib/ld4l/open_annotation_rdf/tag_annotation.rb index 60b8c1a..9d79383 100644 --- a/lib/ld4l/open_annotation_rdf/tag_annotation.rb +++ b/lib/ld4l/open_annotation_rdf/tag_annotation.rb @@ -4,11 +4,11 @@ class TagAnnotation < LD4L::OpenAnnotationRDF::Annotation @localname_prefix="ta" - configure :type => RDFVocabularies::OA.Annotation, + configure :type => RDF::Vocab::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default - property :hasBody, :predicate => RDFVocabularies::OA.hasBody, :class_name => LD4L::OpenAnnotationRDF::TagBody + property :hasBody, :predicate => RDF::Vocab::OA.hasBody, :class_name => LD4L::OpenAnnotationRDF::TagBody # TODO: Should a tag be destroyed when the last annotation referencing the tag is destroyed? @@ -103,7 +103,7 @@ def initialize(*args) # set motivatedBy m = get_values(:motivatedBy) m = m.to_a if Object::ActiveTriples.const_defined?("Relation") && m.kind_of?(ActiveTriples::Relation) - set_value(:motivatedBy, RDFVocabularies::OA.tagging) unless m.kind_of?(Array) && m.size > 0 + set_value(:motivatedBy, RDF::Vocab::OA.tagging) unless m.kind_of?(Array) && m.size > 0 # resume TagBody if it exists tag_uri = get_values(:hasBody).first diff --git a/lib/ld4l/open_annotation_rdf/tag_body.rb b/lib/ld4l/open_annotation_rdf/tag_body.rb index 0e708af..1360620 100644 --- a/lib/ld4l/open_annotation_rdf/tag_body.rb +++ b/lib/ld4l/open_annotation_rdf/tag_body.rb @@ -5,11 +5,11 @@ class TagBody < ActiveTriples::Resource class << self; attr_reader :localname_prefix end @localname_prefix="tb" - configure :type => RDFVocabularies::OA.Tag, + configure :type => RDF::Vocab::OA.Tag, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default - property :tag, :predicate => RDFVocabularies::CNT.chars, :cast => false # :type => XSD.string + property :tag, :predicate => RDF::Vocab::CNT.chars, :cast => false # :type => XSD.string ## # Get a list of annotations using the tag value. @@ -31,8 +31,8 @@ def self::annotations_using( tag_value ) repo = ActiveTriples::Repositories.repositories[repository] query = RDF::Query.new({ :annotation => { - RDF.type => RDFVocabularies::OA.Annotation, - RDFVocabularies::OA.hasBody => tag_uri, + RDF.type => RDF::Vocab::OA.Annotation, + RDF::Vocab::OA.hasBody => tag_uri, } }) results = query.execute(repo) @@ -57,8 +57,8 @@ def self::fetch_by_tag_value( tag_value, parent_annotation=nil ) repo = ActiveTriples::Repositories.repositories[repository] query = RDF::Query.new({ :tagbody => { - RDF.type => RDFVocabularies::OA.Tag, - RDFVocabularies::CNT.chars => tag_value, + RDF.type => RDF::Vocab::OA.Tag, + RDF::Vocab::CNT.chars => tag_value, } }) @@ -76,7 +76,7 @@ def initialize(*args) super(*args) t = get_values(:type) - t << RDFVocabularies::CNT.ContentAsText + t << RDF::Vocab::CNT.ContentAsText set_value(:type,t) end end diff --git a/lib/ld4l/open_annotation_rdf/version.rb b/lib/ld4l/open_annotation_rdf/version.rb index f9c0624..9312f71 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.1.0" + VERSION = "0.2.0" end end diff --git a/lib/ld4l/open_annotation_rdf/vocab/cnt.rb b/lib/ld4l/open_annotation_rdf/vocab/cnt.rb deleted file mode 100644 index 418d1fc..0000000 --- a/lib/ld4l/open_annotation_rdf/vocab/cnt.rb +++ /dev/null @@ -1,6 +0,0 @@ -module RDFVocabularies - class CNT < RDF::Vocabulary("http://www.w3.org/2011/content#") - property :chars - property :ContentAsText - end -end diff --git a/lib/ld4l/open_annotation_rdf/vocab/dctypes.rb b/lib/ld4l/open_annotation_rdf/vocab/dctypes.rb deleted file mode 100644 index a9ef2f5..0000000 --- a/lib/ld4l/open_annotation_rdf/vocab/dctypes.rb +++ /dev/null @@ -1,5 +0,0 @@ -module RDFVocabularies - class DCTYPES < RDF::Vocabulary("http://purl.org/dc/dcmitype/") - term :Text - end -end diff --git a/lib/ld4l/open_annotation_rdf/vocab/oa.rb b/lib/ld4l/open_annotation_rdf/vocab/oa.rb deleted file mode 100644 index d66c48f..0000000 --- a/lib/ld4l/open_annotation_rdf/vocab/oa.rb +++ /dev/null @@ -1,23 +0,0 @@ -module RDFVocabularies - class OA < RDF::Vocabulary("http://www.w3.org/ns/oa#") - - # Class definitions - term :Annotation - term :Motivation - term :Tag - term :SemanticTag - - # Property definitions - property :hasBody - property :hasTarget - property :annotatedBy # relationship identifying the agent responsible for creating the Annotation - property :annotatedAt # the time at which the Annotation was created - property :motivatedBy # relationship for Motivation - - # Instances of :Motivation class used as the object of predicate :motivatedBy - property :commenting # an instance for OA:Motivation (ex. ) - property :tagging # an instance for OA:Motivation (ex. ) - property :describing # an instance for OA:Motivation (ex. ) - property :classifying # an instance for OA:Motivation (ex. ) - end -end diff --git a/spec/ld4l/open_annotation_rdf/annotation_spec.rb b/spec/ld4l/open_annotation_rdf/annotation_spec.rb index d1b080f..5d5b80c 100644 --- a/spec/ld4l/open_annotation_rdf/annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/annotation_spec.rb @@ -21,9 +21,9 @@ describe 'when changing subject' do before do - subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land') subject.set_subject! RDF::URI('http://example.org/moomin') end @@ -33,15 +33,15 @@ end it 'should update graph subjects' do - expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')))).to be true + expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')))).to be true end it 'should update graph objects' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject))).to be true end it 'should leave other uris alone' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land'))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land'))).to be true end end @@ -62,8 +62,8 @@ # ------------------------------------------------- describe 'type' do - it "should be an RDFVocabularies::OA.Annotation" do - expect(subject.type.first.value).to eq RDFVocabularies::OA.Annotation.value + it "should be an RDF::Vocab::OA.Annotation" do + expect(subject.type.first.value).to eq RDF::Vocab::OA.Annotation.value end end @@ -150,14 +150,14 @@ end it "should be settable" do - subject.motivatedBy = RDFVocabularies::OA.describing - expect(subject.motivatedBy.first).to eq RDFVocabularies::OA.describing + subject.motivatedBy = RDF::Vocab::OA.describing + expect(subject.motivatedBy.first).to eq RDF::Vocab::OA.describing end it "should be changeable" do - subject.motivatedBy = RDFVocabularies::OA.describing - subject.motivatedBy = RDFVocabularies::OA.classifying - expect(subject.motivatedBy.first).to eq RDFVocabularies::OA.classifying + subject.motivatedBy = RDF::Vocab::OA.describing + subject.motivatedBy = RDF::Vocab::OA.classifying + expect(subject.motivatedBy.first).to eq RDF::Vocab::OA.classifying end end @@ -190,12 +190,12 @@ 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).to eq RDFVocabularies::OA.commenting + expect(a.motivatedBy.first).to eq RDF::Vocab::OA.commenting b = a.getBody expect(b).to be_a_kind_of(LD4L::OpenAnnotationRDF::CommentBody) - expect(b.type).to include RDFVocabularies::DCTYPES.Text - expect(b.type).to include RDFVocabularies::CNT.ContentAsText + expect(b.type).to include RDF::Vocab::DCMIType.Text + expect(b.type).to include RDF::Vocab::CNT.ContentAsText expect(b.content).to eq ["This is a comment."] expect(b.format.first).to eq "text/plain" end @@ -216,12 +216,12 @@ 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).to eq RDFVocabularies::OA.tagging + expect(a.motivatedBy.first).to eq RDF::Vocab::OA.tagging b = a.getBody expect(b).to be_a_kind_of(LD4L::OpenAnnotationRDF::TagBody) - expect(b.type).to include RDFVocabularies::OA.Tag - expect(b.type).to include RDFVocabularies::CNT.ContentAsText + expect(b.type).to include RDF::Vocab::OA.Tag + expect(b.type).to include RDF::Vocab::CNT.ContentAsText expect(b.tag).to eq ["good"] end @@ -241,11 +241,11 @@ 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).to eq RDFVocabularies::OA.tagging + expect(a.motivatedBy.first).to eq RDF::Vocab::OA.tagging b = a.getBody expect(b).to be_a_kind_of(LD4L::OpenAnnotationRDF::SemanticTagBody) - expect(b.type).to include RDFVocabularies::OA.SemanticTag + expect(b.type).to include RDF::Vocab::OA.SemanticTag expect(b.rdf_subject.to_s).to eq('http://example.org/term/3') end end @@ -274,12 +274,12 @@ 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).to eq RDFVocabularies::OA.commenting + expect(a.motivatedBy.first).to eq RDF::Vocab::OA.commenting b = a.getBody expect(b).to be_a_kind_of(LD4L::OpenAnnotationRDF::CommentBody) - expect(b.type).to include RDFVocabularies::DCTYPES.Text - expect(b.type).to include RDFVocabularies::CNT.ContentAsText + expect(b.type).to include RDF::Vocab::DCMIType.Text + expect(b.type).to include RDF::Vocab::CNT.ContentAsText expect(b.content).to eq ["BLANK NODE COMMENT"] expect(b.format.first).to eq "text/plain" end @@ -306,12 +306,12 @@ 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).to eq RDFVocabularies::OA.tagging + expect(a.motivatedBy.first).to eq RDF::Vocab::OA.tagging b = a.getBody expect(b).to be_a_kind_of(LD4L::OpenAnnotationRDF::TagBody) - expect(b.type).to include RDFVocabularies::OA.Tag - expect(b.type).to include RDFVocabularies::CNT.ContentAsText + expect(b.type).to include RDF::Vocab::OA.Tag + expect(b.type).to include RDF::Vocab::CNT.ContentAsText expect(b.tag).to eq ["BLANK_NODE_TAG"] end @@ -337,11 +337,11 @@ 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).to eq RDFVocabularies::OA.tagging + expect(a.motivatedBy.first).to eq RDF::Vocab::OA.tagging b = a.getBody expect(b).to be_a_kind_of(LD4L::OpenAnnotationRDF::SemanticTagBody) - expect(b.type).to include RDFVocabularies::OA.SemanticTag + expect(b.type).to include RDF::Vocab::OA.SemanticTag expect(b.rdf_subject.to_s).to eq('http://example.org/term/3') end end @@ -371,16 +371,16 @@ it "populates LD4L::OpenAnnotationRDF::CommentAnnotation properly" do expect(@comment_anno.rdf_subject.to_s).to eq @anno_url expect(@comment_anno).to be_a LD4L::OpenAnnotationRDF::CommentAnnotation - expect(@comment_anno.type).to include(RDFVocabularies::OA.Annotation) - expect(@comment_anno.motivatedBy).to include(RDFVocabularies::OA.commenting) + expect(@comment_anno.type).to include(RDF::Vocab::OA.Annotation) + expect(@comment_anno.motivatedBy).to include(RDF::Vocab::OA.commenting) expect(@comment_anno.hasTarget.first.rdf_subject).to eq RDF::URI.new("http://searchworks.stanford.edu/view/666") end it "populates Comment bodies properly" do body = @comment_anno.hasBody.first expect(body).to be_a LD4L::OpenAnnotationRDF::CommentBody expect(body.content.first).to eq @comment_value - expect(body.type).to include(RDFVocabularies::CNT.ContentAsText) - expect(body.type).to include(RDFVocabularies::DCTYPES.Text) + expect(body.type).to include(RDF::Vocab::CNT.ContentAsText) + expect(body.type).to include(RDF::Vocab::DCMIType.Text) end end @@ -408,17 +408,17 @@ it "populates LD4L::OpenAnnotationRDF::TagAnnotation properly" do expect(@tag_anno.rdf_subject.to_s).to eq @anno_url expect(@tag_anno).to be_a LD4L::OpenAnnotationRDF::TagAnnotation - expect(@tag_anno.type).to include(RDFVocabularies::OA.Annotation) - expect(@tag_anno.motivatedBy).to include(RDFVocabularies::OA.tagging) + expect(@tag_anno.type).to include(RDF::Vocab::OA.Annotation) + expect(@tag_anno.motivatedBy).to include(RDF::Vocab::OA.tagging) expect(@tag_anno.hasTarget.first.rdf_subject).to eq RDF::URI.new("http://searchworks.stanford.edu/view/666") end it "populates Tag bodies properly" do body = @tag_anno.hasBody.first expect(body).to be_a LD4L::OpenAnnotationRDF::TagBody expect(body.tag.first).to eq @tag_value - expect(body.type).to include(RDFVocabularies::OA.Tag) - expect(body.type).to include(RDFVocabularies::CNT.ContentAsText) - expect(body.type).to include(RDFVocabularies::DCTYPES.Text) + expect(body.type).to include(RDF::Vocab::OA.Tag) + expect(body.type).to include(RDF::Vocab::CNT.ContentAsText) + expect(body.type).to include(RDF::Vocab::DCMIType.Text) end end @@ -440,15 +440,15 @@ it "populates LD4L::OpenAnnotationRDF::TagAnnotation properly" do expect(@semantic_tag_anno.rdf_subject.to_s).to eq @anno_url expect(@semantic_tag_anno).to be_a LD4L::OpenAnnotationRDF::SemanticTagAnnotation - expect(@semantic_tag_anno.type).to include(RDFVocabularies::OA.Annotation) - expect(@semantic_tag_anno.motivatedBy).to include(RDFVocabularies::OA.tagging) + expect(@semantic_tag_anno.type).to include(RDF::Vocab::OA.Annotation) + expect(@semantic_tag_anno.motivatedBy).to include(RDF::Vocab::OA.tagging) expect(@semantic_tag_anno.hasTarget.first.rdf_subject).to eq RDF::URI.new("http://searchworks.stanford.edu/view/666") end it "populates Tag bodies properly" do body = @semantic_tag_anno.hasBody.first expect(body.rdf_subject.to_s).to eq @term_url expect(body).to be_a LD4L::OpenAnnotationRDF::SemanticTagBody - expect(body.type).to include(RDFVocabularies::OA.SemanticTag) + expect(body.type).to include(RDF::Vocab::OA.SemanticTag) end end end @@ -476,7 +476,7 @@ context "when it is saved" do before do - subject.motivatedBy = RDFVocabularies::OA.commenting + subject.motivatedBy = RDF::Vocab::OA.commenting subject.persist! end @@ -486,7 +486,7 @@ context "and then modified" do before do - subject.motivatedBy = RDFVocabularies::OA.tagging + subject.motivatedBy = RDF::Vocab::OA.tagging end it "should return true" do @@ -499,7 +499,7 @@ end it "should reset the motivatedBy" do - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.commenting.to_s end it "should be persisted" do @@ -521,7 +521,7 @@ # Create inmemory repository @repo = RDF::Repository.new ActiveTriples::Repositories.repositories[:default] = @repo - subject.motivatedBy = RDFVocabularies::OA.commenting + subject.motivatedBy = RDF::Vocab::OA.commenting result end @@ -535,7 +535,7 @@ it "should delete from the repository" do subject.reload - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.commenting.to_s subject.motivatedBy = [] expect(subject.motivatedBy).to eq [] subject.persist! @@ -549,7 +549,7 @@ describe '#destroy!' do before do - subject << RDF::Statement(RDF::DC.LicenseDocument, RDF::DC.title, 'LICENSE') + subject << RDF::Statement(RDF::Vocab::DC.LicenseDocument, RDF::Vocab::DC.title, 'LICENSE') end subject { LD4L::OpenAnnotationRDF::Annotation.new('123') } @@ -615,11 +615,11 @@ context 'with unmodeled data' do before do - subject << RDF::Statement(subject.rdf_subject, RDF::DC.contributor, 'Tove Jansson') - subject << RDF::Statement(subject.rdf_subject, RDF::DC.relation, RDF::URI('http://example.org/moomi')) + subject << RDF::Statement(subject.rdf_subject, RDF::Vocab::DC.contributor, 'Tove Jansson') + subject << RDF::Statement(subject.rdf_subject, RDF::Vocab::DC.relation, RDF::URI('http://example.org/moomi')) node = RDF::Node.new - subject << RDF::Statement(RDF::URI('http://example.org/moomi'), RDF::DC.relation, node) - subject << RDF::Statement(node, RDF::DC.title, 'bnode') + subject << RDF::Statement(RDF::URI('http://example.org/moomi'), RDF::Vocab::DC.relation, node) + subject << RDF::Statement(node, RDF::Vocab::DC.title, 'bnode') end after do @@ -628,21 +628,21 @@ end it 'should include data with URIs as attribute names' do - expect(subject.attributes[RDF::DC.contributor.to_s]).to eq ['Tove Jansson'] + expect(subject.attributes[RDF::Vocab::DC.contributor.to_s]).to eq ['Tove Jansson'] end it 'should return generic Resources' do - expect(subject.attributes[RDF::DC.relation.to_s].first).to be_a ActiveTriples::Resource + expect(subject.attributes[RDF::Vocab::DC.relation.to_s].first).to be_a ActiveTriples::Resource end it 'should build deep data for Resources' do - expect(subject.attributes[RDF::DC.relation.to_s].first.get_values(RDF::DC.relation). - first.get_values(RDF::DC.title)).to eq ['bnode'] + expect(subject.attributes[RDF::Vocab::DC.relation.to_s].first.get_values(RDF::Vocab::DC.relation). + first.get_values(RDF::Vocab::DC.title)).to eq ['bnode'] end it 'should include deep data in serializable_hash' do - expect(subject.serializable_hash[RDF::DC.relation.to_s].first.get_values(RDF::DC.relation). - first.get_values(RDF::DC.title)).to eq ['bnode'] + expect(subject.serializable_hash[RDF::Vocab::DC.relation.to_s].first.get_values(RDF::Vocab::DC.relation). + first.get_values(RDF::Vocab::DC.title)).to eq ['bnode'] end end @@ -719,13 +719,13 @@ describe 'editing the graph' do it 'should write properties when statements are added' do - subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::OA.motivatedBy, 'commenting') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::OA.motivatedBy, 'commenting') expect(subject.motivatedBy).to include 'commenting' end it 'should delete properties when statements are removed' do - subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::OA.motivatedBy, 'commenting') - subject.delete RDF::Statement.new(subject.rdf_subject, RDFVocabularies::OA.motivatedBy, 'commenting') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::OA.motivatedBy, 'commenting') + subject.delete RDF::Statement.new(subject.rdf_subject, RDF::Vocab::OA.motivatedBy, 'commenting') expect(subject.motivatedBy).to eq [] end end @@ -734,18 +734,18 @@ before do class DummyPerson < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Person') - property :foafname, :predicate => RDF::FOAF.name - property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument' - property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson + property :foafname, :predicate => RDF::Vocab::FOAF.name + property :publications, :predicate => RDF::Vocab::FOAF.publications, :class_name => 'DummyDocument' + property :knows, :predicate => RDF::Vocab::FOAF.knows, :class_name => DummyPerson end class DummyDocument < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Document') - property :title, :predicate => RDF::DC.title - property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson' + property :title, :predicate => RDF::Vocab::DC.title + property :creator, :predicate => RDF::Vocab::DC.creator, :class_name => 'DummyPerson' end - LD4L::OpenAnnotationRDF::Annotation.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument + LD4L::OpenAnnotationRDF::Annotation.property :item, :predicate => RDF::Vocab::DC.relation, :class_name => DummyDocument end subject { LD4L::OpenAnnotationRDF::Annotation.new } @@ -800,8 +800,10 @@ class DummyDocument < ActiveTriples::Resource document1.creator = [person1, person2] document2.creator = person1 person1.knows = person2 + person2.knows = person1 subject.item = [document1] - expect(subject.item.first.creator.first.knows.first.foafname).to eq ['Bob'] + expect(subject.item.first.creator.first.knows.first.foafname) + .to satisfy { |names| ['Alice', 'Bob'].include? names.first } end end end diff --git a/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb b/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb index 1ca11cb..169e76d 100644 --- a/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb @@ -21,22 +21,22 @@ describe 'when changing subject' do before do - subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land') subject.set_subject! RDF::URI('http://example.org/moomin') end it 'should update graph subjects' do - expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')))).to be true + expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')))).to be true end it 'should update graph objects' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject))).to be true end it 'should leave other uris alone' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land'))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land'))).to be true end end @@ -57,8 +57,8 @@ # ------------------------------------------------- describe 'type' do - it "should be an RDFVocabularies::OA.Annotation" do - expect(subject.type.first.value).to eq RDFVocabularies::OA.Annotation.value + it "should be an RDF::Vocab::OA.Annotation" do + expect(subject.type.first.value).to eq RDF::Vocab::OA.Annotation.value end end @@ -172,18 +172,18 @@ describe 'motivatedBy' do it "should be OA.commenting if we haven't set it" do - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.commenting end it "should be settable" do - subject.motivatedBy = RDFVocabularies::OA.describing - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.describing + subject.motivatedBy = RDF::Vocab::OA.describing + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.describing end it "should be changeable" do - subject.motivatedBy = RDFVocabularies::OA.describing - subject.motivatedBy = RDFVocabularies::OA.classifying - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.classifying + subject.motivatedBy = RDF::Vocab::OA.describing + subject.motivatedBy = RDF::Vocab::OA.classifying + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.classifying end end @@ -215,7 +215,7 @@ context "when it is saved" do before do - subject.motivatedBy = RDFVocabularies::OA.commenting + subject.motivatedBy = RDF::Vocab::OA.commenting subject.persist! end @@ -225,7 +225,7 @@ context "and then modified" do before do - subject.motivatedBy = RDFVocabularies::OA.tagging + subject.motivatedBy = RDF::Vocab::OA.tagging end it "should return true" do @@ -238,7 +238,7 @@ end it "should reset the motivatedBy" do - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.commenting.to_s end it "should be persisted" do @@ -260,7 +260,7 @@ # Create inmemory repository @repo = RDF::Repository.new ActiveTriples::Repositories.repositories[:default] = @repo - subject.motivatedBy = RDFVocabularies::OA.commenting + subject.motivatedBy = RDF::Vocab::OA.commenting result end @@ -274,7 +274,7 @@ it "should delete from the repository" do subject.reload - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.commenting.to_s subject.motivatedBy = [] expect(subject.motivatedBy).to eq [] subject.persist! @@ -301,7 +301,7 @@ describe '#destroy!' do before do - subject << RDF::Statement(RDF::DC.LicenseDocument, RDF::DC.title, 'LICENSE') + subject << RDF::Statement(RDF::Vocab::DC.LicenseDocument, RDF::Vocab::DC.title, 'LICENSE') end subject { LD4L::OpenAnnotationRDF::CommentAnnotation.new('123') } @@ -391,29 +391,29 @@ context 'with unmodeled data' do before do - subject << RDF::Statement(subject.rdf_subject, RDF::DC.contributor, 'Tove Jansson') - subject << RDF::Statement(subject.rdf_subject, RDF::DC.relation, RDF::URI('http://example.org/moomi')) + subject << RDF::Statement(subject.rdf_subject, RDF::Vocab::DC.contributor, 'Tove Jansson') + subject << RDF::Statement(subject.rdf_subject, RDF::Vocab::DC.relation, RDF::URI('http://example.org/moomi')) node = RDF::Node.new - subject << RDF::Statement(RDF::URI('http://example.org/moomi'), RDF::DC.relation, node) - subject << RDF::Statement(node, RDF::DC.title, 'bnode') + subject << RDF::Statement(RDF::URI('http://example.org/moomi'), RDF::Vocab::DC.relation, node) + subject << RDF::Statement(node, RDF::Vocab::DC.title, 'bnode') end it 'should include data with URIs as attribute names' do - expect(subject.attributes[RDF::DC.contributor.to_s]).to eq ['Tove Jansson'] + expect(subject.attributes[RDF::Vocab::DC.contributor.to_s]).to eq ['Tove Jansson'] end it 'should return generic Resources' do - expect(subject.attributes[RDF::DC.relation.to_s].first).to be_a ActiveTriples::Resource + expect(subject.attributes[RDF::Vocab::DC.relation.to_s].first).to be_a ActiveTriples::Resource end it 'should build deep data for Resources' do - expect(subject.attributes[RDF::DC.relation.to_s].first.get_values(RDF::DC.relation). - first.get_values(RDF::DC.title)).to eq ['bnode'] + expect(subject.attributes[RDF::Vocab::DC.relation.to_s].first.get_values(RDF::Vocab::DC.relation). + first.get_values(RDF::Vocab::DC.title)).to eq ['bnode'] end it 'should include deep data in serializable_hash' do - expect(subject.serializable_hash[RDF::DC.relation.to_s].first.get_values(RDF::DC.relation). - first.get_values(RDF::DC.title)).to eq ['bnode'] + expect(subject.serializable_hash[RDF::Vocab::DC.relation.to_s].first.get_values(RDF::Vocab::DC.relation). + first.get_values(RDF::Vocab::DC.title)).to eq ['bnode'] end end @@ -490,13 +490,13 @@ describe 'editing the graph' do it 'should write properties when statements are added' do - subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::OA.motivatedBy, 'commenting') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::OA.motivatedBy, 'commenting') expect(subject.motivatedBy).to include 'commenting' end it 'should delete properties when statements are removed' do - subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::OA.annotatedBy, 'John Smith') - subject.delete RDF::Statement.new(subject.rdf_subject, RDFVocabularies::OA.annotatedBy, 'John Smith') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::OA.annotatedBy, 'John Smith') + subject.delete RDF::Statement.new(subject.rdf_subject, RDF::Vocab::OA.annotatedBy, 'John Smith') expect(subject.annotatedBy).to eq [] end end @@ -505,18 +505,18 @@ before do class DummyPerson < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Person') - property :foafname, :predicate => RDF::FOAF.name - property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument' - property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson + property :foafname, :predicate => RDF::Vocab::FOAF.name + property :publications, :predicate => RDF::Vocab::FOAF.publications, :class_name => 'DummyDocument' + property :knows, :predicate => RDF::Vocab::FOAF.knows, :class_name => DummyPerson end class DummyDocument < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Document') - property :title, :predicate => RDF::DC.title - property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson' + property :title, :predicate => RDF::Vocab::DC.title + property :creator, :predicate => RDF::Vocab::DC.creator, :class_name => 'DummyPerson' end - LD4L::OpenAnnotationRDF::CommentAnnotation.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument + LD4L::OpenAnnotationRDF::CommentAnnotation.property :item, :predicate => RDF::Vocab::DC.relation, :class_name => DummyDocument end subject { LD4L::OpenAnnotationRDF::CommentAnnotation.new } @@ -569,8 +569,10 @@ class DummyDocument < ActiveTriples::Resource document1.creator = [person1, person2] document2.creator = person1 person1.knows = person2 + person2.knows = person1 subject.item = [document1] - expect(subject.item.first.creator.first.knows.first.foafname).to eq ['Bob'] + expect(subject.item.first.creator.first.knows.first.foafname) + .to satisfy { |names| ['Alice', 'Bob'].include? names.first } end end end diff --git a/spec/ld4l/open_annotation_rdf/comment_body_spec.rb b/spec/ld4l/open_annotation_rdf/comment_body_spec.rb index 8a59c22..a912a04 100644 --- a/spec/ld4l/open_annotation_rdf/comment_body_spec.rb +++ b/spec/ld4l/open_annotation_rdf/comment_body_spec.rb @@ -1,7 +1,4 @@ require 'spec_helper' -require 'ld4l/open_annotation_rdf/vocab/dctypes' -require 'ld4l/open_annotation_rdf/vocab/oa' - describe 'LD4L::OpenAnnotationRDF::CommentBody' do @@ -24,22 +21,22 @@ describe 'when changing subject' do before do - subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land') subject.set_subject! RDF::URI('http://example.org/moomin') end it 'should update graph subjects' do - expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')))).to be true + expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')))).to be true end it 'should update graph objects' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject))).to be true end it 'should leave other uris alone' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land'))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land'))).to be true end end @@ -64,55 +61,55 @@ expected_results = subject.type expected_results = expected_results.to_a if subject.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8 expect(expected_results.size).to eq 2 - expect(expected_results).to include RDFVocabularies::DCTYPES.Text - expect(expected_results).to include RDFVocabularies::CNT.ContentAsText + expect(expected_results).to include RDF::Vocab::DCMIType.Text + expect(expected_results).to include RDF::Vocab::CNT.ContentAsText end it "should be settable" do - subject.type = RDFVocabularies::DCTYPES.Text + subject.type = RDF::Vocab::DCMIType.Text expected_results = subject.type expected_results = expected_results.to_a if subject.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8 expect(expected_results.size).to eq 1 - expect(expected_results).to include RDFVocabularies::DCTYPES.Text + expect(expected_results).to include RDF::Vocab::DCMIType.Text end it "should be settable to multiple values" do - t = [RDFVocabularies::DCTYPES.Text, RDFVocabularies::CNT.ContentAsText] + t = [RDF::Vocab::DCMIType.Text, RDF::Vocab::CNT.ContentAsText] subject.set_value(:type,t) expected_results = subject.type expected_results = expected_results.to_a if subject.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8 expect(expected_results.size).to eq 2 - expect(expected_results).to include RDFVocabularies::DCTYPES.Text - expect(expected_results).to include RDFVocabularies::CNT.ContentAsText + expect(expected_results).to include RDF::Vocab::DCMIType.Text + expect(expected_results).to include RDF::Vocab::CNT.ContentAsText end it "should be changeable" do - subject.type = RDFVocabularies::DCTYPES.Text - subject.type = RDFVocabularies::CNT.ContentAsText + subject.type = RDF::Vocab::DCMIType.Text + subject.type = RDF::Vocab::CNT.ContentAsText expected_results = subject.type expected_results = expected_results.to_a if subject.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8 expect(expected_results.size).to eq 1 - expect(expected_results).to include RDFVocabularies::CNT.ContentAsText + expect(expected_results).to include RDF::Vocab::CNT.ContentAsText end it "should be changeable for multiple values" do - t = [RDFVocabularies::DCTYPES.Text, RDFVocabularies::CNT.ContentAsText] + t = [RDF::Vocab::DCMIType.Text, RDF::Vocab::CNT.ContentAsText] subject.set_value(:type,t) expected_results = subject.type expected_results = expected_results.to_a if subject.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8 expect(expected_results.size).to eq 2 - expect(expected_results).to include RDFVocabularies::DCTYPES.Text - expect(expected_results).to include RDFVocabularies::CNT.ContentAsText + expect(expected_results).to include RDF::Vocab::DCMIType.Text + expect(expected_results).to include RDF::Vocab::CNT.ContentAsText t = subject.get_values(:type).to_a - t[0] = RDFVocabularies::OA.Tag # dummy type for testing - t[1] = RDFVocabularies::OA.SemanticTag # dummy type for testing + t[0] = RDF::Vocab::OA.Tag # dummy type for testing + t[1] = RDF::Vocab::OA.SemanticTag # dummy type for testing subject.set_value(:type,t) expected_results = subject.type expected_results = expected_results.to_a if subject.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8 expect(expected_results.size).to eq 2 - expect(expected_results).to include RDFVocabularies::OA.Tag - expect(expected_results).to include RDFVocabularies::OA.SemanticTag + expect(expected_results).to include RDF::Vocab::OA.Tag + expect(expected_results).to include RDF::Vocab::OA.SemanticTag end end @@ -259,7 +256,7 @@ describe '#destroy!' do before do - subject << RDF::Statement(RDF::DC.LicenseDocument, RDF::DC.title, 'LICENSE') + subject << RDF::Statement(RDF::Vocab::DC.LicenseDocument, RDF::Vocab::DC.title, 'LICENSE') end subject { LD4L::OpenAnnotationRDF::CommentBody.new('456')} @@ -296,13 +293,13 @@ describe 'editing the graph' do it 'should write properties when statements are added' do - subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::CNT.chars, 'Great book!') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::CNT.chars, 'Great book!') expect(subject.content).to include 'Great book!' end it 'should delete properties when statements are removed' do - subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::CNT.chars, 'Great book!') - subject.delete RDF::Statement.new(subject.rdf_subject, RDFVocabularies::CNT.chars, 'Great book!') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::CNT.chars, 'Great book!') + subject.delete RDF::Statement.new(subject.rdf_subject, RDF::Vocab::CNT.chars, 'Great book!') expect(subject.content).to eq [] end end @@ -311,18 +308,18 @@ before do class DummyPerson < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Person') - property :foafname, :predicate => RDF::FOAF.name - property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument' - property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson + property :foafname, :predicate => RDF::Vocab::FOAF.name + property :publications, :predicate => RDF::Vocab::FOAF.publications, :class_name => 'DummyDocument' + property :knows, :predicate => RDF::Vocab::FOAF.knows, :class_name => DummyPerson end class DummyDocument < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Document') - property :title, :predicate => RDF::DC.title - property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson' + property :title, :predicate => RDF::Vocab::DC.title + property :creator, :predicate => RDF::Vocab::DC.creator, :class_name => 'DummyPerson' end - LD4L::OpenAnnotationRDF::CommentBody.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument + LD4L::OpenAnnotationRDF::CommentBody.property :item, :predicate => RDF::Vocab::DC.relation, :class_name => DummyDocument end subject { LD4L::OpenAnnotationRDF::CommentBody.new } @@ -375,8 +372,10 @@ class DummyDocument < ActiveTriples::Resource document1.creator = [person1, person2] document2.creator = person1 person1.knows = person2 + person2.knows = person1 subject.item = [document1] - expect(subject.item.first.creator.first.knows.first.foafname).to eq ['Bob'] + expect(subject.item.first.creator.first.knows.first.foafname) + .to satisfy { |names| ['Alice', 'Bob'].include? names.first } end end end diff --git a/spec/ld4l/open_annotation_rdf/configuration_spec.rb b/spec/ld4l/open_annotation_rdf/configuration_spec.rb index 37a1507..c6804d1 100644 --- a/spec/ld4l/open_annotation_rdf/configuration_spec.rb +++ b/spec/ld4l/open_annotation_rdf/configuration_spec.rb @@ -7,7 +7,7 @@ context "when base_uri is not configured" do before do class DummyAnnotation < LD4L::OpenAnnotationRDF::Annotation - configure :type => RDFVocabularies::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default + configure :type => RDF::Vocab::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default end end after do @@ -24,7 +24,7 @@ class DummyAnnotation < LD4L::OpenAnnotationRDF::Annotation config.base_uri = "http://localhost/test_slash/" end class DummyAnnotation < LD4L::OpenAnnotationRDF::Annotation - configure :type => RDFVocabularies::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default + configure :type => RDF::Vocab::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default end end after do @@ -43,7 +43,7 @@ class DummyAnnotation < LD4L::OpenAnnotationRDF::Annotation config.base_uri = "http://localhost/test_no_slash" end class DummyAnnotation < LD4L::OpenAnnotationRDF::Annotation - configure :type => RDFVocabularies::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default + configure :type => RDF::Vocab::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default end end after do @@ -86,7 +86,7 @@ class DummyAnnotation < LD4L::OpenAnnotationRDF::Annotation context "when minter is nil" do before do class DummyAnnotation < LD4L::OpenAnnotationRDF::Annotation - configure :type => RDFVocabularies::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default + configure :type => RDF::Vocab::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default end end after do @@ -108,7 +108,7 @@ class DummyAnnotation < LD4L::OpenAnnotationRDF::Annotation config.localname_minter = lambda { |prefix=""| prefix+'_configured_'+SecureRandom.uuid } end class DummyAnnotation < LD4L::OpenAnnotationRDF::Annotation - configure :type => RDFVocabularies::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default + configure :type => RDF::Vocab::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default end end after do 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 c1103bb..1a9f644 100644 --- a/spec/ld4l/open_annotation_rdf/semantic_tag_annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/semantic_tag_annotation_spec.rb @@ -23,22 +23,22 @@ describe 'when changing subject' do before do - subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land') subject.set_subject! RDF::URI('http://example.org/moomin') end it 'should update graph subjects' do - expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')))).to be true + expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')))).to be true end it 'should update graph objects' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject))).to be true end it 'should leave other uris alone' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land'))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land'))).to be true end end @@ -59,8 +59,8 @@ # ------------------------------------------------- describe 'type' do - it "should be an RDFVocabularies::OA.Annotation" do - expect(subject.type.first.value).to eq RDFVocabularies::OA.Annotation.value + it "should be an RDF::Vocab::OA.Annotation" do + expect(subject.type.first.value).to eq RDF::Vocab::OA.Annotation.value end end @@ -221,18 +221,18 @@ describe 'motivatedBy' do it "should be OA.tagging if we haven't set it" do - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.tagging + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.tagging end it "should be settable" do - subject.motivatedBy = RDFVocabularies::OA.describing - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.describing + subject.motivatedBy = RDF::Vocab::OA.describing + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.describing end it "should be changeable" do - subject.motivatedBy = RDFVocabularies::OA.describing - subject.motivatedBy = RDFVocabularies::OA.classifying - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.classifying + subject.motivatedBy = RDF::Vocab::OA.describing + subject.motivatedBy = RDF::Vocab::OA.classifying + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.classifying end end @@ -264,7 +264,7 @@ context "when it is saved" do before do - subject.motivatedBy = RDFVocabularies::OA.commenting + subject.motivatedBy = RDF::Vocab::OA.commenting subject.persist! end @@ -274,7 +274,7 @@ context "and then modified" do before do - subject.motivatedBy = RDFVocabularies::OA.tagging + subject.motivatedBy = RDF::Vocab::OA.tagging end it "should return true" do @@ -287,7 +287,7 @@ end it "should reset the motivatedBy" do - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.commenting.to_s end it "should be persisted" do @@ -309,7 +309,7 @@ # Create inmemory repository @repo = RDF::Repository.new ActiveTriples::Repositories.repositories[:default] = @repo - subject.motivatedBy = RDFVocabularies::OA.commenting + subject.motivatedBy = RDF::Vocab::OA.commenting result end @@ -323,7 +323,7 @@ it "should delete from the repository" do subject.reload - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.commenting.to_s subject.motivatedBy = [] expect(subject.motivatedBy).to eq [] subject.persist! @@ -351,7 +351,7 @@ describe '#destroy!' do before do - subject << RDF::Statement(RDF::DC.LicenseDocument, RDF::DC.title, 'LICENSE') + subject << RDF::Statement(RDF::Vocab::DC.LicenseDocument, RDF::Vocab::DC.title, 'LICENSE') end subject { LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new('123') } @@ -441,29 +441,29 @@ context 'with unmodeled data' do before do - subject << RDF::Statement(subject.rdf_subject, RDF::DC.contributor, 'Tove Jansson') - subject << RDF::Statement(subject.rdf_subject, RDF::DC.relation, RDF::URI('http://example.org/moomi')) + subject << RDF::Statement(subject.rdf_subject, RDF::Vocab::DC.contributor, 'Tove Jansson') + subject << RDF::Statement(subject.rdf_subject, RDF::Vocab::DC.relation, RDF::URI('http://example.org/moomi')) node = RDF::Node.new - subject << RDF::Statement(RDF::URI('http://example.org/moomi'), RDF::DC.relation, node) - subject << RDF::Statement(node, RDF::DC.title, 'bnode') + subject << RDF::Statement(RDF::URI('http://example.org/moomi'), RDF::Vocab::DC.relation, node) + subject << RDF::Statement(node, RDF::Vocab::DC.title, 'bnode') end it 'should include data with URIs as attribute names' do - expect(subject.attributes[RDF::DC.contributor.to_s]).to eq ['Tove Jansson'] + expect(subject.attributes[RDF::Vocab::DC.contributor.to_s]).to eq ['Tove Jansson'] end it 'should return generic Resources' do - expect(subject.attributes[RDF::DC.relation.to_s].first).to be_a ActiveTriples::Resource + expect(subject.attributes[RDF::Vocab::DC.relation.to_s].first).to be_a ActiveTriples::Resource end it 'should build deep data for Resources' do - expect(subject.attributes[RDF::DC.relation.to_s].first.get_values(RDF::DC.relation). - first.get_values(RDF::DC.title)).to eq ['bnode'] + expect(subject.attributes[RDF::Vocab::DC.relation.to_s].first.get_values(RDF::Vocab::DC.relation). + first.get_values(RDF::Vocab::DC.title)).to eq ['bnode'] end it 'should include deep data in serializable_hash' do - expect(subject.serializable_hash[RDF::DC.relation.to_s].first.get_values(RDF::DC.relation). - first.get_values(RDF::DC.title)).to eq ['bnode'] + expect(subject.serializable_hash[RDF::Vocab::DC.relation.to_s].first.get_values(RDF::Vocab::DC.relation). + first.get_values(RDF::Vocab::DC.title)).to eq ['bnode'] end end @@ -540,13 +540,13 @@ describe 'editing the graph' do it 'should write properties when statements are added' do - subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::OA.motivatedBy, 'commenting') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::OA.motivatedBy, 'commenting') expect(subject.motivatedBy).to include 'commenting' end it 'should delete properties when statements are removed' do - subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::OA.annotatedBy, 'John Smith') - subject.delete RDF::Statement.new(subject.rdf_subject, RDFVocabularies::OA.annotatedBy, 'John Smith') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::OA.annotatedBy, 'John Smith') + subject.delete RDF::Statement.new(subject.rdf_subject, RDF::Vocab::OA.annotatedBy, 'John Smith') expect(subject.annotatedBy).to eq [] end end @@ -555,18 +555,18 @@ before do class DummyPerson < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Person') - property :foafname, :predicate => RDF::FOAF.name - property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument' - property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson + property :foafname, :predicate => RDF::Vocab::FOAF.name + property :publications, :predicate => RDF::Vocab::FOAF.publications, :class_name => 'DummyDocument' + property :knows, :predicate => RDF::Vocab::FOAF.knows, :class_name => DummyPerson end class DummyDocument < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Document') - property :title, :predicate => RDF::DC.title - property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson' + property :title, :predicate => RDF::Vocab::DC.title + property :creator, :predicate => RDF::Vocab::DC.creator, :class_name => 'DummyPerson' end - LD4L::OpenAnnotationRDF::SemanticTagAnnotation.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument + LD4L::OpenAnnotationRDF::SemanticTagAnnotation.property :item, :predicate => RDF::Vocab::DC.relation, :class_name => DummyDocument end subject { LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new } @@ -619,8 +619,10 @@ class DummyDocument < ActiveTriples::Resource document1.creator = [person1, person2] document2.creator = person1 person1.knows = person2 + person2.knows = person1 subject.item = [document1] - expect(subject.item.first.creator.first.knows.first.foafname).to eq ['Bob'] + expect(subject.item.first.creator.first.knows.first.foafname) + .to satisfy { |names| ['Alice', 'Bob'].include? names.first } end end end diff --git a/spec/ld4l/open_annotation_rdf/semantic_tag_body_spec.rb b/spec/ld4l/open_annotation_rdf/semantic_tag_body_spec.rb index bfb3082..9c821d4 100644 --- a/spec/ld4l/open_annotation_rdf/semantic_tag_body_spec.rb +++ b/spec/ld4l/open_annotation_rdf/semantic_tag_body_spec.rb @@ -1,7 +1,4 @@ require 'spec_helper' -require 'ld4l/open_annotation_rdf/vocab/dctypes' -require 'ld4l/open_annotation_rdf/vocab/oa' - describe 'LD4L::OpenAnnotationRDF::SemanticTagBody' do @@ -24,22 +21,22 @@ describe 'when changing subject' do before do - subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land') subject.set_subject! RDF::URI('http://example.org/moomin') end it 'should update graph subjects' do - expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')))).to be true + expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')))).to be true end it 'should update graph objects' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject))).to be true end it 'should leave other uris alone' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land'))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land'))).to be true end end @@ -64,7 +61,7 @@ expected_results = subject.type expected_results = expected_results.to_a if subject.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8 expect(expected_results.size).to eq 1 - expect(expected_results).to include RDFVocabularies::OA.SemanticTag + expect(expected_results).to include RDF::Vocab::OA.SemanticTag end end @@ -302,7 +299,7 @@ describe '#destroy!' do before do - subject << RDF::Statement(RDF::DC.LicenseDocument, RDF::DC.title, 'LICENSE') + subject << RDF::Statement(RDF::Vocab::DC.LicenseDocument, RDF::Vocab::DC.title, 'LICENSE') end subject { LD4L::OpenAnnotationRDF::SemanticTagBody.new('456')} @@ -341,18 +338,18 @@ before do class DummyPerson < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Person') - property :foafname, :predicate => RDF::FOAF.name - property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument' - property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson + property :foafname, :predicate => RDF::Vocab::FOAF.name + property :publications, :predicate => RDF::Vocab::FOAF.publications, :class_name => 'DummyDocument' + property :knows, :predicate => RDF::Vocab::FOAF.knows, :class_name => DummyPerson end class DummyDocument < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Document') - property :title, :predicate => RDF::DC.title - property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson' + property :title, :predicate => RDF::Vocab::DC.title + property :creator, :predicate => RDF::Vocab::DC.creator, :class_name => 'DummyPerson' end - LD4L::OpenAnnotationRDF::SemanticTagBody.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument + LD4L::OpenAnnotationRDF::SemanticTagBody.property :item, :predicate => RDF::Vocab::DC.relation, :class_name => DummyDocument end subject { LD4L::OpenAnnotationRDF::SemanticTagBody.new } @@ -405,8 +402,10 @@ class DummyDocument < ActiveTriples::Resource document1.creator = [person1, person2] document2.creator = person1 person1.knows = person2 + person2.knows = person1 subject.item = [document1] - expect(subject.item.first.creator.first.knows.first.foafname).to eq ['Bob'] + expect(subject.item.first.creator.first.knows.first.foafname) + .to satisfy { |names| ['Alice', 'Bob'].include? names.first } end end end diff --git a/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb b/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb index 09ede15..85a0e16 100644 --- a/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb @@ -23,22 +23,22 @@ describe 'when changing subject' do before do - subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land') subject.set_subject! RDF::URI('http://example.org/moomin') end it 'should update graph subjects' do - expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')))).to be true + expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')))).to be true end it 'should update graph objects' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject))).to be true end it 'should leave other uris alone' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land'))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land'))).to be true end end @@ -59,8 +59,8 @@ # ------------------------------------------------- describe 'type' do - it "should be an RDFVocabularies::OA.Annotation" do - expect(subject.type.first.value).to eq RDFVocabularies::OA.Annotation.value + it "should be an RDF::Vocab::OA.Annotation" do + expect(subject.type.first.value).to eq RDF::Vocab::OA.Annotation.value end end @@ -273,18 +273,18 @@ describe 'motivatedBy' do it "should be OA.tagging if we haven't set it" do - expect(subject.motivatedBy.first).to eq RDFVocabularies::OA.tagging + expect(subject.motivatedBy.first).to eq RDF::Vocab::OA.tagging end it "should be settable" do - subject.motivatedBy = RDFVocabularies::OA.describing - expect(subject.motivatedBy.first).to eq RDFVocabularies::OA.describing + subject.motivatedBy = RDF::Vocab::OA.describing + expect(subject.motivatedBy.first).to eq RDF::Vocab::OA.describing end it "should be changeable" do - subject.motivatedBy = RDFVocabularies::OA.describing - subject.motivatedBy = RDFVocabularies::OA.classifying - expect(subject.motivatedBy.first).to eq RDFVocabularies::OA.classifying + subject.motivatedBy = RDF::Vocab::OA.describing + subject.motivatedBy = RDF::Vocab::OA.classifying + expect(subject.motivatedBy.first).to eq RDF::Vocab::OA.classifying end end @@ -316,7 +316,7 @@ context "when it is saved" do before do - subject.motivatedBy = RDFVocabularies::OA.commenting + subject.motivatedBy = RDF::Vocab::OA.commenting subject.persist! end @@ -326,7 +326,7 @@ context "and then modified" do before do - subject.motivatedBy = RDFVocabularies::OA.tagging + subject.motivatedBy = RDF::Vocab::OA.tagging end it "should return true" do @@ -339,7 +339,7 @@ end it "should reset the motivatedBy" do - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.commenting.to_s end it "should be persisted" do @@ -361,7 +361,7 @@ # Create inmemory repository @repo = RDF::Repository.new ActiveTriples::Repositories.repositories[:default] = @repo - subject.motivatedBy = RDFVocabularies::OA.commenting + subject.motivatedBy = RDF::Vocab::OA.commenting result end @@ -375,7 +375,7 @@ it "should delete from the repository" do subject.reload - expect(subject.motivatedBy.first.to_s).to eq RDFVocabularies::OA.commenting.to_s + expect(subject.motivatedBy.first.to_s).to eq RDF::Vocab::OA.commenting.to_s subject.motivatedBy = [] expect(subject.motivatedBy).to eq [] subject.persist! @@ -403,7 +403,7 @@ describe '#destroy!' do before do - subject << RDF::Statement(RDF::DC.LicenseDocument, RDF::DC.title, 'LICENSE') + subject << RDF::Statement(RDF::Vocab::DC.LicenseDocument, RDF::Vocab::DC.title, 'LICENSE') end subject { LD4L::OpenAnnotationRDF::TagAnnotation.new('123') } @@ -494,29 +494,29 @@ context 'with unmodeled data' do before do - subject << RDF::Statement(subject.rdf_subject, RDF::DC.contributor, 'Tove Jansson') - subject << RDF::Statement(subject.rdf_subject, RDF::DC.relation, RDF::URI('http://example.org/moomi')) + subject << RDF::Statement(subject.rdf_subject, RDF::Vocab::DC.contributor, 'Tove Jansson') + subject << RDF::Statement(subject.rdf_subject, RDF::Vocab::DC.relation, RDF::URI('http://example.org/moomi')) node = RDF::Node.new - subject << RDF::Statement(RDF::URI('http://example.org/moomi'), RDF::DC.relation, node) - subject << RDF::Statement(node, RDF::DC.title, 'bnode') + subject << RDF::Statement(RDF::URI('http://example.org/moomi'), RDF::Vocab::DC.relation, node) + subject << RDF::Statement(node, RDF::Vocab::DC.title, 'bnode') end it 'should include data with URIs as attribute names' do - expect(subject.attributes[RDF::DC.contributor.to_s]).to eq ['Tove Jansson'] + expect(subject.attributes[RDF::Vocab::DC.contributor.to_s]).to eq ['Tove Jansson'] end it 'should return generic Resources' do - expect(subject.attributes[RDF::DC.relation.to_s].first).to be_a ActiveTriples::Resource + expect(subject.attributes[RDF::Vocab::DC.relation.to_s].first).to be_a ActiveTriples::Resource end it 'should build deep data for Resources' do - expect(subject.attributes[RDF::DC.relation.to_s].first.get_values(RDF::DC.relation). - first.get_values(RDF::DC.title)).to eq ['bnode'] + expect(subject.attributes[RDF::Vocab::DC.relation.to_s].first.get_values(RDF::Vocab::DC.relation). + first.get_values(RDF::Vocab::DC.title)).to eq ['bnode'] end it 'should include deep data in serializable_hash' do - expect(subject.serializable_hash[RDF::DC.relation.to_s].first.get_values(RDF::DC.relation). - first.get_values(RDF::DC.title)).to eq ['bnode'] + expect(subject.serializable_hash[RDF::Vocab::DC.relation.to_s].first.get_values(RDF::Vocab::DC.relation). + first.get_values(RDF::Vocab::DC.title)).to eq ['bnode'] end end @@ -593,13 +593,13 @@ describe 'editing the graph' do it 'should write properties when statements are added' do - subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::OA.motivatedBy, 'commenting') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::OA.motivatedBy, 'commenting') expect(subject.motivatedBy).to include 'commenting' end it 'should delete properties when statements are removed' do - subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::OA.annotatedBy, 'John Smith') - subject.delete RDF::Statement.new(subject.rdf_subject, RDFVocabularies::OA.annotatedBy, 'John Smith') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::OA.annotatedBy, 'John Smith') + subject.delete RDF::Statement.new(subject.rdf_subject, RDF::Vocab::OA.annotatedBy, 'John Smith') expect(subject.annotatedBy).to eq [] end end @@ -608,18 +608,18 @@ before do class DummyPerson < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Person') - property :foafname, :predicate => RDF::FOAF.name - property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument' - property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson + property :foafname, :predicate => RDF::Vocab::FOAF.name + property :publications, :predicate => RDF::Vocab::FOAF.publications, :class_name => 'DummyDocument' + property :knows, :predicate => RDF::Vocab::FOAF.knows, :class_name => DummyPerson end class DummyDocument < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Document') - property :title, :predicate => RDF::DC.title - property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson' + property :title, :predicate => RDF::Vocab::DC.title + property :creator, :predicate => RDF::Vocab::DC.creator, :class_name => 'DummyPerson' end - LD4L::OpenAnnotationRDF::TagAnnotation.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument + LD4L::OpenAnnotationRDF::TagAnnotation.property :item, :predicate => RDF::Vocab::DC.relation, :class_name => DummyDocument end subject { LD4L::OpenAnnotationRDF::TagAnnotation.new } @@ -672,8 +672,10 @@ class DummyDocument < ActiveTriples::Resource document1.creator = [person1, person2] document2.creator = person1 person1.knows = person2 + person2.knows = person1 subject.item = [document1] - expect(subject.item.first.creator.first.knows.first.foafname).to eq ['Bob'] + expect(subject.item.first.creator.first.knows.first.foafname) + .to satisfy { |names| ['Alice', 'Bob'].include? names.first } end end end diff --git a/spec/ld4l/open_annotation_rdf/tag_body_spec.rb b/spec/ld4l/open_annotation_rdf/tag_body_spec.rb index 6659212..8263852 100644 --- a/spec/ld4l/open_annotation_rdf/tag_body_spec.rb +++ b/spec/ld4l/open_annotation_rdf/tag_body_spec.rb @@ -1,7 +1,4 @@ require 'spec_helper' -require 'ld4l/open_annotation_rdf/vocab/dctypes' -require 'ld4l/open_annotation_rdf/vocab/oa' - describe 'LD4L::OpenAnnotationRDF::TagBody' do @@ -24,22 +21,22 @@ describe 'when changing subject' do before do - subject << RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject) - subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject) + subject << RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land') subject.set_subject! RDF::URI('http://example.org/moomin') end it 'should update graph subjects' do - expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::DC.title, RDF::Literal('Comet in Moominland')))).to be true + expect(subject.has_statement?(RDF::Statement.new(subject.rdf_subject, RDF::Vocab::DC.title, RDF::Literal('Comet in Moominland')))).to be true end it 'should update graph objects' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.isPartOf, subject.rdf_subject))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.isPartOf, subject.rdf_subject))).to be true end it 'should leave other uris alone' do - expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::DC.relation, 'http://example.org/moomin_land'))).to be true + expect(subject.has_statement?(RDF::Statement.new(RDF::URI('http://example.org/moomin_comics'), RDF::Vocab::DC.relation, 'http://example.org/moomin_land'))).to be true end end @@ -64,8 +61,8 @@ expected_results = subject.type expected_results = expected_results.to_a if subject.respond_to? 'persistence_strategy' # >= ActiveTriples 0.8 expect(expected_results.size).to eq 2 - expect(expected_results).to include RDFVocabularies::OA.Tag - expect(expected_results).to include RDFVocabularies::CNT.ContentAsText + expect(expected_results).to include RDF::Vocab::OA.Tag + expect(expected_results).to include RDF::Vocab::CNT.ContentAsText end end @@ -307,7 +304,7 @@ describe '#destroy!' do before do - subject << RDF::Statement(RDF::DC.LicenseDocument, RDF::DC.title, 'LICENSE') + subject << RDF::Statement(RDF::Vocab::DC.LicenseDocument, RDF::Vocab::DC.title, 'LICENSE') end subject { LD4L::OpenAnnotationRDF::TagBody.new('456')} @@ -344,13 +341,13 @@ describe 'editing the graph' do it 'should write properties when statements are added' do - subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::CNT.chars, 'good') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::CNT.chars, 'good') expect(subject.tag).to include 'good' end it 'should delete properties when statements are removed' do - subject << RDF::Statement.new(subject.rdf_subject, RDFVocabularies::CNT.chars, 'good') - subject.delete RDF::Statement.new(subject.rdf_subject, RDFVocabularies::CNT.chars, 'good') + subject << RDF::Statement.new(subject.rdf_subject, RDF::Vocab::CNT.chars, 'good') + subject.delete RDF::Statement.new(subject.rdf_subject, RDF::Vocab::CNT.chars, 'good') expect(subject.tag).to eq [] end end @@ -359,18 +356,18 @@ before do class DummyPerson < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Person') - property :foafname, :predicate => RDF::FOAF.name - property :publications, :predicate => RDF::FOAF.publications, :class_name => 'DummyDocument' - property :knows, :predicate => RDF::FOAF.knows, :class_name => DummyPerson + property :foafname, :predicate => RDF::Vocab::FOAF.name + property :publications, :predicate => RDF::Vocab::FOAF.publications, :class_name => 'DummyDocument' + property :knows, :predicate => RDF::Vocab::FOAF.knows, :class_name => DummyPerson end class DummyDocument < ActiveTriples::Resource configure :type => RDF::URI('http://example.org/Document') - property :title, :predicate => RDF::DC.title - property :creator, :predicate => RDF::DC.creator, :class_name => 'DummyPerson' + property :title, :predicate => RDF::Vocab::DC.title + property :creator, :predicate => RDF::Vocab::DC.creator, :class_name => 'DummyPerson' end - LD4L::OpenAnnotationRDF::TagBody.property :item, :predicate => RDF::DC.relation, :class_name => DummyDocument + LD4L::OpenAnnotationRDF::TagBody.property :item, :predicate => RDF::Vocab::DC.relation, :class_name => DummyDocument end subject { LD4L::OpenAnnotationRDF::TagBody.new } @@ -423,8 +420,10 @@ class DummyDocument < ActiveTriples::Resource document1.creator = [person1, person2] document2.creator = person1 person1.knows = person2 + person2.knows = person1 subject.item = [document1] - expect(subject.item.first.creator.first.knows.first.foafname).to eq ['Bob'] + expect(subject.item.first.creator.first.knows.first.foafname) + .to satisfy { |names| ['Alice', 'Bob'].include? names.first } end end end diff --git a/spec/ld4l/open_annotation_rdf_spec.rb b/spec/ld4l/open_annotation_rdf_spec.rb index 31dac00..e279b0b 100644 --- a/spec/ld4l/open_annotation_rdf_spec.rb +++ b/spec/ld4l/open_annotation_rdf_spec.rb @@ -10,7 +10,7 @@ config.unique_tags = false end class DummyAnnotation < LD4L::OpenAnnotationRDF::Annotation - configure :type => RDFVocabularies::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default + configure :type => RDF::Vocab::OA.Annotation, :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default end end after do diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 0cba529..caf0469 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,7 +5,7 @@ Bundler.setup require 'ld4l/open_annotation_rdf' -require 'pry' +require 'pry' unless ENV["CI"] Dir['./spec/support/**/*.rb'].each { |f| require f } From 9abdee476d11833fdcefe19e91bc91909c704685 Mon Sep 17 00:00:00 2001 From: "E. Lynette Rayle" Date: Tue, 2 Aug 2016 11:26:45 -0400 Subject: [PATCH 2/2] Remove classname overrides for hasBody in various types of annotations There is an intermittent bug where sometimes the body would resume correctly and other times where it was nil. I suspect this was due to overriding the hasBody property in subclasses of Annotation. Not sure why the problem was intermittent. --- ld4l-open_annotation_rdf.gemspec | 2 +- lib/ld4l/open_annotation_rdf.rb | 1 + lib/ld4l/open_annotation_rdf/annotation.rb | 42 +++++++++---------- .../annotation_generic_body.rb | 12 ++++++ .../open_annotation_rdf/comment_annotation.rb | 3 -- .../semantic_tag_annotation.rb | 3 -- .../open_annotation_rdf/tag_annotation.rb | 2 - .../open_annotation_rdf/annotation_spec.rb | 13 ++++-- .../comment_annotation_spec.rb | 4 ++ .../open_annotation_rdf/comment_body_spec.rb | 4 ++ .../semantic_tag_annotation_spec.rb | 6 ++- .../semantic_tag_body_spec.rb | 18 +++----- .../tag_annotation_spec.rb | 6 ++- .../ld4l/open_annotation_rdf/tag_body_spec.rb | 18 +++----- spec/spec_helper.rb | 1 - 15 files changed, 72 insertions(+), 63 deletions(-) create mode 100644 lib/ld4l/open_annotation_rdf/annotation_generic_body.rb diff --git a/ld4l-open_annotation_rdf.gemspec b/ld4l-open_annotation_rdf.gemspec index e7c799b..6332f36 100644 --- a/ld4l-open_annotation_rdf.gemspec +++ b/ld4l-open_annotation_rdf.gemspec @@ -13,7 +13,7 @@ Gem::Specification.new do |spec| spec.description = %q{LD4L Open Annotation RDF provides tools for modeling a annotations based on the Open Annotation ontology and persisting to a triplestore.} spec.homepage = "https://github.com/ld4l/open_annotation_rdf" spec.license = "APACHE2" - spec.required_ruby_version = '>= 2.2.2' + spec.required_ruby_version = '>= 2.1' spec.files = `git ls-files -z`.split("\x0") spec.test_files = spec.files.grep(%r{^(test|spec|features)/}) diff --git a/lib/ld4l/open_annotation_rdf.rb b/lib/ld4l/open_annotation_rdf.rb index 124758e..12d252b 100644 --- a/lib/ld4l/open_annotation_rdf.rb +++ b/lib/ld4l/open_annotation_rdf.rb @@ -29,6 +29,7 @@ def self.configure # autoload classes autoload :Configuration, 'ld4l/open_annotation_rdf/configuration' autoload :Annotation, 'ld4l/open_annotation_rdf/annotation' + autoload :AnnotationGenericBody, 'ld4l/open_annotation_rdf/annotation_generic_body' autoload :CommentAnnotation, 'ld4l/open_annotation_rdf/comment_annotation' autoload :CommentBody, 'ld4l/open_annotation_rdf/comment_body' autoload :TagAnnotation, 'ld4l/open_annotation_rdf/tag_annotation' diff --git a/lib/ld4l/open_annotation_rdf/annotation.rb b/lib/ld4l/open_annotation_rdf/annotation.rb index de0ff22..bef38b9 100644 --- a/lib/ld4l/open_annotation_rdf/annotation.rb +++ b/lib/ld4l/open_annotation_rdf/annotation.rb @@ -20,32 +20,17 @@ class << self; attr_reader :localname_prefix end def self.resume(uri_or_str) # Let ActiveTriples::Resource validate uri_or_str when creating new Annotation a = new(uri_or_str) + return nil if a.nil? - # get motivatedBy - m = a.get_values(:motivatedBy) - m = m.to_a if Object::ActiveTriples.const_defined?("Relation") && m.kind_of?(ActiveTriples::Relation) - - # TODO: Should m's class be validated? I've seen it be RDF::Vocabulary::Term and RDF::URI. For now, removing the validation. - return a unless m.kind_of?(Array) && m.size > 0 - # return a unless m.kind_of?(Array) && m.size > 0 && (m.first.kind_of?(RDF::Vocabulary::Term) || m.first.kind_of?(RDF::URI) - - # motivatedBy is set - m_uri = m.first # currently only support commenting and tagging - return LD4L::OpenAnnotationRDF::CommentAnnotation.new(uri_or_str) if m_uri == RDF::Vocab::OA.commenting - return a unless m_uri == RDF::Vocab::OA.tagging + m = motivated_by a + return LD4L::OpenAnnotationRDF::CommentAnnotation.new(uri_or_str) if m.include? RDF::Vocab::OA.commenting # Tagging can be TagAnnotation or SemanticTagAnnotation. Only way to tell is by checking type of body. - sta = LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new(uri_or_str) - stb = sta.getBody - return sta unless stb.type.include?(RDF::Vocab::OA.Tag) || !stb.type.include?(RDF::Vocab::OA.SemanticTag) - - ta = LD4L::OpenAnnotationRDF::TagAnnotation.new(uri_or_str) - tb = ta.getBody - return ta if tb.type.include?(RDF::Vocab::OA.Tag) - - # can't match to a known annotation type, so return as generic annotation - return a + return a unless m.include? RDF::Vocab::OA.tagging + b = body_resource a + return LD4L::OpenAnnotationRDF::TagAnnotation.new(uri_or_str) if b.type.include? RDF::Vocab::OA.Tag + LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new(uri_or_str) end ## @@ -107,6 +92,19 @@ def self::find_by_target(target_uri) results.each { |r| annotations << r.to_hash[:annotation] } annotations end + + private + def self::motivated_by annotation + m = annotation.get_values(:motivatedBy).to_a + return nil unless m.kind_of?(Array) && (m.size > 0) + m + end + + def self::body_resource annotation + body_uris = annotation.hasBody + return nil if body_uris.nil? || body_uris.size < 1 + AnnotationGenericBody.new(body_uris.first) # TODO: a full implementation of OA could have multiple bodies + end end end end diff --git a/lib/ld4l/open_annotation_rdf/annotation_generic_body.rb b/lib/ld4l/open_annotation_rdf/annotation_generic_body.rb new file mode 100644 index 0000000..157913d --- /dev/null +++ b/lib/ld4l/open_annotation_rdf/annotation_generic_body.rb @@ -0,0 +1,12 @@ +module LD4L + module OpenAnnotationRDF + class AnnotationGenericBody < ActiveTriples::Resource + + class << self; attr_reader :localname_prefix end + @localname_prefix="a" + + configure :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, + :repository => :default + end + end +end diff --git a/lib/ld4l/open_annotation_rdf/comment_annotation.rb b/lib/ld4l/open_annotation_rdf/comment_annotation.rb index ff04b08..276125b 100644 --- a/lib/ld4l/open_annotation_rdf/comment_annotation.rb +++ b/lib/ld4l/open_annotation_rdf/comment_annotation.rb @@ -8,9 +8,6 @@ class CommentAnnotation < LD4L::OpenAnnotationRDF::Annotation :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default - property :hasBody, :predicate => RDF::Vocab::OA.hasBody, :class_name => LD4L::OpenAnnotationRDF::CommentBody - - ## # Create a comment annotation body and set the hasBody property to it. # diff --git a/lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb b/lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb index 8d56748..5a783cf 100644 --- a/lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb +++ b/lib/ld4l/open_annotation_rdf/semantic_tag_annotation.rb @@ -8,9 +8,6 @@ class SemanticTagAnnotation < LD4L::OpenAnnotationRDF::Annotation :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default - property :hasBody, :predicate => RDF::Vocab::OA.hasBody, :class_name => LD4L::OpenAnnotationRDF::SemanticTagBody - - # USAGE: Use setTerm to set the hasBody property to be the URI of the controlled vocabulary term that # is the annotation. diff --git a/lib/ld4l/open_annotation_rdf/tag_annotation.rb b/lib/ld4l/open_annotation_rdf/tag_annotation.rb index 9d79383..232efa1 100644 --- a/lib/ld4l/open_annotation_rdf/tag_annotation.rb +++ b/lib/ld4l/open_annotation_rdf/tag_annotation.rb @@ -8,8 +8,6 @@ class TagAnnotation < LD4L::OpenAnnotationRDF::Annotation :base_uri => LD4L::OpenAnnotationRDF.configuration.base_uri, :repository => :default - property :hasBody, :predicate => RDF::Vocab::OA.hasBody, :class_name => LD4L::OpenAnnotationRDF::TagBody - # TODO: Should a tag be destroyed when the last annotation referencing the tag is destroyed? ## diff --git a/spec/ld4l/open_annotation_rdf/annotation_spec.rb b/spec/ld4l/open_annotation_rdf/annotation_spec.rb index 5d5b80c..e5d463c 100644 --- a/spec/ld4l/open_annotation_rdf/annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/annotation_spec.rb @@ -2,6 +2,10 @@ describe 'LD4L::OpenAnnotationRDF::Annotation' do + after do + ActiveTriples::Repositories.repositories[LD4L::OpenAnnotationRDF::CommentAnnotation.repository].clear! + end + subject { LD4L::OpenAnnotationRDF::Annotation.new } describe 'rdf_subject' do @@ -376,7 +380,8 @@ expect(@comment_anno.hasTarget.first.rdf_subject).to eq RDF::URI.new("http://searchworks.stanford.edu/view/666") end it "populates Comment bodies properly" do - body = @comment_anno.hasBody.first + # body = @comment_anno.hasBody.first + body = @comment_anno.getBody expect(body).to be_a LD4L::OpenAnnotationRDF::CommentBody expect(body.content.first).to eq @comment_value expect(body.type).to include(RDF::Vocab::CNT.ContentAsText) @@ -413,7 +418,8 @@ expect(@tag_anno.hasTarget.first.rdf_subject).to eq RDF::URI.new("http://searchworks.stanford.edu/view/666") end it "populates Tag bodies properly" do - body = @tag_anno.hasBody.first + # body = @tag_anno.hasBody.first + body = @tag_anno.getBody expect(body).to be_a LD4L::OpenAnnotationRDF::TagBody expect(body.tag.first).to eq @tag_value expect(body.type).to include(RDF::Vocab::OA.Tag) @@ -445,7 +451,8 @@ expect(@semantic_tag_anno.hasTarget.first.rdf_subject).to eq RDF::URI.new("http://searchworks.stanford.edu/view/666") end it "populates Tag bodies properly" do - body = @semantic_tag_anno.hasBody.first + # body = @semantic_tag_anno.hasBody.first + body = @semantic_tag_anno.getBody expect(body.rdf_subject.to_s).to eq @term_url expect(body).to be_a LD4L::OpenAnnotationRDF::SemanticTagBody expect(body.type).to include(RDF::Vocab::OA.SemanticTag) diff --git a/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb b/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb index 169e76d..69f61d1 100644 --- a/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/comment_annotation_spec.rb @@ -2,6 +2,10 @@ describe 'LD4L::OpenAnnotationRDF::CommentAnnotation' do + after do + ActiveTriples::Repositories.repositories[LD4L::OpenAnnotationRDF::CommentAnnotation.repository].clear! + end + subject { LD4L::OpenAnnotationRDF::CommentAnnotation.new } describe 'rdf_subject' do diff --git a/spec/ld4l/open_annotation_rdf/comment_body_spec.rb b/spec/ld4l/open_annotation_rdf/comment_body_spec.rb index a912a04..66ab178 100644 --- a/spec/ld4l/open_annotation_rdf/comment_body_spec.rb +++ b/spec/ld4l/open_annotation_rdf/comment_body_spec.rb @@ -2,6 +2,10 @@ describe 'LD4L::OpenAnnotationRDF::CommentBody' do + after do + ActiveTriples::Repositories.repositories[LD4L::OpenAnnotationRDF::CommentAnnotation.repository].clear! + end + subject { LD4L::OpenAnnotationRDF::CommentBody.new } describe 'rdf_subject' do 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 1a9f644..53af088 100644 --- a/spec/ld4l/open_annotation_rdf/semantic_tag_annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/semantic_tag_annotation_spec.rb @@ -1,9 +1,11 @@ require 'spec_helper' -# TODO: Uses CommentBody as the annotation body, which is wrong. Should be URI into controlled vocabulary. - describe 'LD4L::OpenAnnotationRDF::SemanticTagAnnotation' do + after do + ActiveTriples::Repositories.repositories[LD4L::OpenAnnotationRDF::CommentAnnotation.repository].clear! + end + subject { LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new } describe 'rdf_subject' do diff --git a/spec/ld4l/open_annotation_rdf/semantic_tag_body_spec.rb b/spec/ld4l/open_annotation_rdf/semantic_tag_body_spec.rb index 9c821d4..57959b2 100644 --- a/spec/ld4l/open_annotation_rdf/semantic_tag_body_spec.rb +++ b/spec/ld4l/open_annotation_rdf/semantic_tag_body_spec.rb @@ -2,6 +2,10 @@ describe 'LD4L::OpenAnnotationRDF::SemanticTagBody' do + after do + ActiveTriples::Repositories.repositories[LD4L::OpenAnnotationRDF::CommentAnnotation.repository].clear! + end + subject { LD4L::OpenAnnotationRDF::SemanticTagBody.new } describe 'rdf_subject' do @@ -93,7 +97,7 @@ end context "when terms exist in the repository" do - before(:all) do + before do # Create inmemory repository sta = LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new('http://example.org/sta1') sta.setTerm(RDF::URI("http://example.org/EXISTING_term")) @@ -104,11 +108,6 @@ stb = LD4L::OpenAnnotationRDF::SemanticTagBody.new('http://example.org/UNUSED_term') stb.persist! end - after(:all) do - LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new('http://example.org/sta1').destroy! - LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new('http://example.org/sta2').destroy! - LD4L::OpenAnnotationRDF::SemanticTagBody.new('http://example.org/UNUSED_term').destroy! - end context "and term is passed as string URI" do it "should find annotations using the term" do @@ -170,7 +169,7 @@ end context "when terms exist in the repository" do - before(:all) do + before do # Create inmemory repository sta = LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new('http://example.org/sta1') sta.setTerm(RDF::URI("http://example.org/EXISTING_term")) @@ -181,11 +180,6 @@ stb = LD4L::OpenAnnotationRDF::SemanticTagBody.new('http://example.org/UNUSED_term') stb.persist! end - after(:all) do - LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new('http://example.org/sta1').destroy! - LD4L::OpenAnnotationRDF::SemanticTagAnnotation.new('http://example.org/sta2').destroy! - LD4L::OpenAnnotationRDF::SemanticTagBody.new('http://example.org/UNUSED_term').destroy! - end context "and term is passed as string URI" do it "should not destroy if used by any annotations" do diff --git a/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb b/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb index 85a0e16..80ce12c 100644 --- a/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb +++ b/spec/ld4l/open_annotation_rdf/tag_annotation_spec.rb @@ -1,9 +1,11 @@ require 'spec_helper' -# TODO: Uses CommentBody as the annotation body, which is wrong. Should be URI into controlled vocabulary. - describe 'LD4L::OpenAnnotationRDF::TagAnnotation' do + after do + ActiveTriples::Repositories.repositories[LD4L::OpenAnnotationRDF::CommentAnnotation.repository].clear! + end + subject { LD4L::OpenAnnotationRDF::TagAnnotation.new } describe 'rdf_subject' do diff --git a/spec/ld4l/open_annotation_rdf/tag_body_spec.rb b/spec/ld4l/open_annotation_rdf/tag_body_spec.rb index 8263852..1230ed0 100644 --- a/spec/ld4l/open_annotation_rdf/tag_body_spec.rb +++ b/spec/ld4l/open_annotation_rdf/tag_body_spec.rb @@ -2,6 +2,10 @@ describe 'LD4L::OpenAnnotationRDF::TagBody' do + after do + ActiveTriples::Repositories.repositories[LD4L::OpenAnnotationRDF::CommentAnnotation.repository].clear! + end + subject { LD4L::OpenAnnotationRDF::TagBody.new } describe 'rdf_subject' do @@ -104,7 +108,7 @@ end context "when tags exist in the repository" do - before(:all) do + before do # Create inmemory repository ta = LD4L::OpenAnnotationRDF::TagAnnotation.new('http://example.org/ta1') ta.setTag('EXISTING_tag') @@ -116,11 +120,6 @@ tb.tag = 'UNUSED_tag' tb.persist! end - after(:all) do - LD4L::OpenAnnotationRDF::TagAnnotation.new('http://example.org/ta1').destroy! - LD4L::OpenAnnotationRDF::TagAnnotation.new('http://example.org/ta2').destroy! - LD4L::OpenAnnotationRDF::TagBody.new('http://example.org/UNUSED_tag').destroy! - end it "should find annotations using a tag" do annotations = LD4L::OpenAnnotationRDF::TagBody.annotations_using('EXISTING_tag') @@ -162,7 +161,7 @@ end context "when tags exist in the repository" do - before(:all) do + before do # Create inmemory repository ta = LD4L::OpenAnnotationRDF::TagAnnotation.new('http://example.org/ta1') ta.setTag('EXISTING_tag') @@ -174,11 +173,6 @@ tb.tag = 'UNUSED_tag' tb.persist! end - after(:all) do - LD4L::OpenAnnotationRDF::TagAnnotation.new('http://example.org/ta1').destroy! - LD4L::OpenAnnotationRDF::TagAnnotation.new('http://example.org/ta2').destroy! - LD4L::OpenAnnotationRDF::TagBody.new('http://example.org/UNUSED_tag').destroy! - end it "should not find non-existent tag" do expect( LD4L::OpenAnnotationRDF::TagBody.fetch_by_tag_value('NONEXISTING_tag') ).to be_nil diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index caf0469..2dacdc6 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,5 +20,4 @@ config.formatter = :progress end -# TODO Need to use allow, receive, and_return instead of creating the repository here to avoid bleed over between tests. ActiveTriples::Repositories.add_repository :default, RDF::Repository.new