Last active
December 28, 2015 21:19
-
-
Save lukasvermeer/7563457 to your computer and use it in GitHub Desktop.
Quick and dirty hack to find alternative sentences that can be created by adding a single letter to an input sentence. Probably only works on Mac (because it expects a dictionary file in a specific place).
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
die "Malfunction. Need input." unless $ARGV[0]; | |
open(W, "/usr/share/dict/words"); | |
my @w; | |
while (my $line = <W>) { | |
chomp($line); | |
push(@w, lc($line)); | |
} | |
close(W); | |
print("*** searching ***\n"); | |
my $before = ""; | |
for my $i (0..scalar @ARGV-1) { | |
for my $j (0..length($ARGV[$i])) { | |
my $r = lc($ARGV[$i]); | |
substr($r, $j, 0) = '.'; | |
my @w = ( grep { /^${r}$/ } @w ); | |
if (scalar @w > 0) { | |
my $after = lc(join(" ", @ARGV[$i+1..scalar @ARGV-1])); | |
for my $k (0..scalar @w-1) { | |
print($before . $w[$k] . " " . $after . "\n"); | |
} | |
} | |
} | |
$before .= lc($ARGV[$i]) . " "; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
aspell-based wordlists can be expanded to very big word lists that encompass many variations of the same word: