我知道如何在单个表中使用基本SQL和活动记录查询语言查找完全重复的记录.但我需要知道如何实现近距离匹配搜索,我想考虑拼写错误.在rails应用程序中查找潜在重复项和关闭匹配项的最佳方法是什么?我正在使用MySQL作为数据库.
编辑:我想要匹配的数据类型是字符串,它们作为字符串存储在数据库中.
ruby ruby-on-rails duplicates duplicate-removal ruby-on-rails-3
我正在尝试采用如下所示的数据集:

并将记录转换为以下格式:

生成的格式有两列,一列用于旧列名,另一列用于值.如果有10,000行,那么新格式应该有10,000组数据.
我对所有不同的方法开放,excel公式,sql(mysql),或者直接ruby代码对我也有用.解决这个问题的最佳方法是什么?
我正在尝试使用cardmagic分类器gem创建一个分类器.这是我的代码:
require 'classifier'
classifications = '1007.09', '1006.03'
traindata = Hash["1007.09" => "ADAPTER- SCREENING FOR VALVES VBS", "1006.03" => "ACTUATOR- LINEAR"]
b = Classifier::Bayes.new classifications
traindata.each do |key, value|
b.train(key, value)
end
Run Code Online (Sandbox Code Playgroud)
但是当我运行这个时,我收到以下错误:
Notice: for 10x faster LSI support, please install http://rb-gsl.rubyforge.org/
c:/Ruby192/lib/ruby/gems/1.9.1/gems/classifier-1.3.3/lib/classifier/bayes.rb:27:in `block in train': undefined method `[]' for nil:NilClass (NoMethodError)
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/classifier-1.3.3/lib/classifier/bayes.rb:26:in `each'
from c:/Ruby192/lib/ruby/gems/1.9.1/gems/classifier-1.3.3/lib/classifier/bayes.rb:26:in `train'
from C:/_Chris/Code/classifier/smdclasser.rb:13:in `block in <main>'
from C:/_Chris/Code/classifier/smdclasser.rb:11:in `each'
from C:/_Chris/Code/classifier/smdclasser.rb:11:in `<main>'
Run Code Online (Sandbox Code Playgroud)
这是gem代码的来源:
# Provides a general training method for all categories specified in …Run Code Online (Sandbox Code Playgroud) 假设我有一个字符串:
s = "one two three"
如何更换第一个空间 ?
返回的字符串应该是"one two three".