Class: SPARQL::Algebra::Operator::Describe

Inherits:
Binary show all
Includes:
Query
Defined in:
lib/sparql/algebra/operator/describe.rb

Overview

The SPARQL GraphPattern describe operator.

Generages a graph across specified terms using RDF::Queryable#concise_bounded_description.

Examples:

(prefix ((exOrg: <http://org.example.com/employees#>))
  (describe (?x)
    (bgp (triple ?x exOrg:employeeId "1234"))))

See Also:

Constant Summary

NAME =
[:describe]

Constants inherited from Binary

Binary::ARITY

Constants inherited from SPARQL::Algebra::Operator

ARITY

Instance Attribute Summary

Attributes included from Query

#solutions

Attributes inherited from SPARQL::Algebra::Operator

#operands, #options

Instance Method Summary collapse

Methods included from Query

#context=, #each_solution, #failed?, #matched?, #unshift, #variables

Methods inherited from Binary

#initialize

Methods inherited from SPARQL::Algebra::Operator

arity, base_uri, #base_uri, base_uri=, #boolean, #constant?, #eql?, #evaluatable?, evaluate, #executable?, for, #initialize, #inspect, #operand, prefixes, #prefixes, prefixes=, #to_sse, #to_sxp, #variable?

Methods included from Evaluatable

#apply, #evaluate, #memoize

Methods included from Expression

cast, #constant?, #evaluate, for, new, open, parse, #to_sse, #variable?

Constructor Details

This class inherits a constructor from SPARQL::Algebra::Operator::Binary

Instance Method Details

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

Executes this query on the given RDF::Queryable object. Generates a graph containing the Concise Bounded Description variables and URIs listed in the first operand.

Examples:

(describe (<http://example/>))
(prefix ((foaf: <http://xmlns.com/foaf/0.1/>))
  (describe (?x)
    (bgp (triple ?x foaf:mbox <mailto:alice@org>))))

See Also:



39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/sparql/algebra/operator/describe.rb', line 39

def execute(queryable, options = {})
  debug("Describe #{operands.first}, #{options.inspect}", options)

  # Describe any constand URIs
  to_describe = operands.first.select {|t| t.uri?}
  
  to_describe.each {|t| debug("=> describe #{t}", options)}

  operands.last.execute(queryable).each do |solution|
    solution.each_variable do |v|
      if operands.first.any? {|bound| v.eql?(bound)}
        debug("=> describe #{v}", options)
        to_describe << v.value
      end
    end
  end

  # Return Concise Bounded Description
  queryable.concise_bounded_description(*to_describe)
end

#optimizeUnion, RDF::Query

Returns an optimized version of this query.

Return optimized query



66
67
68
# File 'lib/sparql/algebra/operator/describe.rb', line 66

def optimize
  operands = operands.map(&:optimize)
end