Sha256: 70c962a86713c0298a4a6cd24e594ec2d197ac0cf58fdec98bebebf83b43bf81

Contents?: true

Size: 1.76 KB

Versions: 7

Compression:

Stored size: 1.76 KB

Contents

module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL Property Path `notoneof` (NegatedPropertySet) operator.
    #
    # @example
    #   (notoneof ex:p1 ex:p2)
    #
    # @see https://www.w3.org/TR/sparql11-query/#eval_negatedPropertySet
    class NotOneOf < Operator
      include Query
      
      NAME = :notoneof

      ##
      # Equivalant to:
      #
      #   (path (:x (noteoneof :p :q) :y))
      #   => (filter (notin ??p :p :q) (bgp (:x ??p :y)))
      #
      # @note all operands are terms, and not operators, so this can be done by filtering results usin
      #
      # @param  [RDF::Queryable] queryable
      #   the graph or repository to query
      # @param  [Hash{Symbol => Object}] options
      #   any additional keyword options
      # @option options [RDF::Term, RDF::Variable] :subject
      # @option options [RDF::Term, RDF::Variable] :object
      # @yield  [solution]
      #   each matching solution
      # @yieldparam  [RDF::Query::Solution] solution
      # @yieldreturn [void] ignored
      # @see    https://www.w3.org/TR/sparql11-query/#sparqlAlgebra
      def execute(queryable, **options, &block)
        debug(options) {"NotOneOf #{operands.to_sse}"}
        subject, object = options[:subject], options[:object]

        v = RDF::Query::Variable.new(distinguished: false)
        bgp = RDF::Query.new do |q|
          q.pattern [subject, v, object]
        end
        query = Filter.new(NotIn.new(v, *operands), bgp)
        queryable.query(query, depth: options[:depth].to_i + 1, **options) do |solution|
          solution.bindings.delete(v.to_sym)
          debug(options) {"(solution)-> #{solution.to_h.to_sse}"}
          block.call(solution)
        end
      end
    end # NotOneOf
  end # Operator
end; end # SPARQL::Algebra

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sparql-3.1.8 lib/sparql/algebra/operator/notoneof.rb
sparql-3.1.7 lib/sparql/algebra/operator/notoneof.rb
sparql-3.1.6 lib/sparql/algebra/operator/notoneof.rb
sparql-3.1.5 lib/sparql/algebra/operator/notoneof.rb
sparql-3.1.4 lib/sparql/algebra/operator/notoneof.rb
sparql-3.1.3 lib/sparql/algebra/operator/notoneof.rb
sparql-3.1.2 lib/sparql/algebra/operator/notoneof.rb