Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit 3315f42

Browse files
authored
[Cross-Train] avoid qna questions with brackets to be added to crosstrained lu file (#1067)
* support output to file for kb:export command * remove questions with brackets to avoid adding to crosstrained lu file
1 parent 954f006 commit 3315f42

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

packages/lu/src/parser/cross-train/crossTrainer.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ const qnaCrossTrainCore = function (luResource, qnaResource, fileName, interrupt
424424
}
425425

426426
// construct questions content
427-
dedupedQuestions = dedupedQuestions.map(q => '- '.concat(q)).filter(i => !patternWithPrebuiltEntity(i))
427+
dedupedQuestions = dedupedQuestions.map(q => '- '.concat(q)).filter(i => !patternWithPrebuiltEntity(i) && !questionWithBrackets(i))
428428
let questionsContent = dedupedQuestions.join(NEWLINE)
429429

430430
// cross training comments
@@ -580,4 +580,10 @@ const patternWithPrebuiltEntity = function (utterance) {
580580
}
581581

582582
return false
583+
}
584+
585+
const questionWithBrackets = function (question) {
586+
let matched = /\([^\)]*\)/g.exec(question)
587+
588+
return matched !== null
583589
}

packages/lu/test/parser/cross-train/crossTrainer.test.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,4 +992,48 @@ describe('luis:cross training tests among lu and qna contents', () => {
992992

993993
assert.equal(luResult.get('dia1').Sections.filter(s => s.SectionType !== sectionTypes.MODELINFOSECTION).length, 0)
994994
})
995+
996+
it('luis:cross training can get expected result when handling brackets in qna question', async () => {
997+
let luContentArray = []
998+
let qnaContentArray = []
999+
1000+
luContentArray.push({
1001+
content:
1002+
`# dia1_trigger
1003+
- book a hotel for me`,
1004+
id: 'main'
1005+
})
1006+
1007+
qnaContentArray.push({
1008+
content:
1009+
`#? What does const [thing, setThing] = useState() mean?
1010+
- how to use it?
1011+
\`\`\`
1012+
Here is the [user guide](http://contoso.com/userguide.pdf)
1013+
\`\`\``,
1014+
id: 'main'
1015+
})
1016+
1017+
let crossTrainConfig = {
1018+
'main': {
1019+
'rootDialog': true,
1020+
'triggers': {}
1021+
}
1022+
}
1023+
1024+
const trainedResult = await crossTrainer.crossTrain(luContentArray, qnaContentArray, crossTrainConfig)
1025+
const luResult = trainedResult.luResult
1026+
const qnaResult = trainedResult.qnaResult
1027+
1028+
let foundIndex = luResult.get('main').Sections.findIndex(s => s.Name === 'DeferToRecognizer_QnA_main')
1029+
assert.isTrue(foundIndex > -1)
1030+
assert.equal(luResult.get('main').Sections[foundIndex].Body, `- how to use it?`)
1031+
1032+
foundIndex = qnaResult.get('main').Sections.findIndex(s => s.Answer === 'intent=DeferToRecognizer_LUIS_main')
1033+
assert.isTrue(foundIndex > -1)
1034+
assert.equal(qnaResult.get('main').Sections[foundIndex].FilterPairs[0].key, 'dialogName')
1035+
assert.equal(qnaResult.get('main').Sections[foundIndex].FilterPairs[0].value, 'main')
1036+
assert.equal(qnaResult.get('main').Sections[foundIndex].Questions.length, 1)
1037+
assert.equal(qnaResult.get('main').Sections[foundIndex].Questions[0], 'book a hotel for me')
1038+
})
9951039
})

0 commit comments

Comments
 (0)