Skip to content

Instantly share code, notes, and snippets.

@ymrl
Created February 19, 2015 10:06
Show Gist options
  • Save ymrl/b7e1effaef084ae0ba17 to your computer and use it in GitHub Desktop.
Save ymrl/b7e1effaef084ae0ba17 to your computer and use it in GitHub Desktop.
「僕だけ」かもしれませんが強調したいことを「不自然」に「カギカッコ」で囲む文章はなんとなく「おっさん」ぽい印象がある
require 'yahoo_parse_api'
VERB_RATIO = 0.3
NOUN_RATIO = 0.3
# IDはこちらからどうぞ https://e.developer.yahoo.co.jp/register
YAHOO_APP_ID ='your app id'
YahooParseApi::Config.app_id = YAHOO_APP_ID
yp = YahooParseApi::Parse.new
sentence = ARGV[0]
if !sentence || sentence.length == 0
exit 1
end
result = yp.parse(sentence, results: 'ma')
words = result['ResultSet']['ma_result']['word_list']['word']
if words.class != Array
puts sentence
exit 0
end
arr = words.map do |w|
str = w['surface']
pos = w['pos']
if (pos == '動詞' && rand < VERB_RATIO) ||
(pos == '名詞' || pos == '形容詞') && rand < NOUN_RATIO
"「#{str}」"
else
str
end
end
puts arr.join('')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment