From 94838f67f689bf2123631555f13b5b2287f07118 Mon Sep 17 00:00:00 2001 From: Peter Wu Date: Wed, 1 Apr 2015 04:10:47 +0200 Subject: Do not include unchanged words --- spellchecker/src/SpellCorrector.java | 2 +- spellchecker/test/SpellCorrectorTest.java | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/spellchecker/src/SpellCorrector.java b/spellchecker/src/SpellCorrector.java index a178a44..92f7479 100644 --- a/spellchecker/src/SpellCorrector.java +++ b/spellchecker/src/SpellCorrector.java @@ -41,7 +41,7 @@ public class SpellCorrector { // tries to add word2 to the list of words. This word2 was generated // from "word" by changing "error" to "correct". TriFunction push = (word2, error, correct) -> { - if (!cr.inVocabulary(word2)) { + if (!cr.inVocabulary(word2) || word.equals(word2)) { return; } diff --git a/spellchecker/test/SpellCorrectorTest.java b/spellchecker/test/SpellCorrectorTest.java index d658914..a826212 100644 --- a/spellchecker/test/SpellCorrectorTest.java +++ b/spellchecker/test/SpellCorrectorTest.java @@ -23,9 +23,14 @@ public class SpellCorrectorTest { private void checkGetCandidateWords(CorpusReader cr, String word, Set expResult) throws IOException { + // ignore unchanged word + expResult.remove(word); + System.out.println("getCandidateWords(" + word + ")"); SpellCorrector instance = new SpellCorrector(cr, cmr); Set result = instance.getCandidateWords(word).keySet(); + + assertFalse("Should not contain word " + word, result.contains(word)); // quick check: are the results of the same size? assertEquals(expResult.size(), result.size()); // verbose test: are all letters as expected? -- cgit v1.2.1