Sha256: e8dd4d6b130c658ff5e1c73332e0ae8a7692093f1c78899b0761d5eab98afa0a

Contents?: true

Size: 479 Bytes

Versions: 5

Compression:

Stored size: 479 Bytes

Contents

# coding: utf-8

module Soulmate
  module Helpers

    def prefixes_for_phrase(phrase)
      words = normalize(phrase).split(' ').reject do |w|
        Soulmate.stop_words.include?(w)
      end
      words.map do |w|
        (MIN_COMPLETE-1..(w.length-1)).map{ |l| w[0..l] }
      end.flatten.uniq
    end

    def normalize(str)
      # Letter, Mark, Number, Connector_Punctuation (Chinese, Japanese, etc.)
      str.downcase.gsub(/[^\p{Word}\ ]/i, '').strip
    end

  end
end

Version data entries

5 entries across 5 versions & 2 rubygems

Version Path
soulmate_rails-0.3.0 lib/soulmate/helpers.rb
soulmate_rails-0.2.1 lib/soulmate/helpers.rb
soulmate_rails-0.2.1.beta lib/soulmate/helpers.rb
soulmate_rails-0.2.0.alpha lib/soulmate/helpers.rb
soulmate-1.0.0 lib/soulmate/helpers.rb