private static void checkForNull(Object value, String parameterName) throws ResourceInitializationException { if (value == null) { throw new ResourceInitializationException( ExceptionMessages.MESSAGE_CATALOG, ExceptionMessages.PARAMETER_NOT_FOUND, new Object[] {parameterName}); } }
public static InputStream getOptionalResourceAsStream(UimaContext context, String name) throws ResourceInitializationException { InputStream inResource; try { inResource = context.getResourceAsStream(name); } catch (ResourceAccessException e) { throw new ResourceInitializationException(e); } return inResource; }
public static String[] getOptionalStringArrayParameter(UimaContext context, String parameter) throws ResourceInitializationException { Object value = getOptionalParameter(context, parameter); if (value instanceof String[]) { return (String[]) value; } else if (value == null) { return new String[0]; } else { throw new ResourceInitializationException( ExceptionMessages.MESSAGE_CATALOG, ExceptionMessages.WRONG_PARAMETER_TYPE, new Object[] {parameter, "String array"}); } }
/** * Retrieves a resource as stream from the given context. * * @param context * @param name * @return the stream * @throws ResourceInitializationException */ public static InputStream getResourceAsStream(UimaContext context, String name) throws ResourceInitializationException { InputStream inResource = getOptionalResourceAsStream(context, name); if (inResource == null) { throw new ResourceInitializationException( ExceptionMessages.MESSAGE_CATALOG, ExceptionMessages.IO_ERROR_MODEL_READING, new Object[] {name + " could not be found!"}); } return inResource; }
/** * Retrieves an optional parameter from the given context. * * @param context * @param parameter * @return the parameter or null if not set * @throws ResourceInitializationException */ public static String getOptionalStringParameter(UimaContext context, String parameter) throws ResourceInitializationException { Object value = getOptionalParameter(context, parameter); if (value instanceof String) { return (String) value; } else if (value == null) { return null; } else { throw new ResourceInitializationException( ExceptionMessages.MESSAGE_CATALOG, ExceptionMessages.WRONG_PARAMETER_TYPE, new Object[] {parameter, "String"}); } }
/** * Retrieves an optional parameter from the given context. * * @param context * @param parameter * @return the parameter or null if not set * @throws ResourceInitializationException */ public static Integer getOptionalIntegerParameter(UimaContext context, String parameter) throws ResourceInitializationException { Object value = getOptionalParameter(context, parameter); if (value instanceof Integer) { return (Integer) value; } else if (value == null) { return null; } else { throw new ResourceInitializationException( ExceptionMessages.MESSAGE_CATALOG, ExceptionMessages.WRONG_PARAMETER_TYPE, new Object[] {parameter, "Integer"}); } }
/** * Retrieves an optional parameter from the given context. * * @param context * @param parameter * @return the parameter or null if not set * @throws ResourceInitializationException */ public static Float getOptionalFloatParameter(UimaContext context, String parameter) throws ResourceInitializationException { Object value = getOptionalParameter(context, parameter); if (value instanceof Float) { return (Float) value; } else if (value == null) { return null; } else { throw new ResourceInitializationException( ExceptionMessages.MESSAGE_CATALOG, ExceptionMessages.WRONG_PARAMETER_TYPE, new Object[] {parameter, "Float"}); } }
/** * Retrieves an optional parameter from the given context. * * @param context * @param parameter * @return the parameter or null if not set * @throws ResourceInitializationException */ public static Boolean getOptionalBooleanParameter(UimaContext context, String parameter) throws ResourceInitializationException { Object value = getOptionalParameter(context, parameter); if (value instanceof Boolean) { return (Boolean) value; } else if (value == null) { return null; } else { throw new ResourceInitializationException( ExceptionMessages.MESSAGE_CATALOG, ExceptionMessages.WRONG_PARAMETER_TYPE, new Object[] {parameter, "Boolean"}); } }
public void load(DataResource resource) throws ResourceInitializationException { try { model = loadModel(resource.getInputStream()); } catch (IOException e) { throw new ResourceInitializationException( ExceptionMessages.MESSAGE_CATALOG, ExceptionMessages.IO_ERROR_MODEL_READING, new Object[] { e.getMessage()}, e); } } }
public static TrainingParameters loadTrainingParams(String inFileValue, boolean isSequenceTrainingAllowed) throws ResourceInitializationException { TrainingParameters params; if (inFileValue != null) { try (InputStream paramsIn = new FileInputStream(new File(inFileValue))) { params = new opennlp.tools.util.TrainingParameters(paramsIn); } catch (IOException e) { throw new ResourceInitializationException(e); } if (!TrainerFactory.isValid(params)) { throw new ResourceInitializationException(new Exception("Training parameters file is invalid!")); } TrainerFactory.TrainerType trainerType = TrainerFactory.getTrainerType(params); if (!isSequenceTrainingAllowed && TrainerFactory.TrainerType.SEQUENCE_TRAINER.equals(trainerType)) { throw new ResourceInitializationException(new Exception("Sequence training is not supported!")); } } else { params = TrainingParameters.defaultParams(); } return params; } }
/** * Initializes the current instance with the given context. * <p> * Note: Do all initialization in this method, do not use the constructor. */ public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); SentenceModel model; try { SentenceModelResource modelResource = (SentenceModelResource) context .getResourceObject(UimaUtil.MODEL_PARAMETER); model = modelResource.getModel(); } catch (ResourceAccessException e) { throw new ResourceInitializationException(e); } sentenceDetector = new SentenceDetectorME(model); }
/** * Initializes the current instance with the given context. * <p> * Note: Do all initialization in this method, do not use the constructor. */ public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); TokenizerModel model; try { TokenizerModelResource modelResource = (TokenizerModelResource) context .getResourceObject(UimaUtil.MODEL_PARAMETER); model = modelResource.getModel(); } catch (ResourceAccessException e) { throw new ResourceInitializationException(e); } tokenizer = new TokenizerME(model); }
/** * 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 { super.initialize(); TokenNameFinderModel model; try { TokenNameFinderModelResource modelResource = (TokenNameFinderModelResource) context.getResourceObject(UimaUtil.MODEL_PARAMETER); model = modelResource.getModel(); } catch (ResourceAccessException e) { throw new ResourceInitializationException(e); } mNameFinder = new NameFinderME(model); }
/** * 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); }
/** * Initializes the current instance with the given context. * <p> * Note: Do all initialization in this method, do not use the constructor. */ public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); this.context = context; mLogger = context.getLogger(); if (mLogger.isLoggable(Level.INFO)) { mLogger.log(Level.INFO, "Initializing the OpenNLP Normalizer annotator."); } try { String modelName = AnnotatorUtil.getOptionalStringParameter(context, UimaUtil.DICTIONARY_PARAMETER); if (modelName != null) { InputStream inModel = AnnotatorUtil.getResourceAsStream(context, modelName); mLookupDictionary = new StringDictionary(inModel); } } catch (IOException e) { throw new ResourceInitializationException( ExceptionMessages.MESSAGE_CATALOG, "io_error_model_reading", new Object[] {e.getMessage()}, e); } }
public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); this.context = context; Logger mLogger = context.getLogger(); if (mLogger.isLoggable(Level.INFO)) { mLogger.log(Level.INFO, "Initializing the OpenNLP Categorizer."); } DoccatModel model; try { DoccatModelResource modelResource = (DoccatModelResource) context .getResourceObject(UimaUtil.MODEL_PARAMETER); model = modelResource.getModel(); } catch (ResourceAccessException e) { throw new ResourceInitializationException(e); } mCategorizer = new DocumentCategorizerME(model); }
/** * Initializes the current instance with the given context. */ public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); this.context = context; mLogger = context.getLogger(); if (mLogger.isLoggable(Level.INFO)) { mLogger.log(Level.INFO, "Initializing the OpenNLP Parser."); } ParserModel model; try { ParserModelResource modelResource = (ParserModelResource) context .getResourceObject(UimaUtil.MODEL_PARAMETER); model = modelResource.getModel(); } catch (ResourceAccessException e) { throw new ResourceInitializationException(e); } mParser = ParserFactory.create(model); }
/** * Initializes the current instance with the given context. * <p> * Note: Do all initialization in this method, do not use the constructor. */ public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); this.context = context; mLogger = context.getLogger(); if (mLogger.isLoggable(Level.INFO)) { mLogger.log(Level.INFO, "Initializing the OpenNLP Chunker annotator."); } ChunkerModel model; try { ChunkerModelResource modelResource = (ChunkerModelResource) context.getResourceObject(UimaUtil.MODEL_PARAMETER); model = modelResource.getModel(); } catch (ResourceAccessException e) { throw new ResourceInitializationException(e); } mChunker = new ChunkerME(model); }
/** * Initializes the current instance with the given context. * <p> * Note: Do all initialization in this method, do not use the constructor. */ @Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); this.context = context; this.logger = context.getLogger(); if (this.logger.isLoggable(Level.INFO)) { this.logger.log(Level.INFO, "Initializing the OpenNLP " + "Part of Speech annotator."); } POSModel model; try { POSModelResource modelResource = (POSModelResource) context .getResourceObject(UimaUtil.MODEL_PARAMETER); model = modelResource.getModel(); } catch (ResourceAccessException e) { throw new ResourceInitializationException(e); } Integer beamSize = AnnotatorUtil.getOptionalIntegerParameter(context, UimaUtil.BEAM_SIZE_PARAMETER); if (beamSize == null) { beamSize = POSTaggerME.DEFAULT_BEAM_SIZE; } this.posTagger = new POSTaggerME(model); }
private static Object getResourceObject(UimaContext aContext, String aKey) throws ResourceInitializationException { Object value; try { value = aContext.getResourceObject(aKey); } catch (ResourceAccessException e) { throw new ResourceInitializationException(e); } return value; }