Redland RDF Application Framework - Ruby RDoc - Class: Redland::Statement

Go to Redland Home - Language Bindings Home - Ruby API Home

Class | Redland::Statement
In: | rdf/redland/statement.rb
Parent: | Object

Redland Statement (triple class). The main means of manipulating statements is by the subject,predicate,and object properties

      require 'rdf'
      Statement creation from nodes
      statement1 = Statement.new(node1,node2,node3)
      statement2 = Statement.new(:statement=>statement)

      if statement2.resource?
        puts "statement2.subject has uri #{statement2.subject.uri}"

### Methods

== create_finalizer new object object= predicate predicate= subject subject= to_s

### Included Modules

Util

### Attributes

statement | [R] | the internal librdf statement

### Public Class methods

create_finalizer(statement)

You shouldn‘t use this. Used internally for cleanup.

[Source]

    # File rdf/redland/statement.rb, line 70
        def Statement.create_finalizer(statement)
          proc {|id| Redland::librdf_free_statement(statement) }
        end

new(subject=nil,predicate=nil,object=nil,model=nil)

create a new Statement with subject,predicate,and object the subject, predicate, and objects can be of class String or Uri.

[Source]

    # File rdf/redland/statement.rb, line 25
        def initialize(subject=nil,predicate=nil,object=nil,model=nil)
          @model = model

          if subject.class == Hash
            if subject.key?(:from_object)
              @statement = Redland.librdf_new_statement_from_statement(subject[:from_object])
              @model = subject[:model]
            end
          else

            unless subject
              s = nil
            else
              if (subject.class == Uri)|| (subject.class == String)
                subject = Node.new(subject)
              end
              s = Redland.librdf_new_node_from_node(subject.node)
            end

            unless predicate
              p = nil
            else
              if (predicate.class == Uri) || (predicate.class == String)
                predicate = Node.new(predicate)
              end
              p = Redland.librdf_new_node_from_node(predicate.node)
            end

            unless object
              o = nil
            else
              if (object.class == Uri) || (object.class == String)
                object = Node.new(object)
              end
              o = Redland.librdf_new_node_from_node(object.node)
            end
            @statement = Redland.librdf_new_statement_from_nodes($world.world,s,p,o)
          end

          raise RedlandError.new("Statement construction failed") if !@statement
          ObjectSpace.define_finalizer(self,Statement.create_finalizer(@statement))

        end

### Public Instance methods

==(other)

Equivalency. Only works for comparing two Statements

[Source]

    # File rdf/redland/statement.rb, line 140
        def ==(other)
          return (Redland.librdf_statement_equals(self.statement,other.statement) != 0)
        end

object()

return the object of the statement triple. The return value is either a Literal or Resource depending if object returned from the store is literal or not

[Source]

    # File rdf/redland/statement.rb, line 94
        def object()
          object_node = Redland.librdf_statement_get_object(self.statement)
          return Literal.from_node(object_node) if is_literal?(object_node)
          return Resource.new(object_node,@model)
        end

object=(value)

set the object of the statement

[Source]

    # File rdf/redland/statement.rb, line 111
        def object=(value)
          if value
            Redland.librdf_statement_set_object(self.statement,
                                                Redland.librdf_new_node_from_node(value.node))
          else
            Redland.librdf_statement_set_object(self.statement, nil)
          end
        end

predicate()

return the predicate of the statement triple.

[Source]

    # File rdf/redland/statement.rb, line 87
        def predicate()
          return wrap_node(Redland.librdf_statement_get_predicate(self.statement))
        end

predicate=(value)

set the predicate of the statement

[Source]

    # File rdf/redland/statement.rb, line 121
        def predicate=(value)
          if value
            Redland.librdf_statement_set_predicate(self.statement,
                                                   Redland.librdf_new_node_from_node(value.node))
          else
            Redland.librdf_statement_set_predicate(self.statement, nil)
          end
        end

subject()

return the subject of the statement triple. The subject is of class Resource

[Source]

    # File rdf/redland/statement.rb, line 82
        def subject()
          return Resource.new(Redland.librdf_statement_get_subject(self.statement),@model)
        end

subject=(value)

set the subject of the statement

[Source]

    # File rdf/redland/statement.rb, line 101
        def subject=(value)
          if value
            Redland.librdf_statement_set_subject(self.statement,
                                                 Redland.librdf_new_node_from_node(value.node))
          else
            Redland.librdf_statement_set_subject(self.statement, nil)
          end
        end

to_s()

Convert this Statement to a string

[Source]

    # File rdf/redland/statement.rb, line 131
        def to_s()
          unless self.statement
            raise RedlandError.new("Statement is invalid")
          else
            return Redland.librdf_statement_to_string(self.statement)
          end
        end

Go to Redland Home - Language Bindings Home - Ruby API Home

(C) Copyright 2004-2011 Dave Beckett, (C) Copyright 2004-2005 University of Bristol