<commit_before># Copyright: 2011 TMX Credit
# Author: <NAME> (aka Blake)

require 'cassandra'

module Juno
  module Adapters
    # Cassandra backend
    # @api public
    class Cassandra < Base
      # Constructor
      #
      # @param [Hash] options
      #
      # Options:
      # * :keyspace - Cassandra keyspace (default 'juno')
      # * :column_family - Cassandra column family (default 'juno')
      # * :host - Server host name (default 127.0.0.1)
      # * :port - Server port (default 9160)
      def initialize(options = {})
        options[:keyspace] ||= 'juno'
        options[:host]     ||= '127.0.0.1'
        options[:port]     ||=  9160
        @cf = (options[:column_family] || 'juno').to_sym
        @client = ::Cassandra.new('system', "#{options[:host]}:#{options[:port]}")
        unless @client.keyspaces.include?(options[:keyspace])
          cf_def = ::Cassandra::ColumnFamily.new(:keyspace => options[:keyspace], :name => @cf.to_s)
          ks_def = ::Cassandra::Keyspace.new(:name => options[:keyspace],
                                             :strategy_class => 'org.apache.cassandra.locator.SimpleStrategy',
                                             :replication_factor => 1,
                                             :cf_defs => [cf_def])
          @client.add_keyspace(ks_def)
        end
        @client.keyspace = options[:keyspace]
      end

      def key?(key, options = {})
        @client.exists?(@cf, key)
      end

      def load(key, options = {})
        value = @client.get(@cf, key)
        if value
          if options.include?(:expires)
            store(key, value['value'], options)
          else
            value['value']
          end
        end
      end

      def delete(key, options = {})
        if value = load(key, options)
          @client.remove(@cf, key)
          value
        end
      end

      def store(key, value, options = {})
        @client.insert(@cf, key, {'value' => value}, :ttl => options[:expires])
        value
      end

      def clear(options = {})<commit_msg>wait for cassandra keyspace to be created<commit_after># Copyright: 2011 TMX Credit
# Author: <NAME> (aka Blake)

require 'cassandra'

module Juno
  module Adapters
    # Cassandra backend
    # @api public
    class Cassandra < Base
      # Constructor
      #
      # @param [Hash] options
      #
      # Options:
      # * :keyspace - Cassandra keyspace (default 'juno')
      # * :column_family - Cassandra column family (default 'juno')
      # * :host - Server host name (default 127.0.0.1)
      # * :port - Server port (default 9160)
      def initialize(options = {})
        options[:host] ||= '127.0.0.1'
        options[:port] ||=  9160
        keyspace = (options[:keyspace] ||= 'juno')
        @cf = (options[:column_family] || 'juno').to_sym
        @client = ::Cassandra.new('system', "#{options[:host]}:#{options[:port]}")
        unless @client.keyspaces.include?(keyspace)
          cf_def = ::Cassandra::ColumnFamily.new(:keyspace => keyspace, :name => @cf.to_s)
          ks_def = ::Cassandra::Keyspace.new(:name => keyspace,
                                             :strategy_class => 'org.apache.cassandra.locator.SimpleStrategy',
                                             :replication_factor => 1,
                                             :cf_defs => [cf_def])
          @client.add_keyspace(ks_def)
          # Wait for keyspace to be created (issue #24)
          10.times do
            break if @client.keyspaces.include?(keyspace)
            sleep 0.1
          end
        end
        @client.keyspace = keyspace
      end

      def key?(key, options = {})
        @client.exists?(@cf, key)
      end

      def load(key, options = {})
        value = @client.get(@cf, key)
        if value
          if options.include?(:expires)
            store(key, value['value'], options)
          else
            value['value']
          end
        end
      end

      def delete(key, options = {})
        if value = load(key, options)
          @client.remove(@cf, key)
          value
        end
      end

      def store(key, value, options = {})
        @client.insert(@cf, key, {'value' => value}, :ttl => options[:expires])
        value
      end

      def clear(options = {})
{'fraction_non_alphanumeric': 0.13552600886400745, 'fraction_numerical': 0.013062747842313973, 'mean_word_length': 1.7916666666666667, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 4, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7125055', 'n_tokens_mistral': 1279, 'n_tokens_neox': 1243, 'n_words': 291}