Source:
public void processSample() throws Exception { LanguageDetectorModel model = LanguageDetectorMETest.trainModel(); LanguageDetectorME langdetector = new LanguageDetectorME(model); final AtomicInteger correctCount = new AtomicInteger(); final AtomicInteger incorrectCount = new AtomicInteger(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); LanguageDetectorEvaluator evaluator = new LanguageDetectorEvaluator(langdetector, new LanguageDetectorEvaluationMonitor() { @Override public void correctlyClassified(LanguageSample reference, LanguageSample prediction) { correctCount.incrementAndGet(); } @Override public void missclassified(LanguageSample reference, LanguageSample prediction) { incorrectCount.incrementAndGet(); } }, new LanguageDetectorEvaluationErrorListener(outputStream)); evaluator.evaluateSample(new LanguageSample(new Language("pob"), "escreve e faz palestras pelo mundo inteiro sobre anjos")); evaluator.evaluateSample(new LanguageSample(new Language("fra"), "escreve e faz palestras pelo mundo inteiro sobre anjos")); evaluator.evaluateSample(new LanguageSample(new Language("fra"), "escreve e faz palestras pelo mundo inteiro sobre anjos")); Assert.assertEquals(1, correctCount.get()); Assert.assertEquals(2, incorrectCount.get()); Assert.assertEquals(3, evaluator.getDocumentCount()); Assert.assertEquals(0.33, evaluator.getAccuracy(), 0.01); String report = outputStream.toString(StandardCharsets.UTF_8.name()); report = report.replaceAll("\r\n", "\n"); Assert.assertEquals("Expected\tPredicted\tContext\n" + "fra\tpob\tescreve e faz palestras pelo mundo inteiro sobre anjos\n" + "fra\tpob\tescreve e faz palestras pelo mundo inteiro sobre anjos\n", report); }

Target:
public void processSample() throws Exception { LanguageDetectorModel model = LanguageDetectorMETest.trainModel(); LanguageDetectorME langdetector = new LanguageDetectorME(model); final AtomicInteger correctCount = new AtomicInteger(); final AtomicInteger incorrectCount = new AtomicInteger(); ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); LanguageDetectorEvaluator evaluator = new LanguageDetectorEvaluator(langdetector, new LanguageDetectorEvaluationMonitor() { @Override public void correctlyClassified(LanguageSample reference, LanguageSample prediction) { correctCount.incrementAndGet(); } @Override public void missclassified(LanguageSample reference, LanguageSample prediction) { incorrectCount.incrementAndGet(); } }, new LanguageDetectorEvaluationErrorListener(outputStream)); evaluator.evaluateSample(new LanguageSample(new Language("pob"), "escreve e faz palestras pelo mundo inteiro sobre anjos")); evaluator.evaluateSample(new LanguageSample(new Language("fra"), "escreve e faz palestras pelo mundo inteiro sobre anjos")); evaluator.evaluateSample(new LanguageSample(new Language("fra"), "escreve e faz palestras pelo mundo inteiro sobre anjos")); Assert.assertEquals(1, correctCount.get()); Assert.assertEquals(2, incorrectCount.get()); Assert.assertEquals(3, evaluator.getDocumentCount()); Assert.assertEquals(0.33, evaluator.getAccuracy(), 0.01); String report = outputStream.toString(StandardCharsets.UTF_8.name()); report = report.replaceAll("\r\n", "\n"); Assert.assertEquals("Expected\tPredicted\tContext" + System.lineSeparator() + "fra\tpob\tescreve e faz palestras pelo mundo inteiro sobre anjos" + System.lineSeparator() + "fra\tpob\tescreve e faz palestras pelo mundo inteiro sobre anjos" + System.lineSeparator(), report); }