Class: RDF::Node
- Includes:
- Resource
- Defined in:
- vendor/bundler/ruby/3.3.0/bundler/gems/ld-patch-a8edc852261e/lib/ld/patch/parser.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/extensions.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/extensions.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/lib/rdf/n3/extensions.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-reasoner-e77a80426b61/lib/rdf/reasoner/extensions.rb,
vendor/bundler/ruby/3.3.0/bundler/gems/rdf-spec-4f36efa2dbbc/lib/rdf/spec/inspects.rb
Overview
An RDF blank node, also known as an anonymous or unlabeled node.
Constant Summary collapse
- @@entailments =
{}
Constants included from SPARQL::Algebra::Expression
SPARQL::Algebra::Expression::PATTERN_PARENTS
Constants included from Util::Logger
Instance Attribute Summary collapse
- #id ⇒ String
-
#original ⇒ RDF::Node
Originally instantiated node, if any.
Class Method Summary collapse
-
.add_entailment(method, proc) ⇒ Object
Add an entailment method.
-
.uuid(format: :default) ⇒ RDF::Node
Returns a blank node with a random UUID-based identifier.
Instance Method Summary collapse
-
#+(other) ⇒ Object
Odd case of appending to a BNode identifier.
-
#==(other) ⇒ Boolean
(also: #===)
Checks whether this blank node is equal to
other
(type checking). -
#anonymous? ⇒ Boolean
(also: #unlabeled?)
Returns
true
. -
#domain_compatible?(resource, queryable, options = {}) ⇒ Boolean
Determine if the domain of a property term is consistent with the specified resource in
queryable
. -
#dup ⇒ RDF::Node
Override #dup to remember original object.
-
#entail(method) {|term| ... } ⇒ Array<Term>
Perform an entailment on this term.
-
#eql?(other) ⇒ Boolean
Determines if
self
is the same term asother
. -
#hash ⇒ Integer
Returns a hash code for this blank node.
-
#initialize(id = nil) ⇒ Node
constructor
A new instance of Node.
- #inspect ⇒ Object
-
#labeled? ⇒ Boolean
Returns
false
. - #lexical ⇒ Object
-
#lexical=(value) ⇒ Object
Original lexical value of this URI to allow for round-trip serialization.
-
#make_unique! ⇒ self
Make this term identifier unique, if it is found to be shared with another node having the same identifier.
-
#node? ⇒ Boolean
Returns
true
. -
#range_compatible?(resource, queryable, options = {}) ⇒ Boolean
Determine if the range of a property term is consistent with the specified resource in
queryable
. -
#to_ndvar(scope) ⇒ Object
Transform to a nondistinguished exisetntial variable in a formula scope.
-
#to_s ⇒ String
Returns a string representation of this blank node.
-
#to_sym ⇒ Symbol
Returns a symbol representation of this blank node.
-
#to_unique_base ⇒ String
Returns a representation of this node independent of any identifier used to initialize it.
-
#valid_extended? ⇒ Boolean
Validate extended RDF.
Methods included from Resource
Methods included from Term
#<=>, #aggregate?, #as_datetime, #as_number, #compatible?, #escape, #evaluate, #ndvars, #optimize, #sameTerm?, #term?, #terms, #to_base, #to_sparql, #to_term, #vars
Methods included from SPARQL::Algebra::Expression
cast, #constant?, #evaluate, extension, extension?, extensions, for, #invalid?, new, open, #optimize, #optimize!, parse, register_extension, #to_sxp_bin, #valid?, #validate!, #variable?
Methods included from Util::Logger
#log_debug, #log_depth, #log_error, #log_fatal, #log_info, #log_recover, #log_recovering?, #log_statistics, #log_warn, #logger
Methods included from Value
#canonicalize, #canonicalize!, #constant?, #formula?, #graph?, #inspect!, #invalid?, #iri?, #list?, #literal?, #resource?, #start_with?, #statement?, #term?, #to_nquads, #to_ntriples, #to_rdf, #to_term, #type_error, #uri?, #valid?, #validate!, #variable?
Constructor Details
#initialize(id = nil) ⇒ Node
Returns a new instance of Node.
77 78 79 80 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/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 |
Instance Attribute Details
#id ⇒ String
73 74 75 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 73 def id @id end |
#original ⇒ RDF::Node
Originally instantiated node, if any
70 71 72 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 70 def original @original end |
Class Method Details
.add_entailment(method, proc) ⇒ Object
Add an entailment method. The method accepts no arguments, and returns or yields an array of values associated with the particular entailment method
68 69 70 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-reasoner-e77a80426b61/lib/rdf/reasoner/extensions.rb', line 68 def add_entailment(method, proc) @@entailments[method] = proc end |
.uuid(format: :default) ⇒ RDF::Node
Returns a blank node with a random UUID-based identifier.
(Depends on availability of either uuid
or uuidtools
gems).
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
39 40 41 42 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 39 def self.uuid(format: :default) uuid = RDF::Util::UUID.generate(format: format) self.new(uuid) end |
Instance Method Details
#+(other) ⇒ Object
Odd case of appending to a BNode identifier
6 7 8 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/extensions.rb', line 6 def +(other) Node.new(id + other.to_s) end |
#==(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
137 138 139 140 141 142 143 144 145 146 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/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 |
#anonymous? ⇒ Boolean Also known as: unlabeled?
Returns true
.
94 95 96 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 94 def anonymous? true end |
#domain_compatible?(resource, queryable, options = {}) ⇒ Boolean
Determine if the domain of a property term is consistent with the specified resource in queryable
.
92 93 94 95 96 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-reasoner-e77a80426b61/lib/rdf/reasoner/extensions.rb', line 92 def domain_compatible?(resource, queryable, = {}) %w(owl rdfs schema).map {|r| "domain_compatible_#{r}?".to_sym}.all? do |meth| !self.respond_to?(meth) || self.send(meth, resource, queryable, **) end 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.
61 62 63 64 65 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 61 def dup node = super node.original = self.original || self node end |
#entail(method) {|term| ... } ⇒ Array<Term>
Perform an entailment on this term.
80 81 82 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-reasoner-e77a80426b61/lib/rdf/reasoner/extensions.rb', line 80 def entail(method, &block) self.send(@@entailments.fetch(method), &block) end |
#eql?(other) ⇒ Boolean
Determines if self
is the same term as other
.
In this case, nodes must be the same object
123 124 125 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 123 def eql?(other) other.is_a?(RDF::Node) && (self.original || self).equal?(other.original || other) end |
#hash ⇒ Integer
Returns a hash code for this blank node.
112 113 114 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 112 def hash @id.hash end |
#inspect ⇒ Object
19 20 21 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-spec-4f36efa2dbbc/lib/rdf/spec/inspects.rb', line 19 def inspect "RDF::Node(#{to_base})" end |
#labeled? ⇒ Boolean
Returns false
.
104 105 106 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 104 def labeled? !unlabeled? end |
#lexical ⇒ Object
579 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ld-patch-a8edc852261e/lib/ld/patch/parser.rb', line 579 def lexical; @lexical; end |
#lexical=(value) ⇒ Object
Original lexical value of this URI to allow for round-trip serialization.
578 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/ld-patch-a8edc852261e/lib/ld/patch/parser.rb', line 578 def lexical=(value); @lexical = value; end |
#make_unique! ⇒ self
Make this term identifier unique, if it is found to be shared with another node having the same identifier
160 161 162 163 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 160 def make_unique! @id = to_unique_base[2..-1] self end |
#node? ⇒ Boolean
Returns true
.
86 87 88 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 86 def node? true end |
#range_compatible?(resource, queryable, options = {}) ⇒ Boolean
Determine if the range of a property term is consistent with the specified resource in queryable
.
Specific entailment regimes should insert themselves before this to apply the appropriate semantic condition
108 109 110 111 112 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-reasoner-e77a80426b61/lib/rdf/reasoner/extensions.rb', line 108 def range_compatible?(resource, queryable, = {}) %w(owl rdfs schema).map {|r| "range_compatible_#{r}?".to_sym}.all? do |meth| !self.respond_to?(meth) || self.send(meth, resource, queryable, ) end end |
#to_ndvar(scope) ⇒ Object
Transform to a nondistinguished exisetntial variable in a formula scope
return [RDF::Query::Variable]
121 122 123 124 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-n3-a6ef81a7e1ce/lib/rdf/n3/extensions.rb', line 121 def to_ndvar(scope) label = "#{id}_#{scope ? scope.id : 'base'}_undext" RDF::Query::Variable.new(label, existential: true, distinguished: false) end |
#to_s ⇒ String
Returns a string representation of this blank node.
169 170 171 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 169 def to_s "_:%s" % @id.to_s end |
#to_sym ⇒ Symbol
Returns a symbol representation of this blank node.
178 179 180 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 178 def to_sym @id.to_s.to_sym end |
#to_unique_base ⇒ String
Returns a representation of this node independent of any identifier used to initialize it
153 154 155 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/rdf-884e3ef78084/lib/rdf/model/node.rb', line 153 def to_unique_base original ? original.to_unique_base : "_:g#{__id__.to_i.abs}" end |
#valid_extended? ⇒ Boolean
Validate extended RDF
30 31 32 |
# File 'vendor/bundler/ruby/3.3.0/bundler/gems/json-ld-f1de87658826/lib/json/ld/extensions.rb', line 30 def valid_extended? valid? end |