package Text::Greeking::zh_TW; use warnings; use strict; use v5.8.0; use utf8; use List::Util qw(shuffle); our $VERSION = '0.0.4'; sub new { my $class =shift; my $self = bless {}, $class; srand; $self->init; } sub init { $_[0]->paragraphs(2,8); $_[0]->sentences(2,8); $_[0]->words(5,15); $_[0]; } sub paragraphs { $_[0]->{paragraphs} = [ $_[1], $_[2] ] } sub sentences { $_[0]->{sentences} = [ $_[1], $_[2] ] } sub words { $_[0]->{words} = [ $_[1], $_[2] ] } sub generate { my $self = shift; my($paramin,$paramax) = @{$self->{paragraphs}}; my($sentmin,$sentmax) = @{$self->{sentences}}; my $pcount = int(rand($paramax-$paramin+1)+$paramin); my $out = ""; for (my $x=0; $x < $pcount; $x++) { my $scount = int(rand($sentmax-$sentmin+1)+$sentmin); for (my $y=0; $y < $scount; $y++) { $out .= random_sentence(); } $out .= "\n\n"; } $out; } sub _generate { my $template = corpus(); $template =~ s{ \p{Han} }{ random_word() }xegs; return $template; } { my @han = (); sub random_word { unless (@han) { my @char = split "", corpus(); @han = shuffle grep /\p{Han}/, @char; } shift @han } my @text = (); sub random_paragraph { unless (@text) { @text = shuffle split /\n+/, _generate(); } shift @text; } my @sentence = (); sub random_sentence { unless (@sentence) { @sentence = split /。|?/, random_paragraph() } (shift(@sentence) || random_sentence() ) . random_punct(); } sub random_punct { my $r = int(rand(20)); if ($r == 1) { "!" } elsif ($r == 2) { "?" } else { "。" } } } my $corpus; sub add_source { my ($self, $source) = @_; if (ref $source) { warn "err - source sould be a scalar."; return; } $corpus .= $source; return $self; } # lukhnos.org sub corpus { if ($corpus) { return $corpus; } else { return <new; $g->paragraphs(3,15); # min of 1 paragraph and a max of 2 $g->sentences(1,10); # min of 2 sentences per paragraph and a max of 5 $g->add_source($scalar); # use text yourself, not requisite print $g->generate; =head1 DESCRIPTION This module is for Chinese speakers to generate vary meanless Chinese text. =head1 INTERFACE =over =item new() Constructor. =item paragraphs($min, $max) Sets the minimum and maximum number of paragraphs to generate. Default is a minimum of 2 and a maximum of 8. =item sentences($min, $max) Sets the minimum and maximum number of sentences to generate per paragraph. Default is a minimum of 2 and a maximum of 8. =item generate Returns a body of random text generated from a randomly selected source using the minimum and maximum values set by paragraphs, sentences, and words minimum and maximum values. If generate is called without any sources a standard Lorem Ipsum block is used added to the sources and then used for processing the random text. =item add_source($scalar) Add text of yourself as corpus. Return instance itself, so we can add source serially. $g->add_source($source_one)->add_source($source_two); =back =head1 SEE ALSO L =head1 DEPENDENCIES None. =head1 INCOMPATIBILITIES None reported. =head1 BUGS AND LIMITATIONS No bugs have been reported. Please report any bugs or feature requests to C, or through the web interface at L. =head1 AUTHOR Lukhnos D. Liu C<< >> Kang-min Liu C<< >> =head1 LICENCE AND COPYRIGHT Copyright (c) 2007, 2008, Kang-min Liu C<< >>, Lukhnos D. Liu C<< >>. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See L. =head1 DISCLAIMER OF WARRANTY BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.