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 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/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)


120
121
122
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/query.rb', line 120

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

#empty?Boolean

Determine if this is an empty query, having no operands

Returns:

  • (Boolean)


92
93
94
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/query.rb', line 92

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}) (defaults to: {})

    any additional keyword options

Options Hash (options):

Yields:

  • (solution)

    each matching solution, statement or boolean

Yield Parameters:

Yield Returns:

  • (void)

    ignored

Returns:

Raises:

  • (NotImplementedError)

    If an attempt is made to perform an unsupported operation

See Also:



53
54
55
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/query.rb', line 53

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:



75
76
77
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/query.rb', line 75

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:



60
61
62
63
64
65
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/query.rb', line 60

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:



87
88
89
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/query.rb', line 87

def matched?
  !failed?
end

#query_yields_boolean?Boolean

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

Returns:

  • (Boolean)


98
99
100
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/query.rb', line 98

def query_yields_boolean?
  false
end

#query_yields_solutions?Boolean

Query results solutions (e.g., SELECT)

Returns:

  • (Boolean)


110
111
112
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/query.rb', line 110

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)


104
105
106
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/query.rb', line 104

def query_yields_statements?
  false
end

#unshift(query)

This method returns an undefined value.

Prepends an operator.

Parameters:



15
16
17
18
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/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.



24
25
26
# File 'vendor/bundler/ruby/2.5.0/bundler/gems/sparql-683a29666c28/lib/sparql/algebra/query.rb', line 24

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