tokenizer.init(); NamedEntityRecognizer ner = new StanfordNamedEntityRecognizer(new File(args[0])); ner.init(); while (!line.equals("exit")) ner.setSentence(line, tokenizer); ner.recognize(); for (NamedEntityWord neWord : ner.getAnnotatedSentence())
public void close() { if(m_tokenizer != null) m_tokenizer.cleanUp(); m_tokenizer = null; if(m_postagger != null) m_postagger.cleanUp(); m_postagger = null; if(m_ner != null) m_ner.cleanUp(); m_ner = null; if(m_lemmatizer != null) m_lemmatizer.cleanUp(); m_lemmatizer = null; }
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); } } }
public BiuTreeBuilder() throws TokenizerException, PosTaggerException, NamedEntityRecognizerException, ParserRunException { splitter = new LingPipeSentenceSplitter(); tokenizer = new MaxentTokenizer(); tagger = new MaxentPosTagger(BiuTestParams.MAXENT_POS_TAGGER_MODEL_FILE); ner = new StanfordNamedEntityRecognizer(new File(BiuTestParams.STANFORD_NER_CLASSIFIER_PATH)); parser = new EasyFirstParser( BiuTestParams.EASYFIRST_HOST, BiuTestParams.EASYFIRST_PORT, tokenizer, tagger ); ner.init(); parser.init(); }
words.add(word); neRecognizer.setSentence(words); neRecognizer.recognize(); List<NamedEntityWord> neWords = neRecognizer.getAnnotatedSentence();
/** * Create an initialized NamedEntityRecognizer using the given configuration params. */ public static NamedEntityRecognizer createNamedEntityRecognizer(ConfigurationParams params) throws InstrumentCombinationException{ boolean doNer; try { doNer = (params.containsKey("do_named_entity_recognition")? params.getBoolean("do_named_entity_recognition"): false); if (doNer) { NamedEntityRecognizer ner = new StanfordNamedEntityRecognizer(new File(params.getFile("ner-classifier-path").getAbsolutePath())); ner.init(); return ner; } else return null; } catch (ConfigurationException e) { throw new InstrumentCombinationException("Nested exception with configuration file while initializing the NER", e); } catch (NamedEntityRecognizerException e) { throw new InstrumentCombinationException("Nested exception while initializing the NER", e); } } }
innerTool.setSentence(tokenStrings); innerTool.recognize(); taggedTokens = innerTool.getAnnotatedSentence();
private void initializeInstruments() throws NamedEntityRecognizerException, ParserRunException, CoreferenceResolutionException { if (doNer) { instruments.getNamedEntityRecognizer().init(); } this.instruments.getParser().init(); this.instruments.getCoreferenceResolver().init(); this.areInstrumentsInitialized=true; }