PartOfSpeechTags implements IAnalyzer { @Override public Object analyze(String q) { Map<String,Integer> tagCount = new LinkedHashMap<String,Integer>(); for(String tag: TAGS) { tagCount.put(tag,0); } Annotation annotation = new Annotation(q); PIPELINE.annotate(annotation); List<CoreMap> question = annotation.get(CoreAnnotations.SentencesAnnotation.class); for (CoreMap sentence : question) { List<CoreLabel> tokens = sentence.get(CoreAnnotations.TokensAnnotation.class); for(CoreLabel token: tokens) { String tag = token.tag(); if(TAGS.contains(tag)) { tagCount.put(tag, tagCount.get(tag) + 1); } } } return tagCount; } PartOfSpeechTags(); @Override Object analyze(String q); ArrayList<Attribute> getAttributes(); @Override Attribute getAttribute(); ArrayList<String> getTags();  }
@SuppressWarnings("unchecked") @Test public void tagsTest() { PartOfSpeechTags dep = new PartOfSpeechTags(); Map<String,Integer> pos = (Map<String, Integer>) dep.analyze("What is the capital of Germany?"); int[] actuals = new int[pos.keySet().size()]; List<String> keyList = new ArrayList<String>(pos.keySet()); for(int i = 0; i<keyList.size(); i++) { actuals[i] = pos.get(keyList.get(i)); } int[] expecteds = {0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 0}; assertArrayEquals(actuals,expecteds); }