Sapi动态语法加载

时间:2013-09-14 15:00:50

标签: c++ sapi

我有一个sapi语法

<rule id="root">
    <item repeat="0-">
       <ruleref uri="#digit"></ruleref>
     </item>
 </rule>

<rule id="digit">
<one-of>
      <item>1</item>
      <item>2</item>
      <item>3</item>
      <item>4</item>
      <item>5</item>
      <item>6</item>
      <item>7</item>
      <item>8</item>
      <item>9</item>
      <item>0</item>
  </one-of>
 </rule>

我想要相当于动态加载语法,任何人都可以帮忙吗?

我试过了

SPSTATEHANDLE hRule;
hr = cpGrammar->GetRule(L"digit", NULL, SPRAF_TopLevel | SPRAF_Active, TRUE,&hRule);
hr = cpGrammar->AddWordTransition(hRule, NULL, L"1", NULL, SPWT_LEXICAL, 1, NULL);
hr = cpGrammar->AddWordTransition(hRule, NULL, L"2", NULL, SPWT_LEXICAL, 1, NULL);
hr = cpGrammar->AddWordTransition(hRule, NULL, L"3", NULL, SPWT_LEXICAL, 1, NULL);
hr = cpGrammar->AddWordTransition(hRule, NULL, L"4", NULL, SPWT_LEXICAL, 1, NULL);
hr = cpGrammar->AddWordTransition(hRule, NULL, L"5", NULL, SPWT_LEXICAL, 1, NULL);
hr = cpGrammar->AddWordTransition(hRule, NULL, L"6", NULL, SPWT_LEXICAL, 1, NULL);
hr = cpGrammar->AddWordTransition(hRule, NULL, L"7", NULL, SPWT_LEXICAL, 1, NULL);
hr = cpGrammar->AddWordTransition(hRule, NULL, L"8", NULL, SPWT_LEXICAL, 1, NULL);
hr = cpGrammar->AddWordTransition(hRule, NULL, L"9", NULL, SPWT_LEXICAL, 1, NULL);
hr = cpGrammar->AddWordTransition(hRule, NULL, L"0", NULL, SPWT_LEXICAL, 1, NULL);
hr = cpGrammar->Commit(NULL);
hr = cpGrammar->SetGrammarState(SPGS_ENABLED);

它对我不起作用,我做对了吗?

1 个答案:

答案 0 :(得分:0)

查看了一些构建动态语法的代码,我确信您需要SPRAF_Dynamic以及SPRAF_TopLevel | SPRAF_Active。 (至少,我写的代码使用了它。)