txt = "中国的企业和经济"
dic = { '企业': 0, '经济': 0, '中国': 0 }
class SearchEngine
attr_accessor :txt, :dic
def initialize(txt, dic)
@txt = txt
@dic = dic
end
#计算文章的云词频
def yunciping
dic.each do |k, v|
dic[k] = txt.scan(k.to_s).count
end
puts dic
return dic
end
#分词过程
def fenci
end
end
se = SearchEngine.new(txt, dic)
se.yunciping
现在我想实现,把 txt,按照 dic 里面的词来分词成为,中国/的/企业/和/经济,应该怎么实现?