POSTagDictCreator { public static POSDictionary createPOSTagDict(File sampleFile, boolean caseSensitive) { Multimap<String, String> tokenTagMap = HashMultimap.create(); List<POSSample> posSamples = readPOSSamples(sampleFile); POSDictionary posDictionary = new POSDictionary(caseSensitive); for (POSSample sample : posSamples) { for (int i = 0; i < sample.getSentence().length; ++i) { String token = sample.getSentence()[i]; if (!caseSensitive) token = token.toLowerCase(); String posTag = sample.getTags()[i]; tokenTagMap.put(token, posTag); } } for (String token : tokenTagMap.keySet()) { Collection<String> tagsForToken = tokenTagMap.get(token); posDictionary.put(token, tagsForToken.toArray(new String[tagsForToken.size()])); } return posDictionary; }  static void main(String[] args); static POSDictionary createPOSTagDict(File sampleFile, boolean caseSensitive); static List<POSSample> readPOSSamples(File sampleFile);  }
@Test public void testCreatePOSTagDict() { POSDictionary posDictionary = POSTagDictCreator.createPOSTagDict(new File("src/test/resources/posSamples.opennlp"), false); Set<String> expectedTags = new HashSet<>(Arrays.asList("TEST2", "TEST", "JJ")); assertEquals(expectedTags, new HashSet<String>(Arrays.asList(posDictionary.getTags("Small")))); assertEquals(expectedTags, new HashSet<String>(Arrays.asList(posDictionary.getTags("small")))); }
@Test public void testCreatePOSTagDictCaseSensitive() { POSDictionary posDictionary = POSTagDictCreator.createPOSTagDict(new File("src/test/resources/posSamples.opennlp"), true); Set<String> expectedTagsLower = new HashSet<>(Arrays.asList("TEST2", "JJ")); Set<String> expectedTagsUpper = new HashSet<>(Arrays.asList("TEST", "JJ")); assertEquals(expectedTagsLower, new HashSet<String>(Arrays.asList(posDictionary.getTags("small")))); assertEquals(expectedTagsUpper, new HashSet<String>(Arrays.asList(posDictionary.getTags("Small")))); }