Download parser_rules.py from DanMM96/Tshiluba-dataset: direct link, hf CLI and curl.
- Browser
- Download file 1.12 kB
-
https://huggingface.co/datasets/DanMM96/Tshiluba-dataset/resolve/main/parser_rules.py
- Command line
-
hf download hf://datasets/DanMM96/Tshiluba-dataset/parser_rules.py
-
curl -L -o parser_rules.py https://huggingface.co/datasets/DanMM96/Tshiluba-dataset/resolve/main/parser_rules.py
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)) | |