Rubyで凄く簡単に誤記の訂正が出来る関数を作りました
なにこれ?
Google検索の「もしかして」部分をスクレイピングしてるだけ。
反省はしていない。
https://gist.github.com/636071
ソースコード
# -*- 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("小がやき") #=> "しょうが焼き"