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

PyThaiNLP / pythainlp / 4698770765

pending completion
4698770765

push

github

Wannaphong Phatthiyaphaibun
Add raise ImportError for deepcut

4 of 4 new or added lines in 1 file covered. (100.0%)

2803 of 6234 relevant lines covered (44.96%)

0.45 hits per line

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

0.0
/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
"""
×
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
×
26

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

33

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

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

44
        return tokenize(text, custom_dict)
×
45

46
    return tokenize(text)
×
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

© 2026 Coveralls, Inc