Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

StreamTokeniser Trouble

 
Rich Charlton
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

im trying to build a text classification program that reads in a text file, tokenises it and stores it in a hashmap. Along the way i would like to instantiate another class which reads a text file full of commonwords. I would then like to remove these common words from the initial hashmap. I have set up two classes one called CommonWords.java and the other called Train.java. I am getting an error which i have posted after my code.

Train.java

CommonWords.java

Error Message:

I think i have something wrong with the adding of the commonwords to the hashtable..

Does anyone have any ideas.

Thanks
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
cWords = new HashMap ();

is missing before usage.
Next time mark line 26, to make it more easy to find it.
Read the message.
Try to understand it yourself.
Use a tool which has linenumbers.
(Everything except Notepad has linenumbers).

Post such basic questions to beginners.
 
Rich Charlton
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thats great am able to get the items added in the commonwords class. although im still having a problem removing the items from the initial hashmap. i have changed it slightly now to use an arraylist for the commonwords instead of a hash table as i had no need for a value next to the string.

im not sure whether the remove statement is going to work now.
as counts is a hashmap and cwords is an arraylist of string objects.

so problems at the moment are that i cant instantiate the arraylist and cannot remove commonwords from hashmap.

any ideas thanks.
 
Stefan Wagner
Ranch Hand
Posts: 1923
Linux Postgres Database Scala
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Printing a class doesn't mean implicitly print all members of the class, and especially not to print all elements in a collection.

You might overwrite toString () in CommonWords, to achieve this, where you have to iterate over the arraylist and print every element, or create a new method like 'printAllElements'.
 
Rich Charlton
Greenhorn
Posts: 19
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help guys....

I have re written my program logic now...although i have another problem...
I have started a new thread in the intermediate java forum if you can spare a look.

Thanks
 
Layne Lund
Ranch Hand
Posts: 3061
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Although this thread is a little old, I'd just like to point out that ArrayList already overrides the toString() method to print out all the elements it contains. In fact, most Collection classes do, afaik. This means you don't have to iterate over a Collection manually when you write a toString() method for your own class.

Layne
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic