#!/usr/local/bin/perl5 # John Eblen # April 14, 1999 # This function inputs a set of given terms, searches for them in the # dictionary structure set up by dictsplit.perl, and stores the results # in the array word_results. The corresponding entry for each term will # either contain a 0 if the term was not found or the IFS entry for the # term if it was found. sub findword { my @query_words = @_; if (!open(INDEX, "INDEX")) { printf("Error - the file INDEX was not found.\n"); exit; } # READ IN INDEX INTO AN ARRAY $i=0; while ($word = ) { $index_words[$i] = $word; $i++; } #print "in find",@query_words; # MAIN LOOP TO HUNT FOR EACH QUERY WORD foreach $query_word (@query_words) { # USING INDEX, FIND CORRECT FILE FOR SEARCHING FOR QUERY WORD $i=0; while (("$query_word\n" ge $index_words[$i]) && ($i< @index_words)) { $i++; } $file_to_open = $i; # IF TERM OCCURS BEFORE FIRST WORD, IT, OF COURSE, IS NOT FOUND if ($file_to_open == 0) { $word_results[$word_number] = 0; } # OTHERWISE, OPEN CORRECT DICTIONARY FILE SEARCH IT else { if (!open(DICTFILE, "dictfiles/dict$file_to_open")) { printf("Error - the file dict$file_to_open was not found.\n"); close INDEX; exit; } # READ IN WORDS IN DICTIONARY UNTIL POSSIBLE MATCH IS FOUND # that is, query is less than or equal to word read in $word = ; @dict_word_parts = split(/:/, $word); while ($query_word gt $dict_word_parts[0]) { $word = ; @dict_word_parts = split(/:/, $word); } # ISOLATE THE TERM OF THE POSSIBLE MATCH AND CHECK AGAINST QUERY @dict_word_parts = split(/:/, $word); if ($query_word eq $dict_word_parts[0]) { $word_results[$word_number] = $word; } else {$word_results[$word_number] = 0; #print "query word",$query_word,"\n"; #print "in dict file",$dict_word_parts[0]; } } $word_number++; } @word_results; } 1;