/****************************************************************************** * AUTHOR : Saravanan * DATE : 24-03-2007 * NAME : mapFeatureExtractor * DESCRIPTION : * ARGUMENTS : * RETURNS : * NOTES : * CHANGE HISTROY * Author Date Description ******************************************************************************/ int LTKShapeFeatureExtractorFactory::mapFeatureExtractor(const string& featureExtractorName, string& outFEName) { LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Entering " << "LTKShapeFeatureExtractorFactory::mapFeatureExtractor()" << endl; int returnCode = SUCCESS; if(LTKSTRCMP(featureExtractorName.c_str(), NAME_POINT_FLOAT_SHAPE_FEATURE_EXTRACTOR) == 0) { outFEName = POINT_FLOAT; } else if(LTKSTRCMP(featureExtractorName.c_str(), NAME_L7_SHAPE_FEATURE_EXTRACTOR) == 0) { outFEName = L7; } else if(LTKSTRCMP(featureExtractorName.c_str(),NAME_NPEN_SHAPE_FEATURE_EXTRACTOR) == 0) { outFEName = NPEN; } else if(LTKSTRCMP(featureExtractorName.c_str(),NAME_SUBSTROKE_SHAPE_FEATURE_EXTRACTOR) == 0) { outFEName = SUBSTROKE; } else { returnCode = EFTR_EXTR_NOT_EXIST; } LOG(LTKLogger::LTK_LOGLEVEL_DEBUG) << "Exiting " << "LTKShapeFeatureExtractorFactory::mapFeatureExtractor()" << endl; return returnCode; }
/********************************************************************************** * AUTHOR : Thanigai Murugan K * DATE : 30-AUG-2005 * NAME : ValidateCommandLineArgs * DESCRIPTION : Validate the command line arguments. Report an error if value is * missing for any command line option * ARGUMENTS : None * RETURNS : 0 on Success and -1 on Error * NOTES : * CHANGE HISTROY * Author Date Description of change *************************************************************************************/ int ValidateCommandLineArgs() { if((LTKSTRCMP(strProjectName, "") == 0)) { LOG(LTKLogger::LTK_LOGLEVEL_ERR)<< "Project Name not Specified ... " << endl; return -1; // No projectname specified } if(LTKSTRCMP(strTestLstFile, "") == 0) { LOG(LTKLogger::LTK_LOGLEVEL_ERR)<< "Option (train/test) not Specified ... " << endl; return -1; // No option specified -test } return 0; }
/********************************************************************************** * AUTHOR : Thanigai Murugan K * DATE : 30-AUG-2005 * NAME : CheckForOption * DESCRIPTION : Check if the argument is matching with any of the option strings * ARGUMENTS : strVal - Value to match * RETURNS : 1 if matching and 0 if not matching * NOTES : * CHANGE HISTROY * Author Date Description of change *************************************************************************************/ int CheckForOption(char* strVal) { if( (LTKSTRCMP(strVal, OPTION_PERF) == 0) || (LTKSTRCMP(strVal, OPTION_TEST) == 0) || (LTKSTRCMP(strVal, OPTION_PROJECT) == 0) || (LTKSTRCMP(strVal, OPTION_PROFILE) == 0) || (LTKSTRCMP(strVal, OPTION_OUTPUT) == 0) || (LTKSTRCMP(strVal, OPTION_LOGFILE) == 0) || (LTKSTRCMP(strVal, OPTION_LOGLEVEL) == 0) || (LTKSTRCMP(strVal, OPTION_NUMCHOICES) == 0)) return 1; return 0; }
/****************************************************************************** * AUTHOR : Nidhi Sharma * DATE : 07-May-2007 * NAME : setLipiLogLevel * DESCRIPTION : To set the value of m_logLevel * ARGUMENTS : String * RETURNS : Nothing * NOTES : * CHANGE HISTROY * Author Date Description of change ******************************************************************************/ int LTKLipiEngineModule::setLipiLogLevel(const string& appLogLevel) { // No log messages as this function is used to configure logger string strLogLevel = ""; if ( appLogLevel.length() != 0 ) { strLogLevel= appLogLevel; } else { LTKReturnError(EINVALID_LOG_LEVEL); } const char * strLogLevelPtr = strLogLevel.c_str(); // mapping m_LogLevel to Logger log levels if(LTKSTRCMP(strLogLevelPtr, LOG_LEVEL_DEBUG) == 0) { m_logLevel = LTKLogger::LTK_LOGLEVEL_DEBUG; } else if(LTKSTRCMP(strLogLevelPtr, LOG_LEVEL_ALL) == 0) { m_logLevel = LTKLogger::LTK_LOGLEVEL_ALL; } else if(LTKSTRCMP(strLogLevelPtr, LOG_LEVEL_VERBOSE) == 0) { m_logLevel = LTKLogger::LTK_LOGLEVEL_VERBOSE; } else if(LTKSTRCMP(strLogLevelPtr, LOG_LEVEL_ERROR) == 0) { m_logLevel = LTKLogger::LTK_LOGLEVEL_ERR; } else if(LTKSTRCMP(strLogLevelPtr, LOG_LEVEL_OFF) == 0) { m_logLevel = LTKLogger::LTK_LOGLEVEL_OFF; } else if(LTKSTRCMP(strLogLevelPtr, LOG_LEVEL_INFO) == 0) { m_logLevel = LTKLogger::LTK_LOGLEVEL_INFO; } else { LTKReturnError(EINVALID_LOG_LEVEL); } return SUCCESS; }
/***************************************************************************** * AUTHOR : Nidhi Sharma * DATE : 11 Aug 2008 * NAME : mapLogLevel * DESCRIPTION : * ARGUMENTS : * RETURNS : * NOTES : * CHANGE HISTROY * Author Date Description of change *****************************************************************************/ int mapLogLevel(const string& logLevelStr, LTKLogger::EDebugLevel& outLogLevel) { const char * strLogLevelPtr = logLevelStr.c_str(); // mapping m_LogLevel to Logger log levels if(LTKSTRCMP(strLogLevelPtr, LOG_LEVEL_DEBUG) == 0) { outLogLevel = LTKLogger::LTK_LOGLEVEL_DEBUG; } else if(LTKSTRCMP(strLogLevelPtr, LOG_LEVEL_ALL) == 0) { outLogLevel = LTKLogger::LTK_LOGLEVEL_ALL; } else if(LTKSTRCMP(strLogLevelPtr, LOG_LEVEL_VERBOSE) == 0) { outLogLevel = LTKLogger::LTK_LOGLEVEL_VERBOSE; } else if(LTKSTRCMP(strLogLevelPtr, LOG_LEVEL_ERROR) == 0) { outLogLevel = LTKLogger::LTK_LOGLEVEL_ERR; } else if(LTKSTRCMP(strLogLevelPtr, LOG_LEVEL_OFF) == 0) { outLogLevel = LTKLogger::LTK_LOGLEVEL_OFF; } else if(LTKSTRCMP(strLogLevelPtr, LOG_LEVEL_INFO) == 0) { outLogLevel = LTKLogger::LTK_LOGLEVEL_INFO; } else { LTKReturnError(EINVALID_LOG_LEVEL); } return SUCCESS; }
/********************************************************************************** * AUTHOR : Thanigai Murugan K * DATE : 30-AUG-2005 * NAME : main * DESCRIPTION : Main function. Process the command line options and invoke the * train/test methods after instantiating LipiEngine module. * ARGUMENTS : Command line arguments, refer to PrintUsage() function for syntax * RETURNS : -1 on error 0 on success * NOTES : * CHANGE HISTROY * Author Date Description of change *************************************************************************************/ int main(int argc, char** argv) { //char *envstring = NULL; char lipienginepath[MAX_PATH]=""; int iErrorCode; LTKOSUtil* utilPtr = LTKOSUtilFactory::getInstance(); void *functionHandle = NULL; globalArg = argv; globalArgCount = argc; utilPtr->recordStartTime(); // Assume the default log file, if user did not specify one... if(LTKSTRCMP(strLogFile, "") == 0) { strcpy(strLogFile, DEFAULT_LOG_FILE); } if(processCommandLineArgs() != 0) { printUsage(); delete utilPtr; return -1; } if(bVersionRequest) /* Then display version and exit */ { cout << "\n Version of runwordrec tool: " << SUPPORTED_MIN_VERSION << endl; delete utilPtr; return 0; } /* Get the LIPI_ROOT environment variable if the user has not provided in the command line */ if(strlen(strLipiRootPath)==0) { char *tempStr=NULL; /* Get the LIPI_ROOT environment variable */ tempStr=getenv(LIPIROOT_ENV_STRING); if(tempStr == NULL) { cout << "Error,LIPI_ROOT is neither provided in the command line nor set as an environment variable\n" << endl; delete utilPtr; return -1; } strcpy(strLipiRootPath,tempStr); } // Load the LipiEngine.DLL hLipiEngine = NULL; iErrorCode = utilPtr->loadSharedLib(strLipiRootPath, LIPIENGINE_MODULE_STR, &hLipiEngine); if(iErrorCode != SUCCESS) { cout << "Error loading LipiEngine module" << endl; delete utilPtr; return -1; } int iMajor_lipiEngine=0, iMinor_lipiEngine=0, iBugfix_lipiEngine=0; iErrorCode = utilPtr->getFunctionAddress(hLipiEngine, "getToolkitVersion", &functionHandle); if(iErrorCode != SUCCESS) { cout << "Error mapping the getToolkitVersion function" << endl; delete utilPtr; return -1; } LipiEngine_getCurrentVersion = (FN_PTR_GETCURRENTVERSION) functionHandle; LipiEngine_getCurrentVersion(&iMajor_lipiEngine, &iMinor_lipiEngine, &iBugfix_lipiEngine); // Version comparison START char toolkitVer[MAX_STRLEN]; sprintf(toolkitVer, "%d.%d.%d",iMajor_lipiEngine,iMinor_lipiEngine,iBugfix_lipiEngine); LTKVersionCompatibilityCheck verTempObj; string supportedMinVersion(SUPPORTED_MIN_VERSION); string toolkitVersion(toolkitVer); bool compatibilityResults = verTempObj.isFirstVersionHigher(toolkitVersion, supportedMinVersion); if(compatibilityResults == false) { cout<< "\nIncompatible version of LipiEngine(ver: " << toolkitVersion << ") with runwordrec(ver: " << supportedMinVersion << ")" << endl; // Unload the DLL from memory utilPtr->unloadSharedLib(hLipiEngine); delete utilPtr; return FAILURE; } // Version comparison END // without reserving memory, it gives an error at the end... strLogFileName.reserve(MAX_PATH); /* Get the function address of "createLTKLipiEngine" function from the DLL module */ functionHandle = NULL; iErrorCode = utilPtr->getFunctionAddress(hLipiEngine, "createLTKLipiEngine", &functionHandle); if(iErrorCode != SUCCESS) { cout << "Error mapping the createLTKLipiEngine function" << endl; delete utilPtr; return -1; } createLTKLipiEngine = (FN_PTR_CREATELTKLIPIENGINE) functionHandle; functionHandle = NULL; // Create an instance of LipiEngine ptrObj = createLTKLipiEngine(); // set the LIPI_ROOT path in Lipiengine module instance ptrObj->setLipiRootPath(strLipiRootPath); // set the Log File Path if (strlen(strLogFile) != 0 ) { string tempString(strLogFile); ptrObj->setLipiLogFileName(tempString); } if(strlen(strLogLevel) != 0) { string tempStringLogLevel(strLogLevel); ptrObj->setLipiLogLevel(tempStringLogLevel); } // Initialize the LipiEngine iErrorCode = ptrObj->initializeLipiEngine(); if(iErrorCode != 0) { cout << "Error initializing lipiengine: " << getErrorMessage(iErrorCode) << endl; cout << "For more details, please see the log file" << endl; // Unload the DLL from memory utilPtr->unloadSharedLib(hLipiEngine); delete utilPtr; return -1; } string strProjName(strProjectName), strProfName(strProfileName); // Now create the word recognizer instance using the project/profile name strings LTKWordRecognizer *pReco; iErrorCode = ptrObj->createWordRecognizer(strProjName, strProfName, &pReco); if(iErrorCode != SUCCESS) { cout << "Error creating word recognizer: " << getErrorMessage(iErrorCode) << endl; cout << "For more details, please see the log file" << endl; // Unload the DLL from memory utilPtr->unloadSharedLib(hLipiEngine); delete utilPtr; return -1; } if(bComputePerformance) { utilPtr->recordStartTime(); } iErrorCode = evaluateWordRecognizer(pReco, strTestLstFile); if(iErrorCode != SUCCESS) { cout << "Error during testing the word recognizer: " << getErrorMessage(iErrorCode) << endl; cout << "For more details, please see the log file" << endl; ptrObj->deleteWordRecognizer(&pReco); // Unload the DLL from memory utilPtr->unloadSharedLib(hLipiEngine); delete utilPtr; return -1; } if(bComputePerformance) { utilPtr->recordEndTime(); string timeTaken = ""; utilPtr->diffTime(timeTaken); cout << "Time taken:" << timeTaken << endl; } // Delete the word recognizer which was created... ptrObj->deleteWordRecognizer(&pReco); // Unload the DLL from memory utilPtr->unloadSharedLib(hLipiEngine); delete utilPtr; return 0; }
/********************************************************************************** * AUTHOR : Thanigai Murugan K * DATE : 30-AUG-2005 * NAME : processCommandLineArgs * DESCRIPTION : Processes all the command line arguments. Report an error if value is * missing for any command line option * ARGUMENTS : None * RETURNS : 0 on Success and -1 on Error * NOTES : * CHANGE HISTROY * Author Date Description of change *************************************************************************************/ int processCommandLineArgs() { bool bProfileAssumed = true; // Minimum MIN_ARGS arguments must... if(globalArgCount >= MIN_ARGS) { if(LTKSTRCMP(globalArg[1], OPTION_VERSION) == 0) { bVersionRequest = true; return 0; } } for(int i = 1; i < globalArgCount; i++) { if((LTKSTRCMP(globalArg[i], OPTION_HELP1) == 0) || (LTKSTRCMP(globalArg[i], OPTION_HELP2) == 0)) { return -1; } if(LTKSTRCMP(globalArg[i], OPTION_VERSION) == 0) { bVersionRequest = true; return 0; } if(LTKSTRCMP(globalArg[i], OPTION_NUMCHOICES) == 0) { if(getIntValue(i, &numChoices) != 0) { printf("\nInvalid or no value specified for -numchoices option.\n"); return -1; } else { i++; continue;} } if(LTKSTRCMP(globalArg[i], OPTION_TEST) == 0) { char tempVal[MAX_PATH], tempMode[124]; strcpy(tempMode, globalArg[i]); // Now get the list file name if(getStringValue(i, tempVal) != 0) { printf("\nMissing list file name for %s option.\n", globalArg[i]); return -1; } i++; if(LTKSTRCMP(tempMode, OPTION_TEST)==0) { strcpy(strTestLstFile, tempVal); } continue; } if(LTKSTRCMP(globalArg[i], OPTION_PERF) == 0) { if(globalArgCount <= MIN_ARGS) { printf("\n Option %s can only be combined with other options.\n", globalArg[i]); return -1; } else { bComputePerformance = true; continue;} } if(LTKSTRCMP(globalArg[i], OPTION_PROJECT) == 0) { if(getStringValue(i, strProjectName) != 0) { printf("\nInvalid or no value specified for -project option.\n"); return -1; } else { i++; continue;} } if(LTKSTRCMP(globalArg[i], OPTION_PROFILE) == 0) { if(getStringValue(i, strProfileName) != 0) { printf("\nInvalid or no value specified for -profile option.\n"); return -1; } else { i++; bProfileAssumed = false; continue;} } if(LTKSTRCMP(globalArg[i], OPTION_OUTPUT) == 0) { if(getStringValue(i, strOutputFileName) != 0) { printf("\nInvalid or no value specified for -output option.\n"); return -1; } else { i++; continue;} } if(LTKSTRCMP(globalArg[i], OPTION_LOGFILE) == 0) { if(getStringValue(i, strLogFile) != 0) { printf("\nInvalid or no value specified for -logfile option.\n"); return -1; } else { i++; continue;} } if(LTKSTRCMP(globalArg[i], LIPI_ROOT) == 0) { if(getStringValue(i, strLipiRootPath) != 0) { printf("\nInvalid or no value specified for -lipiroot option.\n"); return -1; } else { i++; continue;} } if(LTKSTRCMP(globalArg[i], OPTION_LOGLEVEL) == 0) { if(getStringValue(i, strLogLevel) != 0) { printf("\nInvalid or no value specified for -loglevel option.\n"); return -1; } else { i++; continue; } } printf("\nInvalid or Unknown option.\n"); return -1; } if(LTKSTRCMP(strProjectName, "") == 0) { printf("\nNo project name specified using -project.\n"); return -1; } if(ValidateCommandLineArgs() != 0) return -1; if(LTKSTRCMP(strProfileName, "") == 0) strcpy(strProfileName, DEFAULT_PROFILE); if(bProfileAssumed) printf("\n Profile not specified, assuming %s profile.\n", DEFAULT_PROFILE); return 0; }
/********************************************************************************** * AUTHOR : Vijayakumara M * DATE : 23 Aug 2005 * NAME : main * DESCRIPTION : Model Data viewer main function - Takes file name as its argument * and checks the integrity of the file and displays the options user * entered in the command prompt. * ARGUMENTS : int argc, char *argv[] ( file name and user desired options) * RETURNS : 0 on success and -1 on failure. * NOTES : * CHANGE HISTROY * Author Date Description of change ************************************************************************************/ int main(int argc, char* argv[]) { string m_strLipiRootPath = ""; string m_logFileName = DEFAULT_LOG_FILE; string m_logLevelStr = "ERROR"; LTKLogger::EDebugLevel m_logLevel = DEFAULT_LOG_LEVEL; int index = 1; int tmp = 0; int str = 0; int filteredArgc = argc; bool filFlag = false; // Flag to indicate the file name specified in the comman prompt. bool allFlag = false; // Flag to indicate all options to be displayed or not. bool helpFlag = false; bool preprocFlag = false; // Flag to indicate preproc fields to be displayed. stringStringMap headerSequence; // Get the maped header tokenized stings. stringStructMap optMap; // Gets the options and corresponding values. stringStructMap optPreProcMap; // Gets the Preprocessing options and corresponding values. string fileName; // Model Data file Name. string description; // Option description LTKCheckSumGenerate chFile; // instance of checkSum class for checking file integrity. //Display order char optIndex[][20]={"-PROJNAME","-NUMSHAPES","-RECNAME","-RECVER","-CHECKSUM","-CREATETIME","-MODTIME","-HEADERLEN","-DATAOFFSET","-HEADERVER","-BYTEORDER", "-FEATEXTR"}; if (argc == 1) { helpDisplay(); return SUCCESS; } // Get the argument passed through command prompt. while(index < argc) { // If argument is equal to "-a" or "-all" set allFlag for to display all the options. if(LTKSTRCMP(argv[index], OPTION_ALL) == 0) { allFlag = true; index++; continue; } //Preproc if(LTKSTRCMP(argv[index], OPTION_PREPROC) == 0) { preprocFlag = true; index++; continue; } if(LTKSTRCMP(argv[index], OPTION_HELP) == 0) { // Call helpDisplay function for displaying the help notice. helpDisplay(); return SUCCESS; } if(LTKSTRCMP(argv[index], OPTION_LIPI_ROOT) == 0) { if (index+1 >= argc) { cout << "Please specify LIPI_ROOT " << endl; return FAILURE; } m_strLipiRootPath = argv[index+1]; index++; } if(LTKSTRCMP(argv[index], OPTION_INPUT) == 0) { //set filFlag if the file Name is spcified if(index+1 < argc) { filFlag = true; fileName = argv[index+1]; index++; } } if(LTKSTRCMP(argv[index], OPTION_VER) == 0) { cout << CURRENT_VERSION << endl; return SUCCESS; } if(LTKSTRCMP(argv[index], OPTION_LOGFILE) == 0) { if (index+1 >= argc) { cout << "Please specify log file name " << endl; return FAILURE; } m_logFileName = argv[index+1]; filteredArgc = argc-2; index++; } if(LTKSTRCMP(argv[index], OPTION_LOGLEVEL) == 0) { if (index+1 >= argc) { cout << "Please specify log level " << endl; return FAILURE; } m_logLevelStr = argv[index+1]; int errorCode = mapLogLevel(m_logLevelStr, m_logLevel); if (errorCode != SUCCESS) { LTKReturnError(errorCode); } filteredArgc = argc-2; index++; } index++; } // If nothing specified except the file, display all if( (filteredArgc == 5 || filteredArgc == 3) && filFlag) { allFlag = true; } index = 1; if (m_strLipiRootPath.empty()) { char* envstring = NULL; envstring = getenv(LIPIROOT_ENV_STRING); if(envstring == NULL ) { cout << "Error, Environment variable is not set LIPI_ROOT" << endl; return FAILURE; } m_strLipiRootPath = envstring; envstring = NULL; } // Configure logger LTKLoggerUtil::createLogger(m_strLipiRootPath); LTKLoggerUtil::configureLogger(m_logFileName, m_logLevel); //if filFlag is set, display File name is not specified and display help if(filFlag == false) { cout <<endl<<endl<<"Model data file Name is not given " <<endl; cout <<"Please specify the file Name with \"-input\" option" << endl; cout << endl; //Display Help helpDisplay(); cout << endl; LTKLoggerUtil::destroyLogger(); return FAILURE; } // Check file integrity. If file has been altered then set the chflag. if((tmp = chFile.readMDTHeader(fileName, headerSequence)) != SUCCESS) { if( tmp == EMODEL_DATA_FILE_OPEN) { cout << "Unable to open model data file" << endl; LTKLoggerUtil::destroyLogger(); return FAILURE; } else if( tmp == EMODEL_DATA_FILE_FORMAT) { cout << "Incompatible model data file. The header is not in the desired format." << endl; LTKLoggerUtil::destroyLogger(); return FAILURE; } else if( tmp == EINVALID_INPUT_FORMAT) { cout << endl << "Model data file is corrupted" << endl; LTKLoggerUtil::destroyLogger(); return FAILURE; } } else { cout << endl << "Checksum successfully verified"<<endl<<endl; } if(preprocFlag) { // Map preprocessing options with their values. mapPreprocOptions(optPreProcMap, headerSequence); DisplayPreProc(optPreProcMap); LTKLoggerUtil::destroyLogger(); return 0; } // Map options with their values. mapOptions(optMap, headerSequence); // Iterator pointing at the begining of the option mapped address. map<string, option>::iterator the_begiter = optMap.begin(); if(allFlag) { str = 0; while (optIndex[str][0] != '\0') { if(!(optMap[optIndex[str]].description.empty())) cout << optMap[optIndex[str]].description << optMap[optIndex[str]].value << endl; str++; } // Map preprocessing options with their values. mapPreprocOptions(optPreProcMap, headerSequence); DisplayPreProc(optPreProcMap); if( !(headerSequence[PLATFORM].empty())) { cout << "Platform - " << headerSequence[PLATFORM] << endl; cout << " " << headerSequence[OSVERSION] << endl; cout << " " << headerSequence[PROCESSOR_ARCHITEC] << endl; } if( !(headerSequence[COMMENT].empty())) { cout << "Comment - " << headerSequence[COMMENT] << endl; cout << "Comment length - " << headerSequence[COMMENTLEN] << endl; } if( !(headerSequence[DATASET].empty())) { cout << "Dataset name - " << headerSequence[DATASET] << endl; } LTKLoggerUtil::destroyLogger(); return 0; } // Display the values if file is present and in the desired format while((index < argc)) { if( (LTKSTRCMP(argv[index], "-INPUT") == 0) || (LTKSTRCMP(fileName.c_str(), argv[index]) == 0) || (LTKSTRCMP(argv[index], "-LIPIROOT") == 0) || (LTKSTRCMP(m_strLipiRootPath.c_str(), argv[index]) == 0)) { ++index; continue; } if( (LTKSTRCMP(argv[index], "-DATASET") == 0) || (LTKSTRCMP(argv[index], "-COMMENT") == 0) || (LTKSTRCMP(argv[index], "-COMMENTLEN") == 0)) { ++index; continue; } if(LTKSTRCMP(argv[index], "-PLATFORM") == 0) { cout << "Platform - " << headerSequence[PLATFORM] << endl; cout << " " << headerSequence[OSVERSION] << endl; cout << " " << headerSequence[PROCESSOR_ARCHITEC] << endl; ++index; continue; } description = optMap[stringToUpper(argv[index])].description; if(description.empty()) cout << "UnKnown Option - "<< argv[index] << endl; else cout << optMap[argv[index]].description << optMap[argv[index]].value << endl; ++index; } LTKLoggerUtil::destroyLogger(); return SUCCESS; }