public LanguageSample read() throws IOException { LanguageSample sample; if (sampleStream != null && (sample = sampleStream.read()) != null) { return sample; } else { if (sentencesFilesIt.hasNext()) { File sentencesFile = sentencesFilesIt.next(); String lang = sentencesFile.getName().substring(0, 3); sampleStream = new LeipzigSentencesStream(lang, sentencesFile, sentencesPerSample, langSampleCounts.get(lang)); return read(); } } return null; }
@Test(expected = InvalidFormatException.class) public void testNotEnoughSentences() throws IOException { int samplesPerLanguage = 2; int sentencesPerSample = 2; LeipzigLanguageSampleStream stream = new LeipzigLanguageSampleStream(new File(testDataPath), sentencesPerSample, samplesPerLanguage); while (stream.read() != null); }
@Test public void testReadSentenceFiles() { int samplesPerLanguage = 2; int sentencesPerSample = 1; try { LeipzigLanguageSampleStream stream = new LeipzigLanguageSampleStream(new File(testDataPath), sentencesPerSample, samplesPerLanguage); int count = 0; while (stream.read() != null) count++; Assert.assertEquals(4, count); } catch (IOException e) { Assert.fail(); } }
public LanguageSample read() throws IOException { LanguageSample sample; if (sampleStream != null && (sample = sampleStream.read()) != null) { return sample; } else { if (sentencesFilesIt.hasNext()) { File sentencesFile = sentencesFilesIt.next(); String lang = sentencesFile.getName().substring(0, 3); sampleStream = new LeipzigSentencesStream(lang, sentencesFile, sentencesPerSample, langSampleCounts.get(lang)); return read(); } } return null; }
public LanguageSample read() throws IOException { LanguageSample sample; if (sampleStream != null && (sample = sampleStream.read()) != null) { return sample; } else { if (sentencesFilesIt.hasNext()) { File sentencesFile = sentencesFilesIt.next(); String lang = sentencesFile.getName().substring(0, 3); sampleStream = new LeipzigSentencesStream(lang, sentencesFile, sentencesPerSample, langSampleCounts.get(lang)); return read(); } } return null; }