lib/rdf/model/statement.rb in rdf-2.1.0 vs lib/rdf/model/statement.rb in rdf-2.1.1
- old
+ new
@@ -65,10 +65,11 @@
# @option options [RDF::URI] :predicate (nil)
# @option options [RDF::Resource] :object (nil)
# if not a {Resource}, it is coerced to {Literal} or {Node} depending on if it is a symbol or something other than a {Term}.
# @option options [RDF::Term] :graph_name (nil)
# Note, in RDF 1.1, a graph name MUST be an {Resource}.
+ # @option options [Boolean] :inferred used as a marker to record that this statement was inferred based on semantic relationships (T-Box).
# @return [RDF::Statement]
#
# @overload initialize(subject, predicate, object, options = {})
# @param [RDF::Term] subject
# A symbol is converted to an interned {Node}.
@@ -76,10 +77,11 @@
# @param [RDF::Resource] object
# if not a {Resource}, it is coerced to {Literal} or {Node} depending on if it is a symbol or something other than a {Term}.
# @param [Hash{Symbol => Object}] options
# @option options [RDF::Term] :graph_name (nil)
# Note, in RDF 1.1, a graph name MUST be an {Resource}.
+ # @option options [Boolean] :inferred used as a marker to record that this statement was inferred based on semantic relationships (T-Box).
# @return [RDF::Statement]
def initialize(subject = nil, predicate = nil, object = nil, options = {})
if subject.is_a?(Hash)
@options = Hash[subject] # faster subject.dup
@subject = @options.delete(:subject)
@@ -136,11 +138,11 @@
# @return [Boolean]
def variable?
!(has_subject? && subject.resource? &&
has_predicate? && predicate.resource? &&
has_object? && (object.resource? || object.literal?) &&
- (has_graph? ? graph_name.resource? : true ))
+ (has_graph? ? graph_name.resource? : true))
end
##
# @return [Boolean]
def invalid?
@@ -151,11 +153,11 @@
# @return [Boolean]
def valid?
has_subject? && subject.resource? && subject.valid? &&
has_predicate? && predicate.uri? && predicate.valid? &&
has_object? && object.term? && object.valid? &&
- (has_graph? ? graph_name.resource? && graph_name.valid? : true )
+ (has_graph? ? (graph_name.resource? && graph_name.valid?) : true)
end
##
# @return [Boolean]
def asserted?
@@ -169,11 +171,11 @@
end
##
# @return [Boolean]
def inferred?
- false
+ !!@options[:inferred]
end
##
# Determines if the statement is incomplete, vs. invalid. An incomplete statement is one in which any of `subject`, `predicate`, or `object`, are nil.
#
@@ -240,10 +242,16 @@
def eql?(other)
other.is_a?(Statement) && self == other && (self.graph_name || false) == (other.graph_name || false)
end
##
+ # Generates a Fixnum hash value as a quad.
+ def hash
+ @hash ||= to_quad.hash
+ end
+
+ ##
# Checks statement equality as a triple.
#
# @param [Object] other
# @return [Boolean]
#
@@ -343,9 +351,10 @@
self.subject.canonicalize! if has_subject? && !self.subject.frozen?
self.predicate.canonicalize! if has_predicate? && !self.predicate.frozen?
self.object.canonicalize! if has_object? && !self.object.frozen?
self.graph_name.canonicalize! if has_graph? && !self.graph_name.frozen?
self.validate!
+ @hash = nil
self
end
##
# Returns a version of the statement with each position in canonical form