/usr/lib/perl5/Text/Kakasi.pm is in libtext-kakasi-perl 2.04-1build3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 | #
# $Id: Kakasi.pm,v 2.4 2003/05/26 10:42:01 dankogai Exp $
package Text::Kakasi;
use strict;
# use warnings; # 5.00503 does not have one!
use Carp;
require Exporter;
require DynaLoader;
use vars qw($VERSION $DEBUG @ISA @EXPORT_OK %EXPORT_TAGS $HAS_ENCODE);
$VERSION = do { my @r = (q$Revision: 2.4 $ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
@ISA = qw(Exporter DynaLoader);
@EXPORT_OK = qw(getopt_argv do_kakasi close_kanwadict);
%EXPORT_TAGS = (all => [qw(getopt_argv do_kakasi close_kanwadict)]);
bootstrap Text::Kakasi $VERSION;
$HAS_ENCODE = load_encode();
sub load_encode{
$INC{Encode} and return 1;
if ($] >= 5.008){
eval { require Encode };
$@ and return 0;
eval {
Encode->import(qw/find_encoding from_to _utf8_on _utf8_off/)
};
return $@ ? 0 : 1;
}else{
return 0;
}
}
sub new{
my $thingy = shift;
my $class = ref $thingy ? ref $thingy : $thingy;
my $self = bless {} => $class;
@_ and $self->set(@_);
return $self
}
my %k2p =
(
oldjis => "7bit-jis",
newjis => "7bit-jis",
dec => "euc-jp",
euc => "euc-jp",
sjis => "shiftjis",
);
sub set{
my $self = shift;
my @argv;
if ($HAS_ENCODE){
for (@_){
if (/(-[io])\s*(\S+)/){
my $name = $k2p{lc($2)} || $2;
my $enc = find_encoding($name);;
unless (ref $enc){
carp "encoding $name is not supported";
next;
}
$self->{$1} = $enc->name;
# push @argv, "$1euc";
}else{
push @argv, $_;
}
}
}else{
@argv = @_;
}
my $error = getopt_argv(@argv);
$error and
carp "Kakasi returned $error for ", join " " => @argv;
$self->{error} = $error;
$self->{argv} = [ @argv ];
return $self;
}
sub getopt_argv{
my @argv = @_;
$argv[0] and $argv[0] eq 'kakasi' or unshift @argv, 'kakasi';
xs_getopt_argv(@argv);
}
sub error{ shift->{error} };
sub get{
my $self = shift;
my $str = shift;
if ($HAS_ENCODE){
if ($self->{'-i'}){
$self->{'-i'} eq 'utf8' and _utf8_off($str);
from_to($str, $self->{'-i'} =>'eucjp');
}
}
$str = do_kakasi($str);
if (defined $str){
$self->{error} = 0;
if ($HAS_ENCODE){
if ($self->{'-o'}){
from_to($str, 'eucjp' => $self->{'-o'});
$self->{'-o'} eq 'utf8' and _utf8_on($str);
}
}
}else{
warn;
$self->{error} = 1;
}
return $str;
}
sub do_kakasi{
my $str = shift;
$str =~ tr/\0//d;
return xs_do_kakasi($str);
}
sub close_kanwadict { xs_close_kanwadict() };
1;
__END__
=head1 NAME
Text::Kakasi - perl frontend to kakasi
=head1 SYNOPSIS
use Text::Kakasi;
# functional
$res = Text::Kakasi::getopt_argv('-JJ', '-c', '-w');
$str = Text::Kakasi::do_kakasi($japanese_text);
# object-oriented
$obj = Text::Kakasi->new('-JJ', '-c', '-w');
$str = $obj->get($japanese_text);
=head1 DESCRIPTION
This module provides interface to kakasi (kanji kana simple inverter).
kakasi is a set of programs and libraries which does what Japanese
input methods do in reverse order. You feed Japanese and kakasi
converts it to phonetic representation thereof. kakasi can also be
used to tokenizing Japanese text. To find more about kakasi, see
L<http://kakasi.namazu.org/> .
Text::Kakasi now features both functional and object-oriented APIs.
functional APIs are 100% compatible with ver. 1.05. But to take
advantage of L</"Perl 5.8 Features">, you should use OOP APIs instead.
See L<Text::Kakasi::JP> for the Japanese version of this document.
=head1 Functional APIs
Note C<Text::Kakasi::> is omitted. Text::Kakasi does not export these
functions by default. You can import these function as follows;
use Text::Kakasi qw/getopt_argv do_kakasi/;
=over 2
=item $err = getopt_argv($arg1, $arg2, ...)
initializes kakasi with options options are the same as C<kakasi>
command. Here is the summery as of kakasi 2.3.4.
-a[jE] -j[aE] -g[ajE] -k[ajKH]
-E[aj] -K[ajkH] -H[ajkK] -J[ajkKH]
-i{oldjis,newjis,dec,euc,sjis}
-o{oldjis,newjis,dec,euc,sjis}
-r{hepburn,kunrei} -p -s -f -c"chars"
[jisyo1, jisyo2,,,]
Character Sets:
a: ascii j: jisroman g: graphic k: kana
(j,k defined in jisx0201)
E: kigou K: katakana H: hiragana J: kanji
(E,K,H,J defined in jisx0208)
Options:
-i: input coding system -o: output coding system
-r: romaji conversion system
-p: list all readings (with -J option)
-s: insert separate characters (with -J option)
-f: furigana mode (with -J option)
-c: skip chars within jukugo
(with -J option: default TAB CR LF BLANK)
-C: romaji Capitalize (with -Ja or -Jj option)
-U: romaji Upcase (with -Ja or -Jj option)
-u: call fflush() after 1 character output
-w: wakatigaki mode
Returns 0 on success and nonzero on failure.
Unlike version 1.x where you have to start the first argument with
C<kakasi>, you can omit that in version 2.x (adding C<kakasi> does not
harm so compatibility is preserved).
=item $result_str = do_kakasi($str)
apply kakasi to C<$str> and returns result. If anything goes wrong it
return C<undef>.
=item close_kanwadic()
closes dictionary files which are implicitly opened. This function is
for backward compatibity only and you should never have to use this
function today.
=back
=head1 Object-Oriented APIs
As of 2.0, Text::Kakasi also offers OOP APIs.
=over 2
=item $k = Text::Kakasi->new($args ...)
Constructs object. When argument is fed, it is the same as
C<< Text::Kakasi->new->set($args ...) >>
=item $k->set($args ...)
OOP interface to C<getopt_argv>.
my $k = Text::Kakasi->new;
$k->set('-w'); # Text::Kakasi::getopt_argv('-w');
Unlike C<getopt_argv()> which returns the status, C<set> returns the
object itself so you can go like this;
my $tokenized = $k->set('-w')->get($raw_japanese);
To get the status of C<< $k->set >>, use C<< $k->error >>.
See also L</"Perl 5.8 Features">.
=item $k->error
returns the status of last method.
=item $result = $k->get($raw_japanese);
OOP interface to C<do_kakasi>. The following codes are equivalent.
# Functional
getopt_argv('-w'); $result = do_kakasi($raw_japanese);
# OOP
$k->set('-w')->get($raw_japanese);
=back
=head1 Perl 5.8 Features
Perl 5.8 introduces L<Encode> module which transcodes various
encodings. This module takes advantage of this feature but to keep
backward compatibility with version 1.x, This feature is enabled only
when you use OOP interface (version 1.x only provided functional
APIs).
On Perl 5.8 and up, C<< -iI<encoding> >> and C<< -oI<encoding> >>are
handled by L<Encode> module so you can use encodings Kakasi does not
suppport such as utf8. In other words,
$result = $k->set(qw/-iutf8 -outf8 -w/)->get($utf8);
Is analogous to:
$euc = encode('eucjp' => $utf8);
getopt_argv('-w');
$tmp = do_kakasi($euc);
$result = decode('eucjp' => $tmp);
When you specify C<-outf8>, C<< $k->get >> will return the string with
utf8 flag on.
You can suppress this feature by setting C<$Text::Kakasi::HAS_ENCODE>
to 0 in which case this feature is not used.
=head1 SEE ALSO
L<kakasi(1)>, L<http://kakasi.namazu.org/>,L<Encode>,L<perlunicode>
=head1 COPYRIGHT
(C) 1998, 1999, 2000 NOKUBI Takatsugu <knok@daionet.gr.jp>
(C) 2003 Dan Kogai <dankogai@dan.co.jp>
There is no warranty for this free software. Anyone can modify and/or
redistribute this module under GNU GENERAL PUBLIC LICENSE. See COPYING
file that is included in the archive for more details.
=cut
|