### Question:
UnigramStopwordFilter implements ITermFilter { public void filterParsings(TreeSet<Parsing> parsings, List<TreeMap<String,Object>> output){ HashSet<String> uniqueParsings = new HashSet<String>(); int parsingCount = 0; for(Iterator<Parsing> iter = parsings.descendingIterator(); iter.hasNext() && parsingCount < parameterSet.resultLimit;) { Parsing parsing = iter.next(); filterParsing(parsing); if (uniqueParsings.contains(parsing.toString())) { iter.remove(); } else { parsingCount++; uniqueParsings.add(parsing.toString()); } } } UnigramStopwordFilter(TokenizedString tokens,
                                 ParseParameterSet parameterSet); void filterParsings(TreeSet<Parsing> parsings, List<TreeMap<String,Object>> output);  }### Answer:
@Test public void filter_unigrams() { UnigramStopwordFilter target = new UnigramStopwordFilter(tokens, parameterSet); Parsing parsing = new Parsing(tokens, 15); TreeSet<Parsing> parsings = new TreeSet<Parsing>(); parsings.add(parsing); String [] expected = new String [] {"engineer", "quality", "assurance"}; target.filterParsings(parsings, new ArrayList<TreeMap<String,Object>>()); String [] actual = parsings.first().toStringArray(); for(int i = 0; i < actual.length; ++i) { Assert.assertTrue(expected[i].compareTo(actual[i])== 0); } }
@Test public void filter_ngrams() { UnigramStopwordFilter target = new UnigramStopwordFilter(tokens, parameterSet); Parsing parsing = new Parsing(tokens, 14); String [] expected = new String [] {"engineer", "quality", "assurance"}; TreeSet<Parsing> parsings = new TreeSet<Parsing>(); parsings.add(parsing); target.filterParsings(parsings, new ArrayList<TreeMap<String,Object>>()); String [] actual = parsings.first().toStringArray(); for(int i = 0; i < actual.length; ++i) { Assert.assertTrue(expected[i].compareTo(actual[i])== 0); } }
@Test public void filter_nonStopwords() { UnigramStopwordFilter target = new UnigramStopwordFilter(tokens, parameterSet); Parsing parsing = new Parsing(tokens, 0); String [] expected = new String [] {"in at engineer quality assurance"}; TreeSet<Parsing> parsings = new TreeSet<Parsing>(); parsings.add(parsing); target.filterParsings(parsings, new ArrayList<TreeMap<String,Object>>()); String [] actual = parsings.first().toStringArray(); for(int i = 0; i < actual.length; ++i) { Assert.assertTrue(expected[i].compareTo(actual[i])== 0); } }