加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

在Perl中,看到é是e,E的变体

发布时间:2020-12-16 06:23:01 所属栏目:大数据 来源:网络整理
导读:我在Perl中处理以utf-8编码的字符串.一个任务是我需要一种方法来知道以带有变音符号的字母开头的单词,例如“écrit”,以与“elephant”相同的字母开头,以及“England”.我需要一个通用的解决方案,因为我将使用多种语言.我需要知道这一点,因为我正在为索引创
我在Perl中处理以utf-8编码的字符串.一个任务是我需要一种方法来知道以带有变音符号的字母开头的单词,例如“écrit”,以与“elephant”相同的字母开头,以及“England”.我需要一个通用的解决方案,因为我将使用多种语言.我需要知道这一点,因为我正在为索引创建字母标题.我刚提到的每个单词都存储在“E”下.

有一种直截了当的方法吗?

解决方法

我假设您按照英语校对规则排序并使用字母文本.下面的代码是一个良好的开端,但现实世界比这更复杂. (例如,中文文本根据上下文有不同的词典规则,例如通用词典,卡拉OK歌曲列表,电子门铃名单……)我无法提供完美的解决方案,因为这个问题的信息很少.

use 5.010;
use utf8;
use Unicode::Collate::Locale 0.96;
use Unicode::Normalize qw(normalize);

my $c = Unicode::Collate::Locale->new(locale => 'en');
say for $c->sort(qw(
    eye
    egg
    estate
    etc.
    eleven
    e.g.
    England
    ensure
    educate
    each
    equipment
    elephant
    ex-
    ending
    écrit
));
say '-' x 40;
for my $word (qw(écrit ?m?hnt?htt-Rê ênio ècole ēad?eard ?mma ?dward ?fini)) {
    say sprintf '%s should be stored under the heading %s',$word,ucfirst substr normalize('D',$word),1;
}

__END__
each
écrit
educate
e.g.
egg
elephant
eleven
ending
England
ensure
equipment
estate
etc.
ex-
eye
----------------------------------------
écrit should be stored under the heading E
?m?hnt?htt-Rê should be stored under the heading E
ênio should be stored under the heading E
ècole should be stored under the heading E
ēad?eard should be stored under the heading E
?mma should be stored under the heading E
?dward should be stored under the heading E
?fini should be stored under the heading E

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读