Tuesday, April 29, 2008

Using Perl to Improve Poor Spelling


#!/usr/bin/perl
#
# written by sam levine (hn darkscyon dn gmail tld com)
# this software comes with no warranty. it may blow up your computer. you have been warned.
# this code is licensed under the GPL.
# this is some random code I was playing with to better grasp regular expressions
# I will improve it at some point (comments, actually working, etc.), for now feel free to
# have fun with it if you are so inclined.
#
#
sub clean {
my $input = $_[0];
print "problem text = $input\n";
$input =~ s/(.*)/\L\1/;
$input =~ s/(.*)/\u\1/;
$input =~ s/\bliek\b/like/ig;
$input =~ s/\bpwn/defeat/ig;
$input =~ s/\bteh\b/the/ig;
$input =~ s/z(o|0)r\b/ing/ig;
$input =~ s/(!|\?)(!|\?)+/\1/ig;
$input =~ s/kthank?x+/thank you/ig;
$input =~ s/\bwit\b/with/ig;
$input =~ s/\bbiye+/bye/ig;
$input =~ s/\bomg\b/exclamation/ig;
$input =~ s/\breall+y\b/really/ig;
$input =~ s/\bu\b/you/ig;
$input =~ s/\br\b/are/ig;
#print $input;
return $input;
}



while (<>) {
$output = &clean($_);
print $output;

}

No comments: