# encoding: UTF-8 class TextNlp class Synonyms def initialize(synonyms = []) @synonyms = {} @expressions = Expressions.new synonyms.each do |synos| name = synos.shift register(name,synos) end end def register(name,synonyms) name.normalize! synonyms.each do |synonym| synonym.normalize! @expressions << synonym @synonyms[synonym] = name end end def transform(text) @expressions.expressionize(text).map { |expr| @synonyms.key?(expr) ? @synonyms[expr] : expr }.compact.join(' ') end end end