#!/usr/local/bin/perl -w
use strict;
if ($#::ARGV == -1) { @::ARGV = (':snk.txt'); }
my $chapter = undef;
my (%ej, %je, @chapters);
while (<>) {
chomp;
next if /^#/;
next unless /\S/;
if (/^\s*chapter\s+(\d+)\s*$/i) {
$chapter = $1;
$chapters[$chapter] = [] unless defined $chapters[$chapter];
next;
}
my ($kanji, $kana, $english) = split(/(?:\x81\x40| |\t)+/, $_, 3);
unless (defined $english) {
die "I don't know what you mean by:\n$_\n";
}
$english =~ s/\.\s*$//;
my (@english) = split(/;\s*/, $english);
for my $e (@english) { $e = ucfirst $e; }
$english = join('; ', @english);
# for my $ch (split('', $kanji)) { printf "%02x ", ord($ch); } print "\n";
# for my $ch (split('', $kana)) { printf "%02x ", ord($ch); } print "\n";
# print "$english\n";
# add to J->E dictionary
{
my $kanasort = $kana;
$kanasort =~ s/(?:\x81\x60|~)//g;
$kanasort =~ s/^\s*//;
$kanasort =~ s/\s*$//;
$je{$kanasort} = [] unless defined $je{$kanasort};
push(@{$je{$kanasort}}, "
| $chapter | $kanji | $kana | $english |
\n");
}
# add to E->J dictionary
for my $e (@english) {
my $esort = $e;
$esort =~ s/(?:\x81\x60|~)//g;
$esort = lc $e;
$esort =~ y/a-z//dc;
$ej{$esort} = [] unless defined $ej{$esort};
push(@{$ej{$esort}}, "| $chapter | $e | $kanji | $kana |
\n");
}
# add to chapter vocabulary
push(@{$chapters[$chapter]}, "| $kanji | $kana | $english |
\n");
}
# print J->E dictionary
open(OUT, ">snk-je.html") || die "Can't create snk-je.html: $!\n";
MacPerl::SetFileInfo('MOSS', 'TEXT', 'snk-je.html');
print OUT <<"EOF";
Shin Nihongo no Kiso: Japanese-English Vocabulary
Back to SNK
Shin Nihongo no Kiso: Japanese-English Vocabulary
See also English-Japanese and Chapter vocabulary.
| Chapter | \x93\xfa\x96\x7b\x8c\xea | \x82\xc9\x82\xd9\x82\xf1\x82\xb2 | English |
EOF
for my $kana (sort keys %je) {
my $lines = $je{$kana};
print OUT sort @$lines;
}
print OUT <<"EOF";
EOF
close(OUT);
# print E->J dictionary
open(OUT, ">snk-ej.html") || die "Can't create snk-ej.html: $!\n";
MacPerl::SetFileInfo('MOSS', 'TEXT', 'snk-ej.html');
print OUT <<"EOF";
Shin Nihongo no Kiso: English-Japanese Vocabulary
Back to SNK
Shin Nihongo no Kiso: English-Japanese Vocabulary
See also Japanese-English and Chapter vocabulary.
| Chapter | English | \x93\xfa\x96\x7b\x8c\xea | \x82\xc9\x82\xd9\x82\xf1\x82\xb2 |
EOF
for my $e (sort keys %ej) {
my $lines = $ej{$e};
print OUT sort @$lines;
}
print OUT <<"EOF";
EOF
close(OUT);
# print chapter listings
open(OUT, ">snk-ch.html") || die "Can't create snk-ch.html: $!\n";
MacPerl::SetFileInfo('MOSS', 'TEXT', 'snk-ch.html');
print OUT <<"EOF";
Shin Nihongo no Kiso: Vocab by Chapter
Back to SNK
Shin Nihongo no Kiso: Vocab by Chapter
See also English-Japanese and Japanese-English vocabulary.
EOF
for my $ch (1..$#chapters) {
print OUT "
Chapter ";
for my $c (1..$#chapters) {
if ($c == $ch) { print OUT "$c "; }
else { print OUT "$c "; }
}
print OUT "
\n\n";
print OUT "| \x93\xfa\x96\x7b\x8c\xea | \x82\xc9\x82\xd9\x82\xf1\x82\xb2 | English |
\n";
print OUT @{$chapters[$ch]};
print OUT "
\n";
}
print OUT <<"EOF";
EOF
close(OUT);