lib/rdf/reasoner/schema.rb in rdf-reasoner-0.5.3 vs lib/rdf/reasoner/schema.rb in rdf-reasoner-0.6.0

- old
+ new

@@ -20,24 +20,24 @@ # @param [RDF::Resource] resource # @param [RDF::Queryable] queryable # @param [Hash{Symbol => Object}] options # @option options [Array<RDF::Vocabulary::Term>] :types # Fully entailed types of resource, if not provided, they are queried - def domain_compatible_schema?(resource, queryable, options = {}) + def domain_compatible_schema?(resource, queryable, **options) raise RDF::Reasoner::Error, "#{self} can't get domains" unless property? domains = Array(self.domainIncludes) - [RDF::OWL.Thing] # Fully entailed types of the resource - types = entailed_types(resource, queryable, options) unless domains.empty? + types = entailed_types(resource, queryable, **options) unless domains.empty? # Every domain must match some entailed type resource_acceptable = Array(types).empty? || domains.any? {|d| types.include?(d)} # Resource may still be acceptable if types include schema:Role, and any any other resource references `resource` using this property resource_acceptable || types.include?(RDF::Vocab::SCHEMA.Role) && - !queryable.query(predicate: self, object: resource).empty? + !queryable.query({predicate: self, object: resource}).empty? end ## # Schema.org requires that if the property has a range, and the resource has a type that some type matches some range. If the resource is a datatyped Literal, and the range includes a datatype, the resource must be consistent with that. # @@ -50,11 +50,11 @@ # @param [RDF::Resource] resource # @param [RDF::Queryable] queryable # @param [Hash{Symbol => Object}] options ({}) # @option options [Array<RDF::Vocabulary::Term>] :types # Fully entailed types of resource, if not provided, they are queried - def range_compatible_schema?(resource, queryable, options = {}) + def range_compatible_schema?(resource, queryable, **options) raise RDF::Reasoner::Error, "#{self} can't get ranges" unless property? if !(ranges = Array(self.rangeIncludes) - [RDF::OWL.Thing]).empty? if resource.literal? ranges.any? do |range| case range @@ -121,26 +121,26 @@ true # Special case for schema boolean resources elsif ranges.include?(RDF::Vocab::SCHEMA.URL) && resource.uri? true # schema:URL matches URI resources elsif ranges == [RDF::Vocab::SCHEMA.Text] && resource.uri? # Allowed if resource is untyped - entailed_types(resource, queryable, options).empty? + entailed_types(resource, queryable, **options).empty? elsif literal_range?(ranges) false # If resource isn't literal, this is a range violation else # Fully entailed types of the resource - types = entailed_types(resource, queryable, options) + types = entailed_types(resource, queryable, **options) # Every range must match some entailed type resource_acceptable = Array(types).empty? || ranges.any? {|d| types.include?(d)} # Resource may still be acceptable if it has the same property with an acceptable value resource_acceptable || # Resource also acceptable if it is a Role, and the Role object contains the same predicate having a compatible object types.include?(RDF::Vocab::SCHEMA.Role) && - queryable.query(subject: resource, predicate: self).any? do |stmt| + queryable.query({subject: resource, predicate: self}).any? do |stmt| acc = self.range_compatible_schema?(stmt.object, queryable) acc end || # Resource also acceptable if it is a List, and every member of the list is range compatible with the predicate (list = RDF::List.new(subject: resource, graph: queryable)).valid? && list.all? do |member| @@ -172,12 +172,12 @@ def self.included(mod) end private # Fully entailed types - def entailed_types(resource, queryable, options = {}) + def entailed_types(resource, queryable, **options) options.fetch(:types) do - queryable.query(subject: resource, predicate: RDF.type). + queryable.query({subject: resource, predicate: RDF.type}). map {|s| (t = (RDF::Vocabulary.find_term(s.object) rescue nil)) && t.entail(:subClassOf)}. flatten. uniq. compact end \ No newline at end of file