Files
MoviePilot/jieba/__init__.py
2026-05-23 12:59:33 +08:00

45 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""jieba 兼容入口。"""
from collections.abc import Iterator
from typing import Any
import jieba_next as _jieba_next
from jieba_next import cut_for_search as _cut_for_search
from jieba_next import lcut as _lcut
from jieba_next import lcut_for_search as _lcut_for_search
def cut(sentence: str, cut_all: bool = False, HMM: bool = True, use_paddle: bool = False) -> Iterator[str]:
"""
兼容旧 jieba.cut 入口,底层委托给 jieba-next 的 Rust 加速实现。
"""
return _jieba_next.cut(sentence, cut_all=cut_all, HMM=HMM)
def lcut(sentence: str, cut_all: bool = False, HMM: bool = True, use_paddle: bool = False) -> list[str]:
"""
兼容旧 jieba.lcut 入口,保持返回列表的调用习惯。
"""
return _lcut(sentence, cut_all=cut_all, HMM=HMM)
def cut_for_search(sentence: str, HMM: bool = True) -> Iterator[str]:
"""
兼容旧 jieba.cut_for_search 入口,用于搜索模式分词。
"""
return _cut_for_search(sentence, HMM=HMM)
def lcut_for_search(sentence: str, HMM: bool = True) -> list[str]:
"""
兼容旧 jieba.lcut_for_search 入口,用于搜索模式分词列表。
"""
return _lcut_for_search(sentence, HMM=HMM)
def __getattr__(name: str) -> Any:
"""
将未显式封装的 jieba 属性回退到 jieba-next减少旧调用面的迁移成本。
"""
return getattr(_jieba_next, name)