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. This is only set



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

def solutions
  @solutions
end

Instance Method Details

#each_solution {|solution| ... } ⇒ Enumerator

Enumerates over each matching query solution.

Yields:

  • (solution)

Yield Parameters:

Returns:

  • (Enumerator)


122
123
124
# File 'lib/sparql/algebra/query.rb', line 122

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

#empty?Boolean

Determine if this is an empty query, having no operands

Returns:

  • (Boolean)


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

def empty?
  self.operands.empty?
end

#execute(queryable, **options) {|solution| ... } ⇒ RDF::Graph, ...

Executes this query on the given queryable graph or repository.

Parameters:

  • queryable (RDF::Queryable)

    the graph or repository to query

  • options (Hash{Symbol => Object})

    any additional keyword options

Options Hash (**options):

Yields:

  • (solution)

    each matching solution, statement or boolean

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Returns:

  • (RDF::Graph, Boolean, RDF::Query::Solutions::Enumerator)

    Note, results may be used with SPARQL.serialize_results to obtain appropriate output encoding.

Raises:

  • (NotImplementedError)

    If an attempt is made to perform an unsupported operation

See Also:



55
56
57
# File 'lib/sparql/algebra/query.rb', line 55

def execute(queryable, **options, &block)
  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:



77
78
79
# File 'lib/sparql/algebra/query.rb', line 77

def failed?
  solutions.empty?
end

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

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

Parameters:

Returns:



62
63
64
65
66
67
# File 'lib/sparql/algebra/query.rb', line 62

def graph_name=(value)
  operands.each do |operand|
    operand.graph_name = value if operand.respond_to?(:graph_name) && operand.graph_name != false
  end
  value
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:



89
90
91
# File 'lib/sparql/algebra/query.rb', line 89

def matched?
  !failed?
end

#query_yields_boolean?Boolean

Query results in a boolean result (e.g., ASK)

Returns:

  • (Boolean)


100
101
102
# File 'lib/sparql/algebra/query.rb', line 100

def query_yields_boolean?
  false
end

#query_yields_solutions?Boolean

Query results solutions (e.g., SELECT)

Returns:

  • (Boolean)


112
113
114
# File 'lib/sparql/algebra/query.rb', line 112

def query_yields_solutions?
  !(query_yields_boolean? || query_yields_statements?)
end

#query_yields_statements?Boolean

Query results statements (e.g., CONSTRUCT, DESCRIBE, CREATE)

Returns:

  • (Boolean)


106
107
108
# File 'lib/sparql/algebra/query.rb', line 106

def query_yields_statements?
  false
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.respond_to?(:variables) ? hash.merge(o.variables) : hash}
end