We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpSyntax Questions › finding letter combinations
Page Index Toggle Pages: 1
finding letter combinations (Read 971 times)
finding letter combinations
Feb 9th, 2010, 5:58am
 
I would like to find all letter combinations and count them.
This up to 2 and 3 letter combinations, and there requenty.

Like how often is the combination fi present in a text etc.

What are the steps i have to do, i really have problems with non visual things. Like must i store every combination in a array list.
Re: finding letter combinations
Reply #1 - Feb 9th, 2010, 6:25am
 
hashmap?

check existence of the combination in the hash, if it's there increment the value. if it isn't then add it with a count of 1. repeat to end.

a hashmap will grow as necessary and has fast lookup. with an arrayList you'd have to sequentially search it for every addition.
Re: finding letter combinations
Reply #2 - Feb 9th, 2010, 12:59pm
 
what is a iterator?
I looked for a translation but babelfish and google translate give me the same word back.

btw hashmap's look quite difficult, i would like to practise with a hashMap for something easier first. What is a easy usefull thing for them?
Re: finding letter combinations
Reply #3 - Feb 9th, 2010, 2:02pm
 
when you create entries in a hashmap it's pretty random and the name you give it is the name you use to reference it.

HashMap hash = new HashMap();
hash.put("A", 12);
hash.put("B", "Bee");
hash.put("Eleven", new Date());

and you can then access them at random, one at a time:

Date d = (Date)hash.get("Eleven");

but if you need to access to ALL of your buckets you need an iterator - only it knows what buckets you have.

http://www.java-tips.org/java-se-tips/java.util/how-to-use-of-hashmap.html

but you won't need an iterator if you are looking up specific values.

(actually, my example is terrible in that you shouldn't really mix the Classes that you store because you won't know what type they are when you retrieve them)
Re: finding letter combinations
Reply #4 - Feb 10th, 2010, 4:58am
 
clankill3r, I am not sure I fully understood your need. You want to make statistics on frequency of letter pairs or triplets in a given text document
If you look for Markov Chain implementations, you will see they generate random text out of such statistics, so the text is almost looking natural. So there is an initial analysis phase doing what you want.
I believe it uses tree data structure to store the information, for efficient storage and retrieval. But necessarily simple if you don't know what are hash map or iterator. No offense meant here (we all start at zero), I just imply you should get familiar with the base concepts there.

To answer your question, an iterator is a mechanism allowing to "walk" a data structure, often called Collections in Java. These collections can be linear, like an ArrayList or a LinkedList, can Map objects on other objects, like HashMap, can be a Tree, etc.

In Java, an Iterator is a blueprint for objects remembering where they are in a Collection, and how to get next object, if any.
So such object provides methods like hasNext() (is there any more element), and next() (provide next element).
You might also find Enumeration with similar methods, but JavaDoc advise to use the moderner Iterator instead.
Re: finding letter combinations
Reply #5 - Feb 15th, 2010, 1:53pm
 
Quote:
clankill3r, I am not sure I fully understood your need. You want to make statistics on frequency of letter pairs or triplets in a given text document?


yes, but i don't want to use it to generate text.

I will look into this probably next week since i can't find any time for it now.

thx for the replie(s)
Page Index Toggle Pages: 1