本文整理汇总了C++中CComPtr::AddRuleTransition方法的典型用法代码示例。如果您正苦于以下问题:C++ CComPtr::AddRuleTransition方法的具体用法?C++ CComPtr::AddRuleTransition怎么用?C++ CComPtr::AddRuleTransition使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CComPtr
的用法示例。
在下文中一共展示了CComPtr::AddRuleTransition方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setGrammarCustom
bool SpeechRecognizerModule::setGrammarCustom(CComPtr<ISpRecoGrammar> grammarToModify, string grammar, bool append)
{
//Clear the existing runtime grammar
SPSTATEHANDLE runtimeRootRule;
bool everythingIsFine = true;
everythingIsFine &= SUCCEEDED(grammarToModify->SetGrammarState(SPGS_DISABLED));
everythingIsFine &= SUCCEEDED(grammarToModify->GetRule(L"rootRule", NULL, SPRAF_TopLevel | SPRAF_Active, TRUE, &runtimeRootRule));
if(!append)
everythingIsFine &= SUCCEEDED(grammarToModify->ClearRule(runtimeRootRule));
//Build a rule for each vocabulory
map<string, SPSTATEHANDLE> vocabRules;
for(map<string, list<string> >::iterator vIt = m_vocabulories.begin(); vIt != m_vocabulories.end(); vIt++)
{
//Get the rule name from the key in the dictionary (i.e Agent, Action, etc...)
std::wstring tmp = s2ws(vIt->first);
LPCWSTR cwRuleName = tmp.c_str();
//Get the rule or create it
everythingIsFine &= SUCCEEDED(grammarToModify->GetRule(cwRuleName, NULL, SPRAF_Dynamic, TRUE, &vocabRules[vIt->first]));
everythingIsFine &= SUCCEEDED(grammarToModify->ClearRule(vocabRules[vIt->first]));
for(list<string>::iterator wordIt = vIt->second.begin() ; wordIt != vIt->second.end(); wordIt++)
{
std::wstring wordTmp = s2ws(*wordIt);
LPCWSTR cwWord = wordTmp.c_str();
everythingIsFine &= SUCCEEDED( grammarToModify->AddWordTransition(vocabRules[vIt->first], NULL, cwWord, NULL, SPWT_LEXICAL, 1, NULL) );
}
}
//Go through the given string and build the according grammar
//Split the choices
vector<string> sentences = split(grammar,'|');
for(vector<string>::iterator it = sentences.begin() ; it != sentences.end() ; it++)
{
//Split the words
vector<string> words = split(*it,' ');
SPSTATEHANDLE beforeWordHandle = runtimeRootRule;
SPSTATEHANDLE afterWordHandle;
for(vector<string>::iterator itWord = words.begin() ; itWord != words.end() ; itWord++)
{
if((*itWord)=="")
continue;
everythingIsFine &= SUCCEEDED(grammarToModify->CreateNewState(beforeWordHandle, &afterWordHandle));
//Check if the current word is the name of a vocabulory
if ( (*itWord)[0] == '#' && m_vocabulories.find(*itWord) != m_vocabulories.end())
{
everythingIsFine &= SUCCEEDED(grammarToModify->AddRuleTransition(beforeWordHandle, afterWordHandle, vocabRules[*itWord], 1, NULL));
}
else
{
std::wstring wordTmp = s2ws(*itWord);
LPCWSTR cwWord = wordTmp.c_str();
everythingIsFine &= SUCCEEDED( grammarToModify->AddWordTransition(beforeWordHandle, afterWordHandle, cwWord, NULL, SPWT_LEXICAL, 1, NULL) );
}
beforeWordHandle = afterWordHandle;
}
everythingIsFine &= SUCCEEDED( grammarToModify->AddWordTransition(beforeWordHandle, NULL, NULL, NULL, SPWT_LEXICAL, 1, NULL) );
}
everythingIsFine &= SUCCEEDED(grammarToModify->Commit(NULL));
everythingIsFine &= SUCCEEDED(grammarToModify->SetGrammarState(SPGS_ENABLED));
everythingIsFine &= SUCCEEDED(grammarToModify->SetRuleState(NULL, NULL, SPRS_ACTIVE));
everythingIsFine &= SUCCEEDED(m_cpRecoCtxt->Resume(0));
return everythingIsFine;
}