<commit_before>require 'spamcheck/version'
require 'spamcheck/classifier'
require 'rules/country'
require 'rules/dnsblacklist'

# Spamcheck
module Spamcheck
  module_function

  attr_accessor :settings
  DEFAULT_SETTINGS = {
    storage: 'disk',
    store_location: 'spamcheck.dat'
  }

  def settings
    return @settings unless @settings.nil?
    DEFAULT_SETTINGS
  end

  def settings=(settings)
    DEFAULT_SETTINGS.merge!(settings)
  end

  def self.mark(type, text)
    classifier = load_classifier
    classifier.mark(type, text)
    store_classifier(classifier)
  end

  def self.spam?(text)
    classifier = load_classifier
    classifier.classify(text)
  end

  def self.export
    classifier = load_classifier
    classifier.export
  end

  def self.import(data)
    classifier = load_classifier
    classifier.import(data)
    store_classifier(classifier)
    true
  end

  private

  def self.persistence
    return @store if @store
    mod = settings[:storage]
    require 'storage/' + mod
    @store = Object.const_get('Storage')
             .const_get(mod.capitalize).new(settings)
  end

  def self.store_classifier(classifier)
    persistence
    @classifier = @store.save(classifier)
  end

  def self.load_classifier
    persistence
    @classifier = @store.retrieve
  end
end
<commit_msg>Changed mod var to store, makes it more clear.<commit_after>require 'spamcheck/version'
require 'spamcheck/classifier'
require 'rules/country'
require 'rules/dnsblacklist'

# Spamcheck
module Spamcheck
  module_function

  attr_accessor :settings
  DEFAULT_SETTINGS = {
    storage: 'disk',
    store_location: 'spamcheck.dat'
  }

  def settings
    return @settings unless @settings.nil?
    DEFAULT_SETTINGS
  end

  def settings=(settings)
    DEFAULT_SETTINGS.merge!(settings)
  end

  def self.mark(type, text)
    classifier = load_classifier
    classifier.mark(type, text)
    store_classifier(classifier)
  end

  def self.spam?(text)
    classifier = load_classifier
    classifier.classify(text)
  end

  def self.export
    classifier = load_classifier
    classifier.export
  end

  def self.import(data)
    classifier = load_classifier
    classifier.import(data)
    store_classifier(classifier)
    true
  end

  private

  def self.persistence
    return @store if @store
    store = settings[:storage]
    require 'storage/' + store
    @store = Object.const_get('Storage')
             .const_get(store.capitalize).new(settings)
  end

  def self.store_classifier(classifier)
    persistence
    @classifier = @store.save(classifier)
  end

  def self.load_classifier
    persistence
    @classifier = @store.retrieve
  end
end

{'fraction_non_alphanumeric': 0.08273787138021813, 'fraction_numerical': 0.0, 'mean_word_length': 3.448160535117057, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '2435323', 'n_tokens_mistral': 864, 'n_tokens_neox': 849, 'n_words': 186}