]> git.donarmstrong.com Git - bin.git/commitdiff
( update anamang to actually load the databases
authorDon Armstrong <don@donarmstrong.com>
Sat, 17 Jan 2009 01:15:03 +0000 (01:15 +0000)
committerDon Armstrong <don@donarmstrong.com>
Sat, 17 Jan 2009 01:15:03 +0000 (01:15 +0000)
anamang

diff --git a/anamang b/anamang
index 78f0ea322de1328761804e8645de2e031cb046cd..d63874f2e02837cd6ac59ca73f98e5ca98ece314 100755 (executable)
--- a/anamang
+++ b/anamang
@@ -234,6 +234,7 @@ sub find_allowable_words {
 sub update_and_load_database {
     my ($dir,$wordlist) = @_;
     # check to see if the wordlist is newer than our database
+    my @dbs = qw(length position substitution rotation anagram);
     my $update_required = 0;
     my $wordlist_time = 1;
     if (! -r $wordlist) {
@@ -241,7 +242,7 @@ sub update_and_load_database {
     }
     my $wordlist_stat = stat($wordlist);
     $wordlist_time = max($wordlist_time,$wordlist_stat->mtime);
-    for my $db (qw(length position)) {
+    for my $db (@dbs) {
        if (! -e "$dir/db_${db}") {
            $update_required = 1;
        }
@@ -255,7 +256,7 @@ sub update_and_load_database {
        if (not -d "$dir") {
            mkdir($dir) or die "Unable to create directory $dir: $!";
        }
-       for my $db (qw(length position substitution rotation anagram)) {
+       for my $db (@dbs) {
            $database->{$db} = {};
            $disk_db->{$db} = {};
            tie %{$disk_db->{$db}}, MLDBM => "$dir/db_${db}",
@@ -274,7 +275,7 @@ sub update_and_load_database {
            next if exists $seen_words{$word};
            $seen_words{$word} = 1;
            if ((keys %seen_words) % 100 == 0) {
-               print STDERR "Handled ".(keys %seen_words) . "words, on $word\n";
+               print STDERR "Handled ".(keys %seen_words) . " words, on $word\n";
            }
            my @l = split //, $word;
            my $l = length($word);
@@ -317,6 +318,9 @@ sub update_and_load_database {
            # in it, hello becomes axeeh, giddy acxxs
            my $fl = $l[0];
            my $index = $l_o{$fl};
+           if (not defined $index or grep {not exists $l_o{$_}} @l) {
+               print STDERR "Problem with some letters in '$word'\n";
+           }
            $mapped_word = join('',map {$l_o[($l_o{$_} - $index + 26) % 26]} @l);
            $temp = $database->{rotation}{$mapped_word};
            $temp = [] if not defined $temp;
@@ -338,7 +342,7 @@ sub update_and_load_database {
        }
     }
     else {
-       for my $db (qw(length position)) {
+       for my $db (@dbs) {
            $database->{$db} = {};
            tie %{$database->{$db}}, MLDBM => "$dir/db_${db}",
                O_RDONLY, 0666