source code

	# -*- coding: utf-8 -*-
	$KCODE = "u"
	require 'MeCab'
	
	# ---------------------------------------
	# --- define
	# ---------------------------------------
	MECAB_OPTION = ''
	
	# ---------------------------------------
	# --- class
	# ---------------------------------------
	class MecabParse
	  def initialize(sentence)
	    @sentence = sentence
	    @cache = false
	    @mecab = MeCab::Tagger.new()
	    @node = @mecab.parse(sentence)
	    @chunk = []
	    @node.each do |w|
	      next if w =~ /^EOS/
	      @chunk << w
	    end
	  end
	
	  def size
	    @chunk.size
	  end
	
	  def get_node
	    @chunk
	  end
	
	  def get_word( index )
	    val = ''
	    if ((0<=index) && (index < @chunk.size)) then
	      body = @chunk[index].split
	      val = body[0]
	    end
	    val
	  end
	
	  def get_yomi( index )
	    val = ''
	    if ((0<=index) && (index < @chunk.size)) then
	      body = @chunk[index].split
	      data = body[1].split(',')
	      if data.size > 7 then
	        val = data[7]
	      else
	        # - kana
	        val = body[0]
	      end
	    end
	    val
	  end
	
	  def get_hinshi( index )
	    val = ''
	    if ((0<=index) && (index < @chunk.size)) then
	      body = @chunk[index].split
	      data = body[1].split(',')
	      val = data[0]
	    end
	    val
	  end
	
	  def get_noun
	    val = []
	    append = ''
	    append_yomi = ''
	    for i in 0...@chunk.size
	      hinshi = get_hinshi(i)

	        append << get_word(i)
	        append_yomi << get_yomi(i)
	      else
	        if !append.empty? then
	          val << append+' '+append_yomi
	        end
	        append = ''
	        append_yomi = ''
	      end
	    end
	    if !append.empty? then
	      val << append+' '+append_yomi
	    end
	    val
	  end
	
	end

トップ   差分 バックアップ リロード   一覧 単語検索 最終更新   ヘルプ   最終更新のRSS
Last-modified: 2017-11-06 (月) 01:22:22 (2800d)