From 2d77db29524f46e7bb16e2e2e39f3be6fa129c84 Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Thu, 18 Feb 2021 15:01:59 -0800 Subject: [PATCH 1/2] Chech https versions of schema tests and fix range check for schemas:URL. --- lib/rdf/reasoner/schema.rb | 2 +- spec/schema_spec.rb | 134 ++++++++++++++++++++++++++++++++++++- 2 files changed, 134 insertions(+), 2 deletions(-) diff --git a/lib/rdf/reasoner/schema.rb b/lib/rdf/reasoner/schema.rb index 9ea4e13..d3e9092 100644 --- a/lib/rdf/reasoner/schema.rb +++ b/lib/rdf/reasoner/schema.rb @@ -155,7 +155,7 @@ def range_compatible_schema?(resource, queryable, options = {}) ).include?(resource) && (ranges.include?(RDF::URI("http://schema.org/Boolean")) || ranges.include?(RDF::URI("https://schema.org/Boolean"))) true # Special case for schema boolean resources - elsif (ranges.include?(RDF::URI("http://schema.org/URL")) || ranges.include?(RDF::URI("http://schema.org/URL"))) && + elsif (ranges.include?(RDF::URI("http://schema.org/URL")) || ranges.include?(RDF::URI("https://schema.org/URL"))) && resource.uri? true # schema:URL matches URI resources elsif ranges == [RDF::URI("http://schema.org/Text")] && resource.uri? diff --git a/spec/schema_spec.rb b/spec/schema_spec.rb index 49151ad..f78aa3f 100644 --- a/spec/schema_spec.rb +++ b/spec/schema_spec.rb @@ -16,6 +16,14 @@ specify {expect(cls.domainIncludes.map(&:pname)).to include(*entails)} end end + + { + RDF::Vocab::SCHEMAS.about => [RDF::Vocab::SCHEMAS.CreativeWork].map(&:pname), + }.each do |cls, entails| + describe cls.pname do + specify {expect(cls.properties[RDF::Vocab::SCHEMAS.domainIncludes].map(&:pname)).to include(*entails)} + end + end end describe :rangeIncludes do @@ -28,31 +36,62 @@ specify {expect(cls.rangeIncludes.map(&:pname)).to include(*entails)} end end + + { + RDF::Vocab::SCHEMAS.about => [RDF::Vocab::SCHEMAS.Thing].map(&:pname), + RDF::Vocab::SCHEMAS.event => [RDF::Vocab::SCHEMAS.Event].map(&:pname), + }.each do |cls, entails| + describe cls.pname do + specify {expect(Array(cls.properties[RDF::Vocab::SCHEMAS.rangeIncludes]).map(&:pname)).to include(*entails)} + end + end end describe :domain_compatible? do - let!(:queryable) {RDF::Graph.new << RDF::Statement(ex+"a", RDF.type, RDF::Vocab::SCHEMA.Person)} + let!(:queryable) { + RDF::Graph.new do |g| + g << RDF::Statement(ex+"a", RDF.type, RDF::Vocab::SCHEMA.Person) + g << RDF::Statement(ex+"a", RDF.type, RDF::Vocab::SCHEMAS.Person) + end + } context "domain and no provided types" do it "uses entailed types of resource" do expect(RDF::Vocab::SCHEMA.familyName).to be_domain_compatible(ex+"a", queryable) end + + it "uses entailed types of resource (https)" do + expect(RDF::Vocab::SCHEMAS.familyName).to be_domain_compatible(ex+"a", queryable) + end end it "returns true with no domain and no type" do expect(RDF::Vocab::SCHEMA.dateCreated).to be_domain_compatible(ex+"b", queryable) end + it "returns true with no domain and no type (https)" do + expect(RDF::Vocab::SCHEMAS.dateCreated).to be_domain_compatible(ex+"b", queryable) + end + it "uses supplied types" do expect(RDF::Vocab::SCHEMA.dateCreated).not_to be_domain_compatible(ex+"a", queryable) expect(RDF::Vocab::SCHEMA.dateCreated).to be_domain_compatible(ex+"a", queryable, types: [RDF::Vocab::SCHEMA.CreativeWork]) end + it "uses supplied types (https)" do + expect(RDF::Vocab::SCHEMAS.dateCreated).not_to be_domain_compatible(ex+"a", queryable) + expect(RDF::Vocab::SCHEMAS.dateCreated).to be_domain_compatible(ex+"a", queryable, types: [RDF::Vocab::SCHEMAS.CreativeWork]) + end + context "domain violations" do { "subject of wrong type" => %( @prefix schema: . a schema:Person; schema:acceptedOffer [a schema:Offer] . ), + "subject of wrong type (https)" => %( + @prefix schemas: . + a schemas:Person; schemas:acceptedOffer [a schemas:Offer] . + ), }.each do |name, input| it name do graph = RDF::Graph.new << RDF::Turtle::Reader.new(input) @@ -116,6 +155,15 @@ statement = graph.to_a.reject {|s| s.predicate == RDF.type}.first expect(RDF::Vocabulary.find_term(statement.predicate)).to be_range_compatible(statement.object, graph) end + + it "#{name.sub('schema:', 'schemas:')} (https)" do + input = input. + gsub('http://schema.org', 'https://schema.org'). + gsub('schema:', 'schemas:') + graph = RDF::Graph.new << RDF::Turtle::Reader.new(input) + statement = graph.to_a.reject {|s| s.predicate == RDF.type}.first + expect(RDF::Vocabulary.find_term(statement.predicate)).to be_range_compatible(statement.object, graph) + end end context "ISO 8601" do @@ -164,6 +212,7 @@ ).each do |date| it "recognizes #{date.sub('_', ' ')}" do expect(RDF::Vocab::SCHEMA.startDate).to be_range_compatible(RDF::Literal(date.sub('_', ' ')), []) + expect(RDF::Vocab::SCHEMAS.startDate).to be_range_compatible(RDF::Literal(date.sub('_', ' ')), []) end end @@ -195,6 +244,7 @@ ).each do |date| it "does not recognize #{date.sub('_', ' ')}" do expect(RDF::Vocab::SCHEMA.startDate).not_to be_range_compatible(RDF::Literal(date.sub('_', ' ')), []) + expect(RDF::Vocab::SCHEMAS.startDate).not_to be_range_compatible(RDF::Literal(date.sub('_', ' ')), []) end end end @@ -228,6 +278,15 @@ statement = graph.to_a.reject {|s| s.predicate == RDF.type}.first expect(RDF::Vocabulary.find_term(statement.predicate)).not_to be_range_compatible(statement.object, graph) end + + it "#{name.sub('schema:', 'schemas:')} (https)" do + input = input. + gsub('http://schema.org', 'https://schema.org'). + gsub('schema:', 'schemas:') + graph = RDF::Graph.new << RDF::Turtle::Reader.new(input) + statement = graph.to_a.reject {|s| s.predicate == RDF.type}.first + expect(RDF::Vocabulary.find_term(statement.predicate)).not_to be_range_compatible(statement.object, graph) + end end end @@ -272,6 +331,15 @@ statement = graph.to_a.reject {|s| s.predicate == RDF.type}.first expect(RDF::Vocabulary.find_term(statement.predicate)).not_to be_range_compatible(statement.object, graph) end + + it "#{name.sub('schema:', 'schemas:')} (https)" do + input = input. + gsub('http://schema.org', 'https://schema.org'). + gsub('schema:', 'schemas:') + graph = RDF::Graph.new << RDF::Turtle::Reader.new(input) + statement = graph.to_a.reject {|s| s.predicate == RDF.type}.first + expect(RDF::Vocabulary.find_term(statement.predicate)).not_to be_range_compatible(statement.object, graph) + end end end end @@ -428,6 +496,21 @@ predicate: RDF::Vocab::SCHEMA.creator, result: :range }, + "Creator list (https)" => { + input: %( + @prefix rdf: . + @prefix schema: . + a schema:Review; + schema:creator [ + a rdf:List; + rdf:first [a schema:Person; schema:name "John Doe"]; + rdf:rest rdf:nil + ] . + ), + resource: RDF::URI("http://example/Review"), + predicate: RDF::Vocab::SCHEMAS.creator, + result: :range + }, "Creator list with string value" => { input: %( @prefix rdf: . @@ -443,6 +526,21 @@ predicate: RDF::Vocab::SCHEMA.creator, result: :range }, + "Creator list with string value (https)" => { + input: %( + @prefix rdf: . + @prefix schema: . + a schema:Review; + schema:creator [ + a rdf:List; + rdf:first "John Doe"; + rdf:rest rdf:nil + ] . + ), + resource: RDF::URI("http://example/Review"), + predicate: RDF::Vocab::SCHEMAS.creator, + result: :range + }, "Creator list (single invalid value)" => { input: %( @prefix rdf: . @@ -458,6 +556,21 @@ predicate: RDF::Vocab::SCHEMA.creator, result: :not_range }, + "Creator list (single invalid value) (https)" => { + input: %( + @prefix rdf: . + @prefix schema: . + a schema:Review; + schema:creator [ + a rdf:List; + rdf:first [a schema:CreativeWork; schema:name "Website"]; + rdf:rest rdf:nil + ] . + ), + resource: RDF::URI("http://example/Review"), + predicate: RDF::Vocab::SCHEMAS.creator, + result: :not_range + }, "Creator list (mixed valid/invalid)" => { input: %( @prefix rdf: . @@ -477,6 +590,25 @@ predicate: RDF::Vocab::SCHEMA.creator, result: :not_range }, + "Creator list (mixed valid/invalid) (https)" => { + input: %( + @prefix rdf: . + @prefix schema: . + a schema:Review; + schema:creator [ + a rdf:List; + rdf:first [a schema:Person; schema:name "John Doe";]; + rdf:rest [ + a rdf:List; + rdf:first [a schema:CreativeWork; schema:name "Website"]; + rdf:rest rdf:nil + ] + ] . + ), + resource: RDF::URI("http://example/Review"), + predicate: RDF::Vocab::SCHEMAS.creator, + result: :not_range + }, }.each do |name, params| context name do let(:graph) {RDF::Graph.new << RDF::Turtle::Reader.new(params[:input])} From 6b9089fb8c60b50bfdbe1be9044b07b98888f6cc Mon Sep 17 00:00:00 2001 From: Gregg Kellogg Date: Thu, 18 Feb 2021 15:10:49 -0800 Subject: [PATCH 2/2] Version 0.7.1. --- VERSION | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/VERSION b/VERSION index faef31a..39e898a 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.7.0 +0.7.1