|
Lingua::JA::Numbers - Converts numeric values into their Japanese string equivalents and vice versa |
Lingua::JA::Numbers - Converts numeric values into their Japanese string equivalents and vice versa
$Revision: 0.4 $ $Date: 2006/06/10 16:10:39 $
use Lingua::JA::Numbers;
# OO Style
my $ja = Lingua::JA::Numbers->new(1234567890, {style=>'romaji'});
# JuuNiOkuSanzenYonHyakuGoJuuRokuManNanaSenHappyakuKyuuJuu
# $ja->get_string is implictly called
print "$ja\n";
print $ja+0, "\n";
# 1234567890
# $ja->number is implicitly called.
# 1234567890
# Functional Style
my $str = ja2num(1234567890, {style=>'romaji'});
print "$str\n";
# JuuNiOkuSanzenYonHyakuGoJuuRokuManNanaSenHappyakuKyuuJuu
print num2ja($str), "\n";
# 1234567890
To install this module type the following:
perl Makefile.PL make make test make install
This module requires perl 5.8.1 or better. It also uses the bignum manpage internally (that comes with perl core).
This module converts Japanese text in UTF-8 (or romaji in ascii) to number, AND vice versa. Though this pod is in English and all examples are in romaji to make http://search.cpan.org/ happy, this module does accept Japanese in UTF-8. Try the code below to see it.
perl -MLingua::JA::Numbers \
-e '$y="\x{4e8c}\x{5343}\x{4e94}"; printf "(C) %d Dan Kogai\n", ja2num($y)'
DO NOT BE CONFUSED WITH the Lingua::JA::Number manpage by Mike Schilli. This module is far more comprehensive. As of 0.03, it even does its to_string() upon request.
This module supports the following methods. They are compliant with the Lingua::En::Numbers manpage and others.
$str. String can either be number or a string in Japanese that represents a number. Optionally take options. See Functions for options.
$str.
This module supports the funcitons below;
number_to_ja()number_to_ja() is just an alias to num2ja().
# \x{767e}\x{4e8c}\x{5341}\x{4e09}
num2ja(123)
# HyakuNijuuSan
num2ja(123, {style=>"romaji"})
This function supports the options as follows;
When this option is set to non-zero, style is ignored (kanji).
print num2ja(1110, {style=>"romaji"}), "\n";
# SenHyakuJuu
print num2ja(1110, {style=>"romaji", p_one=>1}), "\n";
# IchiSenIchiHyakuIchiJuu
print num2ja(2005, {style=>"romaji"}), "\n";
NiSenGo
print num2ja(2005, {style=>"romaji", fixed4=>1}), "\n";
NiZeroZeroGo
fixed4 but stack these numbers with arabic.
print num2ja(20050831, {style=>"romaji"}), "\n";
# NiSenGoManHappyakuSanJuuIchi
print num2ja(20050831, {style=>"romaji" with_arabic=>1}), "\n";
# 2005Man0831
print num2ja(10**60, {style=>"romaji"}), "\n";
# IchiAsougi
print num2ja(10**60, {style=>"romaji" manman=>1}), "\n";
# IchiManKougasha
ja_to_number()num2ja(), its counterpart, it supports only one option, manman = (0|1)> which toggles 8-digit denomination.
It is pretty liberal on what it takes. For instance they all return 20050831.
ja2num("NisenGoManHappyakuSanjuIchi")
ja2num("NiZeroZeroGoZeroHachiSanIchi")
ja2num("2005Man0831")
ja2num() hacksja2num() acts like a calculator -- the easiest way to support scientific notation was just that. Try
ja2num("6.0225Kakeru10No23Jou")
to_string() of Lingua::JA::NumberThough not exported by default, This module comes with to_string()
that is (upper-)compatibile with the Lingua::JA::Number manpage.
my @words = Lingua::JA::Numbers::to_string(1234);
print join('-', @words), "\n";
# "sen-ni-hyaku-san-ju-yon"
ja2num(), num2ja(), num2ja_ordinal(), ja_to_number(), number_to_ja(), number_to_ja_ordinal()
use bignum;
$j = Lingua::JA::Numbers->new("SanTenIchiYon");
$b = 1 + $ja # bang! does not work;
$b = 1 + $ja->numify; # OK
the Lingua::En::Numbers manpage the Lingua::En::Number manpage http://ja.wikipedia.org/wiki/%E6%BC%A2%E6%95%B0%E5%AD%97
Dan Kogai, <dankogai@dan.co.jp>
Copyright (C) 2005 by Dan Kogai
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.7 or, at your option, any later version of Perl 5 you may have available.
|
Lingua::JA::Numbers - Converts numeric values into their Japanese string equivalents and vice versa |