Tshiluba-dataset / parser_rules.py
DanMM96's picture
Upload folder using huggingface_hub
57fdb55 verified
Raw History Blame Contribute Delete
1.12 kB
import re
# Expanded Tshiluba morphology (from Morrison & Bantu rules)
NOUN_PREFIXES = ["mu", "ba", "lu", "bu", "ki", "mi", "ma", "ntu"]
VERB_PREFIXES = ["ndi", "udi", "u", "tu", "ba", "di", "a", "ku"]
VERB_SUFFIXES = ["ile", "ayi", "yi", "sha", "a"]
def morphological_segment(word):
segments = []
# Noun prefix detection
for p in NOUN_PREFIXES:
if word.startswith(p) and len(word) > len(p) + 2:
segments = [p, word[len(p):]]
return segments
# Verb prefix detection
for p in VERB_PREFIXES:
if word.startswith(p) and len(word) > len(p) + 2:
segments = [p, word[len(p):]]
return segments
# Verb suffix detection
for s in VERB_SUFFIXES:
if word.endswith(s) and len(word) > len(s) + 2:
segments = [word[:-len(s)], s]
return segments
return [word] # default: no segmentation
# Test examples
examples = ["muana", "bantu", "udi", "kulonda", "tubakaye", "lusambu", "balonga", "ndile"]
for ex in examples:
print(ex, "->", morphological_segment(ex))