Return leading consonants (if any), and 'stem' of word
(word)
| 38 | |
| 39 | # -------------------------------------------------- |
| 40 | def stemmer(word): |
| 41 | """Return leading consonants (if any), and 'stem' of word""" |
| 42 | |
| 43 | word = word.lower() |
| 44 | vowels = 'aeiou' |
| 45 | consonants = ''.join( |
| 46 | [c for c in string.ascii_lowercase if c not in vowels]) |
| 47 | pattern = ( |
| 48 | '([' + consonants + ']+)?' # capture one or more, optional |
| 49 | '([' + vowels + '])' # capture at least one vowel |
| 50 | '(.*)' # capture zero or more of anything |
| 51 | ) |
| 52 | pattern = f'([{consonants}]+)?([{vowels}])(.*)' |
| 53 | |
| 54 | match = re.match(pattern, word) |
| 55 | if match: |
| 56 | p1 = match.group(1) or '' |
| 57 | p2 = match.group(2) or '' |
| 58 | p3 = match.group(3) or '' |
| 59 | return (p1, p2 + p3) |
| 60 | else: |
| 61 | return (word, '') |
| 62 | |
| 63 | |
| 64 | # -------------------------------------------------- |
no outgoing calls