ner.recognize(); for (NamedEntityWord neWord : ner.getAnnotatedSentence())
private void addNerInfo(List<String> tokenizedSent, List<TokenInfo> processedSent) throws InstrumentCombinationException { List<NamedEntityWord> nerSent = null; try { m_ner.setSentence(tokenizedSent); m_ner.recognize(); nerSent = m_ner.getAnnotatedSentence(); } catch (NamedEntityRecognizerException e) { throw new InstrumentCombinationException("see nested exception from NamedEntityRecognizer:", e); } if(nerSent.size() != processedSent.size()){ throw new InstrumentCombinationException("the number of ner-tagged tokens is not equal" + " to the number of sentence-tokens in input sentence " + tokenizedSent); } Iterator<TokenInfo> procSentIter = processedSent.iterator(); Iterator<NamedEntityWord> nerSentIter = nerSent.iterator(); while(procSentIter.hasNext()){ TokenInfo tInfo = procSentIter.next(); NamedEntityWord nerTerm = nerSentIter.next(); if(tInfo.getOrigStr().equals(nerTerm.getWord())){ tInfo.setNamedEntity(nerTerm.getNamedEntity()); }else{ throw new InstrumentCombinationException("a mismatch was found between a ner-tagged word" + " and the sentence word " + tInfo.getOrigStr() + " of input sentence " + tokenizedSent); } } }
neRecognizer.recognize(); List<NamedEntityWord> neWords = neRecognizer.getAnnotatedSentence();
innerTool.recognize(); taggedTokens = innerTool.getAnnotatedSentence();