Redland RDF Language Bindings - Ruby RDoc - Class: Redland::QueryResults

### Home Classes Methods

### In Files

- rdf/redland/queryresults.rb

### Parent

Object

### Methods

- ::create_finalizer
- ::new
- #as_stream
- #binding_name
- #binding_names
- #binding_value
- #binding_value_by_name
- #binding_values
- #bindings
- #bindings_count
- #count
- #finished?
- #get_boolean?
- #is_bindings?
- #is_boolean?
- #is_graph?
- #next
- #size
- #to_string

### Files

- Makefile
- Makefile
- Makefile
- Makefile

### Class/Module Index

Quicksearch

- Redland
- Redland::BNode
- Redland::ContextParser
- Redland::FileStore
- Redland::HashOpen
- Redland::HashStore
- Redland::Literal
- Redland::MemoryStore
- Redland::MergedModel
- Redland::Model
- Redland::Namespace
- Redland::Node
- Redland::NodeIterator
- Redland::NodeTypeError
- Redland::OWL
- Redland::Parser
- Redland::Query
- Redland::QueryResults
- Redland::RDFS
- Redland::RedlandError
- Redland::Resource
- Redland::Serializer
- Redland::Statement
- Redland::Stream
- Redland::TripleStore
- Redland::Uri
- Redland::Util
- Redland::World
- DC
- FOAF

No matching classes.

# Redland::QueryResults

This class provides query language results support

### Attributes

results[R]

### Public Class Methods

create_finalizer(results) click to toggle source

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

    # File rdf/redland/queryresults.rb, line 17
    def QueryResults.create_finalizer(results)
      proc{|id| # "Finalizer on #{id}"
        #$log_final.info "closing results"
        Redland::librdf_free_query_results(results)
      }
    end

new(object) click to toggle source

this is not a public constructor

    # File rdf/redland/queryresults.rb, line 11
    def initialize(object)
      @results = object
      ObjectSpace.define_finalizer(self,QueryResults.create_finalizer(@results))
    end

### Public Instance Methods

as_stream() click to toggle source

Get a new Stream object representing the query results as an RDF Graph.

    # File rdf/redland/queryresults.rb, line 92
    def as_stream
      my_stream=Redland.librdf_query_results_as_stream(@results)
      return Stream.new(my_stream, self)
    end

binding_name(index) click to toggle source

Get binding name for the current result

    # File rdf/redland/queryresults.rb, line 45
    def binding_name(index)
      return Redland.librdf_query_results_get_binding_name(@results,index)
    end

binding_names() click to toggle source

Get the names all of the variable bindings as an array

    # File rdf/redland/queryresults.rb, line 50
    def binding_names
      count=Redland.librdf_query_results_get_bindings_count(@results)
      names=[]
      for i in 0..count-1
        names << binding_name(i)
      end
      return names
    end

binding_value(index) click to toggle source

Get one binding value for the current result

    # File rdf/redland/queryresults.rb, line 60
    def binding_value(index)
      node = Redland.librdf_query_results_get_binding_value(@results,index)
      return node.nil? ? nil : Node.new(node)
    end

binding_value_by_name(name) click to toggle source

Get the value of the variable binding name in the current query result.

    # File rdf/redland/queryresults.rb, line 76
    def binding_value_by_name(name)
      node=Redland.librdf_query_results_get_binding_value_by_name(@results,name)
      return node.nil? ? nil : Node.new(node)
    end

binding_values() click to toggle source

Get an array of all the values of all of the variable bindings in the current query result.

    # File rdf/redland/queryresults.rb, line 66
    def binding_values
      count=Redland.librdf_query_results_get_bindings_count(@results)
      values=[]
      for i in 0..count-1
        values << binding_value(i)
      end
      return values
    end

bindings() click to toggle source

Get an array of binding values

    # File rdf/redland/queryresults.rb, line 82
    def bindings
      (0...self.size).each{|i| binding_value( i ) }
    end

bindings_count() click to toggle source

Get number of binding variables

    # File rdf/redland/queryresults.rb, line 40
    def bindings_count
      return Redland.librdf_query_results_get_bindings_count(@results)
    end

count() click to toggle source

Get the number of results so far

    # File rdf/redland/queryresults.rb, line 30
    def count
      return Redland.librdf_query_results_get_count(@results)
    end

finished?() click to toggle source

Test if the results are finished

    # File rdf/redland/queryresults.rb, line 35
    def finished?
      return (Redland.librdf_query_results_finished(@results) != 0)
    end

get_boolean?() click to toggle source

Get the boolean query result

    # File rdf/redland/queryresults.rb, line 139
    def get_boolean?()
      return (Redland.librdf_query_results_get_boolean(@results) != 0)
    end

is_bindings?() click to toggle source

Test if is variable bindings result

    # File rdf/redland/queryresults.rb, line 124
    def is_bindings?()
      return (Redland.librdf_query_results_is_bindings(@results) != 0)
    end

is_boolean?() click to toggle source

Test if is a boolean result

    # File rdf/redland/queryresults.rb, line 129
    def is_boolean?()
      return (Redland.librdf_query_results_is_boolean(@results) != 0)
    end

is_graph?() click to toggle source

Test if is an RDF graph result

    # File rdf/redland/queryresults.rb, line 134
    def is_graph?()
      return (Redland.librdf_query_results_is_graph(@results) != 0)
    end

next() click to toggle source

Move to the next query result

    # File rdf/redland/queryresults.rb, line 87
    def next
      Redland.librdf_query_results_next(@results)
    end

size() click to toggle source

Get the number of results so far

    # File rdf/redland/queryresults.rb, line 25
    def size
      return Redland.librdf_query_results_get_count(@results)
    end

to_string(format_uri = nil, base_uri = nil) click to toggle source

Serialize to a string syntax in format_uri using the optional base_uri. The default format when none is given is determined by librdf_query_results_to_string

    # File rdf/redland/queryresults.rb, line 100
    def to_string(format_uri = nil, base_uri = nil)
      if self.is_graph?()
        tmpmodel=Model.new()
        tmpmodel.add_statements(self.as_stream())
        serializer=Serializer.new()
        return serializer.model_to_string(base_uri, tmpmodel)
      end

      if not self.is_boolean?() and not self.is_bindings?()
        raise RedlandError.new("Unknown query result format cannot be written as a string")
      end

      if format_uri
        format_uri = format_uri.uri
      end
      if base_uri
        base_uri = base_uri.uri
      end

      return Redland.librdf_query_results_to_string(@results, format_uri, base_uri)
    end

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

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