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

Commit 9042f89

Browse files
Vishwac Sena KannanVishwac Sena Kannan
authored andcommitted
Updates to tests
1 parent 1aa1755 commit 9042f89

File tree

21 files changed

+151
-93
lines changed

21 files changed

+151
-93
lines changed

packages/luis/src/commands/luis/convert.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const fs = require('fs-extra')
44
const file = require('./../../utils/filehelper')
55
const luConverter = require('./../../parser/converters/lutoluisconverter')
66
const luisConverter = require('./../../parser/converters/luistoluconverter')
7+
const fileExtEnum = require('./../../parser/lufile/helpers').FileExtTypeEnum
78

89
export default class LuisConvert extends Command {
910
static description = 'Convert .lu file(s) to a LUIS application JSON model or vice versa'
@@ -34,7 +35,7 @@ export default class LuisConvert extends Command {
3435
// Parse the object depending on the input
3536
let result: any
3637
if (isLu) {
37-
const luFiles = await file.getLuObjects(stdin, flags.in, flags.recurse)
38+
const luFiles = await file.getLuObjects(stdin, flags.in, flags.recurse, fileExtEnum.LUFile)
3839
result = await luConverter.parseLuToLuis(luFiles, flags.log, flags.culture)
3940
} else {
4041
const luisFile = stdin ? stdin : await file.getContentFromFile(flags.in)

packages/luis/src/commands/luis/translate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const exception = require('./../../parser/lufile/classes/exception')
66
const luTranslator = require('./../../parser/translator/lutranslate')
77
const luisConverter = require('./../../parser/converters/luistoluconverter')
88
const luConverter = require('./../../parser/lufile/parseFileContents')
9+
const fileExtEnum = require('./../../parser/lufile/helpers').FileExtTypeEnum
910

1011
export default class LuisTranslate extends Command {
1112
static description = ' Translate given LUIS application JSON model or lu file(s)'
@@ -36,7 +37,7 @@ export default class LuisTranslate extends Command {
3637
let isLu = await fileHelper.detectLuContent(stdin, flags.in)
3738
let result: any
3839
if (isLu) {
39-
let luFiles = await fileHelper.getLuObjects(stdin, flags.in, flags.recurse)
40+
let luFiles = await fileHelper.getLuObjects(stdin, flags.in, flags.recurse, fileExtEnum.LUFile)
4041
result = await luTranslator.translateLuList(luFiles, flags.translatekey, flags.tgtlang, flags.srclang, flags.translate_comments, flags.translate_link_text)
4142
} else {
4243
let json = stdin ? stdin : await fileHelper.getContentFromFile(flags.in)

packages/luis/src/commands/qnamaker/convert.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const fs = require('fs-extra')
44
const file = require('./../../utils/filehelper')
55
const luConverter = require('./../../parser/converters/qnatoqnajsonconverter')
66
const qnaConverter = require('./../../parser/converters/qnajsontoqnaconverter')
7+
const fileExtEnum = require('./../../parser/lufile/helpers').FileExtTypeEnum
78

89
export default class QnamakerConvert extends Command {
910
static description = 'Convert .lu file(s) to a QnA application JSON model or vice versa'
@@ -32,7 +33,7 @@ export default class QnamakerConvert extends Command {
3233
// Parse the object depending on the input
3334
let result: any
3435
if (isQnA) {
35-
const luFiles = await file.getLuObjects(stdin, flags.in, flags.recurse)
36+
let luFiles = await file.getLuObjects(stdin, flags.in, flags.recurse, fileExtEnum.QnAFile)
3637
result = await luConverter.parseQnaToJson(luFiles, false, flags.luis_culture)
3738
} else {
3839
const qnAFile = stdin ? stdin : await file.getContentFromFile(flags.in)

packages/luis/src/commands/qnamaker/translate.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const exception = require('./../../parser/lufile/classes/exception')
66
const luTranslator = require('./../../parser/translator/lutranslate')
77
const qnaConverter = require('./../../parser/converters/qnajsontoqnaconverter')
88
const luConverter = require('./../../parser/lufile/parseFileContents')
9+
const fileExtEnum = require('./../../parser/lufile/helpers').FileExtTypeEnum
910

1011
export default class QnamakerTranslate extends Command {
1112
static description = 'Translate given LUIS application JSON model or lu file(s)'
@@ -36,7 +37,7 @@ export default class QnamakerTranslate extends Command {
3637
let isLu = await fileHelper.detectLuContent(stdin, flags.in)
3738
let result: any
3839
if (isLu) {
39-
let luFiles = await fileHelper.getLuObjects(stdin, flags.in, flags.recurse)
40+
let luFiles = await fileHelper.getLuObjects(stdin, flags.in, flags.recurse, fileExtEnum.QnAFile)
4041
result = await luTranslator.translateLuList(luFiles, flags.translatekey, flags.tgtlang, flags.srclang, flags.translate_comments, flags.translate_link_text)
4142
} else {
4243
let json = stdin ? stdin : await fileHelper.getContentFromFile(flags.in)

packages/luis/src/parser/lufile/helpers.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,29 @@ const helpers = {
2020
sanitizeNewLines(fileContent) {
2121
return fileContent.replace(ANY_NEWLINE, NEWLINE);
2222
},
23-
23+
/**
24+
* Enumeration of supported file extension types
25+
*/
26+
FileExtTypeEnum: {
27+
LUFile : '.lu',
28+
QnAFile : '.qna'
29+
},
2430
/**
2531
* Helper function to recursively get all .lu files
2632
* @param {string} inputfolder input folder name
2733
* @param {boolean} getSubFolder indicates if we should recursively look in sub-folders as well
34+
* @param {FileExtTypeEnum} extType indicates if we should look for LUFile or QnAFile
2835
* @returns {Array} Array of .lu files found
2936
*/
30-
findLUFiles: function(inputFolder, getSubFolders) {
37+
findLUFiles: function(inputFolder, getSubFolders, extType = this.FileExtTypeEnum.LUFile) {
3138
let results = [];
32-
const luExt = '.lu';
3339
fs.readdirSync(inputFolder).forEach(function(dirContent) {
3440
dirContent = path.resolve(inputFolder,dirContent);
3541
if(getSubFolders && fs.statSync(dirContent).isDirectory()) {
3642
results = results.concat(helpers.findLUFiles(dirContent, getSubFolders));
3743
}
3844
if(fs.statSync(dirContent).isFile()) {
39-
if(dirContent.endsWith(luExt)) {
45+
if(dirContent.endsWith(extType)) {
4046
results.push(dirContent);
4147
}
4248
}

packages/luis/src/utils/filehelper.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@ const fs = require('fs-extra')
33
const path = require('path')
44
const helpers = require('./../parser/lufile/helpers')
55
const luObject = require('./../parser/lufile/classes/luObject')
6+
67
/* tslint:disable:prefer-for-of no-unused*/
78

8-
export async function getLuObjects(stdin: string, input: string | undefined, recurse = false) {
9+
export async function getLuObjects(stdin: string, input: string | undefined, recurse = false, extType: string | undefined) {
910
let luObjects: any = []
1011
if (stdin) {
1112
luObjects.push(new luObject('stdin', stdin))
1213
} else {
13-
let luFiles = await getLuFiles(input, recurse)
14+
let luFiles = await getLuFiles(input, recurse, extType)
1415
for (let i = 0; i < luFiles.length; i++) {
1516
let luContent = await getContentFromFile(luFiles[i])
1617
luObjects.push(new luObject(path.resolve(luFiles[i]), luContent))
@@ -20,7 +21,7 @@ export async function getLuObjects(stdin: string, input: string | undefined, rec
2021
return luObjects
2122
}
2223

23-
async function getLuFiles(input: string | undefined, recurse = false): Promise<Array<any>> {
24+
async function getLuFiles(input: string | undefined, recurse = false, extType: string | undefined): Promise<Array<any>> {
2425
let filesToParse = []
2526
let fileStat = await fs.stat(input)
2627
if (fileStat.isFile()) {
@@ -32,10 +33,10 @@ async function getLuFiles(input: string | undefined, recurse = false): Promise<A
3233
throw new CLIError('Sorry, ' + input + ' is not a folder or does not exist')
3334
}
3435

35-
filesToParse = helpers.findLUFiles(input, recurse)
36+
filesToParse = helpers.findLUFiles(input, recurse, extType)
3637

3738
if (filesToParse.length === 0) {
38-
throw new CLIError('Sorry, no .lu files found in the specified folder.')
39+
throw new CLIError(`Sorry, no ${extType} files found in the specified folder.`)
3940
}
4041
return filesToParse
4142
}
@@ -133,7 +134,7 @@ export async function detectLuContent(stdin: string, input: string) {
133134
}
134135

135136
let inputStat = await fs.stat(input)
136-
return !inputStat.isFile() ? true : path.extname(input) === '.lu'
137+
return !inputStat.isFile() ? true : (path.extname(input) === '.lu' || path.extname(input) === '.qna')
137138
}
138139

139140
try {

packages/luis/test/commands/qnamaker/convert.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ describe('qnamaker:convert', () => {
4646
})
4747

4848
test
49-
.command(['qnamaker:convert', '--in', `${path.join(__dirname, './../../fixtures/examples/all.lu')}`, '--out', 'qna.json', '--name', 'all-qna'])
49+
.command(['qnamaker:convert', '--in', `${path.join(__dirname, './../../fixtures/examples/all.qna')}`, '--out', 'qna.json', '--name', 'all-qna'])
5050
.it('qnamaker:convert all concepts of lu file definition is parsed correctly [QnA]', async () => {
5151
let parsedObjects = await parseJsonFiles('./../../../qna.json', './../../fixtures/verified/all-qna.json')
5252
expect(parsedObjects[0]).to.deep.equal(parsedObjects[1])
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
> # QnA Definitions
2+
> This is a QnA definition. Follows # ? Question: \<list of questions\> \```markdown \<Answer> ``` format
3+
4+
> You can add URLs for QnA maker to ingest using the #URL reference scheme
5+
### ? How do I change the default message
6+
```markdown
7+
You can change the default message if you use the QnAMakerDialog.
8+
See [this link](https://docs.botframework.com/en-us/azure-bot-service/templates/qnamaker/#navtitle) for details.
9+
```
10+
11+
### ? How do I programmatically update my KB?
12+
```markdown
13+
You can use our REST apis to manage your KB.
14+
\#1. See here for details: https://westus.dev.cognitive.microsoft.com/docs/services/58994a073d9e04097c7ba6fe/operations/58994a073d9e041ad42d9baa
15+
```
16+
17+
> You can add URLs for QnA maker to ingest using the #URL reference scheme
18+
19+
[QnA URL - faqs](https://docs.microsoft.com/en-in/azure/cognitive-services/qnamaker/faqs)
20+
21+
22+
> You can define multilple questions for single answer as well
23+
### ? Who is your ceo?
24+
- get me your ceo info
25+
```markdown
26+
Vishwac
27+
```
28+
29+
> You can define filters for QnA using the \**Filters:** \<list of name=value pairs\> format
30+
### ? Where can I get coffee?
31+
- I need coffee
32+
33+
**Filters:**
34+
- location = seattle
35+
```markdown
36+
You can get coffee in our Seattle store at 1 pike place, Seattle, WA
37+
```
38+
39+
### ? Where can I get coffee?
40+
- I need coffee
41+
42+
**Filters:**
43+
- location = portland
44+
```markdown
45+
You can get coffee in our Portland store at 52 marine drive, Portland, OR
46+
```
47+
48+
> FAQ URLs for QnA maker to ingest.
49+
50+
[QnA maker reference](https://docs.microsoft.com/en-in/azure/cognitive-services/qnamaker/faqs)
51+
52+
[QnA reference](./qna7.lu)

packages/luis/test/fixtures/testcases/collate/11.lu

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,3 @@
66

77
[None intent](./none.lu)
88

9-
[QnA1](./qna3.lu)
10-
11-
[QnA7](./qna7.lu)
12-
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[QnA1](./qna3.lu)
2+
3+
[QnA7](./qna7.lu)
4+

0 commit comments

Comments
 (0)