Sha256: 32dc0a5107e9b6dcea0840fc022410c7a5e28bf49844b31a00c6f7174c68be78

Contents?: true

Size: 582 Bytes

Versions: 1

Compression:

Stored size: 582 Bytes

Contents

require "json"

module Unicoder
  module ReplaceCommonWords
  	def replace_common_words!(which_index, words, count = 500, base = ?[.ord, min_word_length = 4)
  	  puts "Starting to replace the #{count} most common words"
  	  @index[:REPLACE_BASE] = base
  	  @index[:COMMON_WORDS] = words.
  	    select{_1.size >= min_word_length}.
  	    tally.
  	    max_by(count){_2}.
  	    map(&:first)
  	  @index[which_index].each{|_, name|
  	    @index[:COMMON_WORDS].each_with_index{|word, index|
  	      name.gsub! word + " ", [base + index].pack("U")
  	    }
  	  }
  	end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
unicoder-1.1.0 lib/unicoder/replace_common_words.rb