Java Reference
In-Depth Information
4 import java.util.*;
5 import java.io.*;
6
7 public class StopWords {
8 public static void main(String[] args)
9 throws FileNotFoundException {
10 // build the list of stop words
11 ArrayList<String> stopWords = new ArrayList<String>();
12 stopWords.add("a");
13 stopWords.add("be");
14 stopWords.add("by");
15 stopWords.add("how");
16 stopWords.add("in");
17 stopWords.add("is");
18 stopWords.add("it");
19 stopWords.add("of");
20 stopWords.add("on");
21 stopWords.add("or");
22 stopWords.add("that");
23 stopWords.add("the");
24 stopWords.add("this");
25 stopWords.add("to");
26 stopWords.add("why");
27
28 // process the file, printing all but stop words
29 Scanner input = new Scanner( new File("speech.txt"));
30 while (input.hasNext()) {
31 String next = input.next();
32 if (!stopWords.contains(next.toLowerCase())) {
33 System.out.print(next + " ");
34 }
35 }
36 }
37 }
The program produces the following output:
not - question: Whether 'tis nobler mind suffer slings and
arrows outrageous fortune take arms against sea troubles,
And opposing end them.
This output represents the search view of the original text (the core set of words
that will be used by a search engine).
 
Search WWH ::




Custom Search