> -----Original Message-----
> From: amit hetawal [mailto:[EMAIL PROTECTED]
> Sent: Sunday, April 23, 2006 7:23 AM
> To: [EMAIL PROTECTED]; [email protected]
> Subject: Re: unigrams,bigrams,trigrams?
> 
> hello ,
> Thanks for the help .
> But my problem is that i need to get 3 different hashes for all uni bi
> tri grams ..
> coz later in my code i have to calculate the value as
> 
> trigram{hello how are} /bigram{hello how}



I think perhaps instead of 3 different hashes, you should have a different
data structure.

I was thinking of a 3 dimensional hash with each key being a word, but that
would be hard to save the counts.  Perhaps a hash w/ an array where the
first element is the count and the second is a hash. Where the second hash
is similar to the first in that the keys are words and values are arrays,
the first value the count the second a hash for trigrams. Using this method
you could also count out all your uni/bi/trigrams at the same time.

For example you would do this to get the count for selected items:
print "unigrams\n";
print "hello: ", $WordCount{hello}[0], "\n";
print "how: ", $WordCount{how}[0] , "\n";

print "bigrams\n";
print "Hello how: ", $WordCount{hello}[1]->{how}[0], "\n";

print "trigrams\n";
print "hello how are: ", $WordCount{hello}[1]->{how}[1]->{are}[0], "\n";

This way to "relate them" you just need to get the keys leading up to the
trigram. It'd be pretty easy to write a function something like:
Bigram_Divides_Trigram('hello', 'how', 'are') that returns a number.

I leave that as an exercise for the reader. :-D

-Wayne

PS. this solution is only tractable since you're only going up to trigram.
If this is a simple problem to try and answer a larger more general question
that data structure would become hopelessly complex (in my opinion).

-- 
CAM Automation Programmer
Unicircuit Inc.
Littleton, Colorado
303-738-5390

-- Warning Corporate Disclaimer to follow this line. --

This electronic mail transmission and any attachments contain information
belonging to the sender which may be confidential, privileged and exempt
from disclosure under applicable law.  This information is intended only for
the use of the individual or entity to whom this electronic mail
transmission is addressed.  If you are not the intended recipient or the
employee or agent responsible for delivering the message to the intended
recipient, you are hereby notified that any disclosure, copying,
distribution, or action taken or not taken in reliance on the contents of
the information contained in this transmission is strictly prohibited.  If
you have received this transmission in error, please immediately inform me
by "reply" e-mail and delete the message in its entirety.  Thank you.
Unicircuit, Inc.



_______________________________________________
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to