Sha256: 7d008ff238ab6d99ff550c61216ecd174711a5714eebee7e3c72bfccfb94ed8f

Contents?: true

Size: 1.45 KB

Versions: 2

Compression:

Stored size: 1.45 KB

Contents

require "fisher_classifier/version"

module FisherClassifier
  autoload :Classifier, 'fisher_classifier/classifier'
  autoload :Config, 'fisher_classifier/config'
  autoload :Meta, 'fisher_classifier/meta'

  class << self
    def create(&block)
      config = Config.new block

      Classifier.new config
    end

    def create_in_memory
      create do
        @features = {}
        @categories = {}

        inc_feature do |feature, category|
          @features[category] ||= {}

          if @features[category].has_key? feature
            @features[category][feature] += 1
          else
            @features[category][feature] = 1
          end
        end

        inc_category do |category|
          if @categories.has_key? category
            @categories[category] += 1
          else
            @categories[category] = 1
          end
        end

        get_features do |text|
          text.split(' ')
        end

        categories do
          [:good, :bad]
        end

        category_count do |category|
          if @features.has_key?(category)
            @categories[category] || 0
          else
            0
          end
        end

        features_count do |feature, category|
          if @features.has_key?(category) && @features[category].has_key?(feature)
            @features[category][feature] || 0
          else
            0
          end
        end

        default_category do
          :none
        end

      end

    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
fisher_classifier-0.0.3 lib/fisher_classifier.rb
fisher_classifier-0.0.2 lib/fisher_classifier.rb