File size: 757 Bytes
e4b9a7b | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | # -*- coding: utf-8 -*-
# SPDX-FileCopyrightText: 2016-2025 PyThaiNLP Project
# SPDX-FileType: SOURCE
# SPDX-License-Identifier: Apache-2.0
"""
Wrapper for SEFR CUT Thai word segmentation. SEFR CUT is a
Thai Word Segmentation Models using Stacked Ensemble.
:See Also:
* `GitHub repository <https://github.com/mrpeerat/SEFR_CUT>`_
"""
from typing import List
import sefr_cut
DEFAULT_ENGINE = "ws1000"
sefr_cut.load_model(engine=DEFAULT_ENGINE)
def segment(text: str, engine: str = "ws1000") -> List[str]:
global DEFAULT_ENGINE
if not text or not isinstance(text, str):
return []
if engine != DEFAULT_ENGINE:
DEFAULT_ENGINE = engine
sefr_cut.load_model(engine=DEFAULT_ENGINE)
return sefr_cut.tokenize(text)[0]
|