lib/rdf/model/statement.rb in rdf-1.0.10.2 vs lib/rdf/model/statement.rb in rdf-1.1.0.p0
- old
+ new
@@ -7,11 +7,10 @@
# p = RDF::DC.creator
# o = RDF::URI.new("http://ar.to/#self")
# RDF::Statement.new(s, p, o)
#
# @example Creating an RDF statement with a context
- # uri = RDF::URI("http://example/")
# RDF::Statement.new(s, p, o, :context => uri)
#
# @example Creating an RDF statement from a `Hash`
# RDF::Statement.new({
# :subject => RDF::URI.new("http://rubygems.org/gems/rdf"),
@@ -57,19 +56,17 @@
# @option options [RDF::Resource] :subject (nil)
# @option options [RDF::URI] :predicate (nil)
# @option options [RDF::Term] :object (nil)
# @option options [RDF::Resource] :context (nil)
# Note, in RDF 1.1, a context MUST be an IRI.
- # @return [RDF::Statement]
#
# @overload initialize(subject, predicate, object, options = {})
# @param [RDF::Resource] subject
# @param [RDF::URI] predicate
# @param [RDF::Term] object
# @param [Hash{Symbol => Object}] options
# @option options [RDF::Resource] :context (nil)
- # @return [RDF::Statement]
def initialize(subject = nil, predicate = nil, object = nil, options = {})
case subject
when Hash
@options = subject.dup
@subject = @options.delete(:subject)
@@ -107,34 +104,22 @@
def statement?
true
end
##
- # Returns `true` if any element of the statement is not a
- # URI, Node or Literal.
- #
# @return [Boolean]
- def variable?
- !(has_subject? && subject.resource? &&
- has_predicate? && predicate.resource? &&
- has_object? && (object.resource? || object.literal?) &&
- (has_context? ? context.resource? : true ))
- end
-
- ##
- # @return [Boolean]
def invalid?
!valid?
end
##
# @return [Boolean]
def valid?
- has_subject? && subject.resource? && subject.valid? &&
- has_predicate? && predicate.uri? && predicate.valid? &&
- has_object? && object.term? && object.valid? &&
- (has_context? ? context.resource? && context.valid? : true )
+ has_subject? && subject.valid? &&
+ has_predicate? && predicate.valid? &&
+ has_object? && object.valid? &&
+ (has_context? ? context.valid? : true )
end
##
# @return [Boolean]
def asserted?
@@ -182,15 +167,16 @@
def has_object?
!!object
end
##
- # Returns `true` if any resource of this statement is a blank node.
+ # Returns `true` if the subject or object of this statement is a blank
+ # node.
#
# @return [Boolean]
def has_blank_nodes?
- to_quad.compact.any?(&:node?)
+ (has_object? && object.node?) || (has_subject? && subject.node?)
end
##
# @param [Statement] other
# @return [Boolean]
@@ -255,35 +241,9 @@
[subject, predicate, object]
end
alias_method :to_a, :to_triple
alias_method :to_ary, :to_triple
-
- ##
- # Canonicalizes each unfrozen term in the statement
- #
- # @return [RDF::Statement] `self`
- # @since 1.0.8
- # @raise [ArgumentError] if any element cannot be canonicalized.
- def canonicalize!
- 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.context.canonicalize! if has_context? && !self.context.frozen?
- self.validate!
- self
- end
-
- ##
- # Returns a version of the statement with each position in canonical form
- #
- # @return [RDF::Statement] `self` or nil if statement cannot be canonicalized
- # @since 1.0.8
- def canonicalize
- self.dup.canonicalize!
- rescue ArgumentError
- nil
- end
##
# Returns the terms of this statement as a `Hash`.
#
# @param [Symbol] subject_key