Debian Codegraph @

data/tools/delete.pl

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