Class: RDFS::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/objectmanager/rdfs/resource.rb

Overview

Represents an RDF resource and manages manipulations of that resource. Extends the ActiveRDF object by introducing a layer of data handling methods for RDFS resources.

Other objects that currently extend this class:

  • OWL::ObjectProperty

See also

ActiveRubic, OWL::Class and OWL::Thing.

Direct Known Subclasses

Image, OWL::Class, OWL::ObjectProperty, OWL::Thing

Class Attribute Summary collapse

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(resource, options = {}) ⇒ Resource

creates new resource representing an RDF resource

parameters:

  • 1 resource ( RDFS::Resource or URI String )



30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/objectmanager/rdfs/resource.rb', line 30

def initialize( resource, options={} )
  @@log.deep "Formulating new RDFS::Resource #{resource} from #{resource.class}"
  @uri = case resource
  when RDFS::Resource then
    @@log.warn "Redundant new RDFS::Resource, resource already was one."
    resource.uri
  when String then
    resource
  else
    raise ActiveRdfError, "Resource #{resource} (#{resource.class}) is improperly formulated"
    return nil
  end
end

Class Attribute Details

.class_uriObject

Returns the value of attribute class_uri.



20
21
22
# File 'lib/objectmanager/rdfs/resource.rb', line 20

def class_uri
  @class_uri
end

Instance Attribute Details

#uriObject (readonly)

uri of the resource (for instances of this class: rdf resources)



24
25
26
# File 'lib/objectmanager/rdfs/resource.rb', line 24

def uri
  @uri
end

Class Method Details

.==(other) ⇒ Object



50
51
52
# File 'lib/objectmanager/rdfs/resource.rb', line 50

def self.==(other)
  other.respond_to?(:uri) ? other.uri == self.uri : false
end

.uriObject



49
# File 'lib/objectmanager/rdfs/resource.rb', line 49

def self.uri; class_uri.uri; end

Instance Method Details

#ancestorsObject

returns the resource ancestors in the OWL graph



79
80
81
82
83
84
85
86
87
88
89
# File 'lib/objectmanager/rdfs/resource.rb', line 79

def ancestors
  begin
    # the class variable is set if this query has been executed already
    if @ancestors.nil? then
      @ancestors = ActiveRubic::Base.find( :ancestors, :subject => self )
    end
    return @ancestors
  rescue
    return Array.new
  end
end

#geopointObject Also known as: marker, wgs84, location

returns a single geopoint



134
135
136
# File 'lib/objectmanager/rdfs/resource.rb', line 134

def geopoint
  return self.geopoints.first
end

#geopoints(options = {}) ⇒ Object Also known as: markers

Checks if the resource has latitude and longitude, in which case returns self in an Array.

Perhaps this should return GMarkers or a GeoRuby object.



122
123
124
125
126
127
128
129
130
# File 'lib/objectmanager/rdfs/resource.rb', line 122

def geopoints( options={} )
#       limit = options[ :limit ]
  @@log.debug "Looking up marker for #{self.uri}"
  if ( self.has_markers? )
    return [ self ]
  else
    return Array.new
  end
end

#gmarkerObject

:nodoc:



141
142
# File 'lib/objectmanager/rdfs/resource.rb', line 141

def gmarker # :nodoc:
end

#is_class?Boolean

returns true if the resource types include OWL::Class, false otherwise

Returns:

  • (Boolean)


238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/objectmanager/rdfs/resource.rb', line 238

def is_class?
  begin
    if @is_class.nil? then
      @@log.rubic "Detecting whether #{self} is a class or an instance.."

      if ( self.types.include? OWL::Class ) then
        @is_class = true
      else
        @is_class = false
      end
    end
    return @is_class
  rescue
    @@log.error $!
  end
end

#is_image?Boolean

HACK for the Image class. See the comments over there to find out why this method uses hard-coded values (FIXME).

Returns:

  • (Boolean)


70
71
72
73
74
75
76
# File 'lib/objectmanager/rdfs/resource.rb', line 70

def is_image?
  if self.types.include? MEDIA::image
    return true
  else
    return false
  end
end

#is_mappable?Boolean Also known as: has_markers?, has_coordinates?

