• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

PyThaiNLP / pythainlp / 4699361508

pending completion
4699361508

push

github

GitHub
Merge pull request #789 from PyThaiNLP/4.0

22 of 22 new or added lines in 6 files covered. (100.0%)

5749 of 6246 relevant lines covered (92.04%)

0.92 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

86.67
/pythainlp/tokenize/deepcut.py
1
# -*- coding: utf-8 -*-
2
# Copyright (C) 2016-2023 PyThaiNLP Project
3
#
4
# Licensed under the Apache License, Version 2.0 (the "License");
5
# you may not use this file except in compliance with the License.
6
# You may obtain a copy of the License at
7
#
8
#     http://www.apache.org/licenses/LICENSE-2.0
9
#
10
# Unless required by applicable law or agreed to in writing, software
11
# distributed under the License is distributed on an "AS IS" BASIS,
12
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
# See the License for the specific language governing permissions and
14
# limitations under the License.
15
"""
1✔
16
Wrapper for deepcut Thai word segmentation. deepcut is a
17
Thai word segmentation library using 1D Convolution Neural Network.
18

19
User need to install deepcut (and its dependency: tensorflow) by themselves.
20

21
:See Also:
22
    * `GitHub repository <https://github.com/rkcosmos/deepcut>`_
23
"""
24

25
from typing import List, Union
1✔
26

27
try:
1✔
28
    from deepcut import tokenize
1✔
29
except ImportError:
×
30
    raise ImportError("Please install deepcut by pip install deepcut")
×
31
from pythainlp.util import Trie
1✔
32

33

34
def segment(
1✔
35
    text: str, custom_dict: Union[Trie, List[str], str] = None
36
) -> List[str]:
37
    if not text or not isinstance(text, str):
1✔
38
        return []
1✔
39

40
    if custom_dict:
1✔
41
        if isinstance(custom_dict, Trie):
1✔
42
            custom_dict = list(custom_dict)
1✔
43

44
        return tokenize(text, custom_dict)
1✔
45

46
    return tokenize(text)
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc