Class: RMMSeg::Config

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

Overview

Configurations of RMMSeg.

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.dictionariesObject

An array of dictionary files. Each element should be of the form: [file, whether_dic_include_frequency_info]. This should be set before the dictionaries are loaded (They are loaded only when they are used). Or else you should call Dictionary.instance.reload manually to reload the dictionaries.



55
56
57
# File 'lib/rmmseg/config.rb', line 55

def dictionaries
  @dictionaries
end

.max_word_lengthObject

The maximum length of a CJK word. The default value is 4. Making this value too large might slow down the segment operations.



59
60
61
# File 'lib/rmmseg/config.rb', line 59

def max_word_length
  @max_word_length
end

Class Method Details

.algorithmObject

Get the algorithm name currently using



16
17
18
# File 'lib/rmmseg/config.rb', line 16

def algorithm
  @algorithm
end

.algorithm=(algor) ⇒ Object

Set the algorithm name used to segment. Valid values are :complex and :simple . The former is the default one.



21
22
23
24
25
26
# File 'lib/rmmseg/config.rb', line 21

def algorithm=(algor)
  unless [:complex, :simple].include? algor
    raise ArgumentError, "Unknown algorithm #{algor}"
  end
  @algorithm = algor
end

.algorithm_instance(text, tok = Token) ⇒ Object

Get an instance of the algorithm object corresponding to the algorithm name configured. tok is the class of the token oject to be returned. For example, if you want to use with Ferret, you should provide ::Ferret::Analysis::Token .



31
32
33
# File 'lib/rmmseg/config.rb', line 31

def algorithm_instance(text, tok=Token)
  RMMSeg.const_get("#{@algorithm}".capitalize+"Algorithm").new(text, tok)
end

.on_ambiguityObject

Get the behavior description when an unresolved ambiguity occured.



36
37
38
# File 'lib/rmmseg/config.rb', line 36

def on_ambiguity
  @on_ambiguity
end

.on_ambiguity=(behavior) ⇒ Object

Set the behavior on an unresolved ambiguity. Valid values are :raise_exception and :select_first . The latter is the default one.



42
43
44
45
46
47
# File 'lib/rmmseg/config.rb', line 42

def on_ambiguity=(behavior)
  unless [:raise_exception, :select_first].include? behavior
    raise ArgumentError, "Unknown behavior on ambiguity: #{behavior}"
  end
  @on_ambiguity = behavior
end