Created
January 17, 2012 09:08
-
-
Save ymrl/1625777 to your computer and use it in GitHub Desktop.
Twitterのbio生成
This file contains hidden or 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 '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