Class: JiebaRb::Segment

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

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Segment

Returns a new instance of Segment.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/jieba-rb.rb', line 12

def initialize opts = {}
  valid_modes = [:mix, :hmm, :mp]
  if mode = opts[:mode]
    raise "Mode must be one of :mix :hmm :mp" unless valid_modes.include? mode
  else
    mode = :mix #default
  end

  jieba_dict = opts[:jieba_dict] || DEFAULT_JIEBA_DICT
  hmm_dict = opts[:hmm_dict] || DEFAULT_HMM_DICT
  user_dict = opts[:user_dict] || ""
  user_dict = DEFAULT_USER_DICT if user_dict == :default

  _init mode, jieba_dict, hmm_dict, user_dict
end