# 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) normalized_name = name.normalize synonyms.each do |synonym| @expressions << synonym @synonyms[synonym.normalize] = normalized_name end end def translate(text) @expressions.expressionize(text).map { |expr| @synonyms.key?(expr) ? @synonyms[expr] : expr }.join(' ') end end end