/* Similar routine as above just with error info objects instead of err-ids.
This routine just does a hard program exit for any failure!
*/
static void CheckError(ErrorInfo const &errInfo) {
    if (errInfo.getErrorId() != UIMA_ERR_NONE) {
        cerr << endl << "   *** ExampleApplication - Error info:" << endl
        << "Error string  : "
        << AnalysisEngine::getErrorIdAsCString(errInfo.getErrorId())
        << errInfo << endl;                      /* (errInfo starts with a newline) */
        exit((int) errInfo.getErrorId());
    }
}
Beispiel #2
0
void testCallingSequence1(uima::util::ConsoleUI& rclConsole, const TCHAR* cpszConfigFilename)
/* ----------------------------------------------------------------------- */
{
    ErrorInfo errInfo;
    uima::TextAnalysisEngine* pEngine = TextAnalysisEngine::createTextAnalysisEngine(cpszConfigFilename, errInfo);

    failIfNotTrue(errInfo.getErrorId() == UIMA_ERR_NONE);
    failIfNotTrue(pEngine != NULL);
    CAS* cas = pEngine->newCAS();
    failIfNotTrue(cas != NULL);

    uima::UnicodeStringRef us(UnicodeString("a"));
//   UnicodeStringRef uRef(us);
    rclConsole.formatHeader(_TEXT("testing Engine CallingSequence1"));

    cas->setDocumentText(us.getBuffer(), us.length());
    cas->getDocumentAnnotation().setLanguage("en");
    failIfNotTrue(pEngine->process(*cas) == UIMA_ERR_NONE);
    failIfNotTrue(cas->reset() == UIMA_ERR_NONE);
    failIfNotTrue(pEngine->destroy() == UIMA_ERR_NONE);

    cas->setDocumentText(us.getBuffer(), us.length());
    cas->getDocumentAnnotation().setLanguage("en");
    failIfNotTrue(pEngine->process(*cas) == UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);

    TyErrorId deInitRC = pEngine->destroy();
    rclConsole.format("RC of deInit()", deInitRC);
    failIfNotTrue(deInitRC == UIMA_ERR_ENGINE_INVALID_CALLING_SEQUENCE);
    rclConsole.formatBool(_TEXT("testing Engine CallingSequence1 OK"),
                          true);  //lint !e944: argument for operator '!' always evaluates to False
    delete cas;
    delete pEngine;
}  //lint !e715: cpszConfigFilename (line 99) not referenced
Beispiel #3
0
void testDescriptorNotFound(uima::util::ConsoleUI& rclConsole)
/* ----------------------------------------------------------------------- */
{
    rclConsole.info("testDescriptorNotFound start.");
    uima::TextAnalysisEngine* pEngine;

    ErrorInfo errInfo;
    pEngine = TextAnalysisEngine::createTextAnalysisEngine(_TEXT("DUMMY"), errInfo);
    failIfNotTrue(errInfo.getErrorId() == UIMA_ERR_RESOURCE_CORRUPTED);
    failIfNotTrue(pEngine == NULL);
    rclConsole.info("testDescriptorNotFound finished.");
}
Beispiel #4
0
void testMissingResMgr(uima::util::ConsoleUI& rclConsole)
/* ----------------------------------------------------------------------- */
{
    rclConsole.info("testMissingResMgr start.");
    uima::TextAnalysisEngine* pEngine;

    failIfNotTrue(!ResourceManager::hasInstance());
    ErrorInfo errInfo;
    pEngine = TextAnalysisEngine::createTextAnalysisEngine(_TEXT("DUMMY"), errInfo);
    failIfNotTrue(!ResourceManager::hasInstance());
    failIfNotTrue(errInfo.getErrorId() == UIMA_ERR_ENGINE_RESMGR_NOT_INITIALIZED);
    failIfNotTrue(pEngine == NULL);
    rclConsole.info("testMissingResMgr finished.");
}
Beispiel #5
0
void testCallingSequence2(uima::util::ConsoleUI& rclConsole, const TCHAR* cpszConfigFilename)
/* ----------------------------------------------------------------------- */
{
    rclConsole.formatHeader(_TEXT("testing Engine CallingSequence2"));
    {

        uima::TextAnalysisEngine* pEngine = NULL;
        ErrorInfo errInfo;

        pEngine = TextAnalysisEngine::createTextAnalysisEngine(cpszConfigFilename, errInfo);
        failIfNotTrue(errInfo.getErrorId() == UIMA_ERR_NONE);
        failIfNotTrue(pEngine != NULL);
        delete pEngine;
    }
    rclConsole.formatBool(_TEXT("testing Engine CallingSequence2 OK"),
                          true);  //lint !e944: argument for operator '!' always evaluates to False
}
Beispiel #6
0
void testCallingSequence3(uima::util::ConsoleUI& rclConsole, const TCHAR* cpszConfigFilename)
/* ----------------------------------------------------------------------- */
{
    uima::TextAnalysisEngine* pEngine = NULL;
    uima::Language clLanguage(MAIN_DEFAULT_LANG);
    const char* clCCSID = MAIN_DEFAULT_CCSID_STR;
    TyErrorId utErrorId;

    UnicodeString us("a");
    UnicodeStringRef uref(us);

    rclConsole.formatHeader(_TEXT("testing Engine CallingSequence3"));

    ErrorInfo errInfo;
    pEngine = TextAnalysisEngine::createTextAnalysisEngine(cpszConfigFilename, errInfo);
    failIfNotTrue(errInfo.getErrorId() == UIMA_ERR_NONE);
    failIfNotTrue(pEngine != NULL);
    CAS* cas = pEngine->newCAS();
    failIfNotTrue(cas != NULL);

    /* test for NULL ptrs */

    UnicodeStringRef uref2(NULL);
    cas->setDocumentText(uref2.getBuffer(), uref2.length());
    cas->getDocumentAnnotation().setLanguage("en");
    failIfNotTrue(pEngine->process(*cas) == UIMA_ERR_NONE);
    failIfNotTrue(cas->reset() == UIMA_ERR_NONE);


    /* test for subsequent processes */
    cas->setDocumentText(uref2.getBuffer(), uref2.length());
    cas->getDocumentAnnotation().setLanguage("en");

    failIfNotTrue(pEngine->process(*cas) == UIMA_ERR_NONE);

    failIfNotTrue(pEngine->process(*cas) == UIMA_ERR_NONE);


    utErrorId = pEngine->destroy();
    failIfNotTrue(utErrorId == UIMA_ERR_NONE);
    delete cas;
    delete pEngine;
    rclConsole.formatBool(_TEXT("testing Engine CallingSequence3 OK"),
                          true);  //lint !e944: argument for operator '!' always evaluates to False
}
Beispiel #7
0
bool testLoadData(uima::util::ConsoleUI& rclConsole,
                  const char* cpszCCSID,
                  const TCHAR* cpszConfigFilename,
                  const TCHAR* cpszLanguage,
                  size_t uiNumOfIterations)
/* ----------------------------------------------------------------------- */
{
    uima::TextAnalysisEngine* pEngine = NULL;
    ///uima::CCSID                 clCCSID(lCCSID);
    uima::Language clLanguage(cpszLanguage);
    ErrorInfo errInfo;

    rclConsole.formatHeader(_TEXT("testing UIMA Engine loading a document"));
    /* init engine */
    pEngine = TextAnalysisEngine::createTextAnalysisEngine(cpszConfigFilename, errInfo);
    uimaToolHandleErrorId(rclConsole, errInfo.getErrorId(), errInfo.asString().c_str(), _TEXT("uima::Engine::init()"),
                          gs_lExpectedInitRc);
    if (gs_lExpectedInitRc != UIMA_ERR_NONE) {
        return (false);
    }
    failIfNotTrue(pEngine != NULL);

    for (size_t ui = 0; ui < uiNumOfIterations; ui++) {
        const TCHAR* cpszInpTerm = 0;

        /* read in file */
        if (uiNumOfIterations > 1) {
            rclConsole.newline();
            rclConsole.format(_TEXT("Iteration"), (unsigned long) ui);
        }
        if (rclConsole.hasArgString(_TEXT("inpterm"), cpszInpTerm)) {
            testProcessTerm(rclConsole, *pEngine, cpszCCSID, clLanguage, cpszInpTerm);
        } else {
            testProcessDocu(rclConsole, *pEngine, cpszCCSID, clLanguage);
        }
    }
    TyErrorId utErrorId = pEngine->destroy();
    uimaToolHandleErrorId(rclConsole, utErrorId, pEngine->getAnnotatorContext().getLogger().getLastErrorAsCStr(),
                          _TEXT("uima::Engine::deInit"));
    delete pEngine;
    return (true);
}
Beispiel #8
0
void testCasMultiplier(uima::util::ConsoleUI& rclConsole)
/* ----------------------------------------------------------------------- */
{
    rclConsole.info("testCasMultiplier start.");
    uima::TextAnalysisEngine* pEngine;

    ErrorInfo errInfo;

    UnicodeString filename("SimpleTextSegmenter.xml");
    UnicodeString fn = ResourceManager::resolveFilename(filename, filename);
    pEngine = TextAnalysisEngine::createTextAnalysisEngine(UnicodeStringRef(fn).asUTF8().c_str(), errInfo);
    failIfNotTrue(errInfo.getErrorId() == UIMA_ERR_NONE);
    failIfNotTrue(pEngine != NULL);


    //test operational properties settings
    failIfNotTrue(pEngine->getAnalysisEngineMetaData().getOperationalProperties()->getOutputsNewCASes() == true);
    failIfNotTrue(pEngine->getAnalysisEngineMetaData().getOperationalProperties()->getModifiesCas() == false);
    failIfNotTrue(
            pEngine->getAnalysisEngineMetaData().getOperationalProperties()->isMultipleDeploymentAllowed() == true);


    CAS* cas = pEngine->newCAS();
    cas->setDocumentText(
            UnicodeString("This is the first sentence. This is the second sentence. This is the third sentence."));

    CASIterator iter = pEngine->processAndOutputNewCASes(*cas);
    int num = 0;
    while (iter.hasNext()) {
        num++;
        CAS& seg = iter.next();
        failIfNotTrue(seg.getDocumentText().length() > 0);
        pEngine->getAnnotatorContext().releaseCAS(seg);
    }
    failIfNotTrue(num == 3);
    delete pEngine;
    delete cas;
    rclConsole.info("testCasMultiplier finished.");
}