lib/ld/patch/algebra/constraint.rb
##
# If the first operand is :unique
#
# @param  [RDF::Queryable] queryable
#   the graph or repository to write
# @param  [Hash{Symbol => Object}] options
#   any additional options
# @option options [Array<RDF::Term>] starting terms
# @return [RDF::Query::Solutions] solutions with `:term` mapping
If the first operand is :unique
If the first operand is : unique
def execute(queryable, options = {})
      debug(options) {"Constraint"}
      terms = Array(options.fetch(:terms))
      op, value = operands
      results = if op == :unique
        terms.length == 1 ? terms : []
      else
        terms.select do |term|
          output_terms = op.execute(queryable, options.merge(terms: [term])).map(&:path)
          output_terms = output_terms.select {|t| t == value} if value
          !output_terms.empty?
        end
      end
      RDF::Query::Solutions.new(results.map {|t| RDF::Query::Solution.new(path: t)})
    end
def execute ( queryable , options = { } ) debug ( options ) { "Constraint" } terms = Array ( options . fetch ( :terms ) ) op , value = operands results = if op == :unique terms . length == 1 ? terms : [ ] else terms . select do | term | output_terms = op . execute ( queryable , options . merge ( terms : [ term ] ) ) . map ( & :path ) output_terms = output_terms . select { | t | t == value } if value ! output_terms . empty? end end RDF :: Query :: Solutions . new ( results . map { | t | RDF :: Query :: Solution . new ( path : t ) } ) end
If the first operand is :unique
If the first operand is : unique
# op is a path, filter input terms based on the presense or absense of output terms. Additionally, if a constraint value is given, output terms must equal that value
solutions with `:term` mapping
solutions with ` : term ` mapping
RDF::Query::Solutions
queryable
<not_specific>
options
None
<not_specific>
options any additional options
options any additional options