Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions tests/tests/test_normalization.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import sys
import malaya
import malaya.normalizer.rules
import logging

logging.basicConfig(level=logging.DEBUG)
Expand All @@ -23,3 +24,30 @@ def test_normalization():
normalizer = malaya.normalize.normalizer(corrector)
string = 'boleh dtg 8pagi esok tak atau minggu depan? 2 oktober 2019 2pm, tlong bayar rm 3.2k sekali tau'
normalizer.normalize(string)


def test_passport_normalization():
"""
Test that passport numbers are normalized digit-by-digit,
not expanded as cardinal numbers. Regression test for #253.
"""
normalizer = malaya.normalizer.rules.load()

# Passport numbers should be spelled out character-by-character
test_cases = [
'your passport is EL9568719',
'ini adalah passport saya A20964577',
]

for s in test_cases:
result = normalizer.normalize(s)
normalized = result['normalize']

# Should NOT contain cardinal expansions like "million", "thousand", "juta", "ribu"
cardinal_words = ['million', 'thousand', 'hundred', 'juta', 'ribu', 'ratus']
for word in cardinal_words:
assert word not in normalized.lower(), (
f'Passport number in "{s}" was expanded as cardinal number '
f'(found "{word}" in "{normalized}"). '
f'Expected digit-by-digit expansion.'
)