<commit_before># -*- coding: utf-8 -*-
module SolveBio
    class Query
        # A Query API request wrapper that generates a request from Filter
        # objects, and can iterate through streaming result sets.
        include Enumerable

        # 2**62 - 1 fits Rubywise into a 64-bit Fixnum
        INT_MAX ||= 4_611_686_018_427_387_903

        # The maximum number of results fetched in one go. Note however
        # that iterating over a query can cause more fetches.
        DEFAULT_PAGE_SIZE ||= 100

        attr_reader   :dataset_id
        attr_accessor :filters
        attr_accessor :limit
        attr_accessor :page_size
        attr_accessor :range
        attr_reader   :response
        attr_reader   :page_offset

        # Creates a new Query object.
        #
        # Parameters:
        #   - `dataset_id`: Unique ID of dataset to query.
        #   - `genome_build`: The genome build to use for the query.
        #   - `fields` (optional): List of specific fields to retrieve.
        #   - `filters` (optional): List of filter objects.
        #   - `limit` (optional): Maximum number of query results to return.
        #   - `page_size` (optional): Max number of results to fetch per query page.
        def initialize(dataset_id, params={})
            unless dataset_id.is_a?(Fixnum) or dataset_id.respond_to?(:to_str)
                raise TypeError, "'dataset_id' parameter must an Integer or String"
            end

            @dataset_id   = dataset_id
            @data_url     = params[:data_url] || "/v1/datasets/#{dataset_id}/data"
            @genome_build = params[:genome_build]
            @fields       = params[:fields]
            @filters      = params[:filters].kind_of?(SolveBio::Filter) ? params[:filters].filters : (params[:filters] || [])

            @response     = nil
            # Limit defines the total number of results that will be returned
            # from a query involving 1 or more pagination requests.
            @limit        = params[:limit] || INT_MAX
            # Page limit and page offset are the low level API limit and offset params.
            # page_offset may be changed periodically during sequential pagination requests.
            @page_size   = params[:page_size] || DEFAULT_PAGE_SIZE
            # Page offset can only be set by execute()
            # It always contains the current absolute offset contained in the buffer.
            @page_offset  = nil
            # @range is set to tell the Query object that is being sliced and "def each" should not
            # reset the page_offset to 0 before iterating.
            @range        = nil

            begin
                @limit = Integer(@limit)
                raise RangeError if @limit < 0
            rescue
                raise TypeError, "'limit' parameter must an Integer >= 0"
            end

            begin
                @page_size = Integer(@page_size)
                raise RangeError if @page_size <= 0
            rescue
                raise TypeError, "'page_size' parameter must an Integer > 0"
            end

            self
        end

        def clone(filters=[])
            q = Query.new(@dataset_id, {
                :data_url => @data_url,
                :genome_build => @genome_build,
                :fields => @fields,
                :limit => @limit,
                :page_size => @page_size
            })

            q.filters += @filters unless @filters.empty?
            q.filters += filters unless filters.empty?
            q
        end

        # Returns this Query instance with the query args combined with
        # existing set with AND.
        #
        # kwargs are simply passed to a new SolveBio::Filter object and
        # combined to any other filters with AND.
        #
        # By default, everything is combined using AND. If you provide
        # multiple filters in a single filter call, those are ANDed
        # together. If you provide multiple filters in multiple filter
        # calls, those are ANDed together.
        #
        # If you want something different, use the F class which supports
        # ``&`` (and), ``|`` (or) and ``~`` (not) operators. Then call
        # filter once with the resulting Filter instance.
        def filter(params={}, conn=:and)
            return clone(Filter.new(params, conn).filters)
        end

        # Shortcut to do range queries on supported datasets.
        def range(chromosome, start, stop, exact=false)
            return clone([GenomicFilter.new(chromosome, start, stop, exact)])
        end

        # Shortcut to do a single position filter on genomic datasets.
        def position(chromosome, position, exact=false)
            return clone([GenomicFilter.new(chromosome, position, position, exact)])
        end

        # Returns the total number of results in the result-set.<commit_msg>fix range and position methods on Query<commit_after># -*- coding: utf-8 -*-
