#!/usr/bin/perl print "What term?\n"; $term = <>; chop($term); print "Input file?\n"; $input = <>; chop($input); open(INFILE, "$input") || die "Can't open file $corpus_file\n"; open(JUNKFILE, ">junk.kollok") || die "Can't open file junk.kollok\n"; print "Output type? (s/f)\n"; $output = <>; chop($output); if ($output =~ /f/) { print "What filename for output?\n"; $unix_filename = <>; chop($unix_filename); open(UNIXFILE, ">$unix_filename") || die "Can't open outfile $output_filename\n"; } $/ = "\n\n"; $next_word = ""; $loop_word = ""; while () { if ($_ =~ /$term/i) { $rec = $_; $rec =~ s/\n/ /g; $rec =~ s/[ ]+/ /g; while ($rec =~ s/(.*?[\.\?\!])//) { $sentence = $1; if ($sentence =~ m/^$term/ || $sentence =~ m/ $term/) { while (s/([a-zA-Z\-\']+) ([a-zA-Z\-\']+)/$2/) { $next_word = $2; $loop_word = $1; if ($loop_word eq $term) { push(@freq_words, "$next_word\n"); } $next_word = $1; } } } } } close(INFILE); foreach $freq (@freq_words) { $freq =~ tr/A-Z/a-z/; $words{"$freq"}++; } foreach $key (sort {$words{$b} <=> $words{$a}} sort(keys %words)) { if ($output =~ /s/) { print JUNKFILE "$words{$key} $key"; } elsif ($output =~ /f/) { print UNIXFILE "$words{$key} $key"; } } close(JUNKFILE); close(UNIXFILE); if ($output =~ /s/) { system ("more < junk.kollok"); } exit;