Module: Jena::Node
- Defined in:
- lib/jena_jruby/node_utils.rb
Overview
A collection of utilities for manipulating Jena RDF Resources and Literals, collectively known as RDFNodes.
Class Method Summary collapse
-
.literal_types(node, default_type = nil) ⇒ Object
Return an array of the datatype of the given literal, if defined, and including the default_type if non-nil.
-
.resource_types(node, default_type = nil) ⇒ Object
Return the values of ‘rdf:type` for the given resource.
-
.types(node, default_type = nil) ⇒ Object
Return the types of a node, which will be an array of the RDF types for a resource, or an array of the (zero or one) datatypes if the node is a literal.
- .with_default_type(types, default_type) ⇒ Object
Class Method Details
.literal_types(node, default_type = nil) ⇒ Object
Return an array of the datatype of the given literal, if defined, and including the default_type if non-nil
23 24 25 26 |
# File 'lib/jena_jruby/node_utils.rb', line 23 def self.literal_types( node, default_type = nil ) types = node.getDatatype ? [node.getDatatype] : [] with_default_type( types, default_type ) end |
.resource_types(node, default_type = nil) ⇒ Object
Return the values of ‘rdf:type` for the given resource
15 16 17 18 19 |
# File 'lib/jena_jruby/node_utils.rb', line 15 def self.resource_types( node, default_type = nil ) types = [] node.each_property( Jena::Vocab::RDF.type ) {|stmt| types << stmt.getObject} with_default_type( types, default_type ) end |
.types(node, default_type = nil) ⇒ Object
Return the types of a node, which will be an array of the RDF types for a resource, or an array of the (zero or one) datatypes if the node is a literal. Ensures that the returned array includes the default_type f default_type is non-nil
9 10 11 12 |
# File 'lib/jena_jruby/node_utils.rb', line 9 def self.types( node, default_type = nil ) return self.resource_types( node, default_type ) if node.resource? self.literal_types( node, default_type ) end |
.with_default_type(types, default_type) ⇒ Object
30 31 32 33 |
# File 'lib/jena_jruby/node_utils.rb', line 30 def self.with_default_type( types, default_type ) types << default_type if default_type && !types.include?( default_type ) types end |