class RDF::Node
An RDF
blank node, also known as an anonymous or unlabeled node.
@example Creating a blank node with an implicit identifier
bnode = RDF::Node.new
@example Creating a blank node with an UUID identifier
bnode = RDF::Node.uuid bnode.to_s #=> "_:504c0a30-0d11-012d-3f50-001b63cac539"
Attributes
@return [String]
Originally instantiated node, if any @return [RDF::Node]
Public Class Methods
Source
# File lib/rdf/model/node.rb, line 21 def self.cache require 'rdf/util/cache' unless defined?(::RDF::Util::Cache) @cache ||= RDF::Util::Cache.new(RDF.config.node_cache_size) end
Cache size may be set through {RDF.config} using ‘node_cache_size`.
@note caching interned nodes means that two different invocations using the same symbol will result in the same node, which may not be appropriate depending on the graph from which it is used. RDF
requires that bnodes with the same label are, in fact, different bnodes, unless they are used within the same document. @return [RDF::Util::Cache] @private
Source
# File lib/rdf/model/node.rb, line 51 def self.intern(id) (cache[(id = id.to_s).to_sym] ||= self.new(id)).freeze end
Alias for ‘RDF::Node.new`, at the moment.
@private @param [#to_s] id @return [RDF::Node] @since 0.2.0
Source
# File lib/rdf/model/node.rb, line 77 def initialize(id = nil) id = nil if id.to_s.empty? @id = (id || "g#{__id__.to_i.abs}").to_s.freeze end
@param [#to_s] id
Source
# File lib/rdf/model/node.rb, line 39 def self.uuid(format: :default) uuid = RDF::Util::UUID.generate(format: format) self.new(uuid) end
Returns a blank node with a random UUID-based identifier.
(Depends on availability of either ‘uuid` or `uuidtools` gems).
@param [:default, :compact] format (:default) Formats supported by the UUID generator:
* `:default` Produces 36 characters, including hyphens separating the UUID value parts * `:compact` Produces a 32 digits (hexadecimal) value with no hyphens * `:urn` Adds the prefix urn:uuid: to the default format
Requires that the ‘uuid` gem be loadable to use `format` @return [RDF::Node]
Public Instance Methods
Source
# File lib/rdf/model/node.rb, line 137 def ==(other) if other.is_a?(Literal) # If other is a Literal, reverse test to consolodate complex type checking logic other == self else other.respond_to?(:node?) && other.node? && self.hash == other.to_term.hash && other.respond_to?(:id) && @id == other.to_term.id end end
Checks whether this blank node is equal to ‘other` (type checking).
In this case, different nodes having the same id are considered the same.
Per SPARQL data-r2/expr-equal/eq-2-2, numeric can’t be compared with other types
@param [Object] other @return [Boolean] @see www.w3.org/TR/rdf-sparql-query/#func-RDFterm-equal
Source
# File lib/rdf/model/node.rb, line 94 def anonymous? true end
Returns ‘true`.
@return [Boolean]
Source
# File lib/rdf/model/node.rb, line 61 def dup node = super node.original = self.original || self node end
Override dup
to remember original object. This allows .eql? to determine that two nodes are the same thing, and not different nodes instantiated with the same identifier. @return [RDF::Node]
Source
# File lib/rdf/model/node.rb, line 123 def eql?(other) other.is_a?(RDF::Node) && (self.original || self).equal?(other.original || other) end
Determines if ‘self` is the same term as `other`.
In this case, nodes must be the same object
@param [Node] other @return [Boolean]
Source
# File lib/rdf/model/node.rb, line 112 def hash @id.hash end
Returns a hash code for this blank node.
@return [Integer]
Source
# File lib/rdf/model/node.rb, line 104 def labeled? !unlabeled? end
Returns ‘false`.
@return [Boolean]
Source
# File lib/rdf/model/node.rb, line 160 def make_unique! @id = to_unique_base[2..-1] self end
Make this term identifier unique, if it is found to be shared with another node having the same identifier @return [self]
Source
# File lib/rdf/model/node.rb, line 86 def node? true end
Returns ‘true`.
@return [Boolean]
Source
# File lib/rdf/model/node.rb, line 169 def to_s "_:%s" % @id.to_s end
Returns a string representation of this blank node.
@return [String]
Source
# File lib/rdf/model/node.rb, line 178 def to_sym @id.to_s.to_sym end
Returns a symbol representation of this blank node.
@return [Symbol] @since 0.2.0
Source
# File lib/rdf/model/node.rb, line 153 def to_unique_base original ? original.to_unique_base : "_:g#{__id__.to_i.abs}" end
Returns a representation of this node independent of any identifier used to initialize it
@return [String]