Returns true if the object has lat and long, otherwise false.

Returns:

  • (Boolean)


145
146
147
148
149
150
151
# File 'lib/objectmanager/rdfs/resource.rb', line 145

def is_mappable?
  if self.lat and self.long
    return true
  else
    return false
  end
end

#is_property?Boolean

returns true if the resource types include OWL::ObjectProperty, false otherwise

Returns:

  • (Boolean)


256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
# File 'lib/objectmanager/rdfs/resource.rb', line 256

def is_property?
  begin
    if @is_property.nil? then
      @@log.rubic "Detecting whether #{self} is a property.."
      if ( self.types.include? OWL::ObjectProperty ) then
        @is_property = true
      else
        @is_property = false
      end
    end
    return @is_property
  rescue
    @@log.error $!
  end
end

#latitudeObject Also known as: lat

Returns (the first) GEO::lat as Float. uses the private method get_lat_and_long.



157
158
159
160
161
162
163
164
165
166
167
168
# File 'lib/objectmanager/rdfs/resource.rb', line 157

def latitude
#       STDERR.puts "get lat"
  begin
    if @lat.nil? then
      get_lat_and_long
    end
#         @@log.debug "lat: #{@lat.first}"
    return @lat.first if @lat.any?
  rescue
    return nil
  end
end

#localnameObject Also known as: uri_id

Returns the Namespace localname of the resource.



59
60
61
# File 'lib/objectmanager/rdfs/resource.rb', line 59

def localname
  Namespace.localname( self.uri )
end

#longitudeObject Also known as: long

Returns (the first) GEO::long as Float. uses the private method get_lat_and_long.



173
174
175
176
177
178
179
180
181
182
# File 'lib/objectmanager/rdfs/resource.rb', line 173

def longitude
  begin
    if @long.nil? then
      get_lat_and_long
    end
    return @long.first if @long.any?
  rescue
    return nil
  end
end

#parentsObject

returns the resource parents in the OWL graph



92
93
94
95
96
97
98
99
100
101
# File 'lib/objectmanager/rdfs/resource.rb', line 92

def parents
  begin
    if @parents.nil?
      @parents = ActiveRubic::Base.find( :parents, :subject => self )
    end
    return @parents
  rescue
    return Array.new
  end
end

#propertiesObject

get all object properties



106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/objectmanager/rdfs/resource.rb', line 106

def properties
  @@log.debug "Looking up properties for #{self.uri}"
  begin
    # the class variable is set if this query has been executed already
    if @properties.nil? then
      @properties = ActiveRubic::Base.find( :properties, :subject => self )
    end
    return @properties
  rescue
    return Array.new
  end
end

#range(property) ⇒ Object

returns the resources in the range of a property.

parameters:

  • 1 property (OWL::ObjectProperty)



215
216
217
218
219
220
221
222
# File 'lib/objectmanager/rdfs/resource.rb', line 215

def range( property )
  begin
    results = ActiveRubic::Base.find( :within_range, :subject => self, :property => property )
    return results
  rescue
    Array.new
  end
end

#resources_for_property(p) ⇒ Object Also known as: values_for_property, predicate

Returns the results wrapped in RDFS::Resource model – this is OK when working with OWL-DL, where properties can only be assigned to resources (AFAIK) whereas in OWL-FULL the results could be also classes and other properties .. this makes less queries so is faster.



276
277
278
279
280
281
282
# File 'lib/objectmanager/rdfs/resource.rb', line 276

def resources_for_property( p )
  begin
    return my( p.uri )
  rescue
    @@log.error $!
  end
end

#stripped_uriObject

Strips protocol from the URI.



65
66
67
# File 'lib/objectmanager/rdfs/resource.rb', line 65

def stripped_uri
  return self.uri.gsub( /.*:\/\//, '' )
end

#typesObject Also known as: type

Returns resource RDF::type(s).



225
226
227
228
229
230
231
232
233
234
# File 'lib/objectmanager/rdfs/resource.rb', line 225

def types
  begin
    if @types.nil? then
      @types = my( RDF::type )
    end
    return @types
  rescue
    return Array.new
  end
end