You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@uima.apache.org by ea...@apache.org on 2007/02/03 17:57:15 UTC
svn commit: r503250 [4/9] - /incubator/uima/uimacpp/trunk/src/framework/
Added: incubator/uima/uimacpp/trunk/src/framework/internal_aggregate_engine.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/framework/internal_aggregate_engine.cpp?view=auto&rev=503250
==============================================================================
--- incubator/uima/uimacpp/trunk/src/framework/internal_aggregate_engine.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/framework/internal_aggregate_engine.cpp Sat Feb 3 08:57:13 2007
@@ -0,0 +1,323 @@
+/** @name internal_aggregate_engine.cpp
+-----------------------------------------------------------------------------
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+ Description: This file contains class AggregateEngine
+
+-----------------------------------------------------------------------------
+
+
+ 4/27/1999 Initial creation
+
+-------------------------------------------------------------------------- */
+
+#define UIMA_ENGINE_MAIN_CPP
+
+
+/* ----------------------------------------------------------------------- */
+/* Include dependencies */
+/* ----------------------------------------------------------------------- */
+
+#include "uima/pragmas.hpp" //must be included first to disable warnings
+#include "uima/annotator_timing.hpp"
+#include "uima/engine.hpp"
+
+#include "uima/internal_aggregate_engine.hpp"
+#include "uima/internal_fspromoter.hpp"
+#include "uima/resmgr.hpp"
+#include "uima/comp_ids.h"
+#include "uima/err_ids.h"
+#include "uima/annotator_mgr.hpp"
+#include "uima/internal_casimpl.hpp"
+
+#include "uima/macros.h"
+#include "uima/trace.hpp"
+#include "uima/consoleui.hpp"
+
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+namespace uima {
+
+ namespace internal {
+
+ static const char * gs_cpszReservedPrefix = _TEXT("UIMA");
+
+
+ /* ----------------------------------------------------------------------- */
+ /* Forward declarations */
+ /* ----------------------------------------------------------------------- */
+
+ /* ----------------------------------------------------------------------- */
+ /* Types / Classes */
+ /* ----------------------------------------------------------------------- */
+
+ /* ----------------------------------------------------------------------- */
+ /* Private Implementation */
+ /* ----------------------------------------------------------------------- */
+
+ /*
+ Most of the implementations required by uima::internal::EngineBase
+ directly call the ASB.
+ */
+
+
+ TyErrorId AggregateEngine::init2(util::Trace & rclTrace)
+ /* ----------------------------------------------------------------------- */
+ {
+ TyErrorId utErrorId = UIMA_ERR_NONE;
+
+ try {
+ /* now, after all the general init and config has been done,
+ we can init the annotator manager which will init all annotators */
+ utErrorId = iv_annotatorMgr.launchInit();
+ if (utErrorId != UIMA_ERR_NONE) {
+ /* since the init failed, we must deinit all annotators in order
+ to release all user allocated stuff */
+ (void) iv_annotatorMgr.launchDeInit(); /* ignore this RC */
+ return(utErrorId);
+ }
+
+ /* at this point, everything is fine and the engine is up and running! */
+
+ }
+ /* we need to catch any unexpected exceptions from init */
+ catch (Exception & rclException) {
+ rclTrace.dump(_TEXT("UIMACPP exception during init"));
+ rclTrace.dump(_TEXT("UIMACPP exception id"), rclException.getErrorInfo().getErrorId());
+ rclTrace.dump(_TEXT("UIMACPP exception name"), rclException.getName());
+ rclTrace.dump(_TEXT("UIMACPP exception message"), rclException.getErrorInfo().getMessage().asString().c_str());
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo());
+ return(logError(rclTrace, rclException.getErrorInfo().getErrorId()));
+ }
+#ifdef NDEBUG
+ catch (...) {
+ /* this should never occur!!! */
+ rclTrace.dump(_TEXT("Unexpected unknown exception"));
+ assertWithMsg(false, _TEXT("Unexpected unknown exception in init()")); //lint !e506: Constant value Boolean
+ return(logError(rclTrace, UIMA_ERR_ENGINE_UNEXPECTED_EXCEPTION)); /* in case the assert() is no longer here */
+ }
+#endif
+ return(utErrorId);
+ }
+
+
+ /* ----------------------------------------------------------------------- */
+ /* Implementation */
+ /* ----------------------------------------------------------------------- */
+
+
+ AggregateEngine::AggregateEngine(AnnotatorContext & rANC, bool bOwnsANC,
+ bool bOwnsTAESpecififer,
+ uima::internal::CASDefinition & casDefs, bool ownsCasDefs) :
+ EngineBase(rANC, bOwnsANC, bOwnsTAESpecififer, casDefs, ownsCasDefs),
+ iv_annotatorMgr(*this) {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+
+ clTrace.dump(_TEXT("UIMACPP Version"), AggregateEngine::getVersionInfo());
+ clTrace.dump(_TEXT("UIMACPP Level"), AggregateEngine::getLevelInfo());
+ assert(iv_state == EngineState::enEngineState_readyForInit);
+
+#ifndef NDEBUG
+
+ /* taph 18.10.2001: this code can be useful if you want to debug
+ UIMACPP in an environment where you can't start the debugger directly
+ e.g. if UIMACPP is called from Java.
+ The programm will wait in the loop below which gives you time to
+ attach the debugger to the (Java) process and start debugging.
+ */
+ util::Location tempDir;
+ util::Filename clLockfileName(tempDir.getAsCString(), "uimacpplock","lck");
+ clLockfileName.normalizeAbsolute();
+ if (clLockfileName.isExistent()) {
+ cout << "In AggregateEngine Ctor: Debug Lockfile detected." << endl;
+ cout << "Halting UIMACPP execution until " << clLockfileName.getAsCString() << " is deleted/renamed..." << endl;
+ do {
+ apr_sleep(3000000); // 3 seconds
+ } while (clLockfileName.isExistent());
+ cout << "Continuing..." << endl;
+ }
+#endif
+
+ }
+
+
+
+ AggregateEngine::~AggregateEngine(void)
+ /* ----------------------------------------------------------------------- */
+ {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+ destroyIfNeeded();
+
+ }
+
+
+
+ TyErrorId AggregateEngine::initializeImpl(AnalysisEngineDescription const & ) {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+ TyErrorId utErrorId = UIMA_ERR_NONE;
+
+ /* continue with the rest of init() */
+ utErrorId = init2(clTrace);
+ if (utErrorId != UIMA_ERR_NONE) {
+ return(logError(clTrace, utErrorId));
+ }
+
+ return(logError(clTrace, utErrorId));
+ }
+
+
+ TyErrorId AggregateEngine::reinitTypeSystemImpl() {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+ return iv_annotatorMgr.launchReinitTypeSystem();
+ }
+
+
+ TyErrorId AggregateEngine::destroyImpl(void) {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+ return iv_annotatorMgr.launchDeInit();
+ }
+
+
+ TyErrorId AggregateEngine::processImpl(CAS & cas, ResultSpecification const & crResultSpec) {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+ return iv_annotatorMgr.launchProcessDocument(cas, crResultSpec );
+ }
+
+
+ TyErrorId AggregateEngine::reconfigureImpl(void) {
+ util::Trace clTrace(util::enTraceDetailMedium, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+ return iv_annotatorMgr.launchConfig();
+ }
+
+ TyErrorId AggregateEngine::batchProcessCompleteImpl(void) {
+ util::Trace clTrace(util::enTraceDetailMedium, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+ return iv_annotatorMgr.launchCollectionProcessComplete();
+ }
+
+ TyErrorId AggregateEngine::collectionProcessCompleteImpl(void) {
+ util::Trace clTrace(util::enTraceDetailMedium, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+ return iv_annotatorMgr.launchCollectionProcessComplete();
+ }
+
+ bool AggregateEngine::hasNextImpl() {
+ return false;
+ }
+
+ CAS & AggregateEngine::nextImpl() {
+ UIMA_EXC_THROW_NEW(ExcInvalidRequest,
+ UIMA_ERR_NOT_YET_IMPLEMENTED,
+ UIMA_MSG_ID_EXC_INVALID_CALL_TO_NEXT,
+ UIMA_MSG_ID_EXC_INVALID_CALL_TO_NEXT,
+ ErrorInfo::unrecoverable);
+ }
+
+ int AggregateEngine::getCasInstancesRequiredImpl() {
+ return 0;
+ }
+
+
+ /* ----------------------------------------------------------------------- */
+ /* Static functions */
+ /* ----------------------------------------------------------------------- */
+
+#ifdef UIMA_DEBUG_ANNOTATOR_TIMING
+
+ size_t
+ AggregateEngine::getNbrOfAnnotators( void ) const {
+ return iv_annotatorMgr.getNbrOfAnnotators();
+ }
+
+ icu::UnicodeString const &
+ AggregateEngine::getAnnotatorName( size_t uiAnnotatorIndex ) const {
+ // it is not easy to find the names for the delegate engines
+ // given only their position in the flow
+ AnalysisEngineMetaData const * pMetaData =
+ getAnnotatorContext().getTaeSpecifier().getAnalysisEngineMetaData();
+ assert(EXISTS(pMetaData));
+ FlowConstraints const * pFlow = pMetaData->getFlowConstraints();
+ assert(EXISTS(pFlow));
+ return pFlow->getNodes()[uiAnnotatorIndex];
+ }
+
+ uima::Timer
+ AggregateEngine::getAnnotatorTimer( size_t uAnnotatorIndex, EnAnnotatorTimer enAnnotatorTimer) const {
+ return iv_annotatorMgr.getAnnotatorTimer(uAnnotatorIndex, enAnnotatorTimer);
+ }
+
+
+ void AggregateEngine::displayTimingData(util::ConsoleUI const & rConsole, bool bVerbose) const {
+ string strTemp;
+ double dTotalLoadTime = (double)0.0;
+ double dTotalInitTime = (double)0.0;
+ double dTotalDeInitTime = (double)0.0;
+ double dTotalConfigTime = (double)0.0;
+ double dTotalProcessDocumentTime = (double)0.0;
+ double dTotalAnnotatorTime = (double)0.0;
+ size_t i;
+
+
+ // first sum up times to get totals
+ for ( i = 0; i < getNbrOfAnnotators(); ++i ) {
+ dTotalLoadTime += getAnnotatorTimer(i, enLoadAnnotatorTime).getAccumulatedTime();
+ dTotalInitTime += getAnnotatorTimer(i, enInitAnnotatorTime).getAccumulatedTime();
+ dTotalDeInitTime += getAnnotatorTimer(i, enDeinitAnnotatorTime).getAccumulatedTime();
+ dTotalConfigTime += getAnnotatorTimer(i, enConfigAnnotatorTime).getAccumulatedTime();
+ dTotalProcessDocumentTime+= getAnnotatorTimer(i, enProcessAnnotatorTime).getAccumulatedTime();
+ } /* e-o-for */
+ dTotalAnnotatorTime = dTotalLoadTime + dTotalInitTime + dTotalDeInitTime + dTotalConfigTime + dTotalProcessDocumentTime;
+
+ rConsole.formatHeader("Overall annotator timing data");
+ rConsole.format("Total time spent in annotators", uima::Timer::timeString(dTotalAnnotatorTime).c_str());
+ if (bVerbose) {
+ rConsole.format("- library-load time", uima::Timer::timeString(dTotalLoadTime).c_str());
+ rConsole.format("- initialize time", uima::Timer::timeString(dTotalInitTime).c_str());
+ rConsole.format("- reconfigure time", uima::Timer::timeString(dTotalConfigTime).c_str());
+ rConsole.format("- process time", uima::Timer::timeString(dTotalProcessDocumentTime).c_str());
+ }
+
+ // now dump the individual, total and relative times
+ rConsole.header("Individual annotator timing data (% for this annotator)");
+ for ( i = 0; i < getNbrOfAnnotators(); ++i ) {
+ string str;
+ UnicodeStringRef uref(getAnnotatorName(i));
+ uref.extract(str);
+ rConsole.format(str.c_str(), getAnnotatorTimer(i, enTotalAnnotatorTime).timeAndPercentString(dTotalAnnotatorTime).c_str());
+ if (bVerbose) {
+ rConsole.format("- library load time", getAnnotatorTimer(i, enLoadAnnotatorTime).timeAndPercentString(dTotalLoadTime).c_str());
+ rConsole.format("- initialize time", getAnnotatorTimer(i, enInitAnnotatorTime).timeAndPercentString(dTotalInitTime).c_str());
+ rConsole.format("- reconfigure time", getAnnotatorTimer(i, enConfigAnnotatorTime).timeAndPercentString(dTotalConfigTime).c_str());
+ rConsole.format("- process time", getAnnotatorTimer(i, enProcessAnnotatorTime).timeAndPercentString(dTotalProcessDocumentTime).c_str());
+ rConsole.newline();
+ }
+ } /* e-o-for */
+ }
+
+#endif //UIMA_DEBUG_ANNOTATOR_TIMING
+
+ }
+
+} // namespace uima
+
+/* <EOF> */
+
+
Propchange: incubator/uima/uimacpp/trunk/src/framework/internal_aggregate_engine.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/framework/internal_capability_container.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/framework/internal_capability_container.cpp?view=auto&rev=503250
==============================================================================
--- incubator/uima/uimacpp/trunk/src/framework/internal_capability_container.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/framework/internal_capability_container.cpp Sat Feb 3 08:57:13 2007
@@ -0,0 +1,429 @@
+/** \file internal_capability_container.cpp .
+-----------------------------------------------------------------------------
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+ Description:
+
+-----------------------------------------------------------------------------
+
+
+ 02/05/2003 Initial creation
+
+-------------------------------------------------------------------------- */
+//#define DEBUG_VERBOSE
+// ---------------------------------------------------------------------------
+// Includes
+// ---------------------------------------------------------------------------
+#include "uima/pragmas.hpp"
+using namespace std;
+
+
+#include "uima/macros.h"
+#include "uima/internal_capability_container.hpp"
+#include "uima/err_ids.h"
+#include "uima/msg.h"
+
+namespace uima {
+
+ UIMA_EXC_CLASSIMPLEMENT(CapabilityException, Exception);
+
+ namespace internal {
+
+
+ CapabilityContainer::CapabilityContainer( )
+ : iv_psetInputTOFsForUnspecifiedLang(NULL),
+ iv_psetOutputTOFsForUnspecifiedLang(NULL),
+ iv_bHasEmptyOutputTOFsForUnspecifiedLang(false) {}
+
+
+
+ /*static*/
+ void
+ CapabilityContainer::initTypeOrFeatures(
+ TyMapLang2TypeOrFeatures & rMap, // output argument
+ Capability::TyVecCapabilityTofs const & vecTofs,
+ Capability::TyVecCapabilityLanguages const & vecLangs,
+ TypeSystem const & typeSystem) {
+ const int BUF_SIZE = 0x100;
+ char cBuf[BUF_SIZE];
+ Capability::TyVecCapabilityLanguages::const_iterator itLang;
+ for (itLang = vecLangs.begin(); itLang != vecLangs.end(); ++itLang) {
+ // convert unicode lang string to single-byte lang string
+ assert((*itLang).length() < BUF_SIZE);
+ // Note: this conversion can be used only for invariant characters
+ u_UCharsToChars((*itLang).getBuffer(), cBuf, (*itLang).length());
+ // zero terminate single-byte buffer
+ cBuf[(*itLang).length()] = '\0';
+ // Special workaround code for the new way to specify the unspecified language
+ if (strcasecmp(cBuf, "x-unspecified") == 0) {
+ strcpy(cBuf, Language::UNSPECIFIED);
+ }
+ // create a language object based on single-byte lang string
+ Language lang(cBuf);
+ if (!lang.isValid()) {
+ /* taph 06.02.2003: once we have more detailed information about
+ the origin of the error we need to replace "unknown configuration file"
+ with the filename of the XML file (and maybe line number?) */
+ UIMA_EXC_THROW_NEW(uima::CapabilityException, // exc-type
+ UIMA_ERR_ENGINE_LANGUAGE_INVALID, // error code
+ ErrorMessage(UIMA_MSG_ID_EXC_INVALID_LANGUAGE, cBuf), // error message
+ ErrorMessage(UIMA_MSG_ID_EXCON_CHECKING_CAPABILITY_SPEC,"unknown configuration file"), // error context message
+ ErrorInfo::recoverable);
+ }
+ // create a new empty vector in the map for this lang
+ TySetTypeOrFeatures & setTofs = rMap[lang];
+ // now fill the vector with tof objects created from tof strings
+ Capability::TyVecCapabilityTofs::const_iterator itTof;
+ for (itTof = vecTofs.begin(); itTof != vecTofs.end(); ++itTof) {
+ TypeOrFeature tof;
+ // the tof string may be a type...
+ Type t = typeSystem.getType(*itTof);
+ if (t.isValid()) {
+ tof = TypeOrFeature(t);
+ } else {
+ // or the tof string may be a feature
+ Feature f = typeSystem.getFeatureByFullName(*itTof);
+ if (f.isValid()) {
+ tof = TypeOrFeature(f);
+ } else {
+ /* taph 06.02.2003: once we have more detailed information about
+ the origin of the error we need to replace "unknown configuration file"
+ with the filename of the XML file (and maybe line number?) */
+ if (tof.isType()) {
+ UIMA_EXC_THROW_NEW(uima::CapabilityException, // exc-type
+ UIMA_ERR_INVALID_FSTYPE_OBJECT, // error code
+ ErrorMessage(UIMA_MSG_ID_EXC_UNKNOWN_TYPE_NAME, *itTof), // error message
+ ErrorMessage(UIMA_MSG_ID_EXCON_CHECKING_CAPABILITY_SPEC, "unknown configuration file"), // error context message
+ ErrorInfo::recoverable);
+ } else {
+ UIMA_EXC_THROW_NEW(uima::CapabilityException, // exc-type
+ UIMA_ERR_INVALID_FSFEATURE_OBJECT,// error code
+ ErrorMessage(UIMA_MSG_ID_EXC_UNKNOWN_FEATURE_NAME, *itTof), // error message
+ ErrorMessage(UIMA_MSG_ID_EXCON_CHECKING_CAPABILITY_SPEC, "unknown configuration file"), // error context message
+ ErrorInfo::recoverable);
+ }
+ }
+ }
+ assert(tof.isValid());
+ setTofs.insert(tof);
+ } // for all tof strings
+ } // for all lang strings
+ }
+
+
+ void CapabilityContainer::computeClosure(TyMapLang2TypeOrFeatures & rMap, TyMapLang2TypeOrFeatures & noTerritoryMap) {
+ assert( noTerritoryMap.empty() );
+ // 1. all original TOFS from iv_mapLang2*TypesOrFeatures for language codes without territory
+ // are copied as iv_mapLang2*TypesOrFeaturesNoTerritory
+ TyMapLang2TypeOrFeatures::const_iterator cit;
+ for (cit = rMap.begin(); cit != rMap.end(); ++cit) {
+ Language const & lang = (*cit).first;
+ if ( !lang.hasTerritory() ) {
+ noTerritoryMap[lang] = (*cit).second;
+ }
+ }
+
+ // 2. all TOFs from en are appended to en_US, en_GB etc. for iv_mapLang2*TypesOrFeatures
+ TyMapLang2TypeOrFeatures::iterator it;
+ for (it = rMap.begin(); it != rMap.end(); ++it) {
+ Language const & lang = (*it).first;
+ if ( lang.hasTerritory() ) {
+ // put all TOFs "down" from pt to pt_BR
+ Language langWithoutTerritory(lang.getLanguage());
+ TySetTypeOrFeatures & rSet = rMap[langWithoutTerritory];
+ TySetTypeOrFeatures & specificSet = (*it).second;
+ // MSV6 compile error: specificSet.insert( rSet.begin(), rSet.end() );
+ TySetTypeOrFeatures::const_iterator setit;
+ for (setit = rSet.begin(); setit != rSet.end(); ++setit) {
+ specificSet.insert( *setit );
+ }
+ }
+ }
+
+ // 3. all TOFs from en_GB, en_US, etc. are appended to en for iv_mapLang2*TypesOrFeatures
+ for (it = rMap.begin(); it != rMap.end(); ++it) {
+ Language const & lang = (*it).first;
+ if ( lang.hasTerritory() ) {
+ // put all TOFs "up" from pt_BR to pt
+ Language langWithoutTerritory(lang.getLanguage());
+ TySetTypeOrFeatures & rSet = (*it).second;
+ // MSV6 compile error: rMap[langWithoutTerritory].insert( rSet.begin(), rSet.end() );
+ TySetTypeOrFeatures::const_iterator setit;
+ for (setit = rSet.begin(); setit != rSet.end(); ++setit) {
+ rMap[langWithoutTerritory].insert(*setit);
+ }
+
+ }
+ }
+
+#ifdef DEBUG_VERBOSE
+ UIMA_TPRINT("Standard Map:");
+ for (cit = rMap.begin(); cit != rMap.end(); ++cit) {
+ UIMA_TPRINT("Language: " << (*cit).first);
+ UIMA_TPRINT(" TOFs:");
+ TySetTypeOrFeatures const & set = (*cit).second;
+ TySetTypeOrFeatures::const_iterator setcit;
+ for (setcit = set.begin(); setcit != set.end(); ++setcit) {
+ UIMA_TPRINT(" " << (*setcit).getName());
+ }
+ }
+
+#endif
+
+ }
+
+
+ void
+ CapabilityContainer::init( vector<Capability*> const & vecCap, TypeSystem const & typeSystem, EnMatchPolicy enMatchPolicy ) {
+ iv_enMatchPolicy = enMatchPolicy;
+ vector<Capability*>::const_iterator it;
+ assert(iv_mapLang2InputTypesOrFeatures.size() == 0);
+ assert(iv_mapLang2OutputTypesOrFeatures.size() == 0);
+ for (it = vecCap.begin(); it != vecCap.end(); ++it) {
+ assert(EXISTS(*it));
+ Capability const & cap = (*(*it));
+ initTypeOrFeatures(
+ iv_mapLang2InputTypesOrFeatures,
+ cap.getCapabilityTypes(Capability::INPUT),
+ cap.getSupportedLanguages(),
+ typeSystem);
+ initTypeOrFeatures(
+ iv_mapLang2InputTypesOrFeatures,
+ cap.getCapabilityFeatures(Capability::INPUT),
+ cap.getSupportedLanguages(),
+ typeSystem);
+ initTypeOrFeatures(
+ iv_mapLang2OutputTypesOrFeatures,
+ cap.getCapabilityTypes(Capability::OUTPUT),
+ cap.getSupportedLanguages(),
+ typeSystem);
+ initTypeOrFeatures(
+ iv_mapLang2OutputTypesOrFeatures,
+ cap.getCapabilityFeatures(Capability::OUTPUT),
+ cap.getSupportedLanguages(),
+ typeSystem);
+ }
+
+ // try to find input tofs for unspecifed language
+ assert(iv_psetInputTOFsForUnspecifiedLang == NULL);
+ TySetTypeOrFeatures const * pSetInputTOFs =
+ findInputTOFs(Language(Language::UNSPECIFIED));
+ if (pSetInputTOFs != NULL) {
+ iv_psetInputTOFsForUnspecifiedLang = pSetInputTOFs;
+ }
+ // try to find output tofs for unspecifed language
+ assert(iv_psetOutputTOFsForUnspecifiedLang == NULL);
+ TySetTypeOrFeatures const * pSetOutputTOFs =
+ findOutputTOFs(Language(Language::UNSPECIFIED));
+ if (pSetOutputTOFs != NULL) {
+ iv_psetOutputTOFsForUnspecifiedLang = pSetOutputTOFs;
+ }
+
+ copyEntriesForUnspecifedLanguage();
+ if (hasEmptyOutputTypeOrFeatures(Language(Language::UNSPECIFIED))) {
+ iv_bHasEmptyOutputTOFsForUnspecifiedLang = true;
+ }
+
+ computeClosure(iv_mapLang2OutputTypesOrFeatures, iv_mapLang2OutputTypesOrFeaturesNoTerritory );
+ computeClosure(iv_mapLang2InputTypesOrFeatures, iv_mapLang2InputTypesOrFeaturesNoTerritory );
+ }
+
+ void CapabilityContainer::copyEntriesForUnspecifedLanguage() {
+ if (iv_psetInputTOFsForUnspecifiedLang == NULL) {
+ // if it is not in the input it can't be in the output either
+ assert(findOutputTOFs(Language(Language::UNSPECIFIED)) == NULL);
+ return;
+ }
+ assert(EXISTS(iv_psetInputTOFsForUnspecifiedLang));
+ if (iv_psetInputTOFsForUnspecifiedLang->size() != 0) {
+ TyMapLang2TypeOrFeatures::iterator it;
+ for (it = iv_mapLang2InputTypesOrFeatures.begin(); it != iv_mapLang2InputTypesOrFeatures.end(); ++it) {
+ if (&(*it).second != iv_psetInputTOFsForUnspecifiedLang) { // don't append onto ourselves
+ if ((*it).second.size() > 0) { // don't append to empty
+#ifndef NDEBUG
+ size_t uiOldSize = (*it).second.size();
+#endif /* NDEBUG */
+ // MSV6 compile error: (*it).second.insert(iv_psetInputTOFsForUnspecifiedLang->begin(), iv_psetInputTOFsForUnspecifiedLang->end());
+ TySetTypeOrFeatures::const_iterator tofit;
+ for (tofit = iv_psetInputTOFsForUnspecifiedLang->begin(); tofit != iv_psetInputTOFsForUnspecifiedLang->end(); ++tofit) {
+ (*it).second.insert( *tofit );
+ }
+ assert((*it).second.size() >= uiOldSize);
+ }
+ }
+ }
+
+ // Now do the same copying for the output
+
+ // if it is in the input it must be in the output too
+ assert(findOutputTOFs(Language(Language::UNSPECIFIED)) != NULL);
+ assert(EXISTS(iv_psetOutputTOFsForUnspecifiedLang));
+
+ for (it = iv_mapLang2OutputTypesOrFeatures.begin(); it != iv_mapLang2OutputTypesOrFeatures.end(); ++it) {
+ if (&(*it).second != iv_psetOutputTOFsForUnspecifiedLang) { // don't append onto ourselves
+ if ((*it).second.size() > 0) { // don't append to empty
+#ifndef NDEBUG
+ size_t uiOldSize = (*it).second.size();
+#endif /* NDEBUG */
+ // MSV6 compile error: (*it).second.insert(iv_psetOutputTOFsForUnspecifiedLang->begin(), iv_psetOutputTOFsForUnspecifiedLang->end());
+ TySetTypeOrFeatures::const_iterator tofit;
+ for (tofit = iv_psetOutputTOFsForUnspecifiedLang->begin(); tofit != iv_psetOutputTOFsForUnspecifiedLang->end(); ++tofit) {
+ (*it).second.insert(*tofit);
+ }
+ assert((*it).second.size() >= uiOldSize);
+ }
+ }
+ }
+ }
+ }
+
+
+ /*static*/ CapabilityContainer::TySetTypeOrFeatures const *
+ CapabilityContainer::findTOFs(TyMapLang2TypeOrFeatures const & crMap,
+ TyMapLang2TypeOrFeatures const & noTerritoryMap,
+ Language const & lang, EnMatchPolicy enMatchPolicy) {
+ // temporary
+ assert( enMatchPolicy == enStrictThenLooseMatch );
+ //first try strict match using built-in find function
+ TyMapLang2TypeOrFeatures::const_iterator itMap = crMap.find(lang);
+ if (itMap != crMap.end()) {
+ return (&(*itMap).second);
+ }
+
+ if (enMatchPolicy == enStrictMatchOnly) {
+ return NULL;
+ }
+ assert(enMatchPolicy == enStrictThenLooseMatch);
+ // language was not found directly
+ // now try without territory
+ Language newLang(lang.getLanguage());
+ assert( !newLang.hasTerritory() );
+ for (itMap = noTerritoryMap.begin(); itMap != noTerritoryMap.end(); ++itMap) {
+ assert( !(*itMap).first.hasTerritory() );
+ if ((*itMap).first.getLanguage() == lang.getLanguage()) {
+ return (&(*itMap).second);
+ }
+ }
+ return NULL;
+ }
+
+ CapabilityContainer::TySetTypeOrFeatures const *
+ CapabilityContainer::findInputTOFs(Language const & lang) const {
+ // try to find the set for the language
+ TySetTypeOrFeatures const * pSetTOFs =
+ findTOFs(iv_mapLang2InputTypesOrFeatures, iv_mapLang2InputTypesOrFeaturesNoTerritory, lang, iv_enMatchPolicy);
+ // if there is one return that one
+ if (pSetTOFs != NULL) {
+ return pSetTOFs;
+ }
+ // else return whatever we may have for the unspecified language
+ return (iv_psetInputTOFsForUnspecifiedLang);
+ }
+
+ CapabilityContainer::TySetTypeOrFeatures const *
+ CapabilityContainer::findOutputTOFs(Language const & lang) const {
+ // try to find the set for the language
+ TySetTypeOrFeatures const * pSetTOFs =
+ findTOFs(iv_mapLang2OutputTypesOrFeatures, iv_mapLang2OutputTypesOrFeaturesNoTerritory, lang, iv_enMatchPolicy);
+ // if there is one return that one
+ if (pSetTOFs != NULL) {
+ return pSetTOFs;
+ }
+ // else return whatever we may have for the unspecified language
+ return (iv_psetOutputTOFsForUnspecifiedLang);
+ }
+
+
+ CapabilityContainer::TySetTypeOrFeatures const &
+ CapabilityContainer::getInputTypeOrFeatures( Language const & lang) const {
+ // try to find it
+ TySetTypeOrFeatures const * pSetTOFs = findInputTOFs(lang);
+ if (pSetTOFs != NULL) {
+ return (*pSetTOFs);
+ }
+ // don't use the [] operator because would insert and return a
+ // newly created empty vector
+ assert(iv_setEmptyTypeOrFeaturesSet.size() == 0);
+ return iv_setEmptyTypeOrFeaturesSet;
+ }
+
+ bool
+ CapabilityContainer::hasInputTypeOrFeature( TypeOrFeature const & tof, Language const & lang) const {
+ // try to find it
+ TySetTypeOrFeatures const * pSetTOFs = findInputTOFs(lang);
+ if (pSetTOFs == NULL) {
+ return false;
+ }
+ TySetTypeOrFeatures::const_iterator itSet = pSetTOFs->find(tof);
+ if (itSet == pSetTOFs->end()) {
+ return false;
+ }
+ return true;
+ }
+
+ CapabilityContainer::TySetTypeOrFeatures const &
+ CapabilityContainer::getOutputTypeOrFeatures( Language const & lang) const {
+ // try to find it
+ TySetTypeOrFeatures const * pSetTOFs = findOutputTOFs(lang);
+ if (pSetTOFs != NULL) {
+ return (*pSetTOFs);
+ }
+ // don't use the [] operator because will insert and return a
+ // newly created empty vector
+ assert(iv_setEmptyTypeOrFeaturesSet.size() == 0);
+ return iv_setEmptyTypeOrFeaturesSet;
+ }
+
+ bool
+ CapabilityContainer::hasOutputTypeOrFeature( TypeOrFeature const & tof, Language const & lang) const {
+ // try to find it
+ TySetTypeOrFeatures const * pSetTOFs = findOutputTOFs(lang);
+ if (pSetTOFs == NULL) {
+ return false;
+ }
+ TySetTypeOrFeatures::const_iterator itSet = pSetTOFs->find(tof);
+ if (itSet == pSetTOFs->end()) {
+ return false;
+ }
+ return true;
+ }
+
+ bool
+ CapabilityContainer::hasEmptyOutputTypeOrFeatures( Language const & lang) const {
+ // try to find it in output
+ TySetTypeOrFeatures const * pSetTOFs = findOutputTOFs(lang);
+ if (pSetTOFs == NULL) {
+ // we must have an explicit entry for that language in our map
+ // or maybe we have an empty entry for the unspecifed lang
+ return iv_bHasEmptyOutputTOFsForUnspecifiedLang;
+ }
+ // but that explicit entry must be empty
+ if (pSetTOFs->size() > 0) {
+ return false;
+ }
+ return true;
+
+ }
+
+ } // namespace internal
+} // namespace uima
+
+
Propchange: incubator/uima/uimacpp/trunk/src/framework/internal_capability_container.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/uima/uimacpp/trunk/src/framework/internal_engine_base.cpp
URL: http://svn.apache.org/viewvc/incubator/uima/uimacpp/trunk/src/framework/internal_engine_base.cpp?view=auto&rev=503250
==============================================================================
--- incubator/uima/uimacpp/trunk/src/framework/internal_engine_base.cpp (added)
+++ incubator/uima/uimacpp/trunk/src/framework/internal_engine_base.cpp Sat Feb 3 08:57:13 2007
@@ -0,0 +1,511 @@
+/** \file internal_engine_base.cpp .
+-----------------------------------------------------------------------------
+
+
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+
+-----------------------------------------------------------------------------
+
+ Description:
+
+-----------------------------------------------------------------------------
+
+
+-------------------------------------------------------------------------- */
+
+
+/* ----------------------------------------------------------------------- */
+/* Include dependencies */
+/* ----------------------------------------------------------------------- */
+//#define DEBUG_VERBOSE 1
+
+#include "uima/pragmas.hpp"
+
+#include "uima/macros.h"
+#include "uima/internal_engine_base.hpp"
+#include "uima/msg.h"
+#include "uima/annotator_context.hpp"
+#include "uima/log.hpp"
+#include "uima/lowlevel_typesystem.hpp"
+#include "uima/lowlevel_indexrepository.hpp"
+#include "uima/casdefinition.hpp"
+#include "uima/internal_casimpl.hpp"
+#include "uima/trace.hpp"
+
+/* ----------------------------------------------------------------------- */
+/* Constants */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Forward declarations */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Types / Classes */
+/* ----------------------------------------------------------------------- */
+
+/* ----------------------------------------------------------------------- */
+/* Implementation */
+/* ----------------------------------------------------------------------- */
+namespace uima {
+ namespace internal {
+
+ uima::internal::EngineBase & EngineBase::promoteEngine( uima::AnalysisEngine & engine) {
+ return (uima::internal::EngineBase&) engine;
+ }
+
+ EngineBase::EngineBase(AnnotatorContext & rANC, bool bOwnsANC,
+ bool bOwnsTAESpecififer,
+ uima::internal::CASDefinition & casDef, bool ownsCasDef)
+ :
+ iv_pAnnotatorContext( & rANC),
+ iv_bOwnsANC(bOwnsANC),
+ iv_bOwnsTAESpec(bOwnsTAESpecififer),
+ iv_casDefinition( & casDef),
+ iv_ownsCASDefinition(ownsCasDef) {
+ iv_casHolder = NULL;
+ }
+
+ EngineBase::~EngineBase() {
+ if (iv_bOwnsTAESpec) {
+ delete iv_pAnnotatorContext->getTAESpec();
+ }
+ if (iv_bOwnsANC) {
+ delete iv_pAnnotatorContext;
+ }
+ if (iv_ownsCASDefinition) {
+ delete iv_casDefinition;
+ }
+ if (iv_casHolder) {
+ delete iv_casHolder;
+ }
+ }
+
+ /**
+ * pretty simple CAS compatibility check: Just check if they
+ * have the same type system and index definition.
+ */
+ void EngineBase::checkCASCompatibility(CAS const & cas) const {
+ uima::internal::CASImpl const & tcasImpl = uima::internal::CASImpl::promoteCAS(cas);
+ if ( (&tcasImpl.getHeap().getTypeSystem()) != (&iv_casDefinition->getTypeSystem())
+ || (& tcasImpl.getIndexRepository().getIndexDefinition()) != (& iv_casDefinition->getIndexDefinition()) ) {
+ UIMA_EXC_THROW_NEW(CASIncompatibilityException,
+ UIMA_ERR_ENGINE_INCOMPATIBLE_CAS,
+ UIMA_MSG_ID_EXC_INCOMPATIBLE_CAS,
+ UIMA_MSG_ID_EXCON_PROCESSING_CAS,
+ ErrorInfo::recoverable);
+ }
+ }
+
+
+ bool EngineBase::checkAndSetCallingSequenceInitialize() {
+ if (iv_state.getState() != EngineState::enEngineState_readyForInit) {
+ return false;
+ }
+ iv_state.setToState(EngineState::enEngineState_readyForProcessOrReconfigOrDeinit);
+ return true;
+ }
+
+
+ bool EngineBase::checkAndSetCallingSequenceDestroy() {
+ if ( (iv_state.getState() != EngineState::enEngineState_readyForProcessOrReconfigOrDeinit) ) {
+ return false;
+ }
+
+ iv_state.setToState(EngineState::enEngineState_readyForDeletion);
+ return true;
+ }
+
+ bool EngineBase::checkAndSetCallingSequenceProcess() {
+ UIMA_TPRINT("state: " << iv_state.getState());
+ if (iv_state.getState() != EngineState::enEngineState_readyForProcessOrReconfigOrDeinit) {
+ return false;
+ }
+ // dont change state
+ return true;
+ }
+
+
+ bool EngineBase::checkAndSetCallingSequenceReconfigure() {
+ if ( iv_state != EngineState::enEngineState_readyForProcessOrReconfigOrDeinit) {
+ return false;
+ }
+ // dont change state
+ return true;
+ }
+
+ TyErrorId EngineBase::logError(util::Trace & rclTrace, TyErrorId utErrorId) {
+ if (utErrorId != UIMA_ERR_NONE) {
+ rclTrace.dump(_TEXT("Error:"), (size_t) utErrorId);
+ }
+ return(utErrorId);
+ }
+
+
+
+ bool EngineBase::isInitialized(void) const {
+ switch (iv_state.getState()) {
+ case EngineState::enEngineState_readyForInit :
+ case EngineState::enEngineState_readyForDeletion :
+ return false;
+ case EngineState::enEngineState_readyForProcessOrReconfigOrDeinit :
+ return true;
+ }
+ assert(false);
+ return false;
+ }
+
+ CAS * EngineBase::newCAS() const {
+ assert( EXISTS(iv_casDefinition) );
+ assert( EXISTS(iv_pAnnotatorContext) );
+ CAS* tmpCas = uima::internal::CASImpl::createCASImpl(* CONST_CAST(uima::internal::CASDefinition*, iv_casDefinition), *iv_pAnnotatorContext);
+ return tmpCas->getInitialView();
+ }
+
+
+ void EngineBase::destroyIfNeeded() {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+
+ try {
+ if (iv_state == EngineState::enEngineState_readyForProcessOrReconfigOrDeinit) {
+ destroy();
+ iv_state.assertMatch(EngineState::enEngineState_readyForDeletion);
+ }
+ } catch (ExcWinCException & rclException) {
+ // windows "exceptions" are really abort signals: we re-throw for app to handle
+ throw rclException;
+ } catch (Exception & rclException) {
+ clTrace.dump("Unexpected UIMACPP exception");
+ clTrace.dump(rclException.asString().c_str());
+ assertWithMsg(false, _TEXT("Unexpected UIMACPP exception in engine destructor")); //lint !e506: Constant value Boolean
+ } catch (exception & rclException) {
+ clTrace.dump("ANSI C++ exception");
+ clTrace.dump(rclException.what());
+ assertWithMsg(false, _TEXT("Unexpected ANSI C++ exception in engine destructor")); //lint !e506: Constant value Boolean
+ }
+#ifdef NDEBUG
+ catch (...) {
+ /* this should never occur!!! */
+ clTrace.dump(_TEXT("Unexpected exception"));
+ assertWithMsg(false, _TEXT("Unexpected unknown exception in engine destructor")); //lint !e506: Constant value Boolean
+ }
+#endif
+ }
+
+
+ /**
+ * Gathers all output capabilities from the TAE specifier.
+ * This result spec is implicitly assumed when calling process(CAS) without a result spec.
+ */
+ TyErrorId EngineBase::initializeCompleteResultSpec() {
+ iv_completeResultSpec.clear();
+
+ assert( EXISTS(iv_casDefinition) );
+ uima::TypeSystem const & rTypeSystem = iv_casDefinition->getTypeSystem();
+
+ AnnotatorContext const & crANC = getAnnotatorContext();
+
+ AnalysisEngineMetaData::TyVecpCapabilities const & crVecCaps = crANC.getTaeSpecifier().getAnalysisEngineMetaData()->getCapabilites();
+ AnalysisEngineMetaData::TyVecpCapabilities::const_iterator citCaps;
+
+ for (citCaps = crVecCaps.begin(); citCaps != crVecCaps.end(); ++citCaps) {
+ Capability const * cpCap = * citCaps;
+ Capability::TyVecCapabilityTofs const & crTypes = cpCap->getCapabilityTypes(Capability::OUTPUT);
+ Capability::TyVecCapabilityTofs::const_iterator citTOFs;
+ for (citTOFs = crTypes.begin(); citTOFs != crTypes.end(); ++citTOFs) {
+ Type t = rTypeSystem.getType( *citTOFs );
+ if (! t.isValid() ) {
+ ErrorInfo errInf(
+ ErrorMessage(UIMA_MSG_ID_UNKNOWN_FEATURE_IN_CAPBILITY_SPEC,(*citTOFs)),
+ UIMA_ERR_ANNOTATOR_MGR_CONFIG_INVALID_RESULTSPECIFICATION,
+ ErrorInfo::unrecoverable);
+ getAnnotatorContext().getLogger().logError(errInf);
+ return UIMA_ERR_ANNOTATOR_MGR_CONFIG_INVALID_RESULTSPECIFICATION;
+ }
+ iv_completeResultSpec.add(t);
+ }
+
+ Capability::TyVecCapabilityTofs const & crFeatures = cpCap->getCapabilityFeatures(Capability::OUTPUT);
+ for (citTOFs = crFeatures.begin(); citTOFs != crFeatures.end(); ++citTOFs) {
+ Feature f = rTypeSystem.getFeatureByFullName(*citTOFs);
+ if (! f.isValid() ) {
+ ErrorInfo errInf(
+ ErrorMessage(UIMA_MSG_ID_UNKNOWN_FEATURE_IN_CAPBILITY_SPEC,(*citTOFs)),
+ UIMA_ERR_ANNOTATOR_MGR_CONFIG_INVALID_RESULTSPECIFICATION,
+ ErrorInfo::unrecoverable);
+ getAnnotatorContext().getLogger().logError(errInf);
+ return UIMA_ERR_ANNOTATOR_MGR_CONFIG_INVALID_RESULTSPECIFICATION;
+ }
+ iv_completeResultSpec.add(f);
+ }
+
+ }
+ return UIMA_ERR_NONE;
+ }
+
+
+ TyErrorId EngineBase::initialize(AnalysisEngineDescription const & specifier) {
+ try {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+
+ if (!checkAndSetCallingSequenceInitialize()) {
+ return logError(clTrace, UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+ }
+ assert( (& specifier) == (&iv_pAnnotatorContext->getTaeSpecifier()));
+ // call implementation in subclass
+ TyErrorId utErrorId = initializeImpl(specifier);
+ if (utErrorId != UIMA_ERR_NONE) {
+ destroy();
+ return utErrorId;
+ }
+
+ utErrorId = initializeCompleteResultSpec();
+ if (utErrorId != UIMA_ERR_NONE) {
+ destroy();
+ return utErrorId;
+ }
+
+ int numCasRequired = getCasInstancesRequiredImpl();
+ if (numCasRequired > 0) {
+ utErrorId = iv_pAnnotatorContext->defineCASPool(numCasRequired);
+ }
+
+ return utErrorId;
+ } catch (Exception & rclException) {
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo() );
+ return rclException.getErrorInfo().getErrorId();
+ }
+
+ }
+
+
+ TyErrorId EngineBase::reinitTypeSystem() {
+ try {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+ TyErrorId utErrorId = reinitTypeSystemImpl();
+ if (utErrorId != UIMA_ERR_NONE) {
+ destroy();
+ return utErrorId;
+ }
+
+ // we have to re-initialize the result spec since the types and features
+ // may have changed.
+ utErrorId = initializeCompleteResultSpec();
+ if (utErrorId != UIMA_ERR_NONE) {
+ destroy();
+ return utErrorId;
+ }
+ return utErrorId;
+ } catch (Exception & rclException) {
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo() );
+ return rclException.getErrorInfo().getErrorId();
+ }
+
+ }
+
+
+ ResultSpecification const & EngineBase::getCompleteResultSpecification() const {
+ return iv_completeResultSpec;
+ }
+
+
+ TyErrorId EngineBase::destroy() {
+ try {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+
+ if (!checkAndSetCallingSequenceDestroy()) {
+ return logError(clTrace, UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+ }
+ return destroyImpl();
+ } catch (Exception & rclException) {
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo() );
+ return rclException.getErrorInfo().getErrorId();
+ }
+ }
+
+ TyErrorId EngineBase::reconfigure() {
+ try {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+
+ if (!checkAndSetCallingSequenceReconfigure()) {
+ return logError(clTrace, UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+ }
+ return reconfigureImpl();
+ } catch (Exception & rclException) {
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo() );
+ return rclException.getErrorInfo().getErrorId();
+ }
+
+ }
+
+
+ TyErrorId EngineBase::process(CAS & cas) {
+ try {
+ AnalysisEngine * engine = this;
+ return engine->process(cas, getCompleteResultSpecification());
+ } catch (Exception & rclException) {
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo() );
+ UIMA_EXC_RETHROW(rclException,NULL);
+ ///return rclException.getErrorInfo().getErrorId();
+ }
+
+ }
+
+ TyErrorId EngineBase::process(CAS & cas, ResultSpecification const & resultSpec) {
+ try {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+
+ if (!checkAndSetCallingSequenceProcess()) {
+ return logError(clTrace, UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+ }
+ // (ee) WHY DO THIS CHECK???
+ //checkCASCompatibility(cas);
+
+ // Removed code that used to skip the processing if the document
+ // was empty, since not all Sofas have local text. (bll)
+
+ return processImpl(cas, resultSpec);
+ } catch (Exception & rclException) {
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo() );
+ //return rclException.getErrorInfo().getErrorId();
+ UIMA_EXC_RETHROW(rclException,NULL);
+ }
+
+ }
+
+
+ TyErrorId EngineBase::batchProcessComplete() {
+ try {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+
+ if (!checkAndSetCallingSequenceProcess()) {
+ return logError(clTrace, UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+ }
+ return batchProcessCompleteImpl();
+ } catch (Exception & rclException) {
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo() );
+ return rclException.getErrorInfo().getErrorId();
+ }
+
+ }
+
+ TyErrorId EngineBase::collectionProcessComplete() {
+ try {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+
+ if (!checkAndSetCallingSequenceProcess()) {
+ return logError(clTrace, UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+ }
+ return collectionProcessCompleteImpl();
+ } catch (Exception & rclException) {
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo() );
+ return rclException.getErrorInfo().getErrorId();
+ }
+
+ }
+
+ bool EngineBase::hasNext() {
+ try {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+ /** why do this ?? (bi)
+ if (!checkAndSetCallingSequenceProcess()) {
+ logError(clTrace, UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+ return false;
+ } **/
+ return hasNextImpl();
+ } catch (Exception & rclException) {
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo() );
+ throw rclException;
+ }
+ }
+
+ CAS & EngineBase::next() {
+ try {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+ /** why do this (bi)
+ if (!checkAndSetCallingSequenceProcess()) {
+ logError(clTrace, UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+ } **/
+ return nextImpl();
+ } catch (Exception & rclException) {
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo() );
+ //return rclException.getErrorInfo().getErrorId();
+ throw rclException;
+ }
+ }
+
+ int EngineBase::getCasInstancesRequired() {
+ try {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+
+ if (!checkAndSetCallingSequenceProcess()) {
+ logError(clTrace, UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+ return 0;
+ }
+ return getCasInstancesRequiredImpl();
+ } catch (Exception & rclException) {
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo() );
+ //return rclException.getErrorInfo().getErrorId();
+ throw rclException;
+ }
+ }
+
+ CASIterator EngineBase::processAndOutputNewCASes(CAS & cas) {
+ try {
+ util::Trace clTrace(util::enTraceDetailLow, UIMA_TRACE_ORIGIN, UIMA_TRACE_COMPID_ENGINE);
+
+ if (!checkAndSetCallingSequenceProcess()) {
+ logError(clTrace, UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
+
+ UIMA_EXC_THROW_NEW(CASIteratorException,
+ UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE,
+ UIMA_MSG_ID_EXCON_CALLING_ANNOTATOR_FUNCTION,
+ UIMA_MSG_ID_EXCON_CALLING_ANNOTATOR_FUNCTION,
+ ErrorInfo::unrecoverable);
+ }
+ TyErrorId rc = process(cas);
+ if (rc != UIMA_ERR_NONE) {
+ UIMA_EXC_THROW_NEW(CASIteratorException,
+ UIMA_ERR_PROCESS_OUTPUT_CAS,
+ UIMA_MSG_ID_EXCON_CALLING_ANNOTATOR_FUNCTION,
+ UIMA_MSG_ID_EXCON_CALLING_ANNOTATOR_FUNCTION,
+ ErrorInfo::unrecoverable);
+ }
+ return CASIterator(this);
+ } catch (Exception & rclException) {
+ getAnnotatorContext().getLogger().logError(rclException.getErrorInfo() );
+ //return rclException.getErrorInfo().getErrorId();
+ throw rclException;
+ }
+ }
+
+ TyErrorId EngineBase::batchProcessCompleteImpl() {
+ return UIMA_ERR_NOT_YET_IMPLEMENTED;
+ }
+
+ TyErrorId EngineBase::collectionProcessCompleteImpl() {
+ return UIMA_ERR_NOT_YET_IMPLEMENTED;
+ }
+
+ }
+}
+
+/* ----------------------------------------------------------------------- */
+
+
+
Propchange: incubator/uima/uimacpp/trunk/src/framework/internal_engine_base.cpp
------------------------------------------------------------------------------
svn:eol-style = native