Home | History | Annotate | Download | only in src
      1 /*---------------------------------------------------------------------------*
      2  *  SR_Grammar.c  *
      3  *                                                                           *
      4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
      5  *                                                                           *
      6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
      7  *  you may not use this file except in compliance with the License.         *
      8  *                                                                           *
      9  *  You may obtain a copy of the License at                                  *
     10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
     11  *                                                                           *
     12  *  Unless required by applicable law or agreed to in writing, software      *
     13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
     14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
     15  *  See the License for the specific language governing permissions and      *
     16  *  limitations under the License.                                           *
     17  *                                                                           *
     18  *---------------------------------------------------------------------------*/
     19 
     20 
     21 
     22 #include "SR_Grammar.h"
     23 #include "SR_GrammarImpl.h"
     24 #include "plog.h"
     25 #include "pmemory.h"
     26 
     27 
     28 ESR_ReturnCode SR_GrammarCompile(SR_Grammar* self)
     29 {
     30   if (self == NULL)
     31   {
     32     PLogError(L("ESR_INVALID_ARGUMENT"));
     33     return ESR_INVALID_ARGUMENT;
     34   }
     35   return self->compile(self);
     36 }
     37 
     38 ESR_ReturnCode SR_GrammarAddWordToSlot(SR_Grammar* self, const LCHAR* slot, const LCHAR* word,
     39 				        const LCHAR* pronunciation, int weight, const LCHAR* tag)
     40     {
     41 
     42     if ( self == NULL )
     43         {
     44         PLogError(L("ESR_INVALID_ARGUMENT : Grammar Is Null"));
     45         return ESR_INVALID_ARGUMENT;
     46         }
     47     return self->addWordToSlot(self, slot, word, pronunciation, weight, tag);
     48     }
     49 
     50 
     51 ESR_ReturnCode SR_GrammarResetAllSlots(SR_Grammar* self)
     52 {
     53   if (self == NULL)
     54   {
     55     PLogError(L("ESR_INVALID_ARGUMENT"));
     56     return ESR_INVALID_ARGUMENT;
     57   }
     58   return self->resetAllSlots(self);
     59 }
     60 
     61 ESR_ReturnCode SR_GrammarAddNametagToSlot(SR_Grammar* self, const LCHAR* slot,
     62                                           const SR_Nametag* nametag,  int weight, const LCHAR* tag)
     63 {
     64   if (self == NULL)
     65   {
     66     PLogError(L("ESR_INVALID_ARGUMENT"));
     67     return ESR_INVALID_ARGUMENT;
     68   }
     69   return self->addNametagToSlot(self, slot, nametag, weight, tag);
     70 }
     71 
     72 ESR_ReturnCode SR_GrammarSetDispatchFunction(SR_Grammar* self, const LCHAR* name, void* userData, SR_GrammarDispatchFunction function)
     73 {
     74   if (self == NULL)
     75   {
     76     PLogError(L("ESR_INVALID_ARGUMENT"));
     77     return ESR_INVALID_ARGUMENT;
     78   }
     79   return self->setDispatchFunction(self, name, userData, function);
     80 }
     81 
     82 ESR_ReturnCode SR_GrammarSave(SR_Grammar* self, const LCHAR* filename)
     83 {
     84   if (self == NULL)
     85   {
     86     PLogError(L("ESR_INVALID_ARGUMENT"));
     87     return ESR_INVALID_ARGUMENT;
     88   }
     89   return self->save(self, filename);
     90 }
     91 
     92 ESR_ReturnCode SR_GrammarSetParameter(SR_Grammar* self, const LCHAR* key, void* value)
     93 {
     94   if (self == NULL)
     95   {
     96     PLogError(L("ESR_INVALID_ARGUMENT"));
     97     return ESR_INVALID_ARGUMENT;
     98   }
     99   return self->setParameter(self, key, value);
    100 }
    101 
    102 ESR_ReturnCode SR_GrammarSetSize_tParameter(SR_Grammar* self, const LCHAR* key, size_t value)
    103 {
    104   if (self == NULL)
    105   {
    106     PLogError(L("ESR_INVALID_ARGUMENT"));
    107     return ESR_INVALID_ARGUMENT;
    108   }
    109   return self->setSize_tParameter(self, key, value);
    110 }
    111 
    112 ESR_ReturnCode SR_GrammarGetParameter(SR_Grammar* self, const LCHAR* key, void** value)
    113 {
    114   if (self == NULL)
    115   {
    116     PLogError(L("ESR_INVALID_ARGUMENT"));
    117     return ESR_INVALID_ARGUMENT;
    118   }
    119   return self->getParameter(self, key, value);
    120 }
    121 
    122 ESR_ReturnCode SR_GrammarGetSize_tParameter(SR_Grammar* self, const LCHAR* key, size_t* value)
    123 {
    124   if (self == NULL)
    125   {
    126     PLogError(L("ESR_INVALID_ARGUMENT"));
    127     return ESR_INVALID_ARGUMENT;
    128   }
    129   return self->getSize_tParameter(self, key, value);
    130 }
    131 
    132 // ESR_ReturnCode SR_GrammarSetupModels(SR_Grammar* self, SR_AcousticModels* models)
    133 ESR_ReturnCode SR_GrammarSetupRecognizer(SR_Grammar* self, struct SR_Recognizer_t* recognizer)
    134 {
    135   if (self == NULL)
    136   {
    137     PLogError(L("ESR_INVALID_ARGUMENT"));
    138     return ESR_INVALID_ARGUMENT;
    139   }
    140   // retgurn self->setupModels( self, models);
    141   return self->setupRecognizer(self, recognizer);
    142 }
    143 ESR_ReturnCode SR_GrammarUnsetupRecognizer(SR_Grammar* self)
    144 {
    145   if (self == NULL)
    146   {
    147     PLogError(L("ESR_INVALID_ARGUMENT"));
    148     return ESR_INVALID_ARGUMENT;
    149   }
    150   return self->unsetupRecognizer(self);
    151 }
    152 
    153 ESR_ReturnCode SR_GrammarSetupVocabulary(SR_Grammar *self, SR_Vocabulary *vocabulary)
    154 {
    155   if (self == NULL)
    156   {
    157     PLogError(L("ESR_INVALID_ARGUMENT"));
    158     return ESR_INVALID_ARGUMENT;
    159   }
    160   return self->setupVocabulary(self, vocabulary);
    161 }
    162 
    163 /* ESR_ReturnCode SR_GrammarGetModels(SR_Grammar* self, SR_AcousticModels** models)
    164 {
    165   if (self == NULL)
    166   {
    167     PLogError(L("ESR_INVALID_ARGUMENT"));
    168     return ESR_INVALID_ARGUMENT;
    169   }
    170   return self->getModels(self, models);
    171 }
    172 */
    173 ESR_ReturnCode SR_GrammarCheckParse(SR_Grammar* self, const LCHAR* transcription, SR_SemanticResult** result_void, size_t* resultCount)
    174 {
    175   SR_SemanticResult** result = (SR_SemanticResult**)result_void;
    176   if (self == NULL)
    177   {
    178     PLogError(L("ESR_INVALID_ARGUMENT"));
    179     return ESR_INVALID_ARGUMENT;
    180   }
    181   return self->checkParse(self, transcription, result, resultCount);
    182 }
    183 
    184 ESR_ReturnCode SR_GrammarDestroy(SR_Grammar* self)
    185 {
    186   if (self == NULL)
    187   {
    188     PLogError(L("ESR_INVALID_ARGUMENT"));
    189     return ESR_INVALID_ARGUMENT;
    190   }
    191   return self->destroy(self);
    192 }
    193