Class: CppjiebaRb::Segment
- Inherits:
-
Object
- Object
- CppjiebaRb::Segment
- Defined in:
- lib/cppjieba_rb/segment.rb
Overview
Sentence segmentation
Constant Summary collapse
- VALID_MODES =
%i[mix hmm mp query full].freeze
Instance Method Summary collapse
-
#initialize(opts = nil) ⇒ Segment
constructor
A new instance of Segment.
- #segment(str) ⇒ Object
Constructor Details
#initialize(opts = nil) ⇒ Segment
Returns a new instance of Segment.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/cppjieba_rb/segment.rb', line 8 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
19 20 21 |
# File 'lib/cppjieba_rb/segment.rb', line 19 def segment(str) CppjiebaRb.internal.segment(str, @mode, @max_word_length, @hmm) end |