Class: Okura::WordDic::DoubleArray
- Inherits:
-
Object
- Object
- Okura::WordDic::DoubleArray
- Defined in:
- lib/okura/word_dic.rb
Defined Under Namespace
Classes: Builder
Instance Method Summary collapse
-
#initialize(words, base, check) ⇒ DoubleArray
constructor
Words -> [Integer] -> [Integer].
- #possible_words(str, i) ⇒ Object
- #word_size ⇒ Object
Constructor Details
#initialize(words, base, check) ⇒ DoubleArray
Words -> [Integer] -> [Integer]
47 48 49 |
# File 'lib/okura/word_dic.rb', line 47 def initialize words,base,check @words,@base,@check=words,base,check end |
Instance Method Details
#possible_words(str, i) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/okura/word_dic.rb', line 50 def possible_words str,i ret=[] prev=nil cur=1 str[i..-1].bytes.each{|c| next_index=@base[cur]+c+1 break unless @check[next_index]==cur prev,cur=cur,next_index # check EOS node eos_index=@base[cur] if @check[eos_index]==cur raise "@base[#{eos_index}] should < 0 but #{@base[eos_index]}" unless @base[eos_index] < 0 ret.push -@base[eos_index]-1 end } return ret.map{|x|@words.group(x)}.flatten(1) end |
#word_size ⇒ Object
67 68 69 |
# File 'lib/okura/word_dic.rb', line 67 def word_size @words.word_size end |