@Test public void createFeaturesSuccessiveTokensTest() throws IOException { final String[] testSentence = new String[] {"he", "went", "with", "you", "in", "town"}; List<String> features = new ArrayList<>(); generator.createFeatures(features, testSentence, 3, null); Assert.assertEquals(3, features.size()); Assert.assertTrue(features.contains("pbrowncluster,browncluster=0101,0010")); Assert.assertTrue(features.contains("pbrowncluster,browncluster=01010,00101")); Assert.assertTrue(features.contains("browncluster,nbrowncluster=0010,0000")); }
@Override public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) { List<String> wordClasses = BrownTokenClasses.getWordClasses(tokens[index], brownCluster); if (index > 0) { List<String> prevWordClasses = BrownTokenClasses.getWordClasses(tokens[index - 1], brownCluster); for (int i = 0; i < wordClasses.size() && i < prevWordClasses.size(); i++) features.add("p" + "browncluster" + "," + "browncluster" + "=" + prevWordClasses.get(i) + "," + wordClasses.get(i)); } if (index + 1 < tokens.length) { List<String> nextWordClasses = BrownTokenClasses.getWordClasses(tokens[index + 1], brownCluster); for (int i = 0; i < wordClasses.size() && i < nextWordClasses.size(); i++) { features.add("browncluster" + "," + "n" + "browncluster" + "=" + wordClasses.get(i) + "," + nextWordClasses.get(i)); } } }
BrownBigramFeatureGenerator implements AdaptiveFeatureGenerator { @Override public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) { List<String> wordClasses = BrownTokenClasses.getWordClasses(tokens[index], brownCluster); if (index > 0) { List<String> prevWordClasses = BrownTokenClasses.getWordClasses(tokens[index - 1], brownCluster); for (int i = 0; i < wordClasses.size() && i < prevWordClasses.size(); i++) features.add("p" + "browncluster" + "," + "browncluster" + "=" + prevWordClasses.get(i) + "," + wordClasses.get(i)); } if (index + 1 < tokens.length) { List<String> nextWordClasses = BrownTokenClasses.getWordClasses(tokens[index + 1], brownCluster); for (int i = 0; i < wordClasses.size() && i < nextWordClasses.size(); i++) { features.add("browncluster" + "," + "n" + "browncluster" + "=" + wordClasses.get(i) + "," + nextWordClasses.get(i)); } } } }
BrownBigramFeatureGenerator implements AdaptiveFeatureGenerator { @Override public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) { List<String> wordClasses = BrownTokenClasses.getWordClasses(tokens[index], brownCluster); if (index > 0) { List<String> prevWordClasses = BrownTokenClasses.getWordClasses(tokens[index - 1], brownCluster); for (int i = 0; i < wordClasses.size() && i < prevWordClasses.size(); i++) features.add("p" + "browncluster" + "," + "browncluster" + "=" + prevWordClasses.get(i) + "," + wordClasses.get(i)); } if (index + 1 < tokens.length) { List<String> nextWordClasses = BrownTokenClasses.getWordClasses(tokens[index + 1], brownCluster); for (int i = 0; i < wordClasses.size() && i < nextWordClasses.size(); i++) { features.add("browncluster" + "," + "n" + "browncluster" + "=" + wordClasses.get(i) + "," + nextWordClasses.get(i)); } } } BrownBigramFeatureGenerator(BrownCluster brownCluster); }
BrownBigramFeatureGenerator implements AdaptiveFeatureGenerator { @Override public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) { List<String> wordClasses = BrownTokenClasses.getWordClasses(tokens[index], brownCluster); if (index > 0) { List<String> prevWordClasses = BrownTokenClasses.getWordClasses(tokens[index - 1], brownCluster); for (int i = 0; i < wordClasses.size() && i < prevWordClasses.size(); i++) features.add("p" + "browncluster" + "," + "browncluster" + "=" + prevWordClasses.get(i) + "," + wordClasses.get(i)); } if (index + 1 < tokens.length) { List<String> nextWordClasses = BrownTokenClasses.getWordClasses(tokens[index + 1], brownCluster); for (int i = 0; i < wordClasses.size() && i < nextWordClasses.size(); i++) { features.add("browncluster" + "," + "n" + "browncluster" + "=" + wordClasses.get(i) + "," + nextWordClasses.get(i)); } } } BrownBigramFeatureGenerator(BrownCluster brownCluster); @Override void createFeatures(List<String> features, String[] tokens, int index,
      String[] previousOutcomes); }
BrownBigramFeatureGenerator implements AdaptiveFeatureGenerator { @Override public void createFeatures(List<String> features, String[] tokens, int index, String[] previousOutcomes) { List<String> wordClasses = BrownTokenClasses.getWordClasses(tokens[index], brownCluster); if (index > 0) { List<String> prevWordClasses = BrownTokenClasses.getWordClasses(tokens[index - 1], brownCluster); for (int i = 0; i < wordClasses.size() && i < prevWordClasses.size(); i++) features.add("p" + "browncluster" + "," + "browncluster" + "=" + prevWordClasses.get(i) + "," + wordClasses.get(i)); } if (index + 1 < tokens.length) { List<String> nextWordClasses = BrownTokenClasses.getWordClasses(tokens[index + 1], brownCluster); for (int i = 0; i < wordClasses.size() && i < nextWordClasses.size(); i++) { features.add("browncluster" + "," + "n" + "browncluster" + "=" + wordClasses.get(i) + "," + nextWordClasses.get(i)); } } } BrownBigramFeatureGenerator(BrownCluster brownCluster); @Override void createFeatures(List<String> features, String[] tokens, int index,
      String[] previousOutcomes);  }