Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@microsoft/bf-lu

Package Overview
Dependencies
Maintainers
2
Versions
197
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@microsoft/bf-lu

This package is intended for Microsoft use only. It is not designed to be consumed as an independent package.

  • 4.10.0-dev.20200716.d3cbcf0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
548
decreased by-4.53%
Maintainers
2
Weekly downloads
 
Created
Source

This package is intended for Microsoft use only. It is not designed to be consumed as an independent package.

Consuming @microsoft/bf-lu as a library

@microsoft/bf-lu can be used within a Node.js application as an imported library. Install locally:

npm install @microsoft/bf-lu --save

Parsing lu files

To parse LU files, you can use the parseFile() method.

const ludown = require('@microsoft/bf-lu');
const luContent1 = `# Greeting
- hi`;
const log = false;
const locale = 'en-us';
ludown.parser.parseFile(luContent1, log, locale)
    .then(function(parsedContent) {
        // Parsed LUIS object
        console.log(JSON.stringify(parsedContent.LUISJsonStructure, 2, null));
        // Parsed QnA content
        console.log(JSON.stringify(parsedContent.qnaJsonStructure, 2, null));
        // Additional files to parse
        console.log(JSON.stringify(parsedContent.additionalFilesToParse, 2, null));
    })
    .catch(function(err) {
        let errObj = new ludown.helperClasses.Exception(err);
        // err is of type ludown.helperClasses.Exception. 
        // Possible error codes are available under ludown.helperEnums.errorCodes
        if(errObj.errCode === ludown.helperEnums.errorCodes.INVALID_INPUT) {
            // do something specific to this error code
        } else {
            console.log(errObj.text);
        }
    })

Validating parsed lu files

You can use the available validateLUISBlob() function to verify if the parsed LUIS blob is valid. This helps catch name conflicts, invalid labelled utterances etc.

const ludown = require('@microsoft/bf-lu');
const luContent = `# Greeting
- hi {userName=bob}
$userName:first=
-vishwac`;
const log = false;
const locale = 'en-us';
async function parseContent() {
    let parsedContent;
    try {
        parsedContent = await ludown.parser.parseFile(luContent, log, locale);
    } catch (err) {
        let errObj = new ludown.helperClasses.Exception(err);
        // err is of type ludown.helperClasses.Exception. 
        // Possible error codes are available under ludown.helperEnums.errorCodes
        if(errObj.errCode === ludown.helperEnums.errorCodes.INVALID_INPUT) {
            // do something specific to this error code
        } else {
            console.log(errObj.text);
        }
    }
    // validate the parsed luis content
    ludown.parser.validateLUISBlob(parsedContent.LUISJsonStructure)
        .then(res => res)
        .catch(function(err) {
            let exception = new ludown.helperClasses.Exception(err);
            console.error('Oops, invalid LUIS content!\n');
            console.error(exception.errCode + ' : ' + exception.text);
        })
}

parseContent();

Generating lu content from LUIS JSON

You can generate lu content from LUIS and QnA maker JSON using constructMdFromLUIS() and constructMdFromQnA() methods. Here's an example code snippet.

const ludown = require('@microsoft/bf-lu')
const luContent = `# Greeting
- hi
$userName:first=
-vishwac`;
const log = false;
const locale = 'en-us';
async function parseContent() {
    let parsedContent;
    try {
        parsedContent = await ludown.parser.parseFile(luContent, log, locale);
    } catch (err) {
        let errObj = new ludown.helperClasses.Exception(err);
        // err is of type ludown.helperClasses.Exception. 
        // Possible error codes are available under ludown.helperEnums.errorCodes
        if(errObj.errCode === ludown.helperEnums.errorCodes.INVALID_INPUT) {
            // do something specific to this error code
        } else {
            console.log(errObj.text);
        }
    }
    
    if(await ludown.parser.validateLUISBlob(parsedContent.LUISJsonStructure)) {
        // reconstruct md content
        ludown.refresh.constructMdFromLUIS(parsedContent.LUISJsonStructure)
        .then(function(result){
            console.log(result);
        })
        .catch(function(err) {
            let exception = new ludown.helperClasses.Exception(err);
            console.error('Oops, invalid LUIS content!\n');
            console.error(exception.errCode + ' : ' + exception.text);
        })
    }

}

parseContent();

Translating lu files

You can take advantage of the Microsoft text translation API to automatically machine translate .lu files to one or more than 60+ languages supported by the Microsoft text translation cognitive service.

To translate lu file content, you can simply use the parseAndTranslate() method. Here's a code snippet.

const ludown = require('@microsoft/bf-lu');
const luContent = `# Greeting
- hi
$userName:first=
-vishwac`;
const log = false;
const targetLanguage = 'de';
const subscriptionKey = '<YOUR TEXT TRANSLATION KEY>';
const translateComments = true;
const translateLinkText = true;
ludown.translate.parseAndTranslate(luContent, subscriptionKey, targetLanguage, '', translateComments, translateLinkText, log)
    .then(function(result) {
        console.log(result);
    })
    .catch(function(err){
        let exception = new ludown.helperClasses.Exception(err);
        console.error(exception.errCode + ' : ' + exception.text);
    })

V2 API (Preview. Download from here)

Parsing LU Content

To parse LU files, you can use the LUISBuilder class, which returns a LUIS class

const Luis = require('@microsoft/bf-lu').V2.Luis
const LUISBuilder = require('@microsoft/bf-lu').V2.LuisBuilder
const luContent = `# Greeting
- hi`;

const luisObject = await LUISBuilder.fromContentAsync(luContent)

// Parsed LUIS object
console.log(JSON.stringify(luisObject, 2, null));
        

Validating parsed LU content

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.

const LUISBuilder = require('@microsoft/bf-lu').V2.LuisBuilder
const exception = require('@microsoft/bf-lu').V2.Exception
const luContent = `# Greeting
- hi`;

const luisObject = await LUISBuilder.fromLUAsync(luContent)
luisObject.intents[0].name = "testIntent123456789012345678901234567890123"
luisObject.validate()

Generating lu content from LUIS JSON

You can generate lu content from LUIS instance using parseToLuContent() method. Here's an example code snippet.

const LUISBuilder = require('@microsoft/bf-lu').V2.LuisBuilder
const exception = require('@microsoft/bf-lu').V2.Exception
const luContent = `# Greeting
- hi
$userName:first=
-vishwac`;
const log = false;
const locale = 'en-us';
async function parseContent() {

    try {   
        const luisObject = await LUISBuilder.fromContentAsync(luContent)
        luisObject.validate()
        const parsedLuisBackToLu = luisObject.parseToLuContent()
    } catch (error) {
        if (error instanceof exception) {
        // do something specific to this exception
        } else {
            console.log(errObj.text);
        }
    }
}

parseContent();

Translating lu files

You can take advantage of the Microsoft text translation API to automatically machine translate .lu files to one or more than 60+ languages supported by the Microsoft text translation cognitive service.

To translate lu file content, you can simply use the translate() method in the LU class. Here's a code snippet.

const LU = require('@microsoft/bf-lu').V2.LU
const luContent = `# Greeting
- hi
$userName:first=
-vishwac`;
const targetLanguage = 'de';
const subscriptionKey = '<YOUR TEXT TRANSLATION KEY>';
const translateComments = true;
const translateLinkText = true;

const luInstance = new LU(luContent)
await luInstance.translate(subscriptionKey, targetLanguage, translateComments, translateLinkText)
const translatedCode = luInstance.content

FAQs

Package last updated on 16 Jul 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc