#!/usr/local/bin/perl ############################################################################## # Program : googlespell.pl # # # # Programmer : Bridget Thomson McInnes # # # # Description : This program determines the appropriate spelling of a # # misspelled word based on its candidates. # # # ############################################################################## use SOAP::Lite; # Set the key; insert your key here: my $key = ""; # Create an instance of SOAP::Lite $service = SOAP::Lite-> service('file:GoogleSearch.wsdl'); # Get the misspelled word my $word = ; chomp $word; # Get the candidates while() { chomp; push @candidates, $_; } %frequency = (); $total_freq = 0; # Get the results for each of the candidates foreach (@candidates) { $query = $_ . " AND " . $word; $result = $service -> doGoogleSearch( $key, # key $query, # search query 0, # start results 10, # max results "false", # filter: boolean "", # restrict (string) "false", # safeSearch: boolean "", # lr "latin1", # ie "latin1" # oe ); $frequency{$_} = $result->{estimatedTotalResultsCount}; $total_freq+=$frequency{$_}; } # Get the results for the misspelled word $result = $service -> doGoogleSearch( $key, # key $word, # search query 0, # start results 10, # max results "false", # filter: boolean "", # restrict (string) "false", # safeSearch: boolean "", # lr "latin1", # ie "latin1" # oe ); $word_freq = $result->{estimatedTotalResultsCount}; my $max = 0; my $answer = ""; foreach (sort keys %frequency) { $r = $frequency{$_}/$total_freq; if($r > $max) { $max = $r; $answer = $_; } } $googles = $service->doSpellingSuggestion($key,$word); print "MY Suggestion : $answer\n"; print "GOOGLES Suggestion: $googles\n";