#!/usr/bin/perl use Getopt::Std; sub HELP_MESSAGE { print "usage: thirdperson [-fmnps] [-d] [-o outfile] [file ...]\n"; print "-fmnps: feminine, masculine, neuter, plural, slashed (for first person)\n"; #print "-FMNPS: feminine, masculine, neuter, plural, slashed (for second person)\n"; #print "-r: reverse (convert to first person)\n"; #print "-x: ignores HTML or XML-style commands\n"; print "-o: specify where to put the output (default: stdout)\n"; exit 1; } sub VERSION_MESSAGE { print "thirdperson version 1.0"; exit 1; } getopts('FMNPdfmnprsxo:'); print STDERR "warning: second person not supported\n" if($opt_F||$opt_M||$opt_N||$opt_P||$opt_S); print STDERR "warning: -x not yet supported\n" if($opt_x); print STDERR "warning: -r not yet supported\n" if($opt_r); print STDERR "warning: multiple -fmnp present\n" if($opt_f+$opt_m+$opt_n+$opt_p+$opt_s>1); my %n = (I=>'it', me=>'it', my=>'its', mine=>'its', myself=>'itself', "I'm"=>"it's", "I've"=>"it's", "I'll"=>"it'll", "I'd"=>"it'd", s=>1), %f = (I=>'she', me=>'her', my=>'her', mine=>'hers', myself=>'herself', "I'm"=>"she's", "I've"=>"she's", "I'll"=>"she'll", "I'd"=>"she'd", s=>1), %m = (I=>'he', me=>'him', my=>'his', mine=>'his', myself=>'himself', "I'm"=>"he's", "I've"=>"he's", "I'll"=>"he'll", "I'd"=>"he'd", s=>1), %p = (I=>'they', me=>'them', my=>'their', mine=>'their', myself=>'themselves', "I'm"=>"they're", "I've"=>"they've", "I'll"=>"they'll", "I'd"=>"they'd", s=>0), %s = (I=>'he/she', me=>'him/her', my=>'his/her', mine=>'his/hers', myself=>'him/herself', "I'm"=>"he/she is", "I've"=>"he/she has", "I'll"=>"he/she will", "I'd"=>"he/she'd", s=>1); my %pronouns = %n; if($opt_f&&$opt_m) { %pronouns = rand>.5? %m: %f; } elsif($opt_n) { %pronouns = %n; } elsif($opt_f) { %pronouns = %f; } elsif($opt_m) { %pronouns = %m; } elsif($opt_p) { %pronouns = %p; } elsif($opt_s) { %pronouns = %s; } else { %pronouns = rand>.5? %m: %f; } $pronouns{s} = 0 if $opt_d; if($opt_o) { open STDOUT, '>', $opt_o; } while() { if($pronouns{I} eq "they") { s/\bam\b/are/g; s/\bI(\s+)was\b/I$1were/g; } else { s/\bam\b/is/g; s/\bI(\s+)have\b/I$1has/g; } while(/\bI(?:'m|'ve|'ll|'d)?\b/) { my $before = $`, $after = $', $cur = $&; $after =~ s/^(\s*\w+)/$1s/ unless !$pronouns{s} || $cur ne 'I' || $after =~ /^\s*(?:am|are|is|was|were|have|has|had|do|did|will|would|shall|should|can|could|may|might|must|ought)\b/; $cur = $pronouns{$cur}; $cur = ucfirst $cur if $before =~ /^[^A-Za-z0-9]*$/ || $before =~ /[.?!][^A-Za-z0-9]*$/; $_ = $before . $cur . $after; } foreach my $find1 qw(me my mine myself) { my $rep1 = $pronouns{$find1}; my $find2 = ucfirst $find1, $rep2 = ucfirst $rep1; s/\b$find1\b/$rep1/g; s/\b$find2\b/$rep2/g; } print; }