void FileManipulating::CreateHMMFile(System::String *exeFileDir, System::String *outputHmmDir, System::String *prototypeFile, System::String *trainFile) { try { System::String* batchFileName = outputHmmDir + "\\" +"_HInit.bat"; System::IO::StreamWriter* sw = new System::IO::StreamWriter(batchFileName); System::String* tempStr = ""; // building the associate command for the initialization tempStr += "\"" + exeFileDir + "HInit" + "\""; tempStr += " -m 1"; // required for training from single sample tempStr += " -M "; tempStr += "\"" + outputHmmDir + "\""; tempStr += " "; tempStr += "\"" + prototypeFile + "\""; tempStr += " "; tempStr += "\"" + trainFile + "\""; sw->Write(tempStr); sw->Close(); // create a process and execute System::Diagnostics::Process* p = new System::Diagnostics::Process(); p->StartInfo->FileName = batchFileName; p->Start(); p->WaitForExit(); } catch (System::Exception* excp) { // System::Windows::Forms::MessageBox::Show(excp->Message->ToString(),"Can't Create HMM Training File!!",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Error); exit(0); } }
void FileManipulating::RecognizeByHMM(System::String* recDir, System::String* execFile, System::String *mmfFile, System::String *mlfFile, System::String *wdNetFile, System::String *dictFile, System::String* hmmListFile, System::String *scriptFile) { try { System::String* batchFileName = recDir + "_HVite.bat"; System::IO::StreamWriter* sw = new System::IO::StreamWriter(batchFileName); System::String* tempStr = ""; // building the associate command for the initialization tempStr += "\"" + execFile + "HVite" + "\""; tempStr += " -H "; // required for training from single sample tempStr += "\"" + mmfFile + "\""; tempStr += " -i "; tempStr += "\"" + mlfFile + "\""; tempStr += " -w "; tempStr += "\"" + wdNetFile + "\""; tempStr += " "; tempStr += "\"" + dictFile + "\""; tempStr += " "; tempStr += "\"" + hmmListFile + "\""; tempStr += " -S "; tempStr += "\"" + scriptFile + "\""; sw->Write(tempStr); sw->Close(); // create a process and execute System::Diagnostics::Process* p = new System::Diagnostics::Process(); p->StartInfo->FileName = batchFileName; p->Start(); p->WaitForExit(); } catch (System::Exception* excp) { // Forms::MessageBox::Show(excp->Message->ToString(),"Can't Create/Execute Viterbi Decoder!!",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Error); exit(0); } }
void FileManipulating::BuildWordNetwork(System::String *gramFile, System::String *dictFile, System::String *transFile, System::String *wdnetFileDir, System::String* execpath, System::String* modelName) { System::IO::StreamWriter* sw = System::IO::StreamWriter::Null; try { // add model name to the grammer file System::String* text = ""; // check the existance of grammer file if(!System::IO::File::Exists(gramFile)) { sw = new System::IO::StreamWriter(gramFile); text = "$WORD = "+ modelName + ";" + "\n" + "([$WORD])"; sw->Write(text); sw->Close(); } else { // create streamreader System::IO::StreamReader* sr = new System::IO::StreamReader(gramFile); System::String* line; int k; // Read and display lines from the file until the end of // the file is reached. line=sr->ReadLine(); while (line->Length!=0) { k = line->IndexOf(";"); if(k < 0 ) { text += line+"\n"; } else { line = line->Substring(0,k); text += line + "|" + modelName + ";" + "\n"; } line=sr->ReadLine(); } sr->Close(); // write to the grammer file sw = new System::IO::StreamWriter(gramFile); sw->Write(text); sw->Close(); } // add model name to the dictionary file sw = System::IO::File::AppendText(dictFile); modelName = modelName + " [" + modelName + "] " + modelName; sw->WriteLine(modelName); sw->Close(); // add model name & associated transcription to the transcripton database file // build the world network /*1. Creating _HParse.bat*/ System::String* parseFile = wdnetFileDir + "_HParse.bat"; sw = new System::IO::StreamWriter(parseFile); text = "\"" + execpath + "HParse" + "\"" + " "; text += "\"" + gramFile + "\"" + " "; text += "\"" + wdnetFileDir + "net.slf" + "\""; sw->Write(text); sw->Close(); /*2. Creating _HSGen.bat*/ System::String* genFile = wdnetFileDir + "_HSGen.bat"; sw = new System::IO::StreamWriter(genFile); text = "\"" + execpath + "HSGen" + "\"" + " "; text += "\"" + wdnetFileDir + "net.slf" + "\"" + " "; text += "\"" + dictFile + "\""; sw->Write(text); sw->Close(); // create a process and execute the batch files System::Diagnostics::Process* p = new System::Diagnostics::Process(); // execute _HParse.bat p->StartInfo->FileName = parseFile; p->Start(); p->WaitForExit(); // execute _HSGen.bat p->StartInfo->FileName = genFile; p->Start(); p->WaitForExit(); } catch(System::Exception* ex) { //System::Windows::Forms::MessageBox::Show(ex->Message->ToString(),"Building Word Network Failed!!",System::Windows::Forms::MessageBoxButtons::OK,System::Windows::Forms::MessageBoxIcon::Error); exit(0); } }
//************************************************************************* // Method: Navigate // Description: Navigates to the specified URL in the specified frame // // Parameters: // url - the url to navigate to // targetFrame - the frame to use for displaying the page // // Return Value: None //************************************************************************* void HTMLBrowser::Navigate (String * url, String * targetFrame) { bool ieInstalled = true; try { Object * o = System::Reflection::Missing::Value; this->targetFrame = targetFrame; if ((File::Exists(url)) || (url->ToLower()->StartsWith(S"about:")) || (url->ToLower()->StartsWith(S"file:"))) { try { browser->Navigate(url, &o, &o, &o, &o); } catch (...) { } } else { String * externalStr = S"external*"; if (url->ToLower()->StartsWith(externalStr)) { // Request to make any link external, remove tag url = url->Substring(externalStr->Length); } String * iePath = 0; RegistryKey * iePathKey = Registry::LocalMachine->OpenSubKey(S"Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\iexplore.exe"); if (iePathKey != 0) iePath = dynamic_cast <String*> (iePathKey->GetValue(0)); System::Diagnostics::Process * p = new System::Diagnostics::Process(); if (iePath != 0) { p->StartInfo->FileName = iePath; p->StartInfo->WorkingDirectory = Path::GetDirectoryName(iePath); if (!File::Exists(iePath)) { ieInstalled = false; throw new Exception(); } } else { ieInstalled = false; p->StartInfo->FileName = "iexplore.exe"; } p->StartInfo->Arguments = url; p->StartInfo->ErrorDialog = true; p->StartInfo->UseShellExecute = false; p->Start(); } } catch(Exception *) { String * msg = String::Concat(S"Could not launch Internet Explorer to display this link.\nIf you have another browser installed, please navigate to the page ", url, S" in that browser."); // if we couldn't get the IE reg key, and got an exception, IE probably wasn't installed so tell the user if (!ieInstalled) UserNotification::ErrorNotify (msg); // else some other error happened, but don't do anything about it } }