module SPARQL; module Algebra class Operator ## # The SPARQL GraphPattern `describe` operator. # # Generages a graph across specified terms using {RDF::Queryable}`#concise_bounded_description`. # # @example # (prefix ((exOrg: )) # (describe (?x) # (bgp (triple ?x exOrg:employeeId "1234")))) # # @see http://www.w3.org/TR/rdf-sparql-query/#describe class Describe < Operator::Binary include Query NAME = [:describe] ## # 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. # # @example # (describe ()) # # @example # (prefix ((foaf: )) # (describe (?x) # (bgp (triple ?x foaf:mbox )))) # # @param [RDF::Queryable] queryable # the graph or repository to query # @param [Hash{Symbol => Object}] options # any additional keyword options # @return [RDF::Query::Solutions] # the resulting solution sequence # @see http://www.w3.org/TR/rdf-sparql-query/#describe def execute(queryable, options = {}) debug(options) {"Describe #{operands.first}, #{options.inspect}"} # Describe any constand URIs to_describe = operands.first.select {|t| t.uri?} to_describe.each {|t| debug(options) {"=> describe #{t}"}} operands.last.execute(queryable).each do |solution| solution.each_variable do |v| if operands.first.any? {|bound| v.eql?(bound)} debug(options) {"=> describe #{v}"} to_describe << v.value end end end # Return Concise Bounded Description queryable.concise_bounded_description(*to_describe) end ## # Returns an optimized version of this query. # # Return optimized query # # @return [Union, RDF::Query] `self` def optimize operands = operands.map(&:optimize) end end # Construct end # Operator end; end # SPARQL::Algebra