Class: Java::ComHpHplJenaRdfModelImpl::ResourceImpl

Inherits:
Object
  • Object
show all
Defined in:
lib/jena_jruby/node_utils.rb

Instance Method Summary collapse

Instance Method Details

#each_property(property = nil, &block) ⇒ Object

Yield to the given block for each statement of this resource with predicate ‘property`. If `property` is nil, yield to the block for every statement whose subject is this resource.



58
59
60
# File 'lib/jena_jruby/node_utils.rb', line 58

def each_property( property = nil, &block )
  listProperties( property ).each( &block )
end

#property_values(props = nil, model = nil) ⇒ Object

Return a list of the values of the given properties of this resource. Each property may be specified as a Property object, a string denoting the URI, or a string denoting the URI in prefix:name format, which will be expanded using the prefix table attached to the resource’s model



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/jena_jruby/node_utils.rb', line 66

def property_values( props = nil, model = nil )
  model ||= getModel
  return [] unless model

  values = []
  resolve_properties( props, model ).each do |p|
    model.listStatements( self, p, nil ).each do |stmt|
      values << stmt.getObject
    end
  end
  values
end

#resolve_properties(props = nil, model = nil) ⇒ Object

Return a list of Jena Property objects corresponding to the list of property names props. Each member of props is either

  • a Property object, which is returned unchanged

  • a URI string, which is converted to a Property

  • an abbreviated URI in prefix:name form, which is expanded using the prefixes defined in the current model before being converted to a Property object

In the special case of props = nil, the returned list is all of the distinct properties attached to this resource



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/jena_jruby/node_utils.rb', line 88

def resolve_properties( props = nil, model = nil )
  props = [props] unless props.is_a? Array
  model ||= self.getModel

  unless props
    return model.listStatements( self, nil, nil ).map {|stmt| stmt.getPredicate} .uniq
  end

  props.map do |p|
    case
    when p.is_a?( Jena::Core::Property )
      p
    when model
      model.getProperty( model.expandPrefix( p ) )
    else
      Jena::Core::ResourceFactory.getProperty( p )
    end
  end
end

#typesObject

Return the resource types



51
52
53
# File 'lib/jena_jruby/node_utils.rb', line 51

def types
  Jena::Node.types self
end