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

Commit a9a92a5

Browse files
author
Shuai Wang
authored
Fix luis:cross-train generate incorrect culture info from file names (#1300)
* fix locale from file incorrectly parse to luis app * fix qna cross train test cases
1 parent 20a3f98 commit a9a92a5

File tree

14 files changed

+61
-39
lines changed

14 files changed

+61
-39
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,7 @@ const parseAndValidateContent = async function (objectArray, verbose, importReso
517517
if (object.content && object.content !== '') {
518518
if (fileExt === fileExtEnum.LUFile) {
519519
if (!object.id.endsWith(fileExtEnum.LUFile)) object.id += fileExtEnum.LUFile
520-
let result = await LuisBuilderVerbose.build([object], verbose, undefined, importResolver)
520+
let result = await LuisBuilderVerbose.build([object], verbose, object.language, importResolver)
521521
let luisObj = new Luis(result)
522522
fileContent = luisObj.parseToLuContent()
523523
} else {

packages/lu/src/parser/lu/luOptions.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
1+
const getLuisCultureFromPath = require('../../utils/localehelper').getLuisCultureFromPath
2+
13
class LuOptions {
24
constructor(id = '', includeInCollate = true, language = '', path = ''){
5+
let fileLocale
6+
if (id) {
7+
fileLocale = getLuisCultureFromPath(`${id}.lu`)
8+
}
9+
310
this.id = id ? id : get_guid()
411
this.includeInCollate = includeInCollate
5-
this.language = language
12+
this.language = language ? language : fileLocale ? fileLocale : ''
613
this.path = path
714
}
815
}

packages/lu/src/parser/lubuild/builder.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ const path = require('path')
1212
const fs = require('fs-extra')
1313
const delay = require('delay')
1414
const fileHelper = require('./../../utils/filehelper')
15+
const localeHelper = require('./../../utils/localehelper')
1516
const fileExtEnum = require('./../utils/helpers').FileExtTypeEnum
1617
const retCode = require('./../utils/enums/CLI-errors')
1718
const exception = require('./../utils/exception')
@@ -43,7 +44,7 @@ export class Builder {
4344
let fileCulture: string
4445
let fileName: string
4546

46-
let cultureFromPath = fileHelper.getLuisCultureFromPath(file)
47+
let cultureFromPath = localeHelper.getLuisCultureFromPath(file)
4748
if (cultureFromPath) {
4849
fileCulture = cultureFromPath
4950
let fileNameWithCulture = path.basename(file, path.extname(file))

packages/lu/src/parser/lufile/parseFileContents.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ const parseLuAndQnaWithAntlr = async function (parsedContent, fileContent, log,
284284

285285
helpers.checkAndUpdateVersion(parsedContent.LUISJsonStructure);
286286

287+
updateCulture(parsedContent.LUISJsonStructure, locale)
287288
}
288289

289290
const updateIntentAndEntityFeatures = function(luisObj) {
@@ -294,6 +295,12 @@ const updateIntentAndEntityFeatures = function(luisObj) {
294295
})
295296
}
296297

298+
const updateCulture = function(luisObj, locale) {
299+
if (!luisObj.culture) {
300+
luisObj.culture = locale ? locale : 'en-us'
301+
}
302+
}
303+
297304
const updateFeaturesWithPL = function(collection, plName) {
298305
if (collection === null || collection === undefined) return;
299306
if (collection.hasOwnProperty("features")) {

packages/lu/src/parser/luis/luis.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class Luis {
2121
this.versionId = "0.1";
2222
this.name = "";
2323
this.desc = "";
24-
this.culture = "en-us";
24+
this.culture = "";
2525

2626
if (LuisJSON) {
2727
initialize(this, LuisJSON)

packages/lu/src/parser/utils/helpers.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ const retCode = require('./enums/CLI-errors');
88
const exception = require('./exception');
99
const NEWLINE = require('os').EOL;
1010
const ANY_NEWLINE = /\r\n|\r|\n/g;
11-
const url = require('url');
1211
const hClasses = require('../lufile/classes/hclasses');
1312
const helpers = {
1413

packages/lu/src/utils/filehelper.ts

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -300,35 +300,6 @@ export function parseJSON(input: string, appType: string) {
300300
}
301301
}
302302

303-
export function getLuisCultureFromPath(file: string): string | null {
304-
let fn = path.basename(file, path.extname(file))
305-
let lang = path.extname(fn).substring(1)
306-
switch (lang.toLowerCase()) {
307-
case 'en-us':
308-
case 'ar-ar':
309-
case 'zh-cn':
310-
case 'nl-nl':
311-
case 'fr-fr':
312-
case 'fr-ca':
313-
case 'de-de':
314-
case 'gu-in':
315-
case 'hi-in':
316-
case 'it-it':
317-
case 'ja-jp':
318-
case 'ko-kr':
319-
case 'mr-in':
320-
case 'pt-br':
321-
case 'es-es':
322-
case 'es-mx':
323-
case 'ta-in':
324-
case 'te-in':
325-
case 'tr-tr':
326-
return lang
327-
default:
328-
return null
329-
}
330-
}
331-
332303
export function getQnACultureFromPath(file: string): string | null {
333304
let fn = path.basename(file, path.extname(file))
334305
let lang = path.extname(fn).substring(1)
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*!
2+
* Copyright (c) Microsoft Corporation. All rights reserved.
3+
* Licensed under the MIT License.
4+
*/
5+
6+
const path = require('path')
7+
8+
export function getLuisCultureFromPath(file: string): string | null {
9+
let fn = path.basename(file, path.extname(file))
10+
let lang = path.extname(fn).substring(1)
11+
switch (lang.toLowerCase()) {
12+
case 'en-us':
13+
case 'ar-ar':
14+
case 'zh-cn':
15+
case 'nl-nl':
16+
case 'fr-fr':
17+
case 'fr-ca':
18+
case 'de-de':
19+
case 'gu-in':
20+
case 'hi-in':
21+
case 'it-it':
22+
case 'ja-jp':
23+
case 'ko-kr':
24+
case 'mr-in':
25+
case 'pt-br':
26+
case 'es-es':
27+
case 'es-mx':
28+
case 'ta-in':
29+
case 'te-in':
30+
case 'tr-tr':
31+
return lang
32+
default:
33+
return null
34+
}
35+
}

packages/luis/test/fixtures/testcases/interruption/dia2/dia2.lu

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
> !# @app.culture = it-it
2+
13
# dia3_trigger
24
- book a flight from {fromLocation = Seattle} to {toLocation = Beijing}
35

packages/luis/test/fixtures/verified/interruption/dia1.fr-fr.lu

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
> LUIS application information
33
> !# @app.versionId = 0.1
4-
> !# @app.culture = en-us
4+
> !# @app.culture = fr-fr
55
> !# @app.luis_schema_version = 3.2.0
66

77

0 commit comments

Comments
 (0)