| | |
How to discard stopwords contained in class and do word count?
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: Jan 2007
Posts: 7
Reputation:
Solved Threads: 0
package umadas.examples;import java.io.*;import java.util.*;class Counters{int iCount = 1;} public class Wordfreq { public static Reader r; private static String str=""; public static void main(String args[]) { try { r = new BufferedReader(new FileReader(args[0])); fnWordFrequency(); r.close(); } catch (IOException e) { System.err.println(e); } } public static void fnWordFrequency() { HashMap map = new HashMap(); try { StreamTokenizer st = new StreamTokenizer(r); int iToken = st.nextToken(); while (iToken != StreamTokenizer.TT_EOF) { if (iToken == StreamTokenizer.TT_WORD) { if (map.containsKey(st.sval)) { ((Counters)map.get(st.sval)).iCount++; } else { map.put(st.sval, new Counters()); } } iToken = st.nextToken(); } } catch (IOException e) { System.err.println(e); return; } Collection entries = map.entrySet(); Vector vTor = new Vector(entries); Iterator it = vTor.iterator(); Map.Entry ent; String sWord; int iCounter; while(it.hasNext()) { ent = (Map.Entry)it.next(); sWord = ((String)ent.getKey()); iCounter = ((Counters)ent.getValue()).iCount; str+=sWord+"\t"+iCounter+"\t"; System.out.println(sWord + "\t" + iCounter); } try { OutputStream f1=new FileOutputStream("C:/trial/umadas.txt"); byte buf[]=str.getBytes(); f1.write(buf); System.out.println("\n"); } catch(IOException io) { System.out.println(io.getMessage()); } } }THIS PROGRAM TOKENIZES THE WORD READ FROM A FILE IN COMMAND LINE AND PRINTS THE FREQUENCY OF EACH WORD.EX PROGRAM 25.NOW I HAVE A CLASS CONTAINING STOPWORDS LIKE( A ,AN) CONTAINED IN A HASHTABLE.I WANT TO READ THIS STOPWORDS FILEAND DISCARD THOSE AND PRINT THE ABOVE OUTPUT(DISCARDING THIS STOPWORDS).KINDLY HELP
Wow! How do you expect someone to read that message? Please make use of code tags and line breaks.
Last edited by aniseed; Jan 30th, 2007 at 2:27 pm.
![]() |
Similar Threads
- How to discard stopwords contained in class and do word count? (edited) (Java)
- Word count help. (C++)
- Can you please help me write this word count program in another way (Python)
- I Need Help Writing A Word Count Program In My Python (Python)
- I can't implement a word count into my text editor (JAVA) (Java)
Other Threads in the Java Forum
- Previous Thread: Card Game
- Next Thread: how to pass class variable to another class
| Thread Tools | Search this Thread |
addball android api applet application apps array arrays automation binary bluetooth businessintelligence button card chat class classes client code collision component crashcourse css csv database eclipse ee error event exception fractal free game gis givemetehcodez graphics gui html ide image input integer integration j2me java javaarraylist javadoc javafx javaprojects jni jpanel julia jvm key linux list loan loop machine map method methods migrate mobile netbeans newbie nls oracle output phone physics print problem program programming project radio recursion reporting scanner screen server service set size sms socket software sort sql string swing textfield threads time transfer tree trolltech utility windows






