class I18n::Magic::Entity::Alphabet
Constants
- AR_LETTERS
- DE_LETTERS
- EN_LETTERS
- ES_LETTERS
- FR_LETTERS
- HE_LETTERS
- JA_LETTERS
- RU_LETTERS
- TR_LETTERS
- ZH_LETTERS
Attributes
letters[R]
Public Class Methods
new(locale = nil)
click to toggle source
# File lib/i18n/magic/entity/alphabet.rb, line 20 def initialize(locale = nil) @letters = eval("#{locale.upcase}_LETTERS") rescue %w[] end
Public Instance Methods
belonging_score(text)
click to toggle source
# File lib/i18n/magic/entity/alphabet.rb, line 30 def belonging_score(text) score = 0 normalized_text = I18n::Magic::Helpers::StringOps.letters_only(text).downcase return 0 unless normalized_text.present? && normalized_text.size.positive? normalized_text.chars.each { |character| score += (100.0 / normalized_text.size) if @letters.include?(character) } score.to_i end
learn(sample_text)
click to toggle source
# File lib/i18n/magic/entity/alphabet.rb, line 24 def learn(sample_text) return unless sample_text.present? && sample_text.size.positive? normalized_text = I18n::Magic::Helpers::StringOps.letters_only(sample_text).downcase normalized_text.chars.each { |character| @letters.push(character) unless @letters.include?(character) } end