sarvan has asked for the wisdom of the Perl Monks concerning the following question:
use strict; use Data::Dumper; my $candidate = 'the the the the the the the'; my @candidate_words = split (/\W/, $candidate); my $candidate_count=@candidate_words; my %candidate = (); map { $candidate{$_}++ } @candidate_words; my $reference = 'the cat is the on the mat'; my @reference_words = split (/\W/, $reference); my %reference = (); map { $reference{$_}++ } @reference_words; while((my $key, my $val)=each(%candidate)){ print $key."->".$val."\n"; } print "-------------------------------------\n"; while((my $key, my $val)=each(%reference)){ print $key."->".$val."\n"; }
This scripts i m writing to find similarity between two sentences. The two sentences are stored in $candidate and $reference variables.
In the current script i made the program to count the occurence of each type of word and stored them in a hash.. Now,each hash has the words and its count from both candidate and reference sentences.
The help in need is, i want to take each words in the candidate and compare that with the two hashes to find the maximum reference count. for eg. if i have the word called "the" in candidate,i want to find the count of this word in %candidate hash as well as %reference hash and i want to take the minimum values(i.e if 2 and 5 is the count of "the" in two hashes i want 2.) out of this two counts. likewise for all words in the candidate.. Plz help me in this.. thanks
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: hash comparison
by GrandFather (Saint) on Jul 25, 2011 at 08:33 UTC | |
|
Re: hash comparison
by choroba (Cardinal) on Jul 25, 2011 at 07:12 UTC | |
by sarvan (Sexton) on Jul 25, 2011 at 07:47 UTC | |
by choroba (Cardinal) on Jul 25, 2011 at 13:29 UTC | |
|
Re: hash comparison
by FunkyMonk (Bishop) on Jul 25, 2011 at 12:02 UTC | |
|
Re: hash comparison
by Marshall (Canon) on Jul 25, 2011 at 08:15 UTC | |
by sarvan (Sexton) on Jul 25, 2011 at 10:41 UTC | |
by Marshall (Canon) on Jul 25, 2011 at 12:17 UTC |