srsf/devasr/src/devasrvmalgorithmmanager.h
branchRCL_3
changeset 18 cad71a31b7fc
parent 17 8ce15fced3a6
child 19 e36f3802f733
equal deleted inserted replaced
17:8ce15fced3a6 18:cad71a31b7fc
     1 /*
       
     2 * Copyright (c) 2004 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:  Algorithm manager for grammar handling algorihtms.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef DEVASRVMALGORITHMMANAGER_H
       
    20 #define DEVASRVMALGORITHMMANAGER_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include <e32base.h>
       
    24 #include <nsssispeechrecognitiondatadevasr.h>
       
    25 #include <asrsgrcompilerhwdevice.h>
       
    26 #include <asrsvocmanhwdevice.h>
       
    27 #include <asrsttphwdevice.h>
       
    28 
       
    29 //#include "DevASRSrsAlgorithmManager.h"
       
    30 
       
    31 // DATA TYPES
       
    32 enum TTtpHwState
       
    33     {
       
    34     ETtpStateUninitialized = 0,
       
    35     ETtpStateIdle,
       
    36     ETtpStateBusy
       
    37     };
       
    38 
       
    39 enum TGrCompilerState
       
    40     {
       
    41     EGrStateUninitialized = 0,
       
    42     EGrStateIdle,
       
    43     EGrStateBusyCompiling,
       
    44     EGrStateBusyCombining
       
    45     };
       
    46 
       
    47 
       
    48 // FORWARD DECLARATIONS
       
    49 class MDevASRObserver;
       
    50 class MSDGrammarCompiler;
       
    51 //class CASRGrCompilerHwDevice;
       
    52 //class CASRSVocManHwDevice;
       
    53 //class CASRSTtpHwDevice;
       
    54 
       
    55 // CLASS DECLARATIONS
       
    56 
       
    57 /**
       
    58 * Observer mixin.
       
    59 *
       
    60 * @lib NssDevAsr.lib
       
    61 * @since 2.8
       
    62 */
       
    63 class MVmAlgMgrObserver
       
    64     {
       
    65     public:
       
    66         /**
       
    67         * Called when grammars have been combined.
       
    68         */
       
    69         virtual void CombineComplete( HBufC8* aResult, TInt aError ) = 0;
       
    70 
       
    71         /**
       
    72         * Called by CVMAlgorithmManager when it needs a grammar object.
       
    73         * 
       
    74         * @param "TSIGrammarID aGrammarID" Grammar identifier which is needed.
       
    75         * @param "CSICompiledGrammar** aSIActiveGrammar" Output parameter which will
       
    76         *        contain the grammar object pointer if grammar is currently active.
       
    77         * @param "CSICompiledGrammar** aSIDeActivatedGrammar" Output parameter which will
       
    78         *        contain the grammar object pointer if grammar is currently not active.
       
    79         */
       
    80         virtual void GetGrammarL( const TSIGrammarID aGrammarID, 
       
    81                                   CSICompiledGrammar** aSIActiveGrammar,
       
    82                                   CSICompiledGrammar** aSIDeActivatedGrammar ) = 0;
       
    83     };
       
    84 
       
    85 /**
       
    86 * Algorithm manager to handle VocMan, Ttp and Grammar Compiler
       
    87 *
       
    88 * @lib NssDevAsr.lib
       
    89 * @since 2.8
       
    90 */
       
    91 class CVMAlgorithmManager : public CBase, public MASRSTtpHwDeviceObserver, public MASRSGrCompilerHwDeviceObserver
       
    92     {
       
    93     public: // Constructors and destructor
       
    94         
       
    95         /**
       
    96         * Two-phased constructor.
       
    97         */
       
    98         static CVMAlgorithmManager* NewL( MDevASRObserver& aObserver, MVmAlgMgrObserver& aVmObserver );
       
    99         
       
   100         /**
       
   101         * Destructor.
       
   102         */
       
   103         virtual ~CVMAlgorithmManager();
       
   104         
       
   105     public: // New functions
       
   106         
       
   107 
       
   108         /**
       
   109         * Use to adapt rule after recognition.
       
   110         *
       
   111         * @since 2.8
       
   112         * @param "CSIResultSet& aResultSet" Result set.
       
   113         * @param "TInt aResultIndex" Index of correct result.
       
   114         */
       
   115         void AdaptVocabL( const CSIResultSet& aResultSet, 
       
   116                           TInt aResultIndex );
       
   117 
       
   118         /**
       
   119         * Cancels training.
       
   120         *
       
   121         * @since 2.8
       
   122         */
       
   123         void Cancel();
       
   124         
       
   125         /**
       
   126         * Computes number of rule variants for grammar.
       
   127         *
       
   128         * @since 2.8
       
   129         * @param "CSIGrammar& aGrammar" A grammar where to add new rules.
       
   130         * @param "TUint32 aTargetNRuleVariants" Preferable target number of 
       
   131         *        all rule variants after adding new rule variants
       
   132         * @param "TUint32 aMaxNRuleVariants" Maximum number of all rule variants.
       
   133         * @param "RArray<TUint>& aNewRuleScores" Scores for each new rule. The 
       
   134         *         size of array tells also how many	new rules will be added. 
       
   135         *         Based on the scores some rules can get more rule variants 
       
   136         *         than others. If there is no scores available, the array 
       
   137         *         should initialize with constant values.
       
   138         * @param "RArray<TUint>& aNNeNRuleVariants" Array where to add number 
       
   139         *         of new rule variants for new rules. The order is equivalent 
       
   140         *         to aNewRuleScores.
       
   141         * @param "TUint32& aNPrune" Number of rule variants which should be 
       
   142         *         pruned before adding new rule variants.
       
   143         */
       
   144         void ComputeNewGrammarSizeL( const CSIGrammar& aGrammar, 
       
   145                                      const TUint32 aTargetNRuleVariants, 
       
   146                                      const TUint32 aMaxNRuleVariants, 
       
   147                                      const RArray<TUint>& aNewRuleScores, 
       
   148                                      RArray<TUint>& aNNeNRuleVariants, 
       
   149                                      TUint32& aNPrune );
       
   150         
       
   151 
       
   152         /**
       
   153         * Compiles SI or SD grammar to internal format.
       
   154         *
       
   155         * @since 2.8
       
   156         * @param "aGrammar" Reference to grammar object.
       
   157         * @param "aModelBank" Reference to model bank.
       
   158         */
       
   159         void CompileGrammarL( CSICompiledGrammar& aGrammar );
       
   160 
       
   161         /**
       
   162         * Invoked when grammar combining is needed
       
   163         *
       
   164         * @since 2.8
       
   165         * @param "RPointerArray<CSICompiledGrammar>& aCompiledGrammars" 
       
   166         *        Array of previously compiled grammar
       
   167         * @param "const RPointerArray<TSIRuleVariantInfo>& aExcludedRules" 
       
   168         *        Rules to be blacklisted.
       
   169         */
       
   170         void CombineGrammarL( const RPointerArray<CSICompiledGrammar>& aCompiledGrammars,
       
   171                               const RPointerArray<TSIRuleVariantInfo>& aExcludedRules );
       
   172 
       
   173 
       
   174         /**
       
   175         * Determines which rule variants can be removed.
       
   176         *
       
   177         * @since 2.8
       
   178         * @param "CSIGrammar& aGrammar" A grammar to be pruned.
       
   179         * @param "TUint32 aMinNumber" Minimum number of pruned items
       
   180         * @param "RArray<TSIRuleVariantInfo> aPrunedRuleVariants" A array where 
       
   181         *         to put information which variants can be pruned.
       
   182         */
       
   183         TBool PruneGrammar( const CSIGrammar& aGrammar, 
       
   184                             const TUint32 aMinNumber, 
       
   185                             RArray<TSIRuleVariantInfo>& aPrunedRuleVariants );
       
   186         
       
   187         /**
       
   188         * Resolves result using Grammar Compiler.
       
   189         *
       
   190         * @since 2.8
       
   191         * @param "RArray<TUint>& aNBestIDs" List of N-best results
       
   192         * @param "
       
   193         */
       
   194         void ResolveResult( const RArray<TUint>& aNBestIDs,
       
   195                             CSIResultSet& aSIResultSet,
       
   196                             const RPointerArray<CSICompiledGrammar>& aSICompiledGrammar,
       
   197                             const TDesC8& aCombinedData );
       
   198 
       
   199         /**
       
   200         * Starts training from text.
       
   201         *
       
   202         * @since 2.8
       
   203         * @param "CSITtpWordList& aWordList" Text for training.
       
   204         * @param "RArray<TLanguage>& aDefaultLanguage" Default language for 
       
   205         *        pronunciations.
       
   206         * @param "RArray<TUint32>& aMaxNPronunsForWord" Maximum number of 
       
   207         *        pronunciation per word.
       
   208         */
       
   209         void TrainFromTextL( CSITtpWordList& aWordList, 
       
   210                              const RArray<TLanguage>& aDefaultLanguage, 
       
   211                              const RArray<TUint32>& aMaxNPronunsForWord );
       
   212 
       
   213 		/**
       
   214         * Retreive the properties of the engines.
       
   215         *
       
   216         * @since 2.0
       
   217         * @param "RArray<TInt>& aPropertyId" An array of identifiers being querried.
       
   218         * @param "RArray<TInt>& aPropertyValue" An array of values corresponding
       
   219         *        to the querried identifiers.
       
   220         */
       
   221         void GetEnginePropertiesL( const RArray<TInt>& aPropertyId, 
       
   222                                    RArray<TInt>& aPropertyValue );
       
   223 
       
   224         /**
       
   225         * Load the specified parameter(s) to the engines. 
       
   226         *
       
   227         * @param "RArray<TInt>& aParameterId" An array of parameter identifiers.
       
   228         * @param "RArray<TInt>& aParameterValue" An array of parameter values.
       
   229         */
       
   230         void LoadEnginePropertiesL( const RArray<TInt>& aParameterId,
       
   231                                     const RArray<TInt>& aParameterValue );
       
   232 
       
   233         
       
   234     public: // From MASRTtpHwDeviceObserver
       
   235         
       
   236         /**
       
   237         * Callback function to load configuration data.
       
   238         *
       
   239         * @param "TUint32 aPackageType" Type identifier.
       
   240         * @param "TUint32 aPackageID" Package identifier.
       
   241         * @param "TUint32 aStartPosition" First byte.
       
   242         * @param "TUint32 aEndPosition" Last byte. If greater than the size of 
       
   243         *                               the data, rest of the data is given.
       
   244         * @return Pointer to the data buffer, TTP HW Device takes ownership.
       
   245         */	
       
   246         HBufC8* MathdoConfigurationData( TUint32 aPackageType, TUint32 aPackageID,
       
   247                                          TUint32 aStartPosition = 0,
       
   248                                          TUint32 aEndPosition = KMaxTUint32 );
       
   249 
       
   250 		/**
       
   251         * Callback function to notify that word list is converted.
       
   252         *
       
   253         * @param "TInt aError" Error code, KErrNone if successful.
       
   254         */	
       
   255 		void MathdoWordListReady( const TInt aError );
       
   256 
       
   257     public: // From MASRSGrCompilerObserver
       
   258 
       
   259         /**
       
   260         * Grammar has been compiled.
       
   261         *
       
   262         * @param "TInt aError" An error code.
       
   263         */
       
   264         void MghdoGrammarCompilerComplete( TInt aError );
       
   265 
       
   266         /**
       
   267         * Grammars have been combined.
       
   268         *
       
   269         * @param "HBufC8* aResult" Contains the compiled grammar, NULL if error
       
   270         *         happened.
       
   271         * @param "TInt aError" KErrNone if successful.
       
   272         */
       
   273         void MghdoGrammarCombinerComplete( HBufC8* aResult, TInt aError );
       
   274 
       
   275         /**
       
   276         * Called when GrCompilerHwDevice needs an SI lexicon.
       
   277         *
       
   278         * @param "TSILexiconID anID" Requested lexicon id.
       
   279         * @return Pointer to created lexicon.
       
   280         */
       
   281         CSILexicon* MghdoSILexiconL( TSILexiconID anID );
       
   282 
       
   283         /**
       
   284         * Called when GrCompiler needs configuration data package
       
   285         */
       
   286         HBufC8* MghdoConfigurationData( TUint32 aPackageType,
       
   287                                         TUint32 aPackageID,
       
   288                                         TUint32 aStartPosition = 0,
       
   289                                         TUint32 aEndPosition = KMaxTUint32 );
       
   290              
       
   291     private:
       
   292         
       
   293 /*        void DeleteData( TPtrC8& aData );*/
       
   294         
       
   295         /**
       
   296         * C++ default constructor.
       
   297         */
       
   298         CVMAlgorithmManager( MDevASRObserver& aObserver, MVmAlgMgrObserver& aVmObserver );
       
   299         
       
   300         /**
       
   301         * By default Symbian 2nd phase constructor is private.
       
   302         */
       
   303         void ConstructL();
       
   304         
       
   305         // Prohibit copy constructor
       
   306         CVMAlgorithmManager( const CVMAlgorithmManager& );
       
   307         // Prohibit assigment operator
       
   308         CVMAlgorithmManager& operator=( const CVMAlgorithmManager& );
       
   309         
       
   310     private: // Data
       
   311         // Grammar compiler HW device
       
   312         CASRSGrCompilerHwDevice* iGrCompiler;
       
   313         
       
   314         // Vocabulary management HW device
       
   315         CASRSVocManHwDevice* iVocMan;
       
   316         
       
   317         // TTP HW device
       
   318         CASRSTtpHwDevice* iTtp;
       
   319         
       
   320         // Observer
       
   321         MDevASRObserver& iObserver;
       
   322         
       
   323         // Array for data pointers
       
   324 //        RPointerArray<HBufC8> iDataArray;
       
   325         
       
   326         // TtpHwDevice state
       
   327         TTtpHwState iTtpState;
       
   328 
       
   329         // GrCompilerHwDeviceState
       
   330         TGrCompilerState iGrState;
       
   331 
       
   332         // Our own observer
       
   333         MVmAlgMgrObserver& iVmAlgObserver;
       
   334        
       
   335     };
       
   336     
       
   337 #endif // DEVASRVMALGORITHMMANAGER_H
       
   338     
       
   339 // End of File