package org.fisheyefocus.java.lang.Test; import java.util.ArrayList; public class ContinueTest { // List of stop words static String stopWordList[] = { "at", "in", "the", "and", "if", "of", "am", "who" }; static String ignoreWordList[] = { "king", "queen" }; // Split the string based on space character public static String[] tokenize(String text) { return text.split(" "); } // Decide whether to filter the word or not public static boolean filterStopWord(String word) { for (String _word : stopWordList) { if (word.equalsIgnoreCase(_word)) { return true; } } return false; } // Decide whether to filter the sentence or not public static boolean filterIgnoreWord(String word) { for (String _word : ignoreWordList) { if (word.equalsIgnoreCase(_word)) { return true; } } return false; } // Print List of tokens - list as ArrayList public static void printToken(ArrayList list) { for (String item : list) { System.out.print("[" + item + "] "); } System.out.println("\n"); } // Print List of tokens - list as String[] public static void printToken(String[] list) { for (String item : list) { System.out.print("[" + item + "] "); } System.out.println("\n"); } // Main method public static void main(String args[]) { // Setup sample strings String samples[] = { "I am the king of the world!", "For I am the Red Queen", "A man who wasn't there" }; outer: for (String sample : samples) { System.out.println("Original String: " + sample + "\n"); // Create tokens String[] tokens = tokenize(sample); System.out.println("Unfiltered Tokens:"); printToken(tokens); // Filter tokens on stop words ArrayList filteredTokens = new ArrayList(); for (String token : tokens) { if (filterStopWord(token)) { continue; // ---------------- (1) } if (filterIgnoreWord(token)) { System.out.println("Ignore - " + sample + "\n\n"); continue outer; // ---------- (2) } filteredTokens.add(token); // --- (3) } // Print filtered tokens System.out.println("Filtered Tokens:"); printToken(filteredTokens); System.out.println("\n"); } } }