Object
Creates a new blank node with the specified ID (?? confirm)
# File rdf/redland/node.rb, line 84 def Node.anon(id) n = Node.new('') n.bnode(id) n end
You shouldn't use this. Used internally for cleanup.
# File rdf/redland/node.rb, line 79 def Node.create_finalizer(node) proc {|id| Redland::librdf_free_node(node) } end
Ensures that the argument is a node by constructing one or returning nil (?? confirm)
# File rdf/redland/node.rb, line 158 def Node.ensure(node) case node when Node my_node = Redland.librdf_new_node_from_node(node.node) when SWIG::TYPE_p_librdf_node_s my_node = Redland.librdf_new_node_from_node(node) when Uri my_node = Redland.librdf_new_node_from_uri($world.world,node.uri) when URI my_node = Redland.librdf_new_node_from_uri_string($world.world,node.to_s) else my_node = nil end return my_node end
Create an RDF Node
Resource or property node creation
n1 = Node.new(Uri.new("http://example.com/foo"))
String literal node creation
n2 = Node.new("foo")
# File rdf/redland/node.rb, line 21 def initialize(arg=nil) if arg.class == String temp = arg arg = {} arg[:literal]= temp @node = self.node_from_hash(arg) elsif arg.class == Hash @node = node_from_hash(arg) else @node = Node.ensure(arg) end raise RedlandError.new("Node construction failed") if not @node ObjectSpace.define_finalizer(self,Node.create_finalizer(@node)) end
Equivalency. Only works for comparing two Nodes
# File rdf/redland/node.rb, line 106 def ==(other) return (Redland.librdf_node_equals(self.node,other.node) != 0) end
Return true if node is a blank node
# File rdf/redland/node.rb, line 101 def blank? return (Redland.librdf_node_is_blank(self.node) !=0) end
returns the blank identifier for this node if the internal model is a blank node
# File rdf/redland/node.rb, line 148 def blank_identifier() unless self.blank? raise NodeTypeError.new("Can't get blank identifier for node type %s" % self.node_type) else return Redland.librdf_node_get_blank_identifier(self.node) end end
Sets this node's value to a blank node with the specified ID (?? confirm)
# File rdf/redland/node.rb, line 74 def bnode(id=nil) @node = Redland.librdf_new_node_from_blank_identifier($world.world,id) end
returns a Literal if the node is a literal type
# File rdf/redland/node.rb, line 139 def literal unless self.literal? raise NodeTypeError.new("Can't get literal value for node type %s" % self.node_type) end return Literal.from_node(self.node) end
Return true if node is a literal
# File rdf/redland/node.rb, line 91 def literal? return (Redland.librdf_node_is_literal(self.node) !=0) end
sets this node's value using a blank or URI extracted from a Hash (?? confirm)
# File rdf/redland/node.rb, line 38 def node_from_hash(hash) if hash.key?(:blank) node = Redland.librdf_new_node_from_blank_identifier($world.world,hash[:blank]) end if hash.key?(:from_object) if hash.key?(:do_not_copy) node = hash[:from_object] else node = Redland.librdf_new_node_from_node(hash[:from_object]) end end if hash.key?(:uri_string) node = Redland.librdf_new_node_from_uri_string($world.world,hash[:uri_string]) end if hash.key?(:literal) node = node_from_literal(hash) end return node end
sets this node's value using a literal value extracted from a Hash (?? confirm)
# File rdf/redland/node.rb, line 61 def node_from_literal(hash) xml_language = hash.key?(:xml_language) ? hash[:xml_language] : "" wf_xml = hash.key?(:wf_xml?) ? 1 : 0 if hash.key?(:datatype) datatype = hash[:datatype] node = Redland.librdf_new_node_from_typed_literal($world.world,hash[:literal],xml_language,datatype.uri) else node = Redland.librdf_new_node_from_literal($world.world,hash[:literal],xml_language,wf_xml) end return node end
Get the type of this node as a string (Node.node_types)
# File rdf/redland/node.rb, line 125 def node_type() return @@node_types[Redland.librdf_node_get_type(self.node)] end
Return true if node is a resource with a URI
# File rdf/redland/node.rb, line 96 def resource? return (Redland.librdf_node_is_resource(self.node) !=0) end
Convert this to a string
# File rdf/redland/node.rb, line 111 def to_s if self.literal? Redland.librdf_node_get_literal_value(self.node) elsif self.blank? Redland.librdf_node_get_blank_identifier(self.node) elsif self.resource? uri = Redland.librdf_node_get_uri(self.node) Redland.librdf_uri_to_string(uri) unless uri.nil? else nil end end
(C) Copyright 2004-2013 Dave Beckett, (C) Copyright 2004-2005 University of Bristol