• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

StreamTokeniser Trouble

 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
reply
    Bookmark Topic Watch Topic
  • New Topic