@@ -95,6 +95,17 @@ export interface IChronoDuration extends IEntity {
95
95
96
96
export class SimplePromptRecognizer implements IPromptRecognizer {
97
97
public recognize ( args : IPromptRecognizerArgs , callback : ( result : IPromptResult < any > ) => void , session ?: ISession ) : void {
98
+ function findChoice ( args : IPromptRecognizerArgs , text : string ) {
99
+ var best = entities . EntityRecognizer . findBestMatch ( args . enumValues , text ) ;
100
+ if ( ! best ) {
101
+ var n = entities . EntityRecognizer . parseNumber ( text ) ;
102
+ if ( ! isNaN ( n ) && n > 0 && n <= args . enumValues . length ) {
103
+ best = { index : n - 1 , entity : args . enumValues [ n - 1 ] , score : 1.0 } ;
104
+ }
105
+ }
106
+ return best ;
107
+ }
108
+
98
109
// Recognize value
99
110
var score = 0.0 ;
100
111
var response : any ;
@@ -119,11 +130,10 @@ export class SimplePromptRecognizer implements IPromptRecognizer {
119
130
case PromptType . confirm :
120
131
var b = entities . EntityRecognizer . parseBoolean ( text ) ;
121
132
if ( typeof b !== 'boolean' ) {
122
- var n = entities . EntityRecognizer . parseNumber ( text ) ;
123
- if ( ! isNaN ( n ) && n > 0 && n <= 2 ) {
124
- b = ( n === 1 ) ;
133
+ var best = findChoice ( args , text ) ;
134
+ if ( best ) {
135
+ b = ( best . index === 0 ) ; // enumValues == ['yes', 'no']
125
136
}
126
-
127
137
}
128
138
if ( typeof b == 'boolean' ) {
129
139
score = 1.0 ;
@@ -138,13 +148,7 @@ export class SimplePromptRecognizer implements IPromptRecognizer {
138
148
}
139
149
break ;
140
150
case PromptType . choice :
141
- var best = entities . EntityRecognizer . findBestMatch ( args . enumValues , text ) ;
142
- if ( ! best ) {
143
- var n = entities . EntityRecognizer . parseNumber ( text ) ;
144
- if ( ! isNaN ( n ) && n > 0 && n <= args . enumValues . length ) {
145
- best = { index : n - 1 , entity : args . enumValues [ n - 1 ] , score : 1.0 } ;
146
- }
147
- }
151
+ var best = findChoice ( args , text ) ;
148
152
if ( best ) {
149
153
score = best . score ;
150
154
response = best ;
0 commit comments