Skip to content

Instantly share code, notes, and snippets.

@ymrl
Created January 17, 2012 09:08
Show Gist options
  • Save ymrl/1625777 to your computer and use it in GitHub Desktop.
Save ymrl/1625777 to your computer and use it in GitHub Desktop.
Twitterのbio生成
#coding:utf-8
require 'open-uri'
require 'nokogiri'
require 'MeCab'
a = Nokogiri::HTML(open('http://tenki.jp/')).css("#descriptionEntries").text
mecab = MeCab::Tagger.new
node = mecab.parseToNode(a)
b = []
prev = nil
while node do
m = node.feature.split(',')[0].force_encoding("utf-8").match(/名詞/u)
if prev and m
b[b.length-1] = b.last + node.surface.force_encoding("utf-8")
elsif m
b.push(node.surface.force_encoding("utf-8"))
end
prev = m
node = node.next
end
puts b.uniq.sort_by{rand}.join('/')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment