.\" -*- mode: troff; coding: utf-8 -*- .\" Automatically generated by Pod::Man 5.01 (Pod::Simple 3.43) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" \*(C` and \*(C' are quotes in nroff, nothing in troff, for use with C<>. .ie n \{\ . ds C` "" . ds C' "" 'br\} .el\{\ . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Text::MeCab 3pm" .TH Text::MeCab 3pm 2024-03-08 "perl v5.38.2" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH NAME Text::MeCab \- Alternate Interface To libmecab .SH SYNOPSIS .IX Header "SYNOPSIS" .Vb 10 \& use Text::MeCab; \& my $mecab = Text::MeCab\->new({ \& rcfile => $rcfile, \& dicdir => $dicdir, \& userdic => $userdic, \& lattice_level => $lattice_level, \& all_morphs => $all_morphs, \& output_format_type => $output_format_type, \& partial => $partial, \& node_format => $node_format, \& unk_format => $unk_format, \& bos_format => $bos_format, \& eos_format => $eos_format, \& input_buffer_size => $input_buffer_size, \& allocate_sentence => $allocate_sentence, \& nbest => $nbest, \& theta => $theta, \& }); \& \& for (my $node = $mecab\->parse($text); $node; $node = $node\->next) { \& # See perdoc for Text::MeCab::Node for list of methods \& print $node\->surface, "\en"; \& } \& \& # use constants \& use Text::MeCab qw(:all); \& use Text::MeCab qw(MECAB_NOR_NODE); \& \& # check what mecab version we compiled against? \& print "Compiled with ", &Text::MeCab::MECAB_VERSION, "\en"; .Ve .SH DESCRIPTION .IX Header "DESCRIPTION" libmecab (http://mecab.sourceforge.ne.jp) already has a perl interface built with it, so why a new module? I just feel that while a subtle difference, making the perl interface through a tied hash is just... weird. .PP So Text::MeCab gives you a more natural, Perl-ish way to access libmecab! .PP WARNING: Version 0.20015 has only been tested against libmecab 0.99. .SH INSTALLATION .IX Header "INSTALLATION" You need to have mecab already installed. You also need a dictionary, such as ipadic. .PP Because we want to work with UTF\-8 internally, we need to know what your dictionary's charset is. You need to tell our probe script (which gets invoked by Makefile.PL) interactively asks you this. If you want to specify it from elsewhere, you need to specify via environment variable: .PP .Vb 3 \& PERL_TEXT_MECAB_ENCODING=utf\-8 perl Makefile.PL \& # or, say, you\*(Aqre using cpanm \& PERL_TEXT_MECAB_ENCODING=utf\-8 cpanm Text::MeCab .Ve .PP If you want to build Text::MeCab with debugging info, specify it on the command line to Makefile.PL: .PP .Vb 1 \& perl Makefile.PL \-\-debugging .Ve .SH "Text::MeCab AND FORMATS" .IX Header "Text::MeCab AND FORMATS" mecab allows users to specify an output format, via \-\-*\-format options. These are respected ONLY if you use the \fBformat()\fR method: .PP .Vb 4 \& my $mecab = Text::MeCab\->new({ \& output_format_type => "user", \& node_format => "%m %pn" \& }); \& \& for(my $node = $mecab\->parse($text); $node; $node = $node\->next) { \& print $node\->format($mecab); \& } .Ve .PP Note that you also need to set the output_format_type parameter as well. .SH "Text::MeCab AND SCOPING" .IX Header "Text::MeCab AND SCOPING" [NOTE: The memory management issue has been changed since 0.09] .PP libmecab's default behavior is such that when you analyze a text and get a node back, that node is tied to the mecab "tagger" object that performed the analysis. Therefore, when that tagger is destroyed via \fBmecab_destroy()\fR, all nodes that are associated to it are freed as well. .PP Text::MeCab defaults to the same behavior, so the following won't work: .PP .Vb 5 \& sub get_mecab_node { \& my $mecab = Text::MeCab\->new; \& my $node = $mecab\->parse($_[0]); \& return $node; \& } \& \& my $node = get_mecab_node($text); .Ve .PP By the time \fBget_mecab_node()\fR returns, the Text::MeCab object is DESTROY'ed, and so is \f(CW$node\fR (actually, the object exists, but it will complain when you try to access the node's internals, because the C struct that was there has already been freed). .PP In such cases, use the \fBdclone()\fR method. This will copy the *entire* node structure and create a new Text::MeCab::Node::Cloned instance. .PP .Vb 5 \& sub get_mecab_node { \& my $mecab = Text::MeCab\->new; \& my $node = $mecab\->parse($_[0]); \& return $node\->dclone(); \& } .Ve .PP The returned Text::MeCab::Node::Cloned object is exactly the same as Text::MeCab::Node object on the surface. It just uses a different but very similar C struct underneath. It is blessed into a different namespace only because we need to use a different memory management strategy. .PP Do be aware of the memory issue. You WILL use up twice as much memory. .PP Also please note that if you try the first example, accessing the node *WILL* result in a segfault. This is *NOT* a bug: it's a feature :) While it is possible to control the memory management such that accessing a field in a node that has already expired results in a legal \fBcroak()\fR, we do not go to the length to ensure this, because it will result in a performance penalty. .PP Just remember that unless you \fBdclone()\fR a node, then you are NOT allowed to access it when the original tagger goes out scope: .PP .Vb 4 \& { \& my $mecab = Text::MeCab\->new; \& $node = $mecab\->parse(...); \& } \& \& $node\->surface; # segfault!!!! .Ve .PP Always remember to \fBdclone()\fR before doing this! .SH PERFORMANCE .IX Header "PERFORMANCE" Belows is the result of running tools/benchmark.pl on my PowerBook: .PP .Vb 4 \& daisuke@beefcake Text\-MeCab$ perl tools/benchmark.pl \& Rate mecab text_mecab \& mecab 5.53/s \-\- \-63% \& text_mecab 14.9/s 170% \-\- .Ve .SH METHODS .IX Header "METHODS" .SS "new HASHREF | LIST" .IX Subsection "new HASHREF | LIST" Creates a new Text::MeCab instance. .PP You can either specify a hashref and use named parameters, or you can use the exact command line arguments that the mecab command accepts. .PP Below is the list of accepted named options. See the man page for mecab for details about each option. .IP \fBrcfile\fR 4 .IX Item "rcfile" .PD 0 .IP \fBdicdir\fR 4 .IX Item "dicdir" .IP \fBlattice_level\fR 4 .IX Item "lattice_level" .IP \fBall_morphs\fR 4 .IX Item "all_morphs" .IP \fBoutput_format_type\fR 4 .IX Item "output_format_type" .IP "\fBpartial\fR t =item \fBnode_format\fR" 4 .IX Item "partial t =item node_format" .IP \fBunk_format\fR 4 .IX Item "unk_format" .IP \fBbos_format\fR 4 .IX Item "bos_format" .IP \fBeos_format\fR 4 .IX Item "eos_format" .IP \fBinput_buffer_size\fR 4 .IX Item "input_buffer_size" .IP \fBallocate_sentence\fR 4 .IX Item "allocate_sentence" .IP \fBnbest\fR 4 .IX Item "nbest" .IP \fBtheta\fR 4 .IX Item "theta" .PD .ie n .SS "$node = $tagger\->parse(SCALAR)" .el .SS "\f(CW$node\fP = \f(CW$tagger\fP\->parse(SCALAR)" .IX Subsection "$node = $tagger->parse(SCALAR)" Parses the given text via mecab, and returns a Text::MeCab::Node object. .ie n .SS "$version = \fBText::MeCab::version()\fP" .el .SS "\f(CW$version\fP = \fBText::MeCab::version()\fP" .IX Subsection "$version = Text::MeCab::version()" The version number, as returned by libmecab's \fBmecab_version()\fR; .SS CONSTANTS .IX Subsection "CONSTANTS" .IP ENCODING 4 .IX Item "ENCODING" .Vb 1 \& my $encoding = Text::MeCab::ENCODING .Ve .Sp Returns the encoding of the underlying mecab library that was detected at compile time. .IP MECAB_VERSION 4 .IX Item "MECAB_VERSION" The version number, same as \fBText::MeCab::version()\fR .IP MECAB_TARGET_VERSION 4 .IX Item "MECAB_TARGET_VERSION" The version number detected at compile time of Text::MeCab. .IP MECAB_TARGET_MAJOR_VERSION 4 .IX Item "MECAB_TARGET_MAJOR_VERSION" The version number detected at compile time of Text::MeCab. .IP MECAB_TARGET_MINOR_VERSION 4 .IX Item "MECAB_TARGET_MINOR_VERSION" The version number detected at compile time of Text::MeCab. .IP MECAB_CONFIG 4 .IX Item "MECAB_CONFIG" Path to mecab-config, if available. .IP MECAB_NOR_NODE 4 .IX Item "MECAB_NOR_NODE" .PD 0 .IP MECAB_UNK_NODE 4 .IX Item "MECAB_UNK_NODE" .IP MECAB_BOS_NODE 4 .IX Item "MECAB_BOS_NODE" .IP MECAB_EOS_NODE 4 .IX Item "MECAB_EOS_NODE" .IP MECAB_EON_NODE 4 .IX Item "MECAB_EON_NODE" .IP MECAB_SYS_DIC 4 .IX Item "MECAB_SYS_DIC" .IP MECAB_USR_DIC 4 .IX Item "MECAB_USR_DIC" .IP MECAB_UNK_DIC 4 .IX Item "MECAB_UNK_DIC" .IP MECAB_ONE_BEST 4 .IX Item "MECAB_ONE_BEST" .IP MECAB_NBEST 4 .IX Item "MECAB_NBEST" .IP MECAB_PARTIAL 4 .IX Item "MECAB_PARTIAL" .IP MECAB_MARGINAL_PROB 4 .IX Item "MECAB_MARGINAL_PROB" .IP MECAB_ALTERNATIVE 4 .IX Item "MECAB_ALTERNATIVE" .IP MECAB_ALL_MORPHS 4 .IX Item "MECAB_ALL_MORPHS" .IP MECAB_ALLOCATE_SENTENCE 4 .IX Item "MECAB_ALLOCATE_SENTENCE" .PD .SH "SEE ALSO" .IX Header "SEE ALSO" http://mecab.sourceforge.ne.jp .SH LICENSE .IX Header "LICENSE" This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. .PP See http://www.perl.com/perl/misc/Artistic.html .SH AUTHOR .IX Header "AUTHOR" Copyright (c) 2006\-2011 Daisuke Maki All rights reserved.