如何自定义文本分段以不在二合字母之间打断?
How do you customise text segmentation to not break between a digraph?
作品:
#!/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']
需要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)
注意:编写您自己的分段几乎可以保证不会正确实施 UAX #29 算作回避问题。
D:\>perl6 -e "'dhelpëror'.comb(/dh|./).say"
(dh e l p ë r o r)
您可以在旧版 Perl 中执行相同的操作。
print join ' ', 'dhelpëror' =~ /dh|./g
作品:
#!/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']
需要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)
注意:编写您自己的分段几乎可以保证不会正确实施 UAX #29 算作回避问题。
D:\>perl6 -e "'dhelpëror'.comb(/dh|./).say"
(dh e l p ë r o r)
您可以在旧版 Perl 中执行相同的操作。
print join ' ', 'dhelpëror' =~ /dh|./g