Class: Igo::Unknown
- Inherits:
-
Object
- Object
- Igo::Unknown
- Defined in:
- lib/igo/dictionary.rb
Overview
未知語の検索を行うクラス
Instance Method Summary collapse
-
#initialize(data_dir) ⇒ Unknown
constructor
- コンストラクタ data_dir
辞書ファイルのディレクトリパス.
-
#search(text, start, wdic, result) ⇒ Object
- 検索 text
- start
- wdic
result::.
Constructor Details
#initialize(data_dir) ⇒ Unknown
コンストラクタ
- data_dir
辞書ファイルのディレクトリパス
93 94 95 96 97 98 99 |
# File 'lib/igo/dictionary.rb', line 93 def initialize(data_dir) # 文字カテゴリ管理クラス @category = CharCategory.new(data_dir) # 文字カテゴリが空白の文字のID @space_id = @category.category(' '.unpack("U*")[0]).id end |
Instance Method Details
#search(text, start, wdic, result) ⇒ Object
検索
- text
- start
- wdic
- result
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/igo/dictionary.rb', line 106 def search(text, start, wdic, result) if RUBY_VERSION >= '1.9.0' txt = text.bytes.to_a else txt = text.unpack('C*') end txtu = text.unpack("U*") length = txtu.size ch = txtu[start] ct = @category.category(ch) if !result.empty? and !ct.invoke return end is_space = (ct.id == @space_id) limit = [length, ct.length + start].min for i in start..(limit - 1) wdic.search_from_trie_id(ct.id, start, (i - start) + 1, is_space, result) if((i + 1) != limit and !(@category.compatible?(ch, txt[i + 1]))) return end end if ct.group and limit < length for i in limit..(length - 1) if not @category.compatible?(ch, txtu[i]) wdic.search_from_trie_id(ct.id, start, i - start, is_space, result) return end end wdic.search_from_trie_id(ct.id, start, length - start, is_space, result) end end |