mirror of
https://github.com/affaan-m/ECC.git
synced 2026-10-26 18:35:05 +00:00
fix(bengali): preserve decimal tokens
This commit is contained in:
3 files changed
+30
-4
No files matched your search
@@ -131,8 +131,8 @@ import re
|
||||
|
||||
def tokenize_bangla(text: str) -> list[str]:
|
||||
"""Basic Bengali tokenizer — split on whitespace and punctuation."""
|
||||
# Remove Bengali and ASCII punctuation
|
||||
text = re.sub(r'[।,;:!?.\-\'"()\[\]{}]', ' ', text)
|
||||
# Remove Bengali and ASCII punctuation, but preserve decimal points
|
||||
text = re.sub(r'(?<!\d)\.|\.(?!\d)|[।,;:!?\-\'"()\[\]{}]', ' ', text)
|
||||
return [token for token in text.split() if token]
|
||||
|
||||
# For production, use a trained tokenizer:
|
||||
|
||||
@@ -131,8 +131,8 @@ import re
|
||||
|
||||
def tokenize_bangla(text: str) -> list[str]:
|
||||
"""Basic Bengali tokenizer — split on whitespace and punctuation."""
|
||||
# Remove Bengali and ASCII punctuation
|
||||
text = re.sub(r'[।,;:!?.\-\'"()\[\]{}]', ' ', text)
|
||||
# Remove Bengali and ASCII punctuation, but preserve decimal points
|
||||
text = re.sub(r'(?<!\d)\.|\.(?!\d)|[।,;:!?\-\'"()\[\]{}]', ' ', text)
|
||||
return [token for token in text.split() if token]
|
||||
|
||||
# For production, use a trained tokenizer:
|
||||
|
||||
@@ -143,6 +143,32 @@ function run() {
|
||||
});
|
||||
});
|
||||
|
||||
test('Bengali tokenizer preserves decimal quantities', () => {
|
||||
const skill = read('skills/bengali-nlp/SKILL.md');
|
||||
const tokenizer = extractFencedBlocks(skill)
|
||||
.filter(block => block.language === 'python')
|
||||
.find(block => block.code.includes('def tokenize_bangla'));
|
||||
assert.ok(tokenizer, 'Expected the Bengali tokenizer example');
|
||||
|
||||
const python = findPython();
|
||||
if (!python) {
|
||||
throw new SkipError('no Python 3 interpreter on PATH');
|
||||
}
|
||||
|
||||
const check = [
|
||||
tokenizer.code,
|
||||
"assert tokenize_bangla('ওজন ৩.৫ কেজি। মূল্য 12.75 টাকা.') == ['ওজন', '৩.৫', 'কেজি', 'মূল্য', '12.75', 'টাকা']",
|
||||
].join('\n');
|
||||
const result = spawnSync(python.command, [...python.prefix, '-c', check], {
|
||||
encoding: 'utf8',
|
||||
});
|
||||
assert.strictEqual(
|
||||
result.status,
|
||||
0,
|
||||
`Bengali tokenizer changed decimal quantities:\n${result.stderr || result.stdout}`,
|
||||
);
|
||||
});
|
||||
|
||||
test('Bengali skill is exported and installable', () => {
|
||||
const agentYaml = read('agent.yaml');
|
||||
const modules = readJson('manifests/install-modules.json').modules;
|
||||
|
||||
Reference in new issue
Block a user