Skip to content

Commit 1b004ac

Browse files
Copilotbact
andcommitted
Fix Ruff issues: remove unnecessary map(), list() calls, use dict comprehensions, remove unused import, fix default parameter, and remove trailing whitespace
Co-authored-by: bact <128572+bact@users.noreply.github.com>
1 parent c1c2bdf commit 1b004ac

11 files changed

Lines changed: 12 additions & 13 deletions

File tree

pythainlp/benchmarks/word_tokenization.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,5 +257,5 @@ def _find_words_correctly_tokenised(
257257
"""
258258
ref_b = dict(zip(ref_boundaries, [1] * len(ref_boundaries)))
259259

260-
labels = tuple(map(lambda x: ref_b.get(x, 0), predicted_boundaries))
260+
labels = tuple(ref_b.get(x, 0) for x in predicted_boundaries)
261261
return labels

pythainlp/cli/benchmark.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
def _read_file(path):
1515
with open(path, encoding="utf-8") as f:
16-
lines = map(lambda r: r.strip(), f.readlines())
16+
lines = (r.strip() for r in f.readlines())
1717
return list(lines)
1818

1919

pythainlp/corpus/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ def find_synonyms(word: str) -> list[str]:
372372
list_synonym.extend(synonyms["synonym"][idx])
373373
list_synonym.append(synonyms["word"][idx])
374374

375-
list_synonym = sorted(list(set(list_synonym)))
375+
list_synonym = sorted(set(list_synonym))
376376

377377
if word in list_synonym: # remove same word
378378
list_synonym.remove(word)

pythainlp/morpheme/word_formation.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def nighit(w1: str, w2: str) -> str:
3535
raise NotImplementedError(f"The function doesn't support {w1}.")
3636
list_w1 = list(w1)
3737
list_w2 = list(w2)
38-
newword = list()
38+
newword = []
3939
newword.append(list_w1[0])
4040
newword.append("ั")
4141
consonant_start = [i for i in list_w2 if i in set(thai_consonants)][0]

pythainlp/tag/blackboard.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# defined strings for special characters
77
CHAR_TO_ESCAPE = {" ": "_"}
8-
ESCAPE_TO_CHAR = dict((v, k) for k, v in CHAR_TO_ESCAPE.items())
8+
ESCAPE_TO_CHAR = {v: k for k, v in CHAR_TO_ESCAPE.items()}
99

1010

1111
# map from Blackboard treebank POS tag to Universal POS tag

pythainlp/tag/orchid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
";": "<semi_colon>",
3434
"/": "<slash>",
3535
}
36-
ESCAPE_TO_CHAR = dict((v, k) for k, v in CHAR_TO_ESCAPE.items())
36+
ESCAPE_TO_CHAR = {v: k for k, v in CHAR_TO_ESCAPE.items()}
3737

3838
# map from ORCHID POS tag to Universal POS tag
3939
# from Korakot Chaovavanich

pythainlp/tokenize/core.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
from __future__ import annotations
88

9-
import copy
109
import re
1110
from collections import deque
1211
from collections.abc import Iterable

pythainlp/tokenize/crfcut.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ def extract_features(
140140
"""
141141
if not doc:
142142
return []
143-
143+
144144
doc_features = []
145145
# Pad the document with "xxpad" tokens efficiently
146146
padded_doc = ["xxpad"] * window

pythainlp/tokenize/thaisumcut.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def list_to_string(list: list[str]) -> str:
3131
def middle_cut(sentences: list[str]) -> list[str]:
3232
if not sentences:
3333
return []
34-
34+
3535
result_parts = []
3636
for sentence in sentences:
3737
sentence_size = len(word_tokenize(sentence, keep_whitespace=False))

pythainlp/transliterate/thai2rom_onnx.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,9 @@ def run(self, source_seq, source_seq_len):
127127

128128
outputs = np.zeros((max_len, batch_size, self.target_vocab_size))
129129

130-
expected_encoder_outputs = list(
131-
map(lambda output: output.name, self.encoder.get_outputs())
132-
)
130+
expected_encoder_outputs = [
131+
output.name for output in self.encoder.get_outputs()
132+
]
133133
encoder_outputs, encoder_hidden, _ = self.encoder.run(
134134
input_feed={
135135
"input_tensor": source_seq,

0 commit comments

Comments
 (0)