class Elecjar

Elecjar top-level class

Elecjar top-level class

Elecjar top-level class

Public Instance Methods

costar_chawan() click to toggle source
# File lib/rice.rb, line 9
def costar_chawan
nx = Natto::MeCab.new
begin
  file2 = File.open(ARGV[1])
  texts = file2.read
  puts nx.parse(texts).toutf8 do |x|
  puts "#{x.feature}\t#{x.surface}"
  end
rescue Errno::EACCES
  puts 'ファイルへアクセス権限がありません'
rescue LoadError
  puts '対象ファイルがありません'
ensure
  file2.close
end
end
hashi() click to toggle source
# File lib/kome.rb, line 9
def hashi
  m = MeCab::Tagger.new('-Owakati')
  word = Hash.new(0)
  begin
  files = File.open(ARGV[1])
  text = files.read
  m.parse(text).toutf8.scan(/(?:[ぁ-ヶ]|[亜-黑]|[a-zA-Z_0-9]|ー)+/) { |str| word[str] += 1 }
  print word.sort_by { |k, v| k <=> v }
  end
rescue Errno::ENOENT
  puts '読み込みファイルを指定してください'
rescue Errno::EACCES
  puts 'ファイルへアクセス権限がありません'
rescue LoadError
  puts '対象ファイルがありません'
else
ensure
  files.close
end
water() click to toggle source
# File lib/suihan.rb, line 9
def water
  m = MeCab::Tagger.new('-Owakati')
  begin
  file = File.open(ARGV[1])
  text = file.read
  p m.parse(text).toutf8.split(' ')
  end
rescue Errno::ENOENT
  puts '読み込みファイルを指定してください'
rescue Errno::EACCES
  puts 'ファイルへアクセス権限がありません'
rescue LoadError
  puts '対象ファイルがありません'
else
ensure
  file.close
end