1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
|
#! /usr/bin/env perl
#
# insert.pl
#
# Dictionary maintenance tool - insert words into dictionary.
# Given a list of words and a dictionary file, this script
# will insert the words into the file, in alphabetical order,
# with a minimum of disruption of the file itself.
#
# It is assumed that the word-list holds one word per line,
# and that the word-list is already in alphabetical order.
#
# Example usage:
# ./insert.pl wordlist_file en/words/words.adj.1
#
# Copyright (C) 2009 Linas Vepstas <linasvepstas@gmail.com>
#
if ($#ARGV < 1)
{
die "Usage: insert.pl wordlist-file dict-file\n";
}
# Get the word-list, and the dictionary, from the command line
my $wordlist_file = @ARGV[0];
my $dict_file = @ARGV[1];
open(WORDS, $wordlist_file);
my @words = ();
while (<WORDS>)
{
# Get rid of newline at end of word.
chop;
push @words, $_;
}
close(WORDS);
my $word = shift @words;
open (DICT, $dict_file);
while (<DICT>)
{
chop;
my @entries = split;
# Loop over the entries
my $linelen = 0;
foreach (@entries)
{
my $wd = $_;
$linelen += length $_;
while (($_ gt $word) && ($word ne ""))
{
print "$word ";
$linelen += length $word;
$word = shift @words;
# Insert a newline if the resulting line is too long.
if ($linelen > 62)
{
print "\n";
$linelen = 0;
}
}
print "$_ ";
}
print "\n";
}
close (DICT);
|