How to use hadoop for text file?

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

Was this solution helpful to you?

Just Added Q & A:

Find solution

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.