Works:
#!/usr/bin/env python3
from uniseg.graphemecluster import grapheme_clusters
def albanian_digraph_dh(s, breakables):
for i, breakable in enumerate(breakables):
if s.endswith('d', 0, i) and s.startswith('h', i):
yield 0
else:
yield breakable
print(list(grapheme_clusters('dhelpëror', albanian_digraph_dh)))
#['dh', 'e', 'l', 'p', 'ë', 'r', 'o', 'r']
Needs improvement/customisation:
perl -C -Mutf8 -mUnicode::GCString -E'
say join " ", Unicode::GCString
->new("dhelpëror")->as_array
'
#d h e l p ë r o r
perl6 -e'"dhelpëror".comb.say'
#(d h e l p ë r o r)
NB: writing your own segmentation which is almost guaranteed to not implement UAX #29 correctly counts as side-stepping the problem.
D:\>perl6 -e "'dhelpëror'.comb(/dh|./).say"
(dh e l p ë r o r)
You can do the same in old Perl.
print join ' ', 'dhelpëror' =~ /dh|./g
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With