@@ -12,6 +12,7 @@ const DiagnosticSeverity = require('../lufile/diagnostic').DiagnosticSeverity
1212const fileHelper = require ( '../../utils/filehelper' )
1313const exception = require ( '../utils/exception' )
1414const retCode = require ( '../utils/enums/CLI-errors' )
15+ const prebuiltEntityTypes = require ( '../utils/enums/luisbuiltintypes' ) . consolidatedList
1516const NEWLINE = require ( 'os' ) . EOL
1617const path = require ( 'path' )
1718const QNA_GENERIC_SOURCE = "custom editorial"
@@ -185,10 +186,10 @@ const mergeBrothersInterruption = function (resource, result, intentName) {
185186 let brotherUtterances = [ ]
186187 brotherSections . forEach ( s => {
187188 if ( s . SectionType === LUSectionTypes . SIMPLEINTENTSECTION ) {
188- brotherUtterances = brotherUtterances . concat ( s . UtteranceAndEntitiesMap . map ( u => u . utterance ) )
189+ brotherUtterances = brotherUtterances . concat ( s . UtteranceAndEntitiesMap . map ( u => u . utterance ) . filter ( i => ! patternWithPrebuiltEntity ( i ) ) )
189190 } else {
190191 s . SimpleIntentSections . forEach ( section => {
191- brotherUtterances = brotherUtterances . concat ( section . UtteranceAndEntitiesMap . map ( u => u . utterance ) )
192+ brotherUtterances = brotherUtterances . concat ( section . UtteranceAndEntitiesMap . map ( u => u . utterance ) . filter ( i => ! patternWithPrebuiltEntity ( i ) ) )
192193 } )
193194 }
194195 } )
@@ -300,21 +301,20 @@ const removeDupUtterances = function (resource) {
300301
301302const extractIntentUtterances = function ( resource , intentName ) {
302303 const intentSections = resource . Sections . filter ( s => s . SectionType === LUSectionTypes . SIMPLEINTENTSECTION || s . SectionType === LUSectionTypes . NESTEDINTENTSECTION )
303- const curlyRe = / .* \{ .* \} .* /
304304
305305 let intentUtterances = [ ]
306306 if ( intentName && intentName !== '' ) {
307307 const specificSections = intentSections . filter ( s => s . Name === intentName )
308308 if ( specificSections . length > 0 ) {
309- intentUtterances = intentUtterances . concat ( specificSections [ 0 ] . UtteranceAndEntitiesMap . map ( u => u . utterance ) . filter ( i => curlyRe . exec ( i ) === null ) )
309+ intentUtterances = intentUtterances . concat ( specificSections [ 0 ] . UtteranceAndEntitiesMap . map ( u => u . utterance ) )
310310 }
311311 } else {
312312 intentSections . forEach ( s => {
313313 if ( s . SectionType === LUSectionTypes . SIMPLEINTENTSECTION ) {
314- intentUtterances = intentUtterances . concat ( s . UtteranceAndEntitiesMap . map ( u => u . utterance ) . filter ( i => curlyRe . exec ( i ) === null ) )
314+ intentUtterances = intentUtterances . concat ( s . UtteranceAndEntitiesMap . map ( u => u . utterance ) )
315315 } else {
316316 s . SimpleIntentSections . forEach ( section => {
317- intentUtterances = intentUtterances . concat ( section . UtteranceAndEntitiesMap . map ( u => u . utterance ) . filter ( i => curlyRe . exec ( i ) === null ) )
317+ intentUtterances = intentUtterances . concat ( section . UtteranceAndEntitiesMap . map ( u => u . utterance ) )
318318 } )
319319 }
320320 } ) }
@@ -397,7 +397,7 @@ const qnaCrossTrainCore = function (luResource, qnaResource, fileName, interrupt
397397 }
398398
399399 // construct questions content
400- dedupedQuestions = dedupedQuestions . map ( q => '- ' . concat ( q ) )
400+ dedupedQuestions = dedupedQuestions . map ( q => '- ' . concat ( q ) ) . filter ( i => ! patternWithPrebuiltEntity ( i ) )
401401 let questionsContent = dedupedQuestions . join ( NEWLINE )
402402
403403 // cross training comments
@@ -440,8 +440,11 @@ const qnaCrossTrainCore = function (luResource, qnaResource, fileName, interrupt
440440 trainedQnaResource = new SectionOperator ( new LUResource ( [ ] , modelInforContent , [ ] ) ) . addSection ( qnaContents )
441441 }
442442
443+ // remove utterances with curly brackets
444+ const utterancesWithoutPatterns = utterances . filter ( i => / { ( [ ^ } ] + ) } / g. exec ( i ) === null )
445+
443446 // remove utterances which are duplicated with local qna questions
444- const dedupedUtterances = utterances . filter ( u => ! questions . includes ( u ) )
447+ const dedupedUtterances = utterancesWithoutPatterns . filter ( u => ! questions . includes ( u ) )
445448
446449 // construct new question content for qna resource
447450 let utterancesContent = dedupedUtterances . join ( NEWLINE + '- ' )
@@ -494,4 +497,23 @@ const pretreatment = function (luContents, qnaContents) {
494497 const qnaObjectArray = fileHelper . getParsedObjects ( qnaContents )
495498
496499 return { luObjectArray, qnaObjectArray}
500+ }
501+
502+ const patternWithPrebuiltEntity = function ( utterance ) {
503+ let patternAnyEntity
504+ let matchedEntity = / { ( [ ^ } ] + ) } / g. exec ( utterance )
505+
506+ if ( matchedEntity !== null ) {
507+ patternAnyEntity = matchedEntity [ 1 ]
508+
509+ if ( patternAnyEntity && patternAnyEntity . startsWith ( '@' ) ) {
510+ patternAnyEntity = patternAnyEntity . slice ( 1 )
511+ }
512+
513+ if ( prebuiltEntityTypes . includes ( patternAnyEntity ) ) {
514+ return true
515+ }
516+ }
517+
518+ return false
497519}
0 commit comments