Class: RMMSeg::Dictionary

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/rmmseg/dictionary.rb

Overview

The dictionary is a singleton object which is lazily initialized.

Instance Method Summary collapse

Constructor Details

#initializeDictionary

Initialize and load dictionaries from files specified by Config.dictionaries .



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

def initialize
  load_dictionaries
end

Instance Method Details

#get_word(value) ⇒ Object

Get an instance of Word corresponding to value .



20
21
22
23
24
25
26
27
28
29
# File 'lib/rmmseg/dictionary.rb', line 20

def get_word(value)
  word = @dic[value]
  # Construct a Word lazily
  if word.is_a? String
    arr = word.split(" ")
    word = Word.new(arr[0], Word::TYPES[:cjk_word], arr[1].to_i)
    @dic[value] = word
  end
  word
end

#has_word?(value) ⇒ Boolean

Determin whether value is a word in the dictionary.

Returns:

  • (Boolean)


15
16
17
# File 'lib/rmmseg/dictionary.rb', line 15

def has_word?(value)
  @dic.has_key?(value)
end

#reloadObject

Reload all dictionary files.



32
33
34
35
# File 'lib/rmmseg/dictionary.rb', line 32

def reload
  @dic = nil
  load_dictionaries
end