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

Commit f97e0cb

Browse files
authored
Update LU README
1 parent 4aa848c commit f97e0cb

File tree

1 file changed

+89
-88
lines changed

1 file changed

+89
-88
lines changed

packages/lu/README.md

Lines changed: 89 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,95 @@ This package is intended for Microsoft use only. It is not designed to be consum
88
npm install @microsoft/bf-lu --save
99
```
1010

11+
# V2 API
12+
13+
## Parsing LU Content
14+
To parse LU files, you can use the LUISBuilder class, which returns a LUIS class
15+
16+
```js
17+
const Luis = require('@microsoft/bf-lu').V2.Luis
18+
const LUISBuilder = require('@microsoft/bf-lu').V2.LuisBuilder
19+
const luContent = `# Greeting
20+
- hi`;
21+
22+
const luisObject = await LUISBuilder.fromContentAsync(luContent)
23+
24+
// Parsed LUIS object
25+
console.log(JSON.stringify(luisObject, 2, null));
26+
27+
```
28+
29+
## Validating parsed LU content
30+
31+
You can use the available validate() function to verify if the parsed LUIS object is valid. This helps catch name conflicts, invalid labelled utterances etc.
32+
33+
```js
34+
const LUISBuilder = require('@microsoft/bf-lu').V2.LuisBuilder
35+
const exception = require('@microsoft/bf-lu').V2.Exception
36+
const luContent = `# Greeting
37+
- hi`;
38+
39+
const luisObject = await LUISBuilder.fromLUAsync(luContent)
40+
luisObject.intents[0].name = "testIntent123456789012345678901234567890123"
41+
luisObject.validate()
42+
```
43+
44+
## Generating lu content from LUIS JSON
45+
46+
You can generate lu content from LUIS instance using parseToLuContent() method. Here's an example code snippet.
47+
48+
```js
49+
const LUISBuilder = require('@microsoft/bf-lu').V2.LuisBuilder
50+
const exception = require('@microsoft/bf-lu').V2.Exception
51+
const luContent = `# Greeting
52+
- hi
53+
$userName:first=
54+
-vishwac`;
55+
const log = false;
56+
const locale = 'en-us';
57+
async function parseContent() {
58+
59+
try {
60+
const luisObject = await LUISBuilder.fromContentAsync(luContent)
61+
luisObject.validate()
62+
const parsedLuisBackToLu = luisObject.parseToLuContent()
63+
} catch (error) {
64+
if (error instanceof exception) {
65+
// do something specific to this exception
66+
} else {
67+
console.log(errObj.text);
68+
}
69+
}
70+
}
71+
72+
parseContent();
73+
74+
```
75+
## Translating lu files
76+
77+
You can take advantage of the [Microsoft text translation API](https://docs.microsoft.com/en-us/azure/cognitive-services/translator/) to automatically machine translate .lu files to one or more than [60+ languages](https://aka.ms/translate-langs) supported by the Microsoft text translation cognitive service.
78+
79+
To translate lu file content, you can simply use the translate() method in the LU class. Here's a code snippet.
80+
81+
```js
82+
const LU = require('@microsoft/bf-lu').V2.LU
83+
const luContent = `# Greeting
84+
- hi
85+
$userName:first=
86+
-vishwac`;
87+
const targetLanguage = 'de';
88+
const subscriptionKey = '<YOUR TEXT TRANSLATION KEY>';
89+
const translateComments = true;
90+
const translateLinkText = true;
91+
92+
const luInstance = new LU(luContent)
93+
await luInstance.translate(subscriptionKey, targetLanguage, translateComments, translateLinkText)
94+
const translatedCode = luInstance.content
95+
96+
```
97+
98+
99+
# DEPRECATED V1 API
11100
## Parsing lu files
12101
To parse LU files, you can use the parseFile() method.
13102

@@ -150,91 +239,3 @@ ludown.translate.parseAndTranslate(luContent, subscriptionKey, targetLanguage, '
150239
})
151240

152241
```
153-
154-
155-
# V2 API (Preview. Download from [here](https://botbuilder.myget.org/feed/botframework-cli/package/npm/@microsoft/bf-lu))
156-
157-
## Parsing LU Content
158-
To parse LU files, you can use the LUISBuilder class, which returns a LUIS class
159-
160-
```js
161-
const Luis = require('@microsoft/bf-lu').V2.Luis
162-
const LUISBuilder = require('@microsoft/bf-lu').V2.LuisBuilder
163-
const luContent = `# Greeting
164-
- hi`;
165-
166-
const luisObject = await LUISBuilder.fromContentAsync(luContent)
167-
168-
// Parsed LUIS object
169-
console.log(JSON.stringify(luisObject, 2, null));
170-
171-
```
172-
173-
## Validating parsed LU content
174-
175-
You can use the available validate() function to verify if the parsed LUIS object is valid. This helps catch name conflicts, invalid labelled utterances etc.
176-
177-
```js
178-
const LUISBuilder = require('@microsoft/bf-lu').V2.LuisBuilder
179-
const exception = require('@microsoft/bf-lu').V2.Exception
180-
const luContent = `# Greeting
181-
- hi`;
182-
183-
const luisObject = await LUISBuilder.fromLUAsync(luContent)
184-
luisObject.intents[0].name = "testIntent123456789012345678901234567890123"
185-
luisObject.validate()
186-
```
187-
188-
## Generating lu content from LUIS JSON
189-
190-
You can generate lu content from LUIS instance using parseToLuContent() method. Here's an example code snippet.
191-
192-
```js
193-
const LUISBuilder = require('@microsoft/bf-lu').V2.LuisBuilder
194-
const exception = require('@microsoft/bf-lu').V2.Exception
195-
const luContent = `# Greeting
196-
- hi
197-
$userName:first=
198-
-vishwac`;
199-
const log = false;
200-
const locale = 'en-us';
201-
async function parseContent() {
202-
203-
try {
204-
const luisObject = await LUISBuilder.fromContentAsync(luContent)
205-
luisObject.validate()
206-
const parsedLuisBackToLu = luisObject.parseToLuContent()
207-
} catch (error) {
208-
if (error instanceof exception) {
209-
// do something specific to this exception
210-
} else {
211-
console.log(errObj.text);
212-
}
213-
}
214-
}
215-
216-
parseContent();
217-
218-
```
219-
## Translating lu files
220-
221-
You can take advantage of the [Microsoft text translation API](https://docs.microsoft.com/en-us/azure/cognitive-services/translator/) to automatically machine translate .lu files to one or more than [60+ languages](https://aka.ms/translate-langs) supported by the Microsoft text translation cognitive service.
222-
223-
To translate lu file content, you can simply use the translate() method in the LU class. Here's a code snippet.
224-
225-
```js
226-
const LU = require('@microsoft/bf-lu').V2.LU
227-
const luContent = `# Greeting
228-
- hi
229-
$userName:first=
230-
-vishwac`;
231-
const targetLanguage = 'de';
232-
const subscriptionKey = '<YOUR TEXT TRANSLATION KEY>';
233-
const translateComments = true;
234-
const translateLinkText = true;
235-
236-
const luInstance = new LU(luContent)
237-
await luInstance.translate(subscriptionKey, targetLanguage, translateComments, translateLinkText)
238-
const translatedCode = luInstance.content
239-
240-
```

0 commit comments

Comments
 (0)