f13.net

f13.net General Forums => General Discussion => Topic started by: Der Helm on July 23, 2009, 08:17:14 AM



Title: Help with Java needed...
Post by: Der Helm on July 23, 2009, 08:17:14 AM
.... by a fellow student of mine.

Is there someone who would be willing to help her writing a term paper about/with/in the Java language (programming related, Star Wars geeks need not to apply) just raise your hand. She tried to explain the task and her problem to me, but it went right over my head.  :uhrr:

So ? Anyone interested ?

She's cute, btw.  :drill:

edit: Just after posting this, it came to my mind that the tech question thread might be the right place to post this, but here it will probably get more eyeballs, move if you think it is necessary.

edit2: Note to self, improve your punctuation skills.


Title: Re: Help with Java needed...
Post by: Mosesandstick on July 23, 2009, 09:29:35 AM
You probably need to post a picture of her.


Title: Re: Help with Java needed...
Post by: Der Helm on July 23, 2009, 10:25:41 AM
You probably need to post a picture of her.
I'll ask her.  :awesome_for_real:


Title: Re: Help with Java needed...
Post by: craan on July 23, 2009, 10:57:40 AM
Without any inkling of the task I don't know if you need the super-genius programmer in my office or if I can help with my lesser skills/knowledge.  I'll help if I can.



Title: Re: Help with Java needed...
Post by: Der Helm on July 23, 2009, 02:10:04 PM
You probably need to post a picture of her.
I'll ask her.  :awesome_for_real:
Got permission... to hotlink, even...  :awesome_for_real:

