Module: Jieba::MixSegment
- Extended by:
- FFI::Library
- Defined in:
- lib/jieba/mix_segment.rb
Constant Summary collapse
- DEFAULT_DICT_PATH =
Jieba::EXT_BASE + "dict/jieba.dict.utf8"
- DEFAULT_MODEL_PATH =
Jieba::EXT_BASE + "dict/hmm_model.utf8"
Class Method Summary collapse
- .cut(sentence) ⇒ Object
- .init(dict_path = DEFAULT_DICT_PATH, model_path = DEFAULT_MODEL_PATH) ⇒ Object
Class Method Details
.cut(sentence) ⇒ Object
13 14 15 16 17 18 19 20 21 22 |
# File 'lib/jieba/mix_segment.rb', line 13 def self.cut sentence ptr2ptr = FFI::MemoryPointer.new(:pointer) word_count = cut_c(sentence, ptr2ptr) ptr = ptr2ptr.read_pointer words = ptr.get_array_of_string(0, word_count) free_c(word_count, ptr2ptr) words.each do |word| word.force_encoding('UTF-8') end end |
.init(dict_path = DEFAULT_DICT_PATH, model_path = DEFAULT_MODEL_PATH) ⇒ Object
9 10 11 |
# File 'lib/jieba/mix_segment.rb', line 9 def self.init dict_path = DEFAULT_DICT_PATH, model_path = DEFAULT_MODEL_PATH init_c dict_path, model_path end |