This repository was archived by the owner on Jan 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 123
fix pattern issue in cross train core lib #759
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,6 +12,7 @@ const DiagnosticSeverity = require('../lufile/diagnostic').DiagnosticSeverity | |
| const fileHelper = require('../../utils/filehelper') | ||
| const exception = require('../utils/exception') | ||
| const retCode = require('../utils/enums/CLI-errors') | ||
| const prebuiltEntityTypes = require('../utils/enums/luisbuiltintypes').consolidatedList | ||
| const NEWLINE = require('os').EOL | ||
| const path = require('path') | ||
| const QNA_GENERIC_SOURCE = "custom editorial" | ||
|
|
@@ -185,10 +186,10 @@ const mergeBrothersInterruption = function (resource, result, intentName) { | |
| let brotherUtterances = [] | ||
| brotherSections.forEach(s => { | ||
| if (s.SectionType === LUSectionTypes.SIMPLEINTENTSECTION) { | ||
| brotherUtterances = brotherUtterances.concat(s.UtteranceAndEntitiesMap.map(u => u.utterance)) | ||
| brotherUtterances = brotherUtterances.concat(s.UtteranceAndEntitiesMap.map(u => u.utterance).filter(i => !patternWithPrebuiltEntity(i))) | ||
| } else { | ||
| s.SimpleIntentSections.forEach(section => { | ||
| brotherUtterances = brotherUtterances.concat(section.UtteranceAndEntitiesMap.map(u => u.utterance)) | ||
| brotherUtterances = brotherUtterances.concat(section.UtteranceAndEntitiesMap.map(u => u.utterance).filter(i => !patternWithPrebuiltEntity(i))) | ||
| }) | ||
| } | ||
| }) | ||
|
|
@@ -300,21 +301,20 @@ const removeDupUtterances = function (resource) { | |
|
|
||
| const extractIntentUtterances = function(resource, intentName) { | ||
| const intentSections = resource.Sections.filter(s => s.SectionType === LUSectionTypes.SIMPLEINTENTSECTION || s.SectionType === LUSectionTypes.NESTEDINTENTSECTION) | ||
| const curlyRe = /.*\{.*\}.*/ | ||
|
|
||
| let intentUtterances = [] | ||
| if (intentName && intentName !== '') { | ||
| const specificSections = intentSections.filter(s => s.Name === intentName) | ||
| if (specificSections.length > 0) { | ||
| intentUtterances = intentUtterances.concat(specificSections[0].UtteranceAndEntitiesMap.map(u => u.utterance).filter(i => curlyRe.exec(i) === null)) | ||
| intentUtterances = intentUtterances.concat(specificSections[0].UtteranceAndEntitiesMap.map(u => u.utterance)) | ||
| } | ||
| } else { | ||
| intentSections.forEach(s => { | ||
| if (s.SectionType === LUSectionTypes.SIMPLEINTENTSECTION) { | ||
| intentUtterances = intentUtterances.concat(s.UtteranceAndEntitiesMap.map(u => u.utterance).filter(i => curlyRe.exec(i) === null)) | ||
| intentUtterances = intentUtterances.concat(s.UtteranceAndEntitiesMap.map(u => u.utterance)) | ||
| } else { | ||
| s.SimpleIntentSections.forEach(section => { | ||
| intentUtterances = intentUtterances.concat(section.UtteranceAndEntitiesMap.map(u => u.utterance).filter(i => curlyRe.exec(i) === null)) | ||
| intentUtterances = intentUtterances.concat(section.UtteranceAndEntitiesMap.map(u => u.utterance)) | ||
| }) | ||
| } | ||
| })} | ||
|
|
@@ -397,7 +397,7 @@ const qnaCrossTrainCore = function (luResource, qnaResource, fileName, interrupt | |
| } | ||
|
|
||
| // construct questions content | ||
| dedupedQuestions = dedupedQuestions.map(q => '- '.concat(q)) | ||
| dedupedQuestions = dedupedQuestions.map(q => '- '.concat(q)).filter(i => !patternWithPrebuiltEntity(i)) | ||
| let questionsContent = dedupedQuestions.join(NEWLINE) | ||
|
|
||
| // cross training comments | ||
|
|
@@ -440,8 +440,11 @@ const qnaCrossTrainCore = function (luResource, qnaResource, fileName, interrupt | |
| trainedQnaResource = new SectionOperator(new LUResource([], modelInforContent, [])).addSection(qnaContents) | ||
| } | ||
|
|
||
| // remove utterances with curly brackets | ||
| const utterancesWithoutPatterns = utterances.filter(i => /{([^}]+)}/g.exec(i) === null) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This filter could be written as |
||
|
|
||
| // remove utterances which are duplicated with local qna questions | ||
| const dedupedUtterances = utterances.filter(u => !questions.includes(u)) | ||
| const dedupedUtterances = utterancesWithoutPatterns.filter(u => !questions.includes(u)) | ||
|
|
||
| // construct new question content for qna resource | ||
| let utterancesContent = dedupedUtterances.join(NEWLINE + '- ') | ||
|
|
@@ -494,4 +497,23 @@ const pretreatment = function (luContents, qnaContents) { | |
| const qnaObjectArray = fileHelper.getParsedObjects(qnaContents) | ||
|
|
||
| return {luObjectArray, qnaObjectArray} | ||
| } | ||
|
|
||
| const patternWithPrebuiltEntity = function (utterance) { | ||
| let patternAnyEntity | ||
| let matchedEntity = /{([^}]+)}/g.exec(utterance) | ||
|
|
||
| if (matchedEntity !== null) { | ||
| patternAnyEntity = matchedEntity[1] | ||
|
|
||
| if (patternAnyEntity && patternAnyEntity.startsWith('@')) { | ||
| patternAnyEntity = patternAnyEntity.slice(1) | ||
| } | ||
|
|
||
| if (prebuiltEntityTypes.includes(patternAnyEntity)) { | ||
| return true | ||
| } | ||
| } | ||
|
|
||
| return false | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a reason we can't just change these (here and on lines 314 and 317) to
intentUtterances.push()instead of making a whole new array and reassigning the variable to it?