Created
October 20, 2010 09:08
-
-
Save aquarla/636071 to your computer and use it in GitHub Desktop.
Google検索の「もしかして」を利用したスペル訂正メソッド
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: utf-8 -*- | |
require 'rubygems' | |
require 'open-uri' | |
require 'nokogiri' | |
require 'cgi' | |
require 'kconv' | |
def moshikashite(word) | |
begin | |
open("http://www.google.co.jp/search?hl=ja&q=#{CGI.escape(word)}") do |html| | |
Nokogiri::HTML.parse(html.read.toutf8.force_encoding("ASCII-8BIT"), nil, 'UTF-8').search("p.ssp a b")[0].text | |
end | |
rescue | |
word | |
end | |
end | |
puts moshikashite("ラーメソ") #=> "ラーメン" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment