in src/utils/runAECpp.cpp [122:318]
int main(int argc, char * argv[]) {
try {
/* Access the command line arguments to get the name of the input text. */
//if (argc != 3 && argc != 5 && argc != 7 && argc != 9 && argc != 11) {
if (argc < 3) {
tell();
return 1;
}
useSofa = false;
lenient = false;
xcasInput = textFormat;
//std::string sofa;
//std::string pattern("*");
cnfg = NULL;
loglevel = -1;
numinstances = 1;
numruns = 1;
randomize = false;
rdelay = 0;
int index = 0;
while (++index < argc) {
char* arg = argv[index];
if (0 == strcmp(arg, "-x")) {
xcasInput = xcasFormat;
} else if (0 == strcmp(arg, "-xcas")) {
xcasInput = xcasFormat;
} else if (0 == strcmp(arg, "-xmi")) {
xcasInput = xmiFormat;
} else if (0 == strcmp(arg, "-lenient")) {
lenient = true;
} else if (0 == strcmp(arg, "-s")) {
if ( ++index < argc ) {
sofaName = argv[index];
useSofa = true;
}
} else if (0 == strcmp(arg, "-l")) {
if ( ++index < argc ) {
loglevel = atoi(argv[index]);
if (loglevel < LogStream::EnMessage) {
cerr << "LogLevel less than minimum value (Message) = " << LogStream::EnMessage << endl;
return 1;
}
if (loglevel > LogStream::EnError) {
cerr << "LogLevel greater than maximum value (Error) = " << LogStream::EnError << endl;
return 1;
}
}
} else if (0 == strcmp(arg, "-n")) {
if ( ++index < argc ) {
numinstances = atoi(argv[index]);
if (numinstances < 1) {
cerr << "NumInstances less than minimum value 1 "<< endl;
return 1;
}
if (out.length() > 0) {
cerr << "Output directory may not be specified when NumInstances is more than 1." << endl;
return 1;
}
}
} else if (0 == strcmp(arg, "-rand")) {
randomize = true;
} else if (0 == strcmp(arg, "-r")) {
if ( ++index < argc ) {
numruns = atoi(argv[index]);
if (numruns < 1) {
cerr << "Number of runs less than minimum value 1 "<< endl;
return 1;
}
}
} else if (0 == strcmp(arg, "-rdelay")) {
if ( ++index < argc ) {
rdelay = atol(argv[index]);
rdelay = rdelay; //convert to microsec
if (rdelay < 1) {
cerr << "Random delay in millis less than minimum value of 1 "<< endl;
return 1;
}
}
} else { //one of the standard params - whichever we haven't read yet
if (cnfg == NULL) {
cnfg = arg;
} else if (in.length() == 0) {
in.append(arg);
} else if (out.length() == 0) {
out.append(arg);
if (numinstances > 1) {
cerr << "Output directory may not be specified when NumInstances is more than 1." << endl;
return 1;
}
}
}
} //while
if (in.length() == 0 || index > argc) { // Too few args or no arg after -s or -l
tell();
return 1;
}
if (out == in) {
cout << "runAECpp: ERROR: input and output file paths are the same " << endl;
return -1;
}
/* Create/link up to a UIMACPP resource manager instance (singleton) */
(void) ResourceManager::createInstance("runAECpp");
/* check if input file / directory exists */
uima::util::Filename infn(in.c_str());
if (!infn.isExistent() ) {
cout << "runAECpp: ERROR: input file / directory does not exist. " << endl;
return -1;
}
if (loglevel >= 0) {
ResourceManager::getInstance().setLoggingLevel((LogStream::EnEntryType)loglevel);
}
ErrorInfo errorInfo;
if (numinstances == 1) {
AnalysisEngine * pEngine = Framework::createAnalysisEngine(cnfg, errorInfo);
if (errorInfo.getErrorId() != UIMA_ERR_NONE) {
cerr << "runAECpp:" << endl
<< " Error string : "
<< AnalysisEngine::getErrorIdAsCString(errorInfo.getErrorId()) << endl
<< " UIMACPP Error info:" << endl
<< errorInfo << endl;
exit((int)errorInfo.getErrorId());
}
processInputFiles(pEngine);
} else {
apr_status_t rv = 0;
//APR pool
apr_pool_t *pool;
rv = apr_pool_create(&pool, NULL);
if (rv != APR_SUCCESS) {
cerr << "ERROR: apr_pool_create() failed. " << endl;
return -1;
}
/*create as many AnalysisEngine instances as specified
by numinstances. */
vector<AnalysisEngine *> analysisEngines;
for (int i=0; i < numinstances; i++) {
AnalysisEngine * pEngine = Framework::createAnalysisEngine(cnfg, errorInfo);
if (errorInfo.getErrorId() != UIMA_ERR_NONE) {
cerr << "runAECpp:" << endl
<< " Error string : "
<< AnalysisEngine::getErrorIdAsCString(errorInfo.getErrorId()) << endl
<< " UIMACPP Error info:" << endl
<< errorInfo << endl;
exit((int)errorInfo.getErrorId());
}
analysisEngines.push_back(pEngine);
}
cerr << "Initialized AnalysisEngine " << endl;
/* create and start the processing threads */
apr_threadattr_t * thd_attr=0;
rv = apr_threadattr_create(&thd_attr, pool);
assert(rv == APR_SUCCESS);
vector<apr_thread_t *> processingThreads;
for (int i=0; i < numinstances; i++) {
apr_thread_t *thread=0;
rv = apr_thread_create(&thread, thd_attr, process, analysisEngines.at(i), pool);
assert(rv == APR_SUCCESS);
processingThreads.push_back(thread);
apr_sleep(10000); //required so that time function to distinctly seed randomizer.
}
cerr << "Wait for processing threads to finish " << endl;
/* wait for threads to end */
for (size_t i=0; i < processingThreads.size(); i++) {
//cout << "runAECpp: wait for thread " << i << " to end " << endl;
apr_thread_join(&rv, processingThreads.at(i));
}
if (pool) {
apr_pool_destroy(pool);
pool=0;
}
}
} catch (Exception e) {
cout << "runAECpp: " << e << endl;
}
/* If we got this far everything went OK */
cout << "runAECpp: processing finished sucessfully! " << endl;
return(0);
}