Skip to content

Commit

Permalink
✨ Add hmm to enable/disable HMM
Browse files Browse the repository at this point in the history
  • Loading branch information
Freed-Wu committed Nov 22, 2024
1 parent c5ffd72 commit 1a1698c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lua/jieba/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ local function navigate(primary_index_func, secondary_index_func, backward, buff
-- unwrap the row and col from the cursor position
local row, col = cursor_pos[1], cursor_pos[2]
if row == sentinel_row then
pt = parse_tokens(jieba.cut(buffer[row], true))
pt = parse_tokens(jieba.cut(buffer[row], jieba.hmm))
pt = stack_merge(pt)
col = primary_index_func(pt, col)

Expand All @@ -435,23 +435,23 @@ local function navigate(primary_index_func, secondary_index_func, backward, buff
return { row, col }
end
-- similar steps for when row is not the sentinel_row
pt = parse_tokens(jieba.cut(buffer[row], true))
pt = parse_tokens(jieba.cut(buffer[row], jieba.hmm))
pt = stack_merge(pt)
col = primary_index_func(pt, col)
if col ~= nil then
return { row, col }
end
row = row + row_step
while row ~= sentinel_row do
pt = parse_tokens(jieba.cut(buffer[row], true))
pt = parse_tokens(jieba.cut(buffer[row], jieba.hmm))
pt = stack_merge(pt)
col = secondary_index_func(pt)
if col ~= nil then
return { row, col }
end
row = row + row_step
end
pt = parse_tokens(jieba.cut(buffer[row], true))
pt = parse_tokens(jieba.cut(buffer[row], jieba.hmm))
pt = stack_merge(pt)
col = secondary_index_func(pt)
if col == nil then
Expand Down Expand Up @@ -549,7 +549,7 @@ end
M.select_w = function()
local cursor_pos = vim.api.nvim_win_get_cursor(0)
local current_line = Lines[cursor_pos[1]]
local line = parse_tokens(jieba.cut(current_line, true))
local line = parse_tokens(jieba.cut(current_line, jieba.hmm))
print(line)
line = stack_merge(line)
local _, start, row = index_tokens(line, cursor_pos[2])
Expand All @@ -573,7 +573,7 @@ end

-- TODO: 高亮当前光标下的词
-- local function hightlight_under_curosr()
-- local line = parse_tokens(jieba.cut(vim.api.nvim_get_current_line(), false, true))
-- local line = parse_tokens(jieba.cut(vim.api.nvim_get_current_line(), jieba.hmm))
-- line = stack_merge(line)
-- local cursor_pos = vim.api.nvim_win_get_cursor(0)
-- local _, start, row = index_tokens(line, cursor_pos[2] + 1)
Expand Down
1 change: 1 addition & 0 deletions lua/jieba/nvim/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ end

return {
is_init = false,
hmm = true,
jieba_path = jieba_path,
cut = cut
}

0 comments on commit 1a1698c

Please sign in to comment.