File: autokeywords

package info (click to toggle)
gopher 2.3-2
  • links: PTS
  • area: non-free
  • in suites: hamm
  • size: 2,364 kB
  • ctags: 2,030
  • sloc: ansic: 22,451; perl: 1,950; sh: 1,510; makefile: 397; asm: 1
file content (535 lines) | stat: -rwxr-xr-x 6,986 bytes parent folder | download | duplicates (2)
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
#!/usr/local/bin/perl
#######################################################################
# $Author: lindner $
# $Revision: 1.4 $
# $Date: 1995/02/06 22:27:56 $
# $Source: /home/arcwelder/GopherSrc/CVS/gopher+/gopherd/scripts/autokeywords,v $
# $State: Exp $
#
# Paul Lindner, University of Minnesota.
#
# Copyright 1994 by the Regents of the University of Minnesota
# see the file "Copyright" in the distribution for conditions of use.
#######################################################################
# MODULE: autokeywords
# 
# A script to automatically generate a gopher+ KEYWORDS block for an item
# It can be set up to build .keywords files too..
# 
#######################################################################
# Revision History:
# $Log: autokeywords,v $
# Revision 1.4  1995/02/06  22:27:56  lindner
# Use dynamic space for Data_Dir, remove RunLS
#
# Revision 1.3  1994/12/15  17:34:02  lindner
# Fix cached filename, make caching default
#
# Revision 1.2  1994/12/14  22:28:02  lindner
# Add stoplist, better file support
#
#
#######################################################################


#######################################################################
# Parameters you might want to set..
#
# %txtconvert specifies programs that take non-text output and
#             output a text version.
#
# $cacheit    specifies that this script should automatically generate
#             .keywords files for us.  eats disk space like a pig
#######################################################################
#

@ignore = (".dct", ".inv", ".doc");

$txtconvert{'.ps'}    = "ps2ascii \"%s\"";
$txtconvert{'.html'}  = "lynx -dump \"%s\"";
$txtconvert{'.tar.Z'} = "zcat \"%s\" | tar tvf -";
$txtconvert{'.zip'}   = "unzip -l \"%s\"";
$txtconvert{'.tex'}   = "detex %s";

$cacheit              = 1;
$MaxKeywords          = 20;
#
#######################################################################

$filenamebase = shift || die "Need a filename...";
$fname = $filenamebase;
$ENV{'PATH'} = $ENV{'PATH'} . ':/usr/local/bin:/usr/gnu/bin:/usr/local/harvest/bin';

exit if (-d $fname);

if (-f "$fname.keywords") {
   open(moo, "<$fname.keywords");
   while (<moo>) {
      print;
   }
   exit;
}
foreach $i (@ignore) {
   exit if ($fname =~ /$i$/);
}

$fname = &FindTXTfile($fname);

open (f, "<$fname");

foreach $e (keys(%txtconvert)) {
    if ($fname =~ /$e$/i) {
	$cmd = sprintf($txtconvert{"$e"}, $fname);
	close(f);
	open(f, "$cmd |");
	done;
    }
}


&InitStopList;
&InitDict;
#
# Summarize a file for keywords
#

while (<f>) {
    @words = split;
    foreach $i (@words) {
	$loweri = $i;
	$loweri =~ y/[A-Z]/[a-z]/;
	next if (length($i) < 3);
	next if (! ($i =~ /^[A-Z\-a-z]+$/));   # skip numbers and weird suff
	next if ($StopList{$loweri});
	next if ( $i =~ /^[\-]+$/);

	$weight = 1;

	$weight +=3 if ($i =~ /^[A-Z]/);   # Start with Cap
	$weight ++ if ($i =~ /^[A-Z]+$/); # All CAPS

	$weight +=3 if (! &isinDict($loweri));    # Not in Dictionary

	$i =~ y/[A-Z]/[a-z]/;
	$Words{$i} += $weight;
    }
}

@scores = sort {$a <=> $b} values(%Words);

foreach $i (@scores) {
    $total += $i;
}