module SolveBio
    class Query
        # A Query API request wrapper that generates a request from Filter
        # objects, and can iterate through streaming result sets.
        include Enumerable

        # 2**62 - 1 fits Rubywise into a 64-bit Fixnum
        INT_MAX ||= 4_611_686_018_427_387_903

        # The maximum number of results fetched in one go. Note however
        # that iterating over a query can cause more fetches.
        DEFAULT_PAGE_SIZE ||= 100

        attr_reader   :dataset_id
        attr_accessor :filters
        attr_accessor :limit
        attr_accessor :page_size
        attr_accessor :range
        attr_reader   :response
        attr_reader   :page_offset

        # Creates a new Query object.
        #
        # Parameters:
        #   - `dataset_id`: Unique ID of dataset to query.
        #   - `genome_build`: The genome build to use for the query.
        #   - `fields` (optional): List of specific fields to retrieve.
        #   - `filters` (optional): List of filter objects.
        #   - `limit` (optional): Maximum number of query results to return.
        #   - `page_size` (optional): Max number of results to fetch per query page.
        def initialize(dataset_id, params={})
            unless dataset_id.is_a?(Fixnum) or dataset_id.respond_to?(:to_str)
                raise TypeError, "'dataset_id' parameter must an Integer or String"
            end

            @dataset_id   = dataset_id
            @data_url     = params[:data_url] || "/v1/datasets/#{dataset_id}/data"
            @genome_build = params[:genome_build]
            @fields       = params[:fields]
            @filters      = params[:filters].kind_of?(SolveBio::Filter) ? params[:filters].filters : (params[:filters] || [])

            @response     = nil
            # Limit defines the total number of results that will be returned
            # from a query involving 1 or more pagination requests.
            @limit        = params[:limit] || INT_MAX
            # Page limit and page offset are the low level API limit and offset params.
            # page_offset may be changed periodically during sequential pagination requests.
            @page_size   = params[:page_size] || DEFAULT_PAGE_SIZE
            # Page offset can only be set by execute()
            # It always contains the current absolute offset contained in the buffer.
            @page_offset  = nil
            # @range is set to tell the Query object that is being sliced and "def each" should not
            # reset the page_offset to 0 before iterating.
            @range        = nil

            begin
                @limit = Integer(@limit)
                raise RangeError if @limit < 0
            rescue
                raise TypeError, "'limit' parameter must an Integer >= 0"
            end

            begin
                @page_size = Integer(@page_size)
                raise RangeError if @page_size <= 0
            rescue
                raise TypeError, "'page_size' parameter must an Integer > 0"
            end

            self
        end

        def clone(filters=[])
            q = Query.new(@dataset_id, {
                :data_url => @data_url,
                :genome_build => @genome_build,
                :fields => @fields,
                :limit => @limit,
                :page_size => @page_size
            })

            q.filters += @filters unless @filters.empty?
            q.filters += filters unless filters.empty?
            q
        end

        # Returns this Query instance with the query args combined with
        # existing set with AND.
        #
        # kwargs are simply passed to a new SolveBio::Filter object and
        # combined to any other filters with AND.
        #
        # By default, everything is combined using AND. If you provide
        # multiple filters in a single filter call, those are ANDed
        # together. If you provide multiple filters in multiple filter
        # calls, those are ANDed together.
        #
        # If you want something different, use the F class which supports
        # ``&`` (and), ``|`` (or) and ``~`` (not) operators. Then call
        # filter once with the resulting Filter instance.
        def filter(params={}, conn=:and)
            return clone(Filter.new(params, conn).filters)
        end

        # Shortcut to do range queries on supported datasets.
        def range(chromosome, start, stop, exact=false)
            return clone(GenomicFilter.new(chromosome, start, stop, exact).filters)
        end

        # Shortcut to do a single position filter on genomic datasets.
        def position(chromosome, position, exact=false)
            return clone(GenomicFilter.new(chromosome, position, position, exact).filters)
        end

        # Returns the total number of results in the result-set.
{'fraction_non_alphanumeric': 0.07695448050622576, 'fraction_numerical': 0.007348438456827924, 'mean_word_length': 1.8727645851656405, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 17, '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': '6398727', 'n_tokens_mistral': 2560, 'n_tokens_neox': 2399, 'n_words': 935}