Class: RDF::Raptor::FFI::V2::Statement

Inherits:
FFI::Struct
  • Object
show all
Includes:
RDF::Raptor::FFI
Defined in:
lib/rdf/raptor/ffi/v2/statement.rb

Overview

Constant Summary

Constants included from RDF::Raptor::FFI

ENGINE

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from RDF::Raptor::FFI

#version

Constructor Details

#initialize(ptr = nil, factory = nil) ⇒ Statement

Returns a new instance of Statement.

Parameters:

  • ptr (FFI::Pointer) (defaults to: nil)
  • factory (#create_node) (defaults to: nil)


16
17
18
19
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 16

def initialize(ptr = nil, factory = nil)
  super(ptr)
  @factory = factory if factory
end

Instance Attribute Details

#graph_nameRDF::Resource

Returns:

  • (RDF::Resource)


33
34
35
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 33

def graph_name
  @graph_name
end

#idObject

Returns:

  • (Object)


30
31
32
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 30

def id
  @id
end

Instance Method Details

#free Also known as: release

This method returns an undefined value.

Releases libraptor memory associated with this structure.



137
138
139
140
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 137

def free
  V2.raptor_free_statement(self)
  @subject = @predicate = @object = nil # Allow GC to start
end

#objectRDF::Term

Returns:

  • (RDF::Term)


79
80
81
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 79

def object
  @object ||= V2::Term.new(self[:object], @factory).value
end

#object=(value)

This method returns an undefined value.

Sets the object term from an RDF::Term.

The value must be one of RDF::Resource or RDF::Literal.

Parameters:

  • value (RDF::Term)


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 90

def object=(value)
  @object = nil
  case value
    when RDF::Node
      self[:object] = V2.raptor_new_term_from_blank(V2.world, value.id.to_s)
    when RDF::URI
      self[:object] = V2.raptor_new_term_from_uri_string(V2.world, value.to_s)
    when RDF::Literal
      self[:object] = V2.raptor_new_term_from_literal(V2.world, value.to_s,
        value.datatype? ? V2.raptor_new_uri(V2.world, value.datatype.to_s) : nil,
        value.language? ? value.language.to_s : nil)
    else
      raise ArgumentError, "object term must be an RDF::Node, RDF::URI, or RDF::Literal"
  end
  @object = value
end

#predicateRDF::URI

Returns:

  • (RDF::URI)


61
62
63
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 61

def predicate
  @predicate ||= V2::Term.new(self[:predicate], @factory).value
end

#predicate=(uri)

This method returns an undefined value.

Sets the predicate term from an RDF::URI.

Parameters:

  • uri (RDF::URI)

Raises:

  • (ArgumentError)


70
71
72
73
74
75
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 70

def predicate=(uri)
  @predicate = nil
  raise ArgumentError, "predicate term must be an RDF::URI" unless uri.is_a?(RDF::URI)
  self[:predicate] = V2.raptor_new_term_from_uri_string(V2.world, uri.to_s)
  @predicate = uri
end

#reset!

This method returns an undefined value.



129
130
131
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 129

def reset!
  @subject = @predicate = @object = @graph_name = nil
end

#subjectRDF::Resource

Returns:

  • (RDF::Resource)


37
38
39
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 37

def subject
  @subject ||= V2::Term.new(self[:subject], @factory).value
end

#subject=(resource)

This method returns an undefined value.

Sets the subject term from an RDF::Resource.

Parameters:

  • resource (RDF::Resource)


46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 46

def subject=(resource)
  @subject = nil
  case resource
    when RDF::Node
      self[:subject] = V2.raptor_new_term_from_blank(V2.world, resource.id.to_s)
    when RDF::URI
      self[:subject] = V2.raptor_new_term_from_uri_string(V2.world, resource.to_s)
    else
      raise ArgumentError, "subject term must be an RDF::Node or RDF::URI"
  end
  @subject = resource
end

#to_quadArray(RDF::Resource, RDF::URI, RDF::Term, nil)

Returns:

  • (Array(RDF::Resource, RDF::URI, RDF::Term, nil))

See Also:

  • Statement#to_quad


117
118
119
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 117

def to_quad
  [subject, predicate, object, graph_name]
end

#to_rdfRDF::Statement

Returns:

  • (RDF::Statement)


123
124
125
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 123

def to_rdf
  RDF::Statement.new(subject, predicate, object, graph_name: graph_name)
end

#to_tripleArray(RDF::Resource, RDF::URI, RDF::Term)

Returns:

  • (Array(RDF::Resource, RDF::URI, RDF::Term))

See Also:

  • Statement#to_triple


110
111
112
# File 'lib/rdf/raptor/ffi/v2/statement.rb', line 110

def to_triple
  [subject, predicate, object]
end