File size: 1,118 Bytes
57fdb55
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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))