Skip to content

Commit

Permalink
[Cross-Train] avoid qna questions with brackets to be added to crosst…
Browse files Browse the repository at this point in the history
…rained lu file (#1067)

* support output to file for kb:export command

* remove questions with brackets to avoid adding to crosstrained lu file
  • Loading branch information
feich-ms committed Dec 7, 2020
1 parent 954f006 commit 3315f42
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
8 changes: 7 additions & 1 deletion packages/lu/src/parser/cross-train/crossTrainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ const qnaCrossTrainCore = function (luResource, qnaResource, fileName, interrupt
}

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

// cross training comments
Expand Down Expand Up @@ -580,4 +580,10 @@ const patternWithPrebuiltEntity = function (utterance) {
}

return false
}

const questionWithBrackets = function (question) {
let matched = /\([^\)]*\)/g.exec(question)

return matched !== null
}
44 changes: 44 additions & 0 deletions packages/lu/test/parser/cross-train/crossTrainer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -992,4 +992,48 @@ describe('luis:cross training tests among lu and qna contents', () => {

assert.equal(luResult.get('dia1').Sections.filter(s => s.SectionType !== sectionTypes.MODELINFOSECTION).length, 0)
})

it('luis:cross training can get expected result when handling brackets in qna question', async () => {
let luContentArray = []
let qnaContentArray = []

luContentArray.push({
content:
`# dia1_trigger
- book a hotel for me`,
id: 'main'
})

qnaContentArray.push({
content:
`#? What does const [thing, setThing] = useState() mean?
- how to use it?
\`\`\`
Here is the [user guide](http://contoso.com/userguide.pdf)
\`\`\``,
id: 'main'
})

let crossTrainConfig = {
'main': {
'rootDialog': true,
'triggers': {}
}
}

const trainedResult = await crossTrainer.crossTrain(luContentArray, qnaContentArray, crossTrainConfig)
const luResult = trainedResult.luResult
const qnaResult = trainedResult.qnaResult

let foundIndex = luResult.get('main').Sections.findIndex(s => s.Name === 'DeferToRecognizer_QnA_main')
assert.isTrue(foundIndex > -1)
assert.equal(luResult.get('main').Sections[foundIndex].Body, `- how to use it?`)

foundIndex = qnaResult.get('main').Sections.findIndex(s => s.Answer === 'intent=DeferToRecognizer_LUIS_main')
assert.isTrue(foundIndex > -1)
assert.equal(qnaResult.get('main').Sections[foundIndex].FilterPairs[0].key, 'dialogName')
assert.equal(qnaResult.get('main').Sections[foundIndex].FilterPairs[0].value, 'main')
assert.equal(qnaResult.get('main').Sections[foundIndex].Questions.length, 1)
assert.equal(qnaResult.get('main').Sections[foundIndex].Questions[0], 'book a hotel for me')
})
})

0 comments on commit 3315f42

Please sign in to comment.