|
|
|
|
|
import re |
|
from typing import List |
|
|
|
def tokenize_vi_simple(text: str) -> List[str]: |
|
""" |
|
Tokenizes Vietnamese text simply for tasks like BM25. |
|
Converts to lowercase, removes basic punctuation, and splits by whitespace. |
|
|
|
Args: |
|
text (str): The input Vietnamese text. |
|
|
|
Returns: |
|
List[str]: A list of tokens. |
|
""" |
|
if not isinstance(text, str): |
|
|
|
return [] |
|
text = text.lower() |
|
|
|
text = re.sub(r'[^\w\s]', '', text) |
|
return text.split() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__': |
|
print("Testing utils.py...") |
|
|
|
|
|
print("\n--- Test tokenize_vi_simple ---") |
|
test_phrases = [ |
|
"Luật Giao thông Đường bộ Việt Nam 2023!", |
|
"Xe ô tô con và xe máy.", |
|
" Phạt tiền từ 200.000đ đến 400.000đ. ", |
|
"", |
|
None, |
|
123 |
|
] |
|
for phrase in test_phrases: |
|
print(f"Input: '{phrase}' (type: {type(phrase).__name__})") |
|
tokens = tokenize_vi_simple(phrase) |
|
print(f"Tokens: {tokens}") |
|
print("-" * 10) |