1/*---------------------------------------------------------------------------* 2 * rec_nbes.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#include <stdlib.h> 21#include <string.h> 22#ifndef _RTT 23#include <stdio.h> 24#endif 25 26#ifdef unix 27#include <unistd.h> 28#endif 29#include <assert.h> 30 31#include "simapi.h" 32#include "srec.h" 33#include "portable.h" 34 35#ifdef SET_RCSID 36static const char *rcsid = 0 ? (const char *) &rcsid : 37 "$Id: rec_nbes.c,v 1.6.6.7 2007/11/13 22:18:02 rabih_majzoub Exp $"; 38#endif 39 40 41CA_NBestList *CA_PrepareNBestList(CA_Recog *hRecog, int num, asr_int32_t *bestScore) 42{ 43 CA_NBestList *newList; 44 45 TRY_CA_EXCEPT 46 ASSERT(hRecog); 47 48 newList = (CA_NBestList*)srec_nbest_prepare_list(hRecog->recm, num, bestScore); 49 return newList; 50 51 BEG_CATCH_CA_EXCEPT 52 END_CATCH_CA_EXCEPT(hRecog) 53} 54 55 56void CA_DeleteNBestList(CA_NBestList *nbest) 57{ 58 if (nbest) 59 srec_nbest_destroy_list(nbest); 60 return; 61 62 BEG_CATCH_CA_EXCEPT 63 END_CATCH_CA_EXCEPT(nbest) 64} 65 66 67int CA_NBestListCount(CA_NBestList *nbest) 68{ 69 TRY_CA_EXCEPT 70 if (nbest) 71 return srec_nbest_get_num_choices(nbest); 72 else 73 return 0; 74 BEG_CATCH_CA_EXCEPT 75 END_CATCH_CA_EXCEPT(nbest) 76} 77 78int CA_NBestListGetResultConfidenceValue(CA_NBestList *nbest, size_t choice, int *value) 79{ 80 if (nbest) 81 { 82 *value =srec_nbest_get_confidence_value(nbest, choice); 83 return 1; 84 } 85 else 86 return 0; 87} 88 89int CA_NBestListRemoveResult(CA_NBestList *nbest, int index) 90{ 91 return srec_nbest_remove_result(nbest,index); 92} 93 94LCHAR* CA_NBestListGetResultWord(CA_NBestList* nbest, size_t iChoice) 95{ 96 return srec_nbest_get_word(nbest,iChoice); 97} 98 99ESR_ReturnCode CA_NBestListGetResultWordIDs(CA_NBestList* nbest, size_t index, wordID* wordIDs, size_t* len, asr_int32_t* cost) 100{ 101 if (!nbest) 102 { 103 PLogError(L("ESR_INVALID_ARGUMENT")); 104 return ESR_INVALID_ARGUMENT; 105 } 106 return srec_nbest_get_resultWordIDs(nbest, index, wordIDs, len, cost); 107} 108