Class: RDF::Statement
- Inherits:
-
Object
- Object
- RDF::Statement
- Includes:
- Value
- Defined in:
- lib/rdf/model/statement.rb
Overview
An RDF statement.
Direct Known Subclasses
Instance Attribute Summary (collapse)
- - (RDF::Resource) context
- - (Object) id
- - (RDF::Term) object
- - (RDF::URI) predicate
- - (RDF::Resource) subject
Instance Method Summary (collapse)
- - (Boolean) ==(other)
- - (Boolean) ===(other)
- - (RDF::Term) [](index)
- - (RDF::Term) []=(index, value)
- - (Boolean) asserted?
- - (Boolean) eql?(other)
-
- (Boolean) has_blank_nodes?
Returns
trueif the subject or object of this statement is a blank node. - - (Boolean) has_context?
- - (Boolean) has_graph?
- - (Boolean) has_object?
- - (Boolean) has_predicate?
- - (Boolean) has_subject?
- - (Boolean) inferred?
-
- (Statement) initialize(subject = nil, predicate = nil, object = nil, options = {})
constructor
A new instance of Statement.
- - (Boolean) invalid?
- - (Boolean) quoted?
-
- (RDF::Graph) reified(options = {})
Returns a graph containing this statement in reified form.
-
- (Boolean) statement?
Returns
trueto indicate that this value is a statement. -
- (Hash{Symbol => RDF::Term}) to_hash(subject_key = :subject, predicate_key = :predicate, object_key = :object, context_key = :context)
Returns the terms of this statement as a
Hash. - - (Array(RDF::Term)) to_quad
-
- (String) to_s
Returns a string representation of this statement.
- - (Array(RDF::Term)) to_triple (also: #to_ary, #to_a)
- - (Boolean) valid?
Methods included from Value
#graph?, #inspect, #inspect!, #iri?, #literal?, #node?, #resource?, #to_ntriples, #to_rdf, #uri?, #variable?
Constructor Details
- (Object) initialize(options = {}) - (Object) initialize(subject, predicate, object, options = {})
A new instance of Statement
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/rdf/model/statement.rb', line 66 def initialize(subject = nil, predicate = nil, object = nil, = {}) case subject when Hash = subject.dup @subject = .delete(:subject) @predicate = .delete(:predicate) @object = .delete(:object) else = !.empty? ? .dup : {} @subject = subject @predicate = predicate @object = object end @id = .delete(:id) if .has_key?(:id) @context = .delete(:context) initialize! end |
Instance Attribute Details
- (RDF::Resource) context
41 42 43 |
# File 'lib/rdf/model/statement.rb', line 41 def context @context end |
- (Object) id
38 39 40 |
# File 'lib/rdf/model/statement.rb', line 38 def id @id end |
- (RDF::URI) predicate
47 48 49 |
# File 'lib/rdf/model/statement.rb', line 47 def predicate @predicate end |
- (RDF::Resource) subject
44 45 46 |
# File 'lib/rdf/model/statement.rb', line 44 def subject @subject end |
Instance Method Details
- (Boolean) ==(other)
185 186 187 |
# File 'lib/rdf/model/statement.rb', line 185 def ==(other) to_a == other.to_a end |
- (Boolean) ===(other)
192 193 194 195 196 197 198 |
# File 'lib/rdf/model/statement.rb', line 192 def ===(other) return false if has_context? && context != other.context return false if has_subject? && subject != other.subject return false if has_predicate? && predicate != other.predicate return false if has_object? && object != other.object return true end |
- (RDF::Term) [](index)
203 204 205 206 207 208 209 210 211 |
# File 'lib/rdf/model/statement.rb', line 203 def [](index) case index when 0 then self.subject when 1 then self.predicate when 2 then self.object when 3 then self.context else nil end end |
- (RDF::Term) []=(index, value)
217 218 219 220 221 222 223 224 225 |
# File 'lib/rdf/model/statement.rb', line 217 def []=(index, value) case index when 0 then self.subject = value when 1 then self.predicate = value when 2 then self.object = value when 3 then self.context = value else nil end end |
- (Boolean) asserted?
120 121 122 |
# File 'lib/rdf/model/statement.rb', line 120 def asserted? !quoted? end |
- (Boolean) eql?(other)
178 179 180 |
# File 'lib/rdf/model/statement.rb', line 178 def eql?(other) other.is_a?(Statement) && self == other && self.context == other.context end |
- (Boolean) has_blank_nodes?
Returns true if the subject or object of this statement is a blank
node.
171 172 173 |
# File 'lib/rdf/model/statement.rb', line 171 def has_blank_nodes? (has_object? && object.node?) || (has_subject? && subject.node?) end |
- (Boolean) has_context?
144 145 146 |
# File 'lib/rdf/model/statement.rb', line 144 def has_context? !!context end |
- (Boolean) has_graph?
138 139 140 |
# File 'lib/rdf/model/statement.rb', line 138 def has_graph? has_context? end |
- (Boolean) has_object?
162 163 164 |
# File 'lib/rdf/model/statement.rb', line 162 def has_object? !!object end |
- (Boolean) has_predicate?
156 157 158 |
# File 'lib/rdf/model/statement.rb', line 156 def has_predicate? !!predicate end |
- (Boolean) has_subject?
150 151 152 |
# File 'lib/rdf/model/statement.rb', line 150 def has_subject? !!subject end |
- (Boolean) inferred?
132 133 134 |
# File 'lib/rdf/model/statement.rb', line 132 def inferred? false end |
- (Boolean) invalid?
108 109 110 |
# File 'lib/rdf/model/statement.rb', line 108 def invalid? !valid? end |
- (Boolean) quoted?
126 127 128 |
# File 'lib/rdf/model/statement.rb', line 126 def quoted? false end |
- (RDF::Graph) reified(options = {})
Returns a graph containing this statement in reified form.
285 286 287 288 289 290 291 292 293 |
# File 'lib/rdf/model/statement.rb', line 285 def reified( = {}) RDF::Graph.new([:context]) do |graph| subject = [:subject] || RDF::Node.new([:id]) graph << [subject, RDF.type, RDF[:Statement]] graph << [subject, RDF.subject, self.subject] graph << [subject, RDF.predicate, self.predicate] graph << [subject, RDF.object, self.object] end end |
- (Boolean) statement?
Returns true to indicate that this value is a statement.
102 103 104 |
# File 'lib/rdf/model/statement.rb', line 102 def statement? true end |
- (Hash{Symbol => RDF::Term}) to_hash(subject_key = :subject, predicate_key = :predicate, object_key = :object, context_key = :context)
Returns the terms of this statement as a Hash.
249 250 251 |
# File 'lib/rdf/model/statement.rb', line 249 def to_hash(subject_key = :subject, predicate_key = :predicate, object_key = :object, context_key = :context) {subject_key => subject, predicate_key => predicate, object_key => object, context_key => context} end |
- (Array(RDF::Term)) to_quad
229 230 231 |
# File 'lib/rdf/model/statement.rb', line 229 def to_quad [subject, predicate, object, context] end |
- (String) to_s
Returns a string representation of this statement.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
# File 'lib/rdf/model/statement.rb', line 257 def to_s StringIO.open do |buffer| buffer << case subject when RDF::Node then subject.to_s when RDF::URI then "<#{subject}>" else subject.inspect end buffer << " <#{predicate}> " buffer << case object when RDF::Literal then object.to_s when RDF::Node then object.to_s when RDF::URI then "<#{object}>" else object.inspect end buffer << case context when nil then " ." else " <#{context}> ." end buffer.string end end |
- (Array(RDF::Term)) to_triple Also known as: to_ary, to_a
235 236 237 |
# File 'lib/rdf/model/statement.rb', line 235 def to_triple [subject, predicate, object] end |
- (Boolean) valid?
114 115 116 |
# File 'lib/rdf/model/statement.rb', line 114 def valid? has_subject? && has_predicate? && has_object? end |