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
|
from __future__ import annotations
|
||||||
|
|
||||||
import os
|
|
||||||
import re
|
import re
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
import snowballstemmer
|
import snowballstemmer
|
||||||
|
|
||||||
@ -13,8 +13,10 @@ try:
|
|||||||
import jieba # type: ignore[import-not-found]
|
import jieba # type: ignore[import-not-found]
|
||||||
|
|
||||||
JIEBA = True
|
JIEBA = True
|
||||||
|
JIEBA_DEFAULT_DICT = Path(jieba.__file__).parent / jieba.DEFAULT_DICT_NAME
|
||||||
except ImportError:
|
except ImportError:
|
||||||
JIEBA = False
|
JIEBA = False
|
||||||
|
JIEBA_DEFAULT_DICT = Path()
|
||||||
|
|
||||||
english_stopwords = set(
|
english_stopwords = set(
|
||||||
"""
|
"""
|
||||||
@ -234,11 +236,8 @@ class SearchChinese(SearchLanguage):
|
|||||||
|
|
||||||
def init(self, options: dict[str, str]) -> None:
|
def init(self, options: dict[str, str]) -> None:
|
||||||
if JIEBA:
|
if JIEBA:
|
||||||
default_dict_path = os.path.join(
|
dict_path = options.get('dict', JIEBA_DEFAULT_DICT)
|
||||||
os.path.dirname(jieba.__file__), jieba.DEFAULT_DICT_NAME
|
if dict_path and Path(dict_path).is_file():
|
||||||
)
|
|
||||||
dict_path = options.get('dict', default_dict_path)
|
|
||||||
if dict_path and os.path.isfile(dict_path):
|
|
||||||
jieba.load_userdict(dict_path)
|
jieba.load_userdict(dict_path)
|
||||||
|
|
||||||
self.stemmer = snowballstemmer.stemmer('english')
|
self.stemmer = snowballstemmer.stemmer('english')
|
||||||
|
Loading…
Reference in New Issue
Block a user