@telefonica/language-model-converter
Advanced tools
Comparing version 1.0.3 to 2.0.0
"use strict"; | ||
const commander = require('commander'); | ||
const glob = require('glob'); | ||
const parser_1 = require('./parser'); | ||
const cli = commander.option('-p, --path <path>', 'Path to the folder containing language models') | ||
.option('-c, --culture <culture>', 'Culture code (ex. "en-us")') | ||
.parse(process.argv); | ||
const cli = commander | ||
.description('Convert language files defined to LUIS format') | ||
.usage('[options] <files>') | ||
.option('-c, --culture <culture>', 'Culture code this files belongs to (ex. "en-us")'); | ||
commander.on('--help', function () { | ||
console.log(` Examples: | ||
Convert all files in 'models' and its subfolders, starting with 'en', | ||
setting the locale to en-us | ||
$ language-model-converter ./models/**/en*.yaml -c en-us | ||
`); | ||
}); | ||
commander.parse(process.argv); | ||
cli.files = cli.args | ||
.map(pattern => glob.sync(pattern)) | ||
.reduce((a, b) => a.concat(b), []); | ||
let parser = new parser_1.LanguageModelParser(); | ||
let luisModel = parser.parse(cli.path, cli.culture); | ||
let luisModel = parser.parse(cli.files, cli.culture); | ||
console.log(JSON.stringify(luisModel, null, 2)); | ||
//# sourceMappingURL=index.js.map |
import { Luis } from './luis-model'; | ||
export declare class LanguageModelParser { | ||
private doc; | ||
parse(folder: string, culture: string): Luis.Model; | ||
parse(files: string[], culture: string): Luis.Model; | ||
private expandVariables(sentence); | ||
@@ -6,0 +6,0 @@ private extractEntities(sentence); |
"use strict"; | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const yaml = require('js-yaml'); | ||
@@ -9,9 +8,6 @@ class LanguageModelParser { | ||
} | ||
parse(folder, culture) { | ||
parse(files, culture) { | ||
try { | ||
let files = fs.readdirSync(folder) | ||
.filter(file => !fs.statSync(path.join(folder, file)).isDirectory()) | ||
.filter(file => file.startsWith(culture) && file.endsWith('.yaml')); | ||
files.forEach(file => { | ||
let yamlFileContents = fs.readFileSync(path.join(folder, file), 'utf8'); | ||
let yamlFileContents = fs.readFileSync(file, 'utf8'); | ||
Object.assign(this.doc, yaml.safeLoad(yamlFileContents)); | ||
@@ -18,0 +14,0 @@ }); |
@@ -7,3 +7,3 @@ "use strict"; | ||
let parser = new parser_1.LanguageModelParser(); | ||
let luisModel = parser.parse('./test/fixtures', 'en-basic'); | ||
let luisModel = parser.parse(['./test/fixtures/en-basic.yaml'], 'en-basic'); | ||
let expectedIntents = [ | ||
@@ -68,3 +68,3 @@ { | ||
let parser = new parser_1.LanguageModelParser(); | ||
let luisModel = parser.parse('./test/fixtures', 'en-basic'); | ||
let luisModel = parser.parse(['./test/fixtures/en-basic.yaml'], 'en-basic'); | ||
chai_1.expect(luisModel.luis_schema_version).to.not.be.empty; | ||
@@ -77,3 +77,3 @@ chai_1.expect(luisModel.name).to.not.be.empty; | ||
let parser = new parser_1.LanguageModelParser(); | ||
let luisModel = parser.parse('./test/fixtures', 'en-cornercases'); | ||
let luisModel = parser.parse(['./test/fixtures/en-cornercases.yaml'], 'en-cornercases'); | ||
let expectedUtterances = [ | ||
@@ -107,3 +107,3 @@ { | ||
let parser = new parser_1.LanguageModelParser(); | ||
let luisModel = parser.parse('./test/fixtures', 'en-variables'); | ||
let luisModel = parser.parse(['./test/fixtures/en-variables.yaml'], 'en-variables'); | ||
let expectedUtterances = [ | ||
@@ -110,0 +110,0 @@ { |
{ | ||
"name": "@telefonica/language-model-converter", | ||
"version": "1.0.3", | ||
"version": "2.0.0", | ||
"description": "Language model converter for yot-bot", | ||
@@ -32,2 +32,3 @@ "license": "UNLICENSED", | ||
"commander": "^2.9.0", | ||
"glob": "^7.1.0", | ||
"js-yaml": "^3.6.1" | ||
@@ -38,2 +39,3 @@ }, | ||
"@types/commander": "^2.3.30", | ||
"@types/glob": "^5.0.30", | ||
"@types/js-yaml": "^3.5.28", | ||
@@ -40,0 +42,0 @@ "@types/mocha": "^2.2.32", |
@@ -8,8 +8,21 @@ # language-model-converter | ||
```sh | ||
npm install @telefonica/language-model-converter | ||
npm install -g @telefonica/language-model-converter | ||
language-model-converter --help | ||
language-model-converter -p ../language-model -c en-us | ||
language-model-converter -p ../language-model -c es-es | ||
Usage: language-model-converter [options] <files> | ||
Convert language files defined to LUIS format | ||
Options: | ||
-h, --help output usage information | ||
-c, --culture <culture> Culture code this files belongs to (ex. "en-us") | ||
Examples: | ||
Convert all files in 'models' and its subfolders, starting with 'en', | ||
setting the locale to en-us | ||
$ language-model-converter ./models/**/en*.yaml -c en-us | ||
``` | ||
Notice that you can use [luis-cli](../luis-cli) to import or update the generated LUIS models. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27487
350
27
4
17
1
+ Addedglob@^7.1.0
+ Addedbalanced-match@1.0.2(transitive)
+ Addedbrace-expansion@1.1.11(transitive)
+ Addedconcat-map@0.0.1(transitive)
+ Addedfs.realpath@1.0.0(transitive)
+ Addedglob@7.2.3(transitive)
+ Addedinflight@1.0.6(transitive)
+ Addedinherits@2.0.4(transitive)
+ Addedminimatch@3.1.2(transitive)
+ Addedonce@1.4.0(transitive)
+ Addedpath-is-absolute@1.0.1(transitive)
+ Addedwrappy@1.0.2(transitive)