@Test public void testEmpty() throws Exception { NGramFeatureGenerator generator = new NGramFeatureGenerator(); Assert.assertEquals(0, generator.extractFeatures(new String[]{}, Collections.emptyMap()).size()); }
@Test public void testTrigram() throws Exception { NGramFeatureGenerator generator = new NGramFeatureGenerator(3, 3); Assert.assertArrayEquals( new String[]{"ng=:a:b:c", "ng=:b:c:d", "ng=:c:d:e", "ng=:d:e:f", "ng=:e:f:g"}, generator.extractFeatures(TOKENS, Collections.emptyMap()).toArray()); }
@Test public void testUnigram() throws Exception { NGramFeatureGenerator generator = new NGramFeatureGenerator(1, 1); Assert.assertArrayEquals( new String[]{"ng=:a", "ng=:b", "ng=:c", "ng=:d", "ng=:e", "ng=:f", "ng=:g"}, generator.extractFeatures(TOKENS, Collections.emptyMap()).toArray()); }
@Test public void testBigram() throws Exception { NGramFeatureGenerator generator = new NGramFeatureGenerator(2, 2); Assert.assertArrayEquals( new String[]{"ng=:a:b", "ng=:b:c", "ng=:c:d", "ng=:d:e", "ng=:e:f", "ng=:f:g"}, generator.extractFeatures(TOKENS, Collections.emptyMap()).toArray()); }
@Test public void test12gram() throws Exception { NGramFeatureGenerator generator = new NGramFeatureGenerator(1, 2); Assert.assertArrayEquals( new String[]{ "ng=:a", "ng=:a:b", "ng=:b", "ng=:b:c", "ng=:c", "ng=:c:d", "ng=:d", "ng=:d:e", "ng=:e", "ng=:e:f", "ng=:f", "ng=:f:g", "ng=:g" }, generator.extractFeatures(TOKENS, Collections.emptyMap()).toArray()); }
@Test public void testNull() throws Exception { NGramFeatureGenerator generator = new NGramFeatureGenerator(); try { generator.extractFeatures(null, Collections.emptyMap()); Assert.fail("NullPointerException must be thrown"); } catch (NullPointerException expected) { } }
@Test public void test13gram() throws Exception { NGramFeatureGenerator generator = new NGramFeatureGenerator(1, 3); Assert.assertArrayEquals( new String[]{ "ng=:a", "ng=:a:b", "ng=:a:b:c", "ng=:b", "ng=:b:c", "ng=:b:c:d", "ng=:c", "ng=:c:d", "ng=:c:d:e", "ng=:d", "ng=:d:e", "ng=:d:e:f", "ng=:e", "ng=:e:f", "ng=:e:f:g", "ng=:f", "ng=:f:g", "ng=:g" }, generator.extractFeatures(TOKENS, Collections.emptyMap()).toArray()); } }