Share via


Note

Please see Azure Cognitive Services for Speech documentation for the latest supported speech solutions.

Microsoft Speech Platform

ISpGrammarBuilder::ClearRule

ISpGrammarBuilder::ClearRule removes all of the grammar rule information except for the rule's initial state handle.

<pre IsFakePre="true" xmlns="http://www.w3.org/1999/xhtml"> <strong>HRESULT ClearRule(</strong> <strong> SPSTATEHANDLE</strong> <em>hState</em> <strong>);</strong> </pre>

Parameters

  • hState
    [in] Handle to the any of the states in the grammar rule to be cleared. Only the rule's initial state handle is still valid.

Return Values

Value Description
S_OK Function completed successfully.
E_INVALIDARG Value specified in hState is not valid.

Example

The following code snippet illustrates the use of ClearRule.

`

// Declare local identifiers:
HRESULT                       hr = S_OK;
CComPtr<ISpGrammarBuilder>    cpGrammarBuilder;
SPSTATEHANDLE                 hInit;
SPSTATEHANDLE                 hState;

hr = cpGrammarBuilder->GetRule(L"rule1", 1, 0, TRUE, &hInit;);

if (SUCCEEDED (hr)) { hr = cpGrammarBuilder->CreateNewState(hInit, &hState;); }

if (SUCCEEDED (hr)) { hr = cpGrammarBuilder->AddWordTransition(hInit, hState, L"word", NULL, SPWT_LEXICAL, 1, NULL); }

if (SUCCEEDED (hr)) { // Call ClearRule using initial state. hr = cpGrammarBuilder->ClearRule(hInit); }

if (SUCCEEDED (hr)) { hr = cpGrammarBuilder->AddWordTransition(hInit, hState, L"word", NULL, SPWT_LEXICAL, 1, NULL); }

if (FAILED (hr)) {} { // Because hState is no longer valid. _ASSERT(hr == E_INVALIDARG);

// Call ClearRule using hState != hInit. hr = cpGrammarBuilder->CreateNewState(hInit, &hState;); }

if (SUCCEEDED (hr)) { hr = cpGrammarBuilder->AddWordTransition(hInit, hState, L"word", NULL, SPWT_LEXICAL, 1, NULL); }

if (SUCCEEDED (hr)) { hr = cpGrammarBuilder->ClearRule(hState); }

if (SUCCEEDED (hr)) { hr = cpGrammarBuilder->AddWordTransition(hInit, hState, L"word", NULL, SPWT_LEXICAL, 1, NULL); }

if (FAILED (hr)) { // Because hState is no longer valid. _ASSERT(hr == E_INVALIDARG); }

`