perl - 您如何在 Perl 或任何其他编程语言中对 CJK(亚洲)字符进行排序?

标签 perl sorting unicode collation cjk

如何在 Perl 中对中文、日文和韩文 (CJK) 字符进行排序?

据我所知,按笔划数排序 CJK 字符,然后按部首,似乎是这些语言的排序方式。还有一些按声音排序的方法,但这似乎不太常见。

我试过使用:

perl -e 'print join(" ", sort qw(工 然 一 人 三 古 二 )), "\n";'
# Prints: 一 三 二 人 古 工 然 which is incorrect

我试过使用 CPAN 中的 Unicode::Collat​​e,但它说:

By default, CJK Unified Ideographs are ordered in Unicode codepoint order...



如果我可以获得每个字符的笔画数数据库,我可以轻松地对所有字符进行排序,但这似乎不是 Perl 附带的,也没有封装在我能找到的任何模块中。

如果您知道如何用其他语言对 CJK 进行排序,那么在回答这个问题时提及它会很有帮助。

最佳答案

TR38对于肮脏的细节和角落案例。这并不像您想象的那么简单,也不像此代码示例那样简单。

use 5.010;
use utf8;
use Encode;
use Unicode::Unihan;
my $u = Unicode::Unihan->new;

say encode_utf8 sprintf "Character $_ has the radical #%s and %d residual strokes." , split /[.]/, $u->RSUnicode($_) for qw(工 然 一 人 三 古 二);
__END__
Character 工 has the radical #48 and 0 residual strokes.
Character 然 has the radical #86 and 8 residual strokes.
Character 一 has the radical #1 and 0 residual strokes.
Character 人 has the radical #9 and 0 residual strokes.
Character 三 has the radical #1 and 2 residual strokes.
Character 古 has the radical #30 and 2 residual strokes.
Character 二 has the radical #7 and 0 residual strokes.

http://en.wikipedia.org/wiki/List_of_Kangxi_radicals用于从激进序数到笔画数的映射。

关于perl - 您如何在 Perl 或任何其他编程语言中对 CJK(亚洲)字符进行排序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3891556/

相关文章:

python - 排序方法 : The truth value of an array with more than one element is ambiguous. 使用 a.any() 或 a.all()

unicode - 如何在 YAML 多行字符串中进行 Unicode 转义?

python - API 调用 (json) 上的 UnicodeEncodeError

security - 尝试使用 LWP::UserAgent 创建 SSL 连接时,我对领域使用什么?

perl - 我应该使用 CPAN 的替代方案来替换 Frontier::RPC2 吗?

Java 根据值对 Hashmap 进行排序

sql - 在postgres中像excel一样排序

java - 适用于 Latin-1 字符的不区分大小写的索引

regex - Perl - 返回字符串中最后一个数字后的最后一个字母字符并返回修改后的字符串

单引号之间的 Perl 捕获