Class: CppjiebaRb::Segment

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

Constant Summary collapse

VALID_MODES =
%i[mix hmm mp query full].freeze

Instance Method Summary collapse

Constructor Details

#initialize(opts = nil) ⇒ Segment

Returns a new instance of Segment.



5
6
7
8
9
10
11
12
13
14
# File 'lib/cppjieba_rb/segment.rb', line 5

def initialize(opts = nil)
  opts ||= {}
  unless opts[:mode].nil? || VALID_MODES.include?(opts[:mode])
    raise ArgumentError, "The mode is #{opts[:mode]}. It should be one of :mix :hmm :mp"
  end

  @mode = opts[:mode] || :mix
  @max_word_length = opts[:max_word_length] || 8
  @hmm = opts[:hmm] || true
end

Instance Method Details

#segment(str) ⇒ Object



16
17
18
# File 'lib/cppjieba_rb/segment.rb', line 16

def segment(str)
  CppjiebaRb.internal.segment(str, @mode, @max_word_length, @hmm)
end