Module: SPARQL::Algebra::Query Abstract

Included in:
Operator::Ask, Operator::Base, Operator::Construct, Operator::Dataset, Operator::Describe, Operator::Distinct, Operator::Filter, Operator::Join, Operator::LeftJoin, Operator::Order, Operator::Prefix, Operator::Project, Operator::Reduced, Operator::Slice, Operator::Union
Defined in:
lib/sparql/algebra/query.rb

Overview

This module is abstract.

A SPARQL algebra query, may be duck-typed as RDF::Query.

Mixin with SPARQL::Algebra::Operator to provide query-like operations on graphs and filters

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Instance Attribute Details

- (RDF::Query::Solutions) solutions (readonly)

The solution sequence for this query.



32
33
34
# File 'lib/sparql/algebra/query.rb', line 32

def solutions
  @solutions
end

Instance Method Details

- (RDF::URI, RDF::Query::Variable) context=(value)

Add context to sub-items, unless they already have a context

Parameters:

Returns:



57
58
59
60
61
62
# File 'lib/sparql/algebra/query.rb', line 57

def context=(value)
  operands.each do |operand|
    operand.context = value if operand.respond_to?(:context) && operand.context != false
  end
  value
end

- (Enumerator) each_solution {|solution| ... } Also known as: each

Enumerates over each matching query solution.

Yields:

  • (solution)

Yield Parameters:

  • solution (RDF::Query::Solution)

Returns:

  • (Enumerator)


94
95
96
# File 'lib/sparql/algebra/query.rb', line 94

def each_solution(&block)
  solutions.each(&block)
end

- (RDF::Query::Solutions) execute(queryable, options = {})

Executes this query on the given queryable graph or repository.

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to query

  • options (Hash{Symbol => Object}) (defaults to: {})

    any additional keyword options

Options Hash (options):

  • debug (Boolean)

    Query execution debugging

Returns:

Raises:

  • (TypeError)

    TypeError raised if any operands are invalid

  • (NotImplementedError)

    If an attempt is made to perform an unsupported operation

See Also:



50
51
52
# File 'lib/sparql/algebra/query.rb', line 50

def execute(queryable, options = {})
  raise NotImplementedError, "#{self.class}#execute(#{queryable})"
end

- (Boolean) failed?

Returns true if this query did not match when last executed.

When the solution sequence is empty, this method can be used to determine whether the query failed to match or not.

Returns:

  • (Boolean)

See Also:



72
73
74
# File 'lib/sparql/algebra/query.rb', line 72

def failed?
  solutions.empty?
end

- (Boolean) matched?

Returns true if this query matched when last executed.

When the solution sequence is empty, this method can be used to determine whether the query matched successfully or not.

Returns:

  • (Boolean)

See Also:



84
85
86
# File 'lib/sparql/algebra/query.rb', line 84

def matched?
  !failed?
end

- unshift(query)

This method returns an undefined value.

Prepends an operator.

Parameters:



15
16
17
18
# File 'lib/sparql/algebra/query.rb', line 15

def unshift(query)
  @operands.unshift(query)
  self
end

- (Hash{Symbol => RDF::Query::Variable}) variables

The variables used in this query.

Returns:



24
25
26
# File 'lib/sparql/algebra/query.rb', line 24

def variables
  operands.inject({}) {|hash, o| o.executable? ? hash.merge!(o.variables) : hash}
end