Class: Reddy::BNode
- Inherits:
-
Object
- Object
- Reddy::BNode
- Defined in:
- lib/reddy/bnode.rb
Overview
The BNode class creates RDF blank nodes.
Instance Attribute Summary collapse
-
#identifier ⇒ Object
readonly
The identifier used used for this BNode.
Instance Method Summary collapse
-
#eql?(other) ⇒ Boolean
(also: #==)
Compare BNodes.
-
#hash ⇒ Object
Needed for uniq.
-
#initialize(identifier = nil, context = {}) ⇒ BNode
constructor
Create a new BNode, optionally accept a identifier for the BNode.
- #inspect ⇒ Object
-
#to_n3 ⇒ String
Exports the BNode in N-Triples form.
-
#to_ntriples ⇒ Object
Exports the BNode in N-Triples form.
-
#to_s ⇒ Object
Return BNode identifier.
-
#xml_args ⇒ Object
Output URI as resource reference for RDF/XML.
Constructor Details
#initialize(identifier = nil, context = {}) ⇒ BNode
Create a new BNode, optionally accept a identifier for the BNode. Otherwise, generated sequentially.
A BNode may have a bank (empty string) identifier, which will be equivalent to another blank identified BNode.
Identifiers only have meaning within a particular parsing context, and are used to lookup previoiusly defined BNodes using the same identifier. Names are not preserved within the underlying storage model.
20 21 22 23 24 25 26 27 28 |
# File 'lib/reddy/bnode.rb', line 20 def initialize(identifier = nil, context = {}) if identifier != nil && self.valid_id?(identifier) identifier = identifier.sub(/nbn\d+[a-z]+N/, '') # creating a named BNode from a named BNode # Generate a name if it's blank. Always prepend "named" to avoid generation overlap @identifier = context[identifier] ||= generate_bn_identifier(identifier) else @identifier = generate_bn_identifier end end |
Instance Attribute Details
#identifier ⇒ Object (readonly)
The identifier used used for this BNode.
65 66 67 |
# File 'lib/reddy/bnode.rb', line 65 def identifier @identifier end |
Instance Method Details
#eql?(other) ⇒ Boolean Also known as: ==
Compare BNodes. BNodes are equivalent if they have the same identifier
70 71 72 73 |
# File 'lib/reddy/bnode.rb', line 70 def eql?(other) other.class == self.class && other.identifier == self.identifier end |
#hash ⇒ Object
Needed for uniq
77 |
# File 'lib/reddy/bnode.rb', line 77 def hash; self.to_s.hash; end |
#inspect ⇒ Object
79 80 81 |
# File 'lib/reddy/bnode.rb', line 79 def inspect "[bn:#{identifier}]" end |
#to_n3 ⇒ String
Exports the BNode in N-Triples form.
Example
b = BNode.new; b.to_n3 # => returns a string of the BNode in n3 form
44 45 46 |
# File 'lib/reddy/bnode.rb', line 44 def to_n3 "_:#{self.identifier}" end |
#to_ntriples ⇒ Object
Exports the BNode in N-Triples form.
Syonym for to_n3
52 53 54 |
# File 'lib/reddy/bnode.rb', line 52 def to_ntriples self.to_n3 end |
#to_s ⇒ Object
Return BNode identifier
31 32 33 |
# File 'lib/reddy/bnode.rb', line 31 def to_s return self.identifier.to_s end |
#xml_args ⇒ Object
Output URI as resource reference for RDF/XML
Example
b = BNode.new("foo"); b.xml_args # => [{"rdf:nodeID" => "foo"}]
60 61 62 |
# File 'lib/reddy/bnode.rb', line 60 def xml_args [{"rdf:nodeID" => self.identifier}] end |