第7回北海道開発オフ成果:Yma4rを使ってみる

@niku_nameさんが開発オフでも作っていた、yma4rを試してみる。

(1)インストール。cucumberも入れないと動かなかった。

sudo gem source -a http://gems.github.com
sudo gem install cucumber
sudo gem install niku-yma4r


(2)以下ソース。

#!/usr/bin/ruby -Ku
# Yahooのテキスト解析は以下を参照
# http://developer.yahoo.co.jp/webapi/jlp/ma/v1/parse.html

require 'rubygems'
require 'yma4r'

puts "###### 形態素解析(ma)"
yma4r = Yma4r.new(
# YahooアプリケーションID
:appid => '自分で取得したYahooアプリケーションID',
# 解析対象のテキスト
:sentence => '友達の友達は皆友達、俺の友達とお前の友達は皆友達。',
# ma->形態素解析結果、uniq->出現頻度情報
:results => :ma,
# 戻り値を指定、以下の5種類がある
:response => [:surface, :reading, :pos, :baseform, :feature]
)

yma4r.parse.ma_result.word_list.each do |e|
puts "surface:#{e.surface}, reading:#{e.reading}, pos:#{e.pos}, baseform:#{e.baseform}, feature:#{e.feature}"
end

puts "###### 出現頻度数(uniq)"
yma4r = Yma4r.new(
# YahooアプリケーションID
:appid => '自分で取得したYahooアプリケーションID',
# 解析対象のテキスト
:sentence => '友達の友達は皆友達、俺の友達とお前の友達は皆友達。',
# ma->形態素解析結果、uniq->出現頻度情報
:results => :uniq,
# 戻り値を指定、以下の5種類がある
:response => [:surface, :reading, :pos, :baseform, :feature]
)

yma4r.parse.uniq_result.word_list.each do |e|
puts "#{e.count}, surface:#{e.surface}, reading:#{e.reading}, pos:#{e.pos}, baseform:#{e.baseform}, feature:#{e.feature}"
end


(3)出力結果。

###### 形態素解析(ma)
surface:友達, reading:ともだち, pos:名詞, baseform:友達, feature:名詞,名詞,*,友達,ともだち,友達
surface:の, reading:の, pos:助詞, baseform:の, feature:助詞,助詞連体化,*,の,の,の
surface:友達, reading:ともだち, pos:名詞, baseform:友達, feature:名詞,名詞,*,友達,ともだち,友達
surface:は, reading:は, pos:助詞, baseform:は, feature:助詞,係助詞,*,は,は,は
surface:皆, reading:みな, pos:名詞, baseform:皆, feature:名詞,名詞,*,皆,みな,皆
surface:友達, reading:ともだち, pos:名詞, baseform:友達, feature:名詞,名詞,*,友達,ともだち,友達
surface:、, reading:、, pos:特殊, baseform:、, feature:特殊,読点,*,、,、,、
surface:俺, reading:おれ, pos:名詞, baseform:俺, feature:名詞,名詞,*,俺,おれ,俺
surface:の, reading:の, pos:助詞, baseform:の, feature:助詞,助詞連体化,*,の,の,の
surface:友達, reading:ともだち, pos:名詞, baseform:友達, feature:名詞,名詞,*,友達,ともだち,友達
surface:と, reading:と, pos:助詞, baseform:と, feature:助詞,並立助詞,*,と,と,と
surface:お前, reading:おまえ, pos:名詞, baseform:お前, feature:名詞,名詞,*,お前,おまえ,お前
surface:の, reading:の, pos:助詞, baseform:の, feature:助詞,助詞連体化,*,の,の,の
surface:友達, reading:ともだち, pos:名詞, baseform:友達, feature:名詞,名詞,*,友達,ともだち,友達
surface:は, reading:は, pos:助詞, baseform:は, feature:助詞,係助詞,*,は,は,は
surface:皆, reading:みな, pos:名詞, baseform:皆, feature:名詞,名詞,*,皆,みな,皆
surface:友達, reading:ともだち, pos:名詞, baseform:友達, feature:名詞,名詞,*,友達,ともだち,友達
surface:。, reading:。, pos:特殊, baseform:。, feature:特殊,句点,*,。,。,。
###### 出現頻度数(uniq)
6, surface:友達, reading:, pos:名詞, baseform:友達, feature:名詞,*,*,友達,,友達
3, surface:の, reading:, pos:助詞, baseform:の, feature:助詞,*,*,の,,の
2, surface:は, reading:, pos:助詞, baseform:は, feature:助詞,*,*,は,,は
2, surface:皆, reading:, pos:名詞, baseform:皆, feature:名詞,*,*,皆,,皆
1, surface:、, reading:, pos:特殊, baseform:、, feature:特殊,*,*,、,,、
1, surface:。, reading:, pos:特殊, baseform:。, feature:特殊,*,*,。,,。
1, surface:お前, reading:, pos:名詞, baseform:お前, feature:名詞,*,*,お前,,お前
1, surface:と, reading:, pos:助詞, baseform:と, feature:助詞,*,*,と,,と
1, surface:俺, reading:, pos:名詞, baseform:俺, feature:名詞,*,*,俺,,俺

このブログの人気の投稿

転職のお知らせ

40代の減量戦略 〜体重-14kg、体脂肪率-12%を実現した具体的な方法〜

45歳になりました