srsf/sisrscontrollerplugin/src/sindetraining.h
branchRCL_3
changeset 23 e36f3802f733
parent 0 bf1d17376201
equal deleted inserted replaced
22:cad71a31b7fc 23:e36f3802f733
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Class which takes care of SINDE voice tag training.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef SINDETRAINING_H
       
    20 #define SINDETRAINING_H
       
    21 
       
    22 // ============================================================================
       
    23 // Uncomment the following directive for Bit Exact Testing.
       
    24 // ============================================================================
       
    25 //
       
    26  
       
    27 // INCLUDES
       
    28 #include "srsfbldvariant.hrh"
       
    29 #include "sicontrollerplugininterface.h"
       
    30 #include "sicontrollerplugin.h"
       
    31 #include <e32base.h>
       
    32 #include <bamdesca.h>
       
    33 #include <nsssispeechrecognitiondatacommon.h>
       
    34 #include <nssdevasr.h>
       
    35 
       
    36 // FORWARD DECLARATIONS
       
    37 
       
    38 
       
    39 // CLASS DECLARATION
       
    40 
       
    41 /**
       
    42 * Class which takes care of SIND with Extensions training.
       
    43 * Training is done in several batches to get optimal
       
    44 * number of pronunciations for each type of word.
       
    45 *
       
    46 * @lib nsssicontrollerplugin.lib
       
    47 * @since 3.1
       
    48 */
       
    49 class CSindeTrainer : public CActive
       
    50     {
       
    51     public: // Constructors and destructor
       
    52     
       
    53 	    /**
       
    54         * Two-phased constructor.
       
    55         * 
       
    56         * @param aDevAsr DevASR reference
       
    57         * @param aControllerIf Controller Interface to send callbacks to client
       
    58         * @param aPlugin Plugin reference
       
    59         * @param aDatabase SI Database
       
    60         * @param aGrammarDatabase Grammar Database
       
    61         * @param aLexiconDatabase Lexicon Database
       
    62 	    */
       
    63 	    static CSindeTrainer* NewL( CDevASR& aDevAsr, 
       
    64 	                                CSIControllerPluginInterface& aControllerIf,
       
    65 	                                CSIControllerPlugin& aPlugin,
       
    66 	                                CSIDatabase& aDatabase,
       
    67                                     CSIGrammarDB& aGrammarDatabase,
       
    68                                     CSILexiconDB& aLexiconDatabase );
       
    69 	
       
    70 	    /**
       
    71 	    * Destructor.
       
    72 	    */
       
    73 	    virtual ~CSindeTrainer();
       
    74 	    
       
    75 	public: // New functions
       
    76 	
       
    77 	    /**
       
    78 	    * Starts the process of SINDE voice tag addition.
       
    79 	    * Client thread is called is signalled directly when training completes.
       
    80 	    *
       
    81 	    * @param aTrainArrays Training texts
       
    82 	    * @param aLanguageArray Languages which are used when training
       
    83 	    * @param aLexiconId Lexicon ID where to add new pronunciations
       
    84 	    * @param aGrammarId Grammar ID where to add new rules
       
    85 	    * @param aModelBankId Model bank ID which is used in training process
       
    86 	    * @param aClientUid UID of the client which is doing the update (to verify ownership)
       
    87 	    * @param aRuleIds Output parameter, will contain the list IDs of the added rules
       
    88 	    */
       
    89 	    void AddSindeVoiceTagsL( RPointerArray<MDesCArray>* aTrainArrays,
       
    90 	                             RArray<RLanguageArray>& aLanguageArray, 
       
    91                                  TSILexiconID aLexiconId,
       
    92                                  TSIGrammarID aGrammarId,
       
    93                                  TSIModelBankID aModelBankId,
       
    94                                  TUid aClientUid,
       
    95                                  RArray<TSIRuleID>& aRuleIds );
       
    96                                  
       
    97                                  
       
    98         /**
       
    99         * Handles an event originating from DevASR.
       
   100         *
       
   101         * @param aEvent Event code
       
   102         * @param aError Error code
       
   103         */
       
   104         void HandleEvent( TDevASREvent aEvent, TDevASRError aError );
       
   105 	
       
   106 	protected: // From CActive
       
   107 	
       
   108         /**
       
   109         * RunL from CActive class.
       
   110         */
       
   111 		void RunL();
       
   112 		
       
   113         /**
       
   114         * Cancel handle from CActive class.
       
   115         */
       
   116 		void DoCancel();
       
   117 
       
   118 	private:
       
   119 
       
   120         /**
       
   121         * C++ default constructor.
       
   122         *
       
   123         * @param aDevAsr DevASR reference
       
   124         * @param aControllerIf Controller Interface to send callbacks to client
       
   125         * @param aPlugin Plugin reference
       
   126         * @param aDatabase SI Database
       
   127         * @param aGrammarDatabase Grammar Database
       
   128         * @param aLexiconDatabase Lexicon Database
       
   129         */
       
   130         CSindeTrainer( CDevASR& aDevAsr,
       
   131                        CSIControllerPluginInterface& aControllerIf,
       
   132                        CSIControllerPlugin& aPlugin,
       
   133                        CSIDatabase& aDatabase,
       
   134                        CSIGrammarDB& aGrammarDatabase,
       
   135                        CSILexiconDB& aLexiconDatabase );
       
   136 		
       
   137         /**
       
   138         * By default Symbian 2nd phase constructor is private.
       
   139         */
       
   140 		void ConstructL();
       
   141 		
       
   142 		/**
       
   143 		* Sets the active object as active and ready to run.
       
   144 		*/
       
   145 		void SetReady();
       
   146 		
       
   147 		/**
       
   148 		* Does one step of training.
       
   149 		*/
       
   150 		void DoOneTrainingStepL();
       
   151 		
       
   152 		/**
       
   153 		* Does the updates to lexicon and grammar database.
       
   154 		*/
       
   155 		void DoDatabaseUpdateL();
       
   156 
       
   157         /**
       
   158         * Does the grammar compilation using DevASR.
       
   159         */		
       
   160 		void DoGrammarCompilationL();
       
   161 		
       
   162 		/**
       
   163 		* Saves compiled grammar into database.
       
   164 		*/
       
   165 		void StoreCompiledGrammar();
       
   166 
       
   167 		/**
       
   168 		* Utility function to add pronunciations from other batches than first one
       
   169 		* to lexicon and grammar.
       
   170 		*
       
   171 		* @param aIndex Index within TTP word lists
       
   172 		* @param aLexicon Lexicon where additions are done
       
   173 		* @param aPronunIds Pronunciation id array where new ids are appended
       
   174 		*/
       
   175 		void AppendPronunciationsL( TInt aIndex, 
       
   176 		                            CSILexicon& aLexicon, 
       
   177 		                            RArray<TSIPronunciationID>& aPronunIds );
       
   178 
       
   179     private: // Data
       
   180     
       
   181         // States for this object
       
   182         enum TSindeTrainerState
       
   183             {
       
   184             ESindeTrainerIdle,
       
   185             ESindeTrainerTraining,
       
   186             ESindeTrainerDbUpdate,
       
   187             ESindeGrammarCompilation,
       
   188             ESindeTrainerFinished
       
   189             };
       
   190             
       
   191         // Current object state
       
   192         TSindeTrainerState iState;
       
   193         
       
   194         // Input for TTP via DevASR
       
   195         CSITtpWordList* iTtpWordList;
       
   196         
       
   197         // Position of language array processing
       
   198         TInt iLanguageIndex;
       
   199         
       
   200         // Position of text array processing
       
   201         TInt iTextIndex; 
       
   202 	
       
   203 	    // Stored parameters
       
   204     	RPointerArray<MDesCArray>* iTrainArrays;
       
   205     	RArray<RLanguageArray>* iLanguageArray;
       
   206     	RArray<TSIRuleID>* iRuleIds;
       
   207     	TSIGrammarID iGrammarId;
       
   208     	TSILexiconID iLexiconId;
       
   209     	TSIModelBankID iModelBankId;
       
   210         CSICompiledGrammar* iCompiledGrammar;
       
   211     	    	
       
   212     	// Reference to DevASR module
       
   213     	CDevASR& iDevAsr;
       
   214 	
       
   215     	RArray<TUint32> iMaxPronunsForWord;
       
   216     	
       
   217     	// Array which contains collected set of TTP data structures
       
   218     	RPointerArray<CSITtpWordList> iTtpDataArray;
       
   219 	    
       
   220 	    // Asynchronous processing result, will be sent within callback
       
   221 	    TInt iError;
       
   222 	    
       
   223 	    // To do callbacks to client side
       
   224 	    CSIControllerPluginInterface& iControllerIf;
       
   225 	    
       
   226 	    // Controller plugin
       
   227 	    CSIControllerPlugin& iPlugin;
       
   228 	    
       
   229 	    // Plugin database classes
       
   230 		CSIDatabase& iDatabase;
       
   231         CSIGrammarDB& iGrammarDatabase;
       
   232         CSILexiconDB& iLexiconDatabase;
       
   233         
       
   234         // UID of the client
       
   235         TUid iClientUid;        
       
   236     };
       
   237 	
       
   238 #endif // SINDETRAINING_H
       
   239 	
       
   240 // End of File