Module: SPARQL::Algebra::Query Abstract

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

#solutionsRDF::Query::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

#context=(value) ⇒ RDF::URI, RDF::Query::Variable

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

#each_solution {|solution| ... } ⇒ Enumerator 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

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

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

#failed?Boolean

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

#matched?Boolean

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

#variablesHash{Symbol => RDF::Query::Variable}

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