Skip to content

Commit 2d1466a

Browse files
authored
Merge pull request #1185 from what-in-the-nim/fix-base-dependencies
Fix base dependencies
2 parents 8819cfe + 33ba93b commit 2d1466a

3 files changed

Lines changed: 13 additions & 11 deletions

File tree

pythainlp/cli/benchmark.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,8 @@
88
import json
99
import os
1010

11-
import yaml
1211

1312
from pythainlp import cli
14-
from pythainlp.benchmarks import word_tokenization
1513
from pythainlp.tools import safe_print
1614

1715

@@ -88,6 +86,14 @@ def __init__(self, name, argv):
8886
% (args.input_file, args.test_file, len(actual))
8987
)
9088

89+
try:
90+
import yaml
91+
from pythainlp.benchmarks import word_tokenization
92+
except ImportError:
93+
raise ImportError(
94+
"Please install the extra dependencies `benchmarks` to use this command by running `pip install pythainlp[benchmarks]`"
95+
)
96+
9197
df_raw = word_tokenization.benchmark(expected, actual)
9298

9399
columns = [

pythainlp/tools/misspell.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
# SPDX-License-Identifier: Apache-2.0
55
from typing import List
66

7-
import numpy as np
7+
import math
8+
import random
89

910
THAI_CHARACTERS_WITHOUT_SHIFT = [
1011
"ผปแอิืทมใฝ",
@@ -126,10 +127,8 @@ def misspell(sentence: str, ratio: float = 0.05):
126127
# output:
127128
ภาษาไทยปรากฏครั้งแรกในกุทธศักราช 1727
128129
"""
129-
num_misspells = np.floor(len(sentence) * ratio).astype(int)
130-
positions = np.random.choice(
131-
len(sentence), size=num_misspells, replace=False
132-
)
130+
num_misspells = math.floor(len(sentence) * ratio)
131+
positions = random.sample(range(len(sentence)), k=num_misspells)
133132

134133
# convert strings to array of characters
135134
misspelled = list(sentence)
@@ -138,7 +137,7 @@ def misspell(sentence: str, ratio: float = 0.05):
138137
if potential_candidates is None:
139138
continue
140139

141-
candidate = np.random.choice(potential_candidates)
140+
candidate = random.choice(potential_candidates)
142141

143142
misspelled[pos] = candidate
144143

setup.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,6 @@
4545
requirements = [
4646
"backports.zoneinfo; python_version<'3.9'",
4747
"requests>=2.31",
48-
PYYAML,
49-
PANDAS,
50-
NUMPY,
5148
"tzdata; sys_platform == 'win32'",
5249
]
5350

0 commit comments

Comments
 (0)