Class: NHKore::DictFormVariator

Inherits:
Variator
  • Object
show all
Defined in:
lib/nhkore/variator.rb

Overview

Guesses a word’s dictionary/plain form (辞書形).

It doesn’t work very well,but better than nothing…

Direct Known Subclasses

BestVariator

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Variator

#begin_variate, #variate

Constructor Details

#initializeDictFormVariator

Returns a new instance of DictFormVariator.



40
41
42
43
44
45
46
47
# File 'lib/nhkore/variator.rb', line 40

def initialize(*)
  require 'set' # Must require manually because JapaneseDeinflector is old
  require 'japanese_deinflector'

  super

  @deinflector = JapaneseDeinflector.new
end

Instance Attribute Details

#deinflectorObject

Returns the value of attribute deinflector.



38
39
40
# File 'lib/nhkore/variator.rb', line 38

def deinflector
  @deinflector
end

Instance Method Details

#end_variate(str) ⇒ Object



49
50
51
52
53
54
55
56
# File 'lib/nhkore/variator.rb', line 49

def end_variate(str)
  guess = @deinflector.deinflect(str)

  return [] if guess.length < 1
  return [] if (guess = guess[0])[:weight] < 0.5

  return [guess[:word]]
end