How to use stop words in a text file so that it does not get counted in a word count program using java?
-
I have a text file from where the count of each words has to be displayed and words like "to,the,and" should not be counted. I have program for counting but i don't know to use stop words. Any help? This is the count program import java.util.Map; import java.util.Set; import java.util.TreeMap; import java.util.Date; public class count { public static void main(String[] file) throws FileNotFoundException, IOException { String filename = "D:\\filename.txt"; BufferedReader bufferedReader = null; bufferedReader = new BufferedReader(new FileReader(filename)); String inputLine = null; TreeMap<String, Integer> map = new TreeMap<String, Integer>(); try { while ((inputLine = bufferedReader.readLine()) != null) { String[] words = inputLine.split("[ \n\t\r.,;:!?(){}]"); for (String word : words) { Integer frequency = map.get(word); if (frequency == null) { frequency = 0; } frequency++; map.put(word, frequency); } } System.out.println(map); } catch (IOException error) { System.out.println("Invalid File"); } finally { bufferedReader.close(); } } }
-
Answer:
Create a TreeSet and fill it with your stop words. Before entering the logic to increment the frequency of a word, check to see if your target word is in the stop word TreeSet. If it is, don't increment the counter.
Raksani at Yahoo! Answers Visit the source
Related Q & A:
- How to extract frequency range from a Wav file?Best solution by Stack Overflow
- How to search for a particular string in a text file using java?Best solution by Stack Overflow
- How do you program using Java?Best solution by wikihow.com
- How can i send some one a text through my computer?Best solution by Yahoo! Answers
- What does it take to get accepted into a vocational educational program?Best solution by answers.com
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.