Skip to content

Commit

Permalink
Finish 0.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
gkellogg committed Feb 18, 2021
2 parents 23a6b4b + 6b9089f commit a6f6ed3
Show file tree
Hide file tree
Showing 3 changed files with 135 additions and 3 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.0
0.7.1
2 changes: 1 addition & 1 deletion lib/rdf/reasoner/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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?
Expand Down
134 changes: 133 additions & 1 deletion spec/schema_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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: <http://schema.org/> .
<foo> a schema:Person; schema:acceptedOffer [a schema:Offer] .
),
"subject of wrong type (https)" => %(
@prefix schemas: <https://schema.org/> .
<foo> a schemas:Person; schemas:acceptedOffer [a schemas:Offer] .
),
}.each do |name, input|
it name do
graph = RDF::Graph.new << RDF::Turtle::Reader.new(input)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -428,6 +496,21 @@
predicate: RDF::Vocab::SCHEMA.creator,
result: :range
},
"Creator list (https)" => {
input: %(
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <https://schema.org/> .
<http://example/Review> 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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
Expand All @@ -443,6 +526,21 @@
predicate: RDF::Vocab::SCHEMA.creator,
result: :range
},
"Creator list with string value (https)" => {
input: %(
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <https://schema.org/> .
<http://example/Review> 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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
Expand All @@ -458,6 +556,21 @@
predicate: RDF::Vocab::SCHEMA.creator,
result: :not_range
},
"Creator list (single invalid value) (https)" => {
input: %(
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <https://schema.org/> .
<http://example/Review> 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: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
Expand All @@ -477,6 +590,25 @@
predicate: RDF::Vocab::SCHEMA.creator,
result: :not_range
},
"Creator list (mixed valid/invalid) (https)" => {
input: %(
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
@prefix schema: <https://schema.org/> .
<http://example/Review> 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])}
Expand Down

0 comments on commit a6f6ed3

Please sign in to comment.