Class: Okura::Tagger

Inherits:
Object
  • Object
show all
Defined in:
lib/okura.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dic, mat) ⇒ Tagger

Returns a new instance of Tagger.



6
7
8
# File 'lib/okura.rb', line 6

def initialize dic,mat
  @dic,@mat=dic,mat
end

Instance Attribute Details

#dicObject (readonly)

Returns the value of attribute dic.



9
10
11
# File 'lib/okura.rb', line 9

def dic
  @dic
end

#matObject (readonly)

Returns the value of attribute mat.



10
11
12
# File 'lib/okura.rb', line 10

def mat
  @mat
end

Instance Method Details

#parse(str) ⇒ Object

-> Nodes



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/okura.rb', line 18

def parse str
  chars=str.split(//)
  nodes=Nodes.new(chars.length+2,@mat)
  nodes.add(0,Node.mk_bos_eos)
  nodes.add(chars.length+1,Node.mk_bos_eos)
  str.length.times{|i|
    @dic.possible_words(str,i).each{|w|
      nodes.add(i+1,Node.new(w))
    }
  }
  nodes
end

#wakati(str, mat) ⇒ Object

-> [String]



12
13
14
15
16
# File 'lib/okura.rb', line 12

def wakati str,mat
  mincost_path=parse(str).mincost_path
  return nil if mincost_path.nil?
  return mincost_path.map{|node|node.word.surface}
end