$avg = $total/$#scores;
$median = $scores[($#scores/2)+1];
$highend = $scores[3*($#scores/4)];
if (($#scores/4) > $MaxKeywords) {
    $highend = $scores[$#scores - $MaxKeywords];
}

#print "Average score for culled words $avg\n";
#print "Median value is $median\n\n";
#print "Highend value is $highend\n";

$linelen = 0;

foreach $i (sort(keys(%Words))) {
    next if ($Words{$i} < ($highend+1));
#    printf("%3d %s\n", $Words{$i}, $i);
    if ($linelen + length($i) > 70) {
	$keywords .= "\n";
	$linelen = 0;
    }	
	
    $keywords .= "$i ";
    $linelen += length($i) + 1;
}


if ($keywords =~ /[A-Za-z]/) {
    print "$keywords\n";
    
    if ($cacheit) {
	open(keywordsout, ">$filenamebase.keywords");
	print keywordsout "$keywords\n";
	close(keywordsout);
    }

}



#
# Load /usr/dict/words
#

sub InitDict {
    open(dict, "</usr/dict/words");
    while (<dict>) {
	chop;
	next if (length($_) < 3);
	$Dict{"$_"} = 1;
    }
    close(dict);
}


sub FindTXTfile {
    local($fname) = @_;
    local($base, $f);

    return($fname) if ( -f $fname);

    #
    # Probably not a text file...
    #

    $fname =~ m/^(.*)\/([^\/]+)$/;
    $base = $1;
    $f = $2;

    
    if (!($fname =~ /\//)) { 
	$base = ".";
	$f = $fname;
    }


    opendir(thedir, $base);
    @files = readdir(thedir);
    foreach $i (@files) {
	if ($i =~ /^$f/) {
	    foreach $t (keys(%txtconvert)) {
		return("$base/$i") if ($i =~ /$t$/i);
	    }
	    return("$base/$i") if ($i =~ /txt$/i);
	    push(@ourfiles, $i) 
	}
    }
    closedir(thedir);

    return($ourfiles[1]);
}


sub isinDict {
    local($word) = @_;
    local($word2);

    if ($word =~ /^(.*)s$/) {
	$word2 = $1;
    } elsif ($word =~ /^(.*)ed$/) {
	$word2 = $1 . "e";
    }

    if ($Dict{$word} || $Dict{$word2}) {
	return(1);
    }

    return(0);
}


sub InitStopList {
    &SnarfStopList;
    foreach $i (split(/\n/,$sl)) {
	$StopList{"$i"} = 1;
    }
}

sub SnarfStopList {
    $sl = <<;
above
according
across
actually
adj
after
afterwards
again
against
all
almost
alone
along
already
also
although
always
among
amongst
and
another
any
anyhow
anyone
anything
anywhere
are
around
became
because
become
becomes
becoming
been
before
beforehand
begin
beginning
behind
being
below
beside
besides
between
beyond
billion
both
but
can
cannot
caption
could
did
does
down
during
each
eight
eighty
either
else
elsewhere
end
ending
enough
etc
even
ever
every
everyone
everything
everywhere
except
few
fifty
first
five
for
former
formerly
forty
found
four
from
fri
further
had
has
hasn't
have
haven't
hence
here
here's
hereafter
hereby
herein
hereupon
hers
herself
him
himself
his
how
however
hundred
inc.
indeed
instead
into
its
itself
last
later
latter
latterly
least
less
let
like
likely
ltd
made
make
makefile
makes
many
maybe
meantime
meanwhile
might
million
miss
mon
more
moreover
most
mostly
mrs
much
must
myself
namely
neither
never
nevertheless
new
nine
ninety
nobody
none
nonetheless
noone
nor
not
nothing
now
nowhere
off
often
once
one
one's
only
onto
other
others
otherwise
our
ours
ourselves
out
over
overall
own
per
perhaps
rather
recent
recently
same
sat
seem
seemed
seeming
seems
seven
seventy
several
she
should
shouldn't
since
six
sixty
some
somehow
someone
something
sometime
sometimes
somewhere
still
stop
such
taking
ten
than
that
the
their
them
themselves
then
thence
there
thereafter
thereby
therefore
therein
thereupon
these
they
thirty
this
those
though
thousand
three
through
throughout
thru
thu
thus
thur
together
toward
towards
trillion
tue
twenty
two
under
unless
unlike
unlikely
until
upon
use
used
using
very
via
was
wed
were
what
whatever
when
whence
whenever
where
whereafter
whereas
whereby
wherein
whereupon
wherever
whether
which
while
whither
who
whoever
whole
whom
whomever
whose
why
will
with
within
without
would
yes
yet
you
your
yours
yourself
yourselves

}