Journal(2005) | Blog(2006) | RandomLink | WhoAmI | LiveBookmark | HomePage

<<Previous: Lingua::Han::Cantonese for 广东话  >>Next: 汉字比划模块

针对汉字的 Lingua::Han::Utils

Category: MyCPAN   Keywords: 汉字

这是一个我今天刚写的 module: Lingua::Han::Utils
主要用于封装一些我常用的与汉字处理有关的函数。目前封装了四个函数,分别介绍如下:

Unihan_value

返回 Unihan.txt 的第一个字段(出去+U)。 Unihan: http://www.unicode.org/Public/UNIDATA/
Unihan 的用处自然不用说,我写的拼音,比划还有广东化都来自这个文件。

use Lingua::Han::Utils qw/Unihan_value/;
# Unihan_value
# return the first field of Unihan.txt on unicode.org
my $word = "我";
my $unihan = Unihan_value($word); # return '6211'
my $words = "爱你";
my @unihan = Unihan_value($word); # return (7231, 4F60)
my $unihan = Unihan_value($word); # return 72314F60

cdecode

感谢 joe jiang 的帮助, Encode::Guess 正好满足要求。
一般来说,我们写的代码都有两种情况,一种是 ASCII 编辑模式,一种是在 Unicode 编辑模式下写的。
此模块用 Guess 封装了两者,大家如果要 decode 的话直接使用 cdecode, 而不必考虑在什么模式下。

csplit

用于分割文字。可以是纯中文或中英文混合字。
use Lingua::Han::Utils qw/csplit/;
my $words = "我爱你";
my @words = csplit($words); # return ("我", "爱", "你")

csubstr

用于截取文字。可以是纯中文或中英文混合字。
use Lingua::Han::Utils qw/csubstr/;
my $words = "我爱你啊";
my @words = csubstr($words, 1, 2); # return ("爱", "你")
my @words = csubstr($words, 1); # return ("爱", "你", "啊")
my $words = csubstr($words, 1, 2); # 爱你

clength

将汉字对待成一个单词。
my $words = "我ya爱你";
print clength($words); # 5

结论

此模块在去往 CPAN 的路上。如果急着用可以从这下: http://www.fayland.org/CPAN/

<<Previous: Lingua::Han::Cantonese for 广东话  >>Next: 汉字比划模块

Options: +Del.icio.us

Related items Created on 2005-11-18 18:37:41, Last modified on 2005-11-25 11:45:57
Copyright 2004-2005 All Rights Reserved. Powered by Eplanet && Catalyst 5.62.