<commit_before>module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL GraphPattern `order` operator.
    #
    # @see http://www.w3.org/TR/rdf-sparql-query/#sparqlAlgebra
    class Order < Operator::Binary
      include Query
      
      NAME = [:order]

      ##
      # Executes this query on the given `queryable` graph or repository.
      # Really a pass-through, as this is a syntactic object used for providing
      # context for URIs.
      #
      # @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/#sparqlAlgebra
      def execute(queryable, options = {})
        @solutions = operands.last.execute(queryable, options.merge(:depth => options[:depth].to_i + 1)).order do |a, b|
          operand(0).inject(false) do |memo, op|
            memo ||= begin
              comp = case op
              when RDF::Query::Variable
                a[op.to_sym] <=> b[op.to_sym]
              when Operator::Desc
                op.evaluate(b) <=> op.evaluate(a)
              when Operator
                op.evaluate(a) <=> op.evaluate(b)
              else
                raise TypeError, "Unexpected order expression #{op.inspect}"
              end
              comp == 0 ? false : comp
            end
          end || 0  # They compare equivalently if there are no matches
        end
      end
      
      ##<commit_msg>Operator::Order uses Array evaluation, as implemented in Array#evaluate extension.<commit_after>module SPARQL; module Algebra
  class Operator
    ##
    # The SPARQL GraphPattern `order` operator.
    #
    # @see http://www.w3.org/TR/rdf-sparql-query/#sparqlAlgebra
    class Order < Operator::Binary
      include Query
      
      NAME = [:order]

      ##
      # Executes this query on the given `queryable` graph or repository.
      # Really a pass-through, as this is a syntactic object used for providing
      # context for URIs.
      #
      # @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/#sparqlAlgebra
      def execute(queryable, options = {})
        debug("Order", options)
        @solutions = operands.last.execute(queryable, options.merge(:depth => options[:depth].to_i + 1)).order do |a, b|
          operand(0).inject(false) do |memo, op|
            debug("=> #{op}", options)
            memo ||= begin
              comp = case op
              when RDF::Query::Variable
                a[op.to_sym] <=> b[op.to_sym]
              when Operator, Array
                op.evaluate(b) <=> op.evaluate(a)
              else
                raise TypeError, "Unexpected order expression #{op.inspect}"
              end
              comp == 0 ? false : comp
            end
          end || 0  # They compare equivalently if there are no matches
        end
      end
      
      ##
{'fraction_non_alphanumeric': 0.10706638115631692, 'fraction_numerical': 0.0036708473539308656, 'mean_word_length': 1.8759894459102902, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2254147', 'n_tokens_mistral': 953, 'n_tokens_neox': 921, 'n_words': 264}