(http://lh5.google.com/fachschaft.anglistik/R63KwZISh6I/AAAAAAAAA1A/EwiVjjSRt8w/s288/n687990117_361998_1525.jpg)


Title: Re: Help with Java needed...
Post by: Der Helm on July 23, 2009, 02:11:48 PM
Without any inkling of the task I don't know if you need the super-genius programmer in my office or if I can help with my lesser skills/knowledge.  I'll help if I can.
Something about "reading" "files" from a "directory" "into"  a "programm".

As you might see, I don't know anything about this topic.


Title: Re: Help with Java needed...
Post by: Murgos on July 23, 2009, 02:18:02 PM
Java file handling demo (http://www.javacoffeebreak.com/java103/java103.html).


Title: Re: Help with Java needed...
Post by: Lantyssa on July 23, 2009, 07:04:10 PM
Don't know Java, but I'm willing to learn... :drillf:

More seriously, maybe she should type up a quick description of what she needs you can cut-n-paste for us instead of trying to remember terms you don't know about?


Title: Re: Help with Java needed...
Post by: Kail on July 23, 2009, 11:12:08 PM

I'm just wrapping up my second year of Comp Sci courses (which are mostly done with Java), so I can probably help once that's out of the way, assuming it's fairly basic stuff.


Title: Re: Help with Java needed...
Post by: Oban on July 24, 2009, 01:48:52 AM
http://kenai.com/projects/alice/downloads (http://kenai.com/projects/alice/downloads)


Title: Re: Help with Java needed...
Post by: Der Helm on July 24, 2009, 01:51:33 AM
Don't know Java, but I'm willing to learn... :drillf:
No square nails  :drill:


Title: Re: Help with Java needed...
Post by: Der Helm on July 28, 2009, 08:14:58 AM
OK, got her to translate her task into English...

Quote
I have to generate a lexicon for a mobile phone. Several directories with textfiles have to generate the lexicon. The program then has to read the contents of the files, split them into words only and then the single words must be counted so that the most common word will be suggested when a particular combination of keys is pressed.

Any takers ?  :awesome_for_real:



Title: Re: Help with Java needed...
Post by: voodoolily on July 28, 2009, 10:37:22 AM
I got your Java right here. (http://www.youtube.com/watch?v=42aQY_LtXsw)


Title: Re: Help with Java needed...
Post by: schild on July 28, 2009, 11:34:49 AM
I had to do basically that very same project in my first year of compsci in college. Only not for a mobile phone and not in java because java is the devil's work.

What's her major that she has to do this?


Title: Re: Help with Java needed...
Post by: Lantyssa on July 28, 2009, 12:03:53 PM
Any takers ?  :awesome_for_real:
So predictive text, basically.  I have ideas for the concept, but don't know enough java to be of any use on specifics.


Title: Re: Help with Java needed...
Post by: Samwise on July 28, 2009, 06:26:07 PM
What precisely is the assignment (you said "term paper" before -- is she supposed to write an essay/paper or actually code the thing?), and what specific part of it does she need help in?  That all sounds pretty straightforward to me, but I don't particularly want to relearn Java and code the whole thing up for her.   :awesome_for_real:

Also, does performance/scalability matter for the purposes of this assignment?  It's pretty easy either way, but if you don't care about performance it's even easier.


Title: Re: Help with Java needed...
Post by: Evil Elvis on July 28, 2009, 06:43:01 PM
(This is all drycode, using java 1.5 notation)

This is a very simplistic form of predictive search, so I'll display a simple solution (which wouldn't scale well).  I won't get into the file parsing, as I'm not sure what the file formats are, or what they want these lexicons to look like (if the lexicon actually stores the word frequency, then the wordCount() method is fairly superfluous)




Quote
// A "Dictionary" of our words, storing the occurance count of each word
HashMap<String, Integer> words = HashMap<String, Integer>();

// Everytime you find a word in the text files you parse, pass it into this method
public void countWord(String word)
{
   if (words.containsKey(word))
   {
      Integer occuranceCount = words.get(word) + 1;
      words.put(word, occuranceCount);
   }
   else
   {
      words.put(word, 1);
   }
}

// Returns the best match for currentText
public void predictWord(String currentText)
{
   // Nothing to see here, move along
   if (currentText == null || currentText.isEmpty())
      return "";

   int highestMatchVal = 0;
   String highestMatchWord = "";

   // Loop over every word
   Iterator iter = words.keySet().iterator();
   while ( iter.hasNext() )
   {
      // Find the word that begins with currentText, and has the
      // highest occurance count
      String word = iter.next().toString();
      if ( word.startsWith(currentText) )
      {
         Integer occuranceCount = words.get(word);
         if (count > highestMatchVal)
         {
            highestMatchVal = count;
            highestMatchWord = word;   
         }
      }
   }

   return highestMatchWord;
}



....
Assume a JTextField named "inputField" exists and is displayed
Assume a JLabel named "predictedWordLabel" exists and is displayed
....



inputField.addKeyListener(
   new KeyAdapter()
   {
      public void keyPressed(KeyEvent ke)
      {
         String predictedWord = predictWord( inputField.getText() );
         predictedWordLabel.setText( predictedWord );
      }
   }
);

edit: small fixes


Title: Re: Help with Java needed...
Post by: Samwise on July 28, 2009, 10:23:34 PM
Lol, that's almost exactly what I had in mind when I asked if we could ignore performance.   :why_so_serious:

For better performance, use a great big hash (hashing not only the words but also all the relevant subsets so that you can do lookups on fragments).  In theory that makes your lookup work in constant time, but that depends on how good the hash implementation is.

Personally, my angle of attack would be to build a tree stucture with each branch corresponding to a letter and each word corresponding to a path in the tree.  As you insert paths into the tree, increment a count on each node that tells you how many paths (words) include it.  That would make your lookup a function of fragment length rather than dictionary size.


Title: Re: Help with Java needed...
Post by: Evil Elvis on July 28, 2009, 11:05:43 PM
Yeah, a tree is the way to go.

Specifically, a Patricia Tree (http://en.wikipedia.org/wiki/Radix_tree)


Title: Re: Help with Java needed...
Post by: Torinak on July 28, 2009, 11:15:16 PM
OK, got her to translate her task into English...

Quote
I have to generate a lexicon for a mobile phone. Several directories with textfiles have to generate the lexicon. The program then has to read the contents of the files, split them into words only and then the single words must be counted so that the most common word will be suggested when a particular combination of keys is pressed.

Any takers ?  :awesome_for_real:



Does "particular combination of keys" mean numbers (that may map to multiple letters, such as "1" -> "abc"), or does it mean actual letters?

Is the goal to have any functional program? One that makes use of minimal memory? One with best performance? If the program is for a phone, what JVM(s) and Java versions can one target?

Is the goal to (ab)use standard java.util classes, to write one's own data structures, to discover data structures that may make variants of this problem trivial (http://en.wikipedia.org/wiki/Trie)?

What language are the words in?  How should accent marks be handled?

etc., etc.


Title: Re: Help with Java needed...
Post by: craan on July 29, 2009, 10:01:10 AM
I was thinking something similar to what Evil Evis posted.   God bless you Elvis.


Title: Re: Help with Java needed...
Post by: Tarami on July 29, 2009, 03:56:25 PM
As Lantyssa said, this looks like text prediction, not text completion. It takes a slightly different form, but still a radix tree (a dec tree basically, each node having 0-9 as child nodes, which could simply be an array of length 10 for unparallelled memory use/performance.) The paths don't build words, but the keys instead and every node contains a list of words that the qualified key maps to. Each list could be another radix tree, but that's really overshooting the target in my opinion, since every list will be quite succinct (every key can only produce a handful legible words.) The inner list will then be ordered by hits.

If you want to be really fancy-schmancy you could build two radix trees, one for words and one for keys, then cross-reference the trees so that the lists kept in the key tree reference nodes in the word tree and every node in the word tree references the corresponding key node in the other tree, making it one SUPER MEGA TREE! Ahem. Or you could just look-up normally (which would be a little more demanding on memory.)

Either way, that would let you combine completion with prediction, as you can look-up the key in one tree, find the best match there and then go to the word tree for completion suggestions. My phone gives me completion suggestions if I exhaust the prediction list, for example.


Title: Re: Help with Java needed...
Post by: Der Helm on July 29, 2009, 04:06:20 PM
I had to do basically that very same project in my first year of compsci in college. Only not for a mobile phone and not in java because java is the devil's work.

What's her major that she has to do this?
Fennistic, Anglistic and Computer Linguistic.

I THINK she has to come up with some sort of coding herself and THEN she has to write an essay about the linguistic aspects of the code.

Thanks for all that input guys (and gals   :drillf:), can't answer most of the other questions because I don't know anything about Java or coding.

Anyone who is interested (in helping her out  :awesome_for_real: ), please send me a pm with your email-adresses, I'll get you in touch with the woman herself.