33 * Licensed under the MIT License.
44 */
55
6- // import assert = require('assert');
6+ import assert = require( 'assert' ) ;
77
88import { } from 'mocha' ;
99
@@ -16,6 +16,8 @@ import {OrchestratorHelper} from '../src/orchestratorhelper';
1616
1717import { Utility } from '../src/utility' ;
1818import { LabelType , Utility as UtilityDispatcher } from '@microsoft/bf-dispatcher' ;
19+ import { Example } from '@microsoft/bf-dispatcher' ;
20+
1921import { UnitTestHelper } from './utility.test' ;
2022
2123describe ( 'Test Suite - LabelResolver' , ( ) => {
@@ -27,40 +29,131 @@ describe('Test Suite - LabelResolver', () => {
2729 Utility . resetFlagToPrintDebuggingLogToConsole ( UnitTestHelper . getDefaultUnitTestDebuggingLogFlag ( ) ) ;
2830 this . timeout ( UnitTestHelper . getDefaultFunctionalTestTimeout ( ) ) ;
2931 const baseModelPath : string = path . resolve ( './resources/model/model_dte_bert_3l' ) ;
30- Utility . debuggingLog ( 'Test.0000 LabelResolver.scoreBatch()-Bert-3-layer : downloading a base nerual network language model for unit test' ) ;
32+ Utility . debuggingLog ( 'Test.0000 LabelResolver.scoreBatch(): downloading a base nerual network language model for unit test' ) ;
3133 await UnitTestHelper . downloadModelFileForTest (
3234 baseModelPath ,
3335 OrchestratorBaseModel . defaultHandler ,
3436 OrchestratorBaseModel . defaultHandler ) ;
3537 const modelConfig : string = Utility . loadFile ( path . resolve ( baseModelPath , 'config.json' ) ) ;
36- Utility . debuggingLog ( `Test.0000 LabelResolver.scoreBatch()-Bert-3-layer : modelConfig=${ modelConfig } ` ) ;
37- Utility . debuggingLog ( `Test.0000 LabelResolver.scoreBatch()-Bert-3-layer : process.cwd()=${ process . cwd ( ) } ` ) ;
38+ Utility . debuggingLog ( `Test.0000 LabelResolver.scoreBatch(): modelConfig=${ modelConfig } ` ) ;
39+ Utility . debuggingLog ( `Test.0000 LabelResolver.scoreBatch(): process.cwd()=${ process . cwd ( ) } ` ) ;
3840 const inputPath : string = './resources/data/Columnar/Email_bert.blu' ;
3941 // -----------------------------------------------------------------------
4042 // ---- NOTE ---- create a LabelResolver object and load the snapshot set.
41- Utility . debuggingLog ( 'LabelResolver.scoreBatch(), ready to call LabelResolver.createAsync()' ) ;
43+ Utility . debuggingLog ( 'Test.0000 LabelResolver.scoreBatch(), ready to call LabelResolver.createAsync()' ) ;
4244 await LabelResolver . createAsync ( baseModelPath , '' ) ;
43- Utility . debuggingLog ( 'LabelResolver.scoreBatch(), after calling LabelResolver.createAsync()' ) ;
45+ Utility . debuggingLog ( 'Test.0000 LabelResolver.scoreBatch(), after calling LabelResolver.createAsync()' ) ;
4446 // Utility.debuggingLog('LabelResolver.scoreBatch(), ready to call UtilityLabelResolver.resetLabelResolverSettingUseCompactEmbeddings()');
4547 // UtilityLabelResolver.resetLabelResolverSettingUseCompactEmbeddings(fullEmbeddings);
4648 // Utility.debuggingLog('LabelResolver.scoreBatch(), after calling UtilityLabelResolver.resetLabelResolverSettingUseCompactEmbeddings()');
47- Utility . debuggingLog ( 'LabelResolver.scoreBatch(), ready to call OrchestratorHelper.getSnapshotFromFile()' ) ;
49+ Utility . debuggingLog ( 'Test.0000 LabelResolver.scoreBatch(), ready to call OrchestratorHelper.getSnapshotFromFile()' ) ;
4850 const snapshot : Uint8Array = OrchestratorHelper . getSnapshotFromFile ( inputPath ) ;
49- Utility . debuggingLog ( `LabelResolver.scoreBatch(): typeof(snapshot)=${ typeof snapshot } ` ) ;
50- Utility . debuggingLog ( `LabelResolver.scoreBatch(): snapshot.byteLength=${ snapshot . byteLength } ` ) ;
51- Utility . debuggingLog ( 'LabelResolver.scoreBatch(), after calling OrchestratorHelper.getSnapshotFromFile()' ) ;
52- Utility . debuggingLog ( 'LabelResolver.scoreBatch(), ready to call LabelResolver.addSnapshot()' ) ;
51+ Utility . debuggingLog ( `Test.0000 LabelResolver.scoreBatch(): typeof(snapshot)=${ typeof snapshot } ` ) ;
52+ Utility . debuggingLog ( `Test.0000 LabelResolver.scoreBatch(): snapshot.byteLength=${ snapshot . byteLength } ` ) ;
53+ Utility . debuggingLog ( 'Test.0000 LabelResolver.scoreBatch(), after calling OrchestratorHelper.getSnapshotFromFile()' ) ;
54+ Utility . debuggingLog ( 'Test.0000 LabelResolver.scoreBatch(), ready to call LabelResolver.addSnapshot()' ) ;
5355 await LabelResolver . addSnapshot ( snapshot ) ;
54- Utility . debuggingLog ( 'LabelResolver.scoreBatch(), after calling LabelResolver.addSnapshot()' ) ;
56+ Utility . debuggingLog ( 'Test.0000 LabelResolver.scoreBatch(), after calling LabelResolver.addSnapshot()' ) ;
5557 // -----------------------------------------------------------------------
5658 const utterances : string [ ] = [
5759 'add a flag to it' ,
5860 'add some more info' ,
5961 ] ;
6062 // -----------------------------------------------------------------------
6163 const results : any = LabelResolver . scoreBatch ( utterances , LabelType . Intent ) ;
62- UtilityDispatcher . debuggingNamedLog1 ( 'LabelResolver.scoreBatch(utterances, LabelType.Intent)' , results , 'results' ) ;
64+ UtilityDispatcher . debuggingNamedLog1 ( 'Test.0000 LabelResolver.scoreBatch(utterances, LabelType.Intent)' , results , 'results' ) ;
65+ // -----------------------------------------------------------------------
66+ UtilityDispatcher . debuggingLog ( 'THE END - Test.0000 LabelResolver.scoreBatch()' ) ;
67+ } ) ;
68+
69+ it ( 'Test.0001 LabelResolver.addExample()' , async function ( ) : Promise < void > {
70+ const ignore : boolean = UnitTestHelper . getIgnoreFlag ( ) ;
71+ if ( ignore ) {
72+ return ;
73+ }
74+ Utility . resetFlagToPrintDebuggingLogToConsole ( UnitTestHelper . getDefaultUnitTestDebuggingLogFlag ( ) ) ;
75+ this . timeout ( UnitTestHelper . getDefaultFunctionalTestTimeout ( ) ) ;
76+ const baseModelPath : string = path . resolve ( './resources/model/model_dte_bert_3l' ) ;
77+ Utility . debuggingLog ( 'Test.0001 LabelResolver.addExample(): downloading a base nerual network language model for unit test' ) ;
78+ await UnitTestHelper . downloadModelFileForTest (
79+ baseModelPath ,
80+ OrchestratorBaseModel . defaultHandler ,
81+ OrchestratorBaseModel . defaultHandler ,
82+ 'pretrained.20200924.microsoft.dte.00.06.en.onnx' ) ;
83+ const modelConfig : string = Utility . loadFile ( path . resolve ( baseModelPath , 'config.json' ) ) ;
84+ Utility . debuggingLog ( `Test.0001 LabelResolver.addExample(): modelConfig=${ modelConfig } ` ) ;
85+ Utility . debuggingLog ( `Test.0001 LabelResolver.addExample(): process.cwd()=${ process . cwd ( ) } ` ) ;
86+ // -----------------------------------------------------------------------
87+ // ---- NOTE ---- create a LabelResolver object and load the snapshot set.
88+ Utility . debuggingLog ( 'Test.0001 LabelResolver.addExample(), ready to call LabelResolver.createAsync()' ) ;
89+ await LabelResolver . createAsync ( baseModelPath , '' ) ;
90+ Utility . debuggingLog ( 'Test.0001 LabelResolver.addExample(), after calling LabelResolver.createAsync()' ) ;
91+ // Utility.debuggingLog('LabelResolver.addExample(), ready to call UtilityLabelResolver.resetLabelResolverSettingUseCompactEmbeddings()');
92+ // UtilityLabelResolver.resetLabelResolverSettingUseCompactEmbeddings(fullEmbeddings);
93+ // Utility.debuggingLog('LabelResolver.addExample(), after calling UtilityLabelResolver.resetLabelResolverSettingUseCompactEmbeddings()');
94+ const example : Example = Example . newIntentExample (
95+ 'where is the news on agility' ,
96+ [ 'Keyword' ] ) ;
97+ const exampleObject : any = example . toAlternateObject ( ) ;
98+ Utility . debuggingLog ( `Test.0001 LabelResolver.addExample(): exampleObject=${ Utility . jsonStringify ( exampleObject ) } ` ) ;
99+ const rvAddExample : any = LabelResolver . addExample ( exampleObject ) ;
100+ Utility . debuggingLog ( `Test.0001 LabelResolver.addExample(): rv=${ rvAddExample } ` ) ;
101+ const snapshot : any = LabelResolver . createSnapshot ( ) ;
102+ Utility . debuggingLog ( `Test.0001 LabelResolver.addExample(): snapshot=${ snapshot } ` ) ;
103+ Utility . debuggingLog ( `Test.0001 LabelResolver.addExample(): snapshot.byteLength=${ snapshot . byteLength } ` ) ;
104+ const snapshotInString : string = new TextDecoder ( ) . decode ( snapshot ) ;
105+ Utility . debuggingLog ( `Test.0001 LabelResolver.addExample(): snapshotInString=${ snapshotInString } ` ) ;
106+ // -----------------------------------------------------------------------
107+ UtilityDispatcher . debuggingLog ( 'THE END - Test.0001 LabelResolver.addExample()' ) ;
108+ } ) ;
109+
110+ it ( 'Test.0002 LabelResolver.removeExample()' , async function ( ) : Promise < void > {
111+ const ignore : boolean = UnitTestHelper . getIgnoreFlag ( ) ;
112+ if ( ignore ) {
113+ return ;
114+ }
115+ Utility . resetFlagToPrintDebuggingLogToConsole ( UnitTestHelper . getDefaultUnitTestDebuggingLogFlag ( ) ) ;
116+ this . timeout ( UnitTestHelper . getDefaultFunctionalTestTimeout ( ) ) ;
117+ const baseModelPath : string = path . resolve ( './resources/model/model_dte_bert_3l' ) ;
118+ Utility . debuggingLog ( 'Test.0002 LabelResolver.addExample(): downloading a base nerual network language model for unit test' ) ;
119+ await UnitTestHelper . downloadModelFileForTest (
120+ baseModelPath ,
121+ OrchestratorBaseModel . defaultHandler ,
122+ OrchestratorBaseModel . defaultHandler ,
123+ 'pretrained.20200924.microsoft.dte.00.06.en.onnx' ) ;
124+ const modelConfig : string = Utility . loadFile ( path . resolve ( baseModelPath , 'config.json' ) ) ;
125+ Utility . debuggingLog ( `Test.0002 LabelResolver.addExample(): modelConfig=${ modelConfig } ` ) ;
126+ Utility . debuggingLog ( `Test.0002 LabelResolver.addExample(): process.cwd()=${ process . cwd ( ) } ` ) ;
127+ // -----------------------------------------------------------------------
128+ // ---- NOTE ---- create a LabelResolver object and load the snapshot set.
129+ Utility . debuggingLog ( 'Test.0002 LabelResolver.addExample(), ready to call LabelResolver.createAsync()' ) ;
130+ await LabelResolver . createAsync ( baseModelPath , '' ) ;
131+ Utility . debuggingLog ( 'Test.0002 LabelResolver.addExample(), after calling LabelResolver.createAsync()' ) ;
132+ // Utility.debuggingLog('LabelResolver.addExample(), ready to call UtilityLabelResolver.resetLabelResolverSettingUseCompactEmbeddings()');
133+ // UtilityLabelResolver.resetLabelResolverSettingUseCompactEmbeddings(fullEmbeddings);
134+ // Utility.debuggingLog('LabelResolver.addExample(), after calling UtilityLabelResolver.resetLabelResolverSettingUseCompactEmbeddings()');
135+ const example : Example = Example . newIntentExample (
136+ 'where is the news on agility' ,
137+ [ 'Keyword' ] ) ;
138+ const exampleObject : any = example . toAlternateObject ( ) ;
139+ Utility . debuggingLog ( `Test.0002 LabelResolver.addExample(): exampleObject=${ Utility . jsonStringify ( exampleObject ) } ` ) ;
140+ const rvAddExample : any = LabelResolver . addExample ( exampleObject ) ;
141+ Utility . debuggingLog ( `Test.0002 LabelResolver.addExample(): rv=${ rvAddExample } ` ) ;
142+ const snapshot : any = LabelResolver . createSnapshot ( ) ;
143+ Utility . debuggingLog ( `Test.0002 LabelResolver.addExample(): snapshot=${ snapshot } ` ) ;
144+ Utility . debuggingLog ( `Test.0002 LabelResolver.addExample(): snapshot.byteLength=${ snapshot . byteLength } ` ) ;
145+ const snapshotInString : string = new TextDecoder ( ) . decode ( snapshot ) ;
146+ Utility . debuggingLog ( `Test.0002 LabelResolver.addExample(): snapshotInString=${ snapshotInString } ` ) ;
147+ // -----------------------------------------------------------------------
148+ const examples : any = LabelResolver . getExamples ( ) ;
149+ assert . strictEqual ( examples . length , 1 ) ;
150+ // -----------------------------------------------------------------------
151+ const rvRemoveExample : any = LabelResolver . removeExample ( exampleObject ) ;
152+ Utility . debuggingLog ( `Test.0002 LabelResolver.removeExample(): rv=${ rvRemoveExample } ` ) ;
153+ // -----------------------------------------------------------------------
154+ const examplesAfterRemoveExample : any = LabelResolver . getExamples ( ) ;
155+ assert . strictEqual ( examplesAfterRemoveExample . length , 0 ) ;
63156 // -----------------------------------------------------------------------
64- UtilityDispatcher . debuggingLog ( 'THE END - Test.0000 LabelResolver.runAsync ()' ) ;
157+ UtilityDispatcher . debuggingLog ( 'THE END - Test.0002 LabelResolver.addExample ()' ) ;
65158 } ) ;
66159} ) ;
0 commit comments