Ruby Ruby 的字符串匹配方法很丰富, 怎么写中文分词算法?

u1432043059 · 2015年06月26日 · 最后由 lostleaf 回复于 2015年06月28日 · 2195 次阅读
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 里面的词来分词成为,中国/的/企业/和/经济,应该怎么实现?

额 可是分词时用 c++ 写的把。不知道怎么实现的

#2 楼 @u1432043059 应该是基于词典和最大匹配的吧 人家论文都放网上

需要 登录 后方可回复, 如果你还没有账号请 注册新账号