Skip to content

Instantly share code, notes, and snippets.

@aquarla
Created October 20, 2010 09:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aquarla/636071 to your computer and use it in GitHub Desktop.
Save aquarla/636071 to your computer and use it in GitHub Desktop.
Google検索の「もしかして」を利用したスペル訂正メソッド
# -*- 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