public void setDictionary(String name, Dictionary dict) { isg = new InSpanGenerator(name, new DictionaryNameFinder(dict)); }
@Before public void setUp() throws Exception { mNameFinder = new DictionaryNameFinder(mDictionary); }
/** * Initializes the current instance with the given context. * <p> * Note: Do all initialization in this method, do not use the constructor. */ public void initialize() throws ResourceInitializationException { Dictionary nameFinderDictionary; try { DictionaryResource modelResource = (DictionaryResource) context .getResourceObject(UimaUtil.DICTIONARY_PARAMETER); nameFinderDictionary = modelResource.getDictionary(); } catch (ResourceAccessException e) { try { String modelName = AnnotatorUtil.getRequiredStringParameter(context, UimaUtil.DICTIONARY_PARAMETER); InputStream inModel = AnnotatorUtil.getResourceAsStream(context, modelName); nameFinderDictionary = new Dictionary(inModel); } catch (IOException ie) { throw new ResourceInitializationException( ExceptionMessages.MESSAGE_CATALOG, ExceptionMessages.IO_ERROR_DICTIONARY_READING, new Object[] {ie.getMessage()}); } } mNameFinder = new opennlp.tools.namefind.DictionaryNameFinder( nameFinderDictionary); }
public void setDictionary(String name, Dictionary dict) { isg = new InSpanGenerator(name, new DictionaryNameFinder(dict)); }
public void setDictionary(String name, Dictionary dict) { isg = new InSpanGenerator(name, new DictionaryNameFinder(dict)); }
@Test public void testEvaluator() throws IOException, URISyntaxException { DictionaryNameFinder nameFinder = new DictionaryNameFinder( createDictionary()); TokenNameFinderEvaluator evaluator = new TokenNameFinderEvaluator( nameFinder, new NameEvaluationErrorListener()); ObjectStream<NameSample> sample = createSample(); evaluator.evaluate(sample); sample.close(); FMeasure fmeasure = evaluator.getFMeasure(); Assert.assertTrue(fmeasure.getFMeasure() == 1); Assert.assertTrue(fmeasure.getRecallScore() == 1); }
/** * Initializes the current instance with the given context. * <p> * Note: Do all initialization in this method, do not use the constructor. */ public void initialize() throws ResourceInitializationException { Dictionary nameFinderDictionary; try { DictionaryResource modelResource = (DictionaryResource) context .getResourceObject(UimaUtil.DICTIONARY_PARAMETER); nameFinderDictionary = modelResource.getDictionary(); } catch (ResourceAccessException e) { try { String modelName = AnnotatorUtil.getRequiredStringParameter(context, UimaUtil.DICTIONARY_PARAMETER); InputStream inModel = AnnotatorUtil.getResourceAsStream(context, modelName); nameFinderDictionary = new Dictionary(inModel); } catch (IOException ie) { throw new ResourceInitializationException( ExceptionMessages.MESSAGE_CATALOG, ExceptionMessages.IO_ERROR_DICTIONARY_READING, new Object[] {ie.getMessage()}); } } mNameFinder = new opennlp.tools.namefind.DictionaryNameFinder( nameFinderDictionary); }
/** * Gets the configured {@link TokenNameFinder} for the dictionary model. * @param tokenizer A {@link Tokenizer} used to tokenize each line in the dictionary file. * @return A {@link TokenNameFinder}. * @throws Exception */ public TokenNameFinder getDictionaryNameFinder(Tokenizer tokenizer) throws Exception { final boolean caseSensitive = false; final Dictionary dictionary = new Dictionary(caseSensitive); File modelFile = new File(modelDirectory + File.separator + modelManifest.getModelFileName()); try (BufferedReader br = new BufferedReader(new FileReader(modelFile))) { String line; while ((line = br.readLine()) != null) { if(!StringUtils.isEmpty(modelManifest.getEncryptionKey())) { line = OpenNLPEncryptionFactory.getDefault().decrypt(line, modelManifest.getEncryptionKey()); } final String[] tokenized = tokenizer.tokenize(line); // StringList tokens = new StringList("George", "Washington"); StringList tokens = new StringList(tokenized); dictionary.put(tokens); } } return new DictionaryNameFinder(dictionary, modelManifest.getType()); }