2012-02-21 12 views

答えて

2

最初の素朴な推測は、コンテンツを取得してハッシュを作成することです。しかし、コンテンツに全く動的な振る舞いがある場合、これは良い指標ではありません。

require 'open-uri' 
require 'digest/md5' 

f1 = open("http://rubyonrails.org/?id=1") 
c1 = f1.read 
d1 = Digest::MD5.hexdigest(c1) 

f2 = open("http://rubyonrails.org/"); 
c2 = f2.read 
d2 = Digest::MD5.hexdigest(c2) 

d1 == d2 # true 

私たちが言うと、同じことを繰り返した場合:www.google.comとgoogle.comコンテンツへのわずかな変動があるかもしれないので、ハッシュが一致しません。

文字列にはJaro Winkler小節を使用できます。これは、2つの類似した文字列の類似度が0と1の間の値を提供します。 純粋なimplementationのアルゴリズムもRubyにあります。ネイティブ実装ははるかに高速です。私は過去にamatchライブラリを使用しました。

require 'open-uri' 
require 'fuzzystringmatch' 

f1 = open("http://www.google.com/") 
c1 = f1.read 

f2 = open("http://google.com/") 
c2 = f2.read 

delta = 0.1 
jarow = FuzzyStringMatch::JaroWinkler.create(:pure) 
distance = jarow.getDistance(c1, c2) # 0.85 .. that is the text looks to be 85% similar 
関連する問題