Class: RDF::Node
Overview
An RDF blank node, also known as an anonymous or unlabeled node.
Instance Attribute Summary collapse
- #id ⇒ String
-
#original ⇒ RDF::Node
Originally instantiated node, if any.
Class Method Summary collapse
-
.intern(id) ⇒ RDF::Node
Alias for ‘RDF::Node.new`, at the moment.
-
.uuid(options = {}) ⇒ RDF::Node
Returns a blank node with a random UUID-based identifier.
Instance Method Summary collapse
-
#==(other) ⇒ Boolean
(also: #===)
Checks whether this blank node is equal to ‘other` (type checking).
-
#anonymous? ⇒ Boolean
(also: #unlabeled?)
Returns ‘true`.
-
#dup ⇒ RDF::Node
Override #dup to remember original object.
-
#eql?(other) ⇒ Boolean
Determins if ‘self` is the same term as `other`.
-
#hash ⇒ Fixnum
Returns a hash code for this blank node.
-
#initialize(id = nil) ⇒ Node
constructor
A new instance of Node.
-
#labeled? ⇒ Boolean
Returns ‘false`.
-
#node? ⇒ Boolean
Returns ‘true`.
-
#to_s ⇒ String
Returns a string representation of this blank node.
-
#to_sym ⇒ Symbol
Returns a symbol representation of this blank node.
Methods included from Resource
Methods included from Term
Methods included from Value
#graph?, #inspect, #inspect!, #iri?, #literal?, #resource?, #statement?, #to_ntriples, #to_quad, #to_rdf, #type_error, #uri?, #variable?
Constructor Details
#initialize(id = nil) ⇒ Node
Returns a new instance of Node.
69 70 71 |
# File 'lib/rdf/model/node.rb', line 69 def initialize(id = nil) @id = (id || "g#{__id__.to_i.abs}").to_s end |
Instance Attribute Details
#id ⇒ String
65 66 67 |
# File 'lib/rdf/model/node.rb', line 65 def id @id end |
#original ⇒ RDF::Node
Originally instantiated node, if any
62 63 64 |
# File 'lib/rdf/model/node.rb', line 62 def original @original end |
Class Method Details
.intern(id) ⇒ RDF::Node
Alias for ‘RDF::Node.new`, at the moment.
43 44 45 |
# File 'lib/rdf/model/node.rb', line 43 def self.intern(id) self.new(id) end |
.uuid(options = {}) ⇒ RDF::Node
Returns a blank node with a random UUID-based identifier.
22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/rdf/model/node.rb', line 22 def self.uuid( = {}) case when [:grammar] # The UUID is generated such that its initial part is guaranteed # to match the given `grammar`, e.g. `/^[A-Za-z][A-Za-z0-9]*/`. # Some RDF storage systems (e.g. AllegroGraph) require this. # @see http://github.com/bendiken/rdf/pull/43 uuid = RDF::Util::UUID.generate() until uuid =~ [:grammar] else uuid = RDF::Util::UUID.generate() end self.new(uuid) end |
Instance Method Details
#==(other) ⇒ Boolean Also known as: ===
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
128 129 130 131 132 133 134 135 136 |
# File 'lib/rdf/model/node.rb', line 128 def ==(other) case other when Literal # If other is a Literal, reverse test to consolodate complex type checking logic other == self else other.respond_to?(:node?) && other.node? && other.respond_to?(:id) && @id == other.id end end |
#anonymous? ⇒ Boolean Also known as: unlabeled?
Returns ‘true`.
85 86 87 |
# File 'lib/rdf/model/node.rb', line 85 def anonymous? true end |
#dup ⇒ RDF::Node
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.
53 54 55 56 57 |
# File 'lib/rdf/model/node.rb', line 53 def dup node = super node.original = self.original || self node end |
#eql?(other) ⇒ Boolean
Determins if ‘self` is the same term as `other`.
In this case, nodes must be the same object
114 115 116 |
# File 'lib/rdf/model/node.rb', line 114 def eql?(other) other.is_a?(RDF::Node) && (self.original || self).equal?(other.original || other) end |
#hash ⇒ Fixnum
Returns a hash code for this blank node.
103 104 105 |
# File 'lib/rdf/model/node.rb', line 103 def hash @id.hash end |
#labeled? ⇒ Boolean
Returns ‘false`.
95 96 97 |
# File 'lib/rdf/model/node.rb', line 95 def labeled? !unlabeled? end |
#node? ⇒ Boolean
Returns ‘true`.
77 78 79 |
# File 'lib/rdf/model/node.rb', line 77 def node? true end |
#to_s ⇒ String
Returns a string representation of this blank node.
143 144 145 |
# File 'lib/rdf/model/node.rb', line 143 def to_s "_:%s" % @id.to_s end |
#to_sym ⇒ Symbol
Returns a symbol representation of this blank node.
152 153 154 |
# File 'lib/rdf/model/node.rb', line 152 def to_sym @id.to_s.to_sym end |