Acme-Yoda

 view release on metacpan or  search on metacpan

lib/Acme/Yoda.pm  view on Meta::CPAN

=head1 BUGS
    Right now Acme::Yoda does not handle contractions nor does it have a 
    comprehensive list of verbs.

    You can only deyoda sentences you have yoda'ed, since I have no 
    reliable way to discern the subject of the sentence.

    Both issues need to be fixed.


=head1 SUPPORT

    email me if you need help.



=head1 AUTHOR

	Christian Brink
        GREP
	cbrink@flylines.org
	http://www.yoda-speak.org

=head1 COPYRIGHT

This program is free software; you can redistribute
it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the
LICENSE file included with this module.


=head1 SEE ALSO

perl(1).

=cut

############################################# main pod documentation end ##


################################################ subroutine header begin ##

=head2 new()

 Usage     : new( sentence => 'I am a sentence') or just new();
 Purpose   : constructor
 Returns   : Acme::Yoda object
 Argument  : can take a sentence 

=cut

my $_link = Lingua::LinkParser->new(verbosity => 0,
				    display_walls => 0);

sub new {
	my $class = shift;
	my %args = @_;
	$args{_link_parser} = $_link;
	
	my $self = bless \%args, ref($class) || $class ;

	return $self;
}



=head2 yoda()

 Usage     : yoda('sentence')
 Purpose   : Translates your sentenece into yoda speak
 Returns   : string
 Argument  : string 
 Comments  : You can sent the sentence in new() or send it here

=cut
sub yoda {
    my $self = shift;
    my $sentence = shift() || '';
    $sentence =  $sentence || $self->{sentence};

    return if (!$sentence);
    $self->{sentence} = $sentence;

    my $ending;
    if ($sentence =~ /([.?!])$/) {
	chomp($sentence);
	$ending = chop($sentence);
    }

    if (!$self->{_no_contractions}) {
	my %contractions = ( "I'll"    => "I will",
			     "I'm"     => "I am",
			     "he'll"   => "he will",
			     "you'll"  => "you will",
			     "doesn't" => "does not",
			     "can't"   => "can not",
			     "aren't"  => "are not",
			     "I've"    => "I have",
			     "we've"   => "we have",
			     "they've" => "they have",
			     "he's"    => "he is",
			     "she's"   => "she is",
			     "isn't"   => "is not",
			     "you're"  => "you are",
			     "where's" => "where is",
			     "we'll"   => "we will",
			     "they'll" => "they will",
			     "didn't"  => "did not",
			     "I'd"     => "i would",
			     "he'd"    => "he would",
			     "she'd"   => "she would",
			     "its"     => "it is"
			     );
	
	foreach (keys %contractions) {
	    if ($sentence =~ /\b\Q$_\E\b/ig) {
		$sentence =~ s/\b\Q$_\E\b/$contractions{$_}/ige;
	    }
	}
    }



( run in 0.855 second using v1.01-cache-2.11-cpan-5c0b1e786e0 )