<commit_before>module Pacer::Core::Graph

  # This module adds route methods to the basic graph classes returned from the
  # blueprints library.
  module GraphRoute
    # Returns a new route to all graph vertices. Standard filter options.
    def v(*filters, &block)
      route = indexed_route(:vertex, filters, block)
      unless route
        route = chain_route :element_type => :vertex,
          :pipe_class => Pacer::Pipes::GraphElementPipe,
          :pipe_args => Pacer::Pipes::GraphElementPipe::ElementType::VERTEX,
          :route_name => 'GraphV'
        route = Pacer::Route.property_filter(route, filters, block)
      end
      route
    end

    # Returns a new route to all graph edges. Standard filter options.
    def e(*filters, &block)
      route = indexed_route(:edge, filters, block)
      unless route
        route = chain_route :element_type => :edge,
          :pipe_class => Pacer::Pipes::GraphElementPipe,
          :pipe_args => Pacer::Pipes::GraphElementPipe::ElementType::EDGE,
          :route_name => 'GraphE'
        route = Pacer::Route.property_filter(route, filters, block)
      end
      route
    end

    def filter(*args)
      raise 'Not implemented'
    end

    # Specialization of result simply returns self.
    def result
      self
    end

    # The graph itself is as root as you can get.
    def root?
      true
    end

    def graph
      # This must be defined here to overwrite the #graph method in Route.
      self
    end

    def ==(other)
      equal?(other)
    end

    protected

    # Don't try to inspect the graph data when inspecting.
    def hide_elements
      true
    end

    def each_property_filter(filters)
      filters.each do |filter|
        if filter.is_a? Hash
          filter.each { |key, value| yield key, value, nil if key }
        elsif filter.is_a? Module or filter.is_a? Class
          if filter.respond_to? :route_conditions
            each_property_filter([filter.route_conditions]) { |k, v, f| yield k, v, (f || filter) }
          elsif filter.respond_to? :route
            yield filter, filter, filter
          end
        end
      end
      nil
    end

    def use_index?(index, element_type, index_name, index_value)
      if index.index_class == element_type.java_class
        key, value, index_specified = index_key_value(index_name, index_value)
        if index.index_type == Pacer.automatic_index
          keys = index.auto_index_keys_in_use
          return false if keys and not keys.include? key
        end
        index.index_name == index_name or (not index_specified and index.index_type == Pacer.automatic_index)
      end
    end

    def index_key_value(key, value)
      index_specified = value.is_a? Hash
      key, value = value.first if index_specified
      [key.to_s, value, index_specified]
    end<commit_msg>AutoIndexKeysInUse is actually not necessary.<commit_after>module Pacer::Core::Graph

  # This module adds route methods to the basic graph classes returned from the
  # blueprints library.
  module GraphRoute
    # Returns a new route to all graph vertices. Standard filter options.
    def v(*filters, &block)
      route = indexed_route(:vertex, filters, block)
      unless route
        route = chain_route :element_type => :vertex,
          :pipe_class => Pacer::Pipes::GraphElementPipe,
          :pipe_args => Pacer::Pipes::GraphElementPipe::ElementType::VERTEX,
          :route_name => 'GraphV'
        route = Pacer::Route.property_filter(route, filters, block)
      end
      route
    end

    # Returns a new route to all graph edges. Standard filter options.
    def e(*filters, &block)
      route = indexed_route(:edge, filters, block)
      unless route
        route = chain_route :element_type => :edge,
          :pipe_class => Pacer::Pipes::GraphElementPipe,
          :pipe_args => Pacer::Pipes::GraphElementPipe::ElementType::EDGE,
          :route_name => 'GraphE'
        route = Pacer::Route.property_filter(route, filters, block)
      end
      route
    end

    def filter(*args)
      raise 'Not implemented'
    end

    # Specialization of result simply returns self.
    def result
      self
    end

    # The graph itself is as root as you can get.
    def root?
      true
    end

    def graph
      # This must be defined here to overwrite the #graph method in Route.
      self
    end

    def ==(other)
      equal?(other)
    end

    protected

    # Don't try to inspect the graph data when inspecting.
    def hide_elements
      true
    end

    def each_property_filter(filters)
      filters.each do |filter|
        if filter.is_a? Hash
          filter.each { |key, value| yield key, value, nil if key }
        elsif filter.is_a? Module or filter.is_a? Class
          if filter.respond_to? :route_conditions
            each_property_filter([filter.route_conditions]) { |k, v, f| yield k, v, (f || filter) }
          elsif filter.respond_to? :route
            yield filter, filter, filter
          end
        end
      end
      nil
    end

    def use_index?(index, element_type, index_name, index_value)
      if index.index_class == element_type.java_class
        key, value, index_specified = index_key_value(index_name, index_value)
        if index.index_type == Pacer.automatic_index
          keys = index.getAutoIndexKeys
          return false if keys and not keys.include? key
        end
        index.index_name == index_name or (not index_specified and index.index_type == Pacer.automatic_index)
      end
    end

    def index_key_value(key, value)
      index_specified = value.is_a? Hash
      key, value = value.first if index_specified
      [key.to_s, value, index_specified]
    end
{'fraction_non_alphanumeric': 0.08070728291316527, 'fraction_numerical': 0.0, 'mean_word_length': 2.466626213592233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '4651074', 'n_tokens_mistral': 1670, 'n_tokens_neox': 1627, 'n_words': 515}