mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Use pathlib for the Jieba default dict path
This commit is contained in:
parent
d773a43f59
commit
3dc73cbdf4
@ -2,8 +2,8 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
from pathlib import Path
|
||||
|
||||
import snowballstemmer
|
||||
|
||||
@ -13,8 +13,10 @@ try:
|
||||
import jieba # type: ignore[import-not-found]
|
||||
|
||||
JIEBA = True
|
||||
JIEBA_DEFAULT_DICT = Path(jieba.__file__).parent / jieba.DEFAULT_DICT_NAME
|
||||
except ImportError:
|
||||
JIEBA = False
|
||||
JIEBA_DEFAULT_DICT = Path()
|
||||
|
||||
english_stopwords = set(
|
||||
"""
|
||||
@ -234,11 +236,8 @@ class SearchChinese(SearchLanguage):
|
||||
|
||||
def init(self, options: dict[str, str]) -> None:
|
||||
if JIEBA:
|
||||
default_dict_path = os.path.join(
|
||||
os.path.dirname(jieba.__file__), jieba.DEFAULT_DICT_NAME
|
||||
)
|
||||
dict_path = options.get('dict', default_dict_path)
|
||||
if dict_path and os.path.isfile(dict_path):
|
||||
dict_path = options.get('dict', JIEBA_DEFAULT_DICT)
|
||||
if dict_path and Path(dict_path).is_file():
|
||||
jieba.load_userdict(dict_path)
|
||||
|
||||
self.stemmer = snowballstemmer.stemmer('english')
|
||||
|
Loading…
Reference in New Issue
Block a user