protected void process(CAS cas, AnnotationFS sentenceAnnotation) { FSIndex<AnnotationFS> allTokens = cas.getAnnotationIndex(mTokenType); ContainingConstraint containingConstraint = new ContainingConstraint(sentenceAnnotation); String sentence = sentenceAnnotation.getCoveredText(); Iterator<AnnotationFS> containingTokens = cas.createFilteredIterator( allTokens.iterator(), containingConstraint); List<Span> tokenSpans = new LinkedList<>(); while (containingTokens.hasNext()) { AnnotationFS token = containingTokens.next(); tokenSpans.add(new Span(token.getBegin() - sentenceAnnotation.getBegin(), token.getEnd() - sentenceAnnotation.getBegin())); } ParseConverter converter = new ParseConverter(sentence, tokenSpans.toArray(new Span[tokenSpans.size()])); Parse unparsedTree = converter.getParseForTagger(); if (unparsedTree.getChildCount() > 0) { Parse parse = mParser.parse(unparsedTree); // TODO: We need a strategy to handle the case that a full // parse could not be found. What to do in this case? parse = converter.transformParseFromTagger(parse); if (mLogger.isLoggable(Level.INFO)) { StringBuffer parseString = new StringBuffer(); parse.show(parseString); mLogger.log(Level.INFO, parseString.toString()); } createAnnotation(cas, sentenceAnnotation.getBegin(), parse); } }
private static Object getOptionalParameter(UimaContext context, String parameter) throws ResourceInitializationException { Object value = context.getConfigParameterValue(parameter); Logger logger = context.getLogger(); if (logger.isLoggable(Level.INFO)) { logger.log(Level.INFO, parameter + " = " + (value != null ? value.toString() : "not set")); } return value; }
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); this.context = context; logger = context.getLogger(); if (logger.isLoggable(Level.INFO)) { logger.log(Level.INFO, "Initializing the OpenNLP Sentence annotator."); } isRemoveExistingAnnotations = AnnotatorUtil.getOptionalBooleanParameter( context, UimaUtil.IS_REMOVE_EXISTINGS_ANNOTAIONS); if (isRemoveExistingAnnotations == null) { isRemoveExistingAnnotations = false; } }
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); }
@Override protected Chunker produceResource(InputStream aStream) throws Exception { ChunkerModel model = new ChunkerModel(aStream); Tagset tsdp = new OpenNlpChunkerTagsetDescriptionProvider(getResourceMetaData() .getProperty("chunk.tagset"), Chunk.class, model.getChunkerModel()); addTagset(tsdp); if (printTagSet) { getContext().getLogger().log(INFO, tsdp.toString()); } return new ChunkerME(model); } };
public void removeMessageOrigin(String aCasReferenceId) { if (originMap.containsKey(aCasReferenceId)) { originMap.remove(aCasReferenceId); if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINEST)) { UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINEST, CLASS_NAME.getName(), "removeMessageOrigin", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_remove_msg_origin_entry__FINEST", new Object[] { getComponentName(), aCasReferenceId }); } } }
@Override protected POSTaggerME produceResource(InputStream aStream) throws Exception { // Load the POS tagger model from the location the model provider offers POSModel model = new POSModel(aStream); // end::model-provider-decl[] // Extract tagset information from the model OpenNlpTagsetDescriptionProvider tsdp = new OpenNlpTagsetDescriptionProvider( getResourceMetaData().getProperty("pos.tagset"), POS.class, model.getPosModel()); if (getResourceMetaData().containsKey("pos.tagset.tagSplitPattern")) { tsdp.setTagSplitPattern(getResourceMetaData().getProperty( "pos.tagset.tagSplitPattern")); } addTagset(tsdp); if (printTagSet) { getContext().getLogger().log(INFO, tsdp.toString()); } // tag::model-provider-decl[] // Create a new POS tagger instance from the loaded model return new POSTaggerME(model); } };
/** * Disable a CASProcessor in the processing pipeline. * * @param aCasProcessorName CASProcessor to be added to the processing pipeline */ public void enableCasProcessor(String aCasProcessorName) { for (int i = 0; i < annotatorList.size(); i++) { ProcessingContainer pc = ((ProcessingContainer) annotatorList.get(i)); if (pc.getName().equals(aCasProcessorName)) { if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) { UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_enabled_cp__FINEST", new Object[] { Thread.currentThread().getName(), aCasProcessorName }); } pc.setStatus(Constants.CAS_PROCESSOR_RUNNING); } } }
public synchronized void addCasProcessor(CasProcessor aCasProcessor) { if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) { UIMAFramework.getLogger(this.getClass()).logrb( Level.FINEST, this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_add_cp_to_pool__FINEST", new Object[] { Thread.currentThread().getName(), aCasProcessor.getProcessingResourceMetaData().getName() }); } mAllInstances.add(aCasProcessor); mFreeInstances.add(aCasProcessor); if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) { UIMAFramework.getLogger(this.getClass()).logrb( Level.FINEST, this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_show_cp_pool_size__FINEST", new Object[] { Thread.currentThread().getName(), String.valueOf(mAllInstances.size()), String.valueOf(mFreeInstances.size()) }); } }
UIMAFramework.getLogger(this.getClass()).log(Level.CONFIG, " Adding New Annotator:" + aCpName); if (analysisEngines.containsKey(aCpName)) { if (UIMAFramework.getLogger().isLoggable(Level.CONFIG)) { UIMAFramework.getLogger(this.getClass()).logrb(Level.CONFIG, this.getClass().getName(), "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_add_pcp_to_existing_list__CONFIG", ((List) annotatorDeployList.get(listIndex)).add(aProcessor); } else { ArrayList newList = new ArrayList(); newList.add(0, aProcessor); analysisEngines.put(aCpName, newList); annotatorDeployList.add(0, newList); if (UIMAFramework.getLogger().isLoggable(Level.CONFIG)) { UIMAFramework.getLogger(this.getClass()).logrb(Level.CONFIG, this.getClass().getName(), "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_add_pcp_to_new_list__CONFIG",
if (!mFreeInstances.isEmpty()) { if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) { UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_checking_out_cp_from_pool__FINEST", new Object[] { Thread.currentThread().getName() }); CasProcessor r = (CasProcessor) mFreeInstances.remove(0); if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) { UIMAFramework.getLogger(this.getClass()).logrb( Level.FINEST, this.getClass().getName(), "UIMA_CPM_show_cp_pool_size__FINEST", new Object[] { Thread.currentThread().getName(), String.valueOf(mAllInstances.size()), String.valueOf(mFreeInstances.size()) }); if (UIMAFramework.getLogger().isLoggable(Level.WARNING)) { UIMAFramework.getLogger(this.getClass()).logrb( Level.WARNING, this.getClass().getName(),
if (UIMAFramework.getLogger().isLoggable(Level.WARNING)) { UIMAFramework.getLogger(this.getClass()).logrb(Level.WARNING, this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_invalid_checkin__WARNING", new Object[] { Thread.currentThread().getName() }); aCas.reset(); int index = checkedOutInstances.indexOf(aCas); // new code JC 05/11/2005 if (index != -1) { checkedOutInstances.remove(index); if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) { UIMAFramework.getLogger(this.getClass()).logrb( Level.FINEST, this.getClass().getName(), "UIMA_CPM_removed_from_checkedout_list__FINEST", new Object[] { Thread.currentThread().getName(), String.valueOf(checkedOutInstances.size()) }); if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) { UIMAFramework.getLogger(this.getClass()).logrb( Level.FINEST, this.getClass().getName(),
public synchronized void saveTime(long aTime, String aCasReferenceId, String anEndpointName) { String key = aCasReferenceId + anEndpointName; if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.FINE)) { UIMAFramework.getLogger(CLASS_NAME).logrb(Level.FINE, CLASS_NAME.getName(), "saveTime", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_save_time__FINE", new Object[] { aTime, aCasReferenceId, getComponentName(), anEndpointName, key }); } statsMap.put(key, Long.valueOf(aTime)); }
protected void stopTransportLayer() { if (transports.size() > 0) { Set<Entry<String, UimaTransport>> set = transports.entrySet(); for (Entry<String, UimaTransport> entry : set) { UimaTransport transport = entry.getValue(); try { transport.stopIt(); } catch (Exception e) { if (UIMAFramework.getLogger(CLASS_NAME).isLoggable(Level.WARNING)) { UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, CLASS_NAME.getName(), "stopTransportLayer", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_service_exception_WARNING", getComponentName()); UIMAFramework.getLogger(CLASS_NAME).logrb(Level.WARNING, getClass().getName(), "stopTransportLayer", UIMAEE_Constants.JMS_LOG_RESOURCE_BUNDLE, "UIMAEE_exception__WARNING", e); } } } } }
Object anObject = queue.remove(aQueueIndex); if (UIMAFramework.getLogger().isLoggable(Level.FINEST)) { UIMAFramework.getLogger(this.getClass()).logrb(Level.FINEST, this.getClass().getName(), "process", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_chunk_state_false_timeout__FINEST",
@Override public void initialize(UimaContext context) throws ResourceInitializationException { super.initialize(context); featureStore = new SimpleFeatureStore(); if (featureExtractors.length == 0) { context.getLogger().log(Level.SEVERE, "No feature extractors have been defined."); throw new ResourceInitializationException(); } }
@Override public void process(CAS cas) throws AnalysisEngineProcessException { FSIndex<AnnotationFS> sentences = cas.getAnnotationIndex(sentenceType); .createAnnotation(tokenType, sentenceOffset + tokenSpans[i].getStart(), sentenceOffset + tokenSpans[i].getEnd()); cas.getIndexRepository().addFS(tokenAnnotations[i]); if (logger.isLoggable(Level.FINER)) { tokeninzedSentenceLog.append(tokenAnnotations[i].getCoveredText()); tokeninzedSentenceLog.append(' '); if (logger.isLoggable(Level.FINER)) { logger.log(Level.FINER, "\"" + tokeninzedSentenceLog.toString() + "\"");
if (anObject instanceof UimaTimer) { timer = (UimaTimer) anObject; if (UIMAFramework.getLogger().isLoggable(Level.CONFIG)) { UIMAFramework.getLogger(TimerFactory.class).logrb(Level.CONFIG, TimerFactory.class.getName(), "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_show_timer_class__CONFIG", throw new ResourceInitializationException(ResourceInitializationException.CLASS_NOT_FOUND, new Object[] { aClassName, "CPE" }, e); } catch (IllegalAccessException e) { throw new ResourceInitializationException( ResourceInitializationException.COULD_NOT_INSTANTIATE, new Object[] { aClassName, "CPE" }, e); } catch (InstantiationException e) { throw new ResourceInitializationException( ResourceInitializationException.COULD_NOT_INSTANTIATE, new Object[] { aClassName, "CPE" }, e); if (UIMAFramework.getLogger().isLoggable(Level.CONFIG)) { UIMAFramework.getLogger(TimerFactory.class).logrb(Level.CONFIG, TimerFactory.class.getName(), "initialize", CPMUtils.CPM_LOG_RESOURCE_BUNDLE, "UIMA_CPM_java_timer__CONFIG", new Object[] { Thread.currentThread().getName() });
throw new ResourceInitializationException(e1); UIMAFramework.getLogger().logrb(Level.CONFIG, ResourceManager_impl.class.getName(), "initializeExternalResources", LOG_RESOURCE_BUNDLE, "UIMA_overridden_resource__CONFIG", new Object[] { e.getKey(), aQualifiedContextName, definingContext }); } else { UIMAFramework.getLogger().logrb(Level.WARNING, ResourceManager_impl.class.getName(), "initializeExternalResources", LOG_RESOURCE_BUNDLE, "UIMA_duplicate_resource_name__WARNING", throw new ResourceInitializationException(e1);
@Override public void load(DataResource aData) throws ResourceInitializationException { CharStream input; try { UIMAFramework.getLogger().log(Level.FINE, "Loading resource " + KEY_TOKEN_REGEX_RULES + " at: " + aData.getUri()); input = CharStreams.fromStream(aData.getInputStream()); UimaTokenRegexLexer lexer = new UimaTokenRegexLexer(input); CommonTokenStream tokens = new CommonTokenStream(lexer); UimaTokenRegexParser parser = new UimaTokenRegexParser(tokens); listener = new AutomataParserListener( parser ); listener.setAllowMatchingEmptySequences(false); ParseTreeWalker.DEFAULT.walk(listener, parser.ruleList()); } catch (IOException e) { throw new ResourceInitializationException(e); } }