virtual-core
Advanced tools
Comparing version 0.0.12-0 to 0.0.12
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Intent { | ||
constructor(name, builtin) { | ||
var Intent = (function () { | ||
function Intent(name, builtin) { | ||
this.name = name; | ||
@@ -10,3 +10,3 @@ this.builtin = false; | ||
} | ||
addSlot(slot) { | ||
Intent.prototype.addSlot = function (slot) { | ||
if (this.slots === null) { | ||
@@ -16,5 +16,6 @@ this.slots = []; | ||
this.slots.push(slot); | ||
} | ||
slotForName(name) { | ||
for (const slot of this.slots) { | ||
}; | ||
Intent.prototype.slotForName = function (name) { | ||
for (var _i = 0, _a = this.slots; _i < _a.length; _i++) { | ||
var slot = _a[_i]; | ||
if (name.toLowerCase() === slot.name.toLowerCase()) { | ||
@@ -25,12 +26,14 @@ return slot; | ||
return undefined; | ||
} | ||
} | ||
}; | ||
return Intent; | ||
}()); | ||
exports.Intent = Intent; | ||
class IntentSlot { | ||
constructor(name, type) { | ||
var IntentSlot = (function () { | ||
function IntentSlot(name, type) { | ||
this.name = name; | ||
this.type = type; | ||
} | ||
} | ||
return IntentSlot; | ||
}()); | ||
exports.IntentSlot = IntentSlot; | ||
//# sourceMappingURL=IIntentSchema.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class SampleUtterances { | ||
constructor() { | ||
var SampleUtterances = (function () { | ||
function SampleUtterances() { | ||
this.samples = {}; | ||
} | ||
setInteractionModel(interactionModel) { | ||
SampleUtterances.prototype.setInteractionModel = function (interactionModel) { | ||
this._interactionModel = interactionModel; | ||
} | ||
interactionModel() { | ||
}; | ||
SampleUtterances.prototype.interactionModel = function () { | ||
return this._interactionModel; | ||
} | ||
addSample(intent, sample) { | ||
}; | ||
SampleUtterances.prototype.addSample = function (intent, sample) { | ||
if (!(intent in this.samples)) { | ||
@@ -18,4 +18,4 @@ this.samples[intent] = []; | ||
this.samples[intent].push(new SamplePhrase(this, intent, sample)); | ||
} | ||
samplesForIntent(intent) { | ||
}; | ||
SampleUtterances.prototype.samplesForIntent = function (intent) { | ||
if (!(intent in this.samples)) { | ||
@@ -25,11 +25,12 @@ return []; | ||
return this.samples[intent]; | ||
} | ||
defaultUtterance() { | ||
const firstIntent = Object.keys(this.samples)[0]; | ||
}; | ||
SampleUtterances.prototype.defaultUtterance = function () { | ||
var firstIntent = Object.keys(this.samples)[0]; | ||
return this.samples[firstIntent][0]; | ||
} | ||
} | ||
}; | ||
return SampleUtterances; | ||
}()); | ||
exports.SampleUtterances = SampleUtterances; | ||
class SamplePhrase { | ||
constructor(sampleUtterances, intent, phrase) { | ||
var SamplePhrase = (function () { | ||
function SamplePhrase(sampleUtterances, intent, phrase) { | ||
this.sampleUtterances = sampleUtterances; | ||
@@ -42,3 +43,3 @@ this.intent = intent; | ||
} | ||
slotName(index) { | ||
SamplePhrase.prototype.slotName = function (index) { | ||
if (index >= this.slotNames.length) { | ||
@@ -48,16 +49,16 @@ return undefined; | ||
return this.slotNames[index]; | ||
} | ||
slotCount() { | ||
}; | ||
SamplePhrase.prototype.slotCount = function () { | ||
return this.slotNames.length; | ||
} | ||
regex() { | ||
}; | ||
SamplePhrase.prototype.regex = function () { | ||
return new RegExp("^" + this._regex + "$", "i"); | ||
} | ||
matchesUtterance(utterance) { | ||
}; | ||
SamplePhrase.prototype.matchesUtterance = function (utterance) { | ||
return new SamplePhraseTest(this, utterance); | ||
} | ||
phraseToRegex(phrase) { | ||
const startIndex = phrase.indexOf("{"); | ||
}; | ||
SamplePhrase.prototype.phraseToRegex = function (phrase) { | ||
var startIndex = phrase.indexOf("{"); | ||
if (startIndex !== -1) { | ||
const endIndex = phrase.indexOf("}", startIndex); | ||
var endIndex = phrase.indexOf("}", startIndex); | ||
this.slotNames.push(phrase.substring(startIndex + 1, endIndex)); | ||
@@ -68,15 +69,16 @@ phrase = phrase.substring(0, startIndex).trim() + "(.*)" + phrase.substring(endIndex + 1).trim(); | ||
return phrase; | ||
} | ||
} | ||
}; | ||
return SamplePhrase; | ||
}()); | ||
exports.SamplePhrase = SamplePhrase; | ||
class SamplePhraseTest { | ||
constructor(samplePhrase, utterance) { | ||
var SamplePhraseTest = (function () { | ||
function SamplePhraseTest(samplePhrase, utterance) { | ||
this.samplePhrase = samplePhrase; | ||
this.utterance = utterance; | ||
this.matched = false; | ||
const cleanUtterance = utterance.replace(/[\!\"\¿\?|\#\$\%\/\(\)\=\+\-\_\<\>\*\{\}\·\¡\[\]\.\,\;\:]/g, ""); | ||
const matchArray = cleanUtterance.match(samplePhrase.regex()); | ||
var cleanUtterance = utterance.replace(/[\!\"\¿\?|\#\$\%\/\(\)\=\+\-\_\<\>\*\{\}\·\¡\[\]\.\,\;\:]/g, ""); | ||
var matchArray = cleanUtterance.match(samplePhrase.regex()); | ||
this.matched = false; | ||
if (matchArray) { | ||
const slotMatches = this.checkSlots(matchArray[0], matchArray.slice(1)); | ||
var slotMatches = this.checkSlots(matchArray[0], matchArray.slice(1)); | ||
if (slotMatches) { | ||
@@ -89,15 +91,17 @@ this.slotMatches = slotMatches; | ||
} | ||
matches() { | ||
SamplePhraseTest.prototype.matches = function () { | ||
return this.matched; | ||
} | ||
score() { | ||
let slotValueLength = 0; | ||
for (const slotValue of this.slotValues()) { | ||
}; | ||
SamplePhraseTest.prototype.score = function () { | ||
var slotValueLength = 0; | ||
for (var _i = 0, _a = this.slotValues(); _i < _a.length; _i++) { | ||
var slotValue = _a[_i]; | ||
slotValueLength += slotValue.length; | ||
} | ||
return this.matchString.length - slotValueLength; | ||
} | ||
scoreSlots() { | ||
let typed = 0; | ||
for (const slotMatch of this.slotMatches) { | ||
}; | ||
SamplePhraseTest.prototype.scoreSlots = function () { | ||
var typed = 0; | ||
for (var _i = 0, _a = this.slotMatches; _i < _a.length; _i++) { | ||
var slotMatch = _a[_i]; | ||
if (!slotMatch.untyped) { | ||
@@ -108,14 +112,16 @@ typed++; | ||
return typed; | ||
} | ||
slotValues() { | ||
const values = []; | ||
for (const slotMatch of this.slotMatches) { | ||
}; | ||
SamplePhraseTest.prototype.slotValues = function () { | ||
var values = []; | ||
for (var _i = 0, _a = this.slotMatches; _i < _a.length; _i++) { | ||
var slotMatch = _a[_i]; | ||
values.push(slotMatch.value); | ||
} | ||
return values; | ||
} | ||
checkSlots(input, slotValues) { | ||
const result = []; | ||
let index = 0; | ||
for (const slotValue of slotValues) { | ||
}; | ||
SamplePhraseTest.prototype.checkSlots = function (input, slotValues) { | ||
var result = []; | ||
var index = 0; | ||
for (var _i = 0, slotValues_1 = slotValues; _i < slotValues_1.length; _i++) { | ||
var slotValue = slotValues_1[_i]; | ||
if (input !== slotValue) { | ||
@@ -126,8 +132,8 @@ if (slotValue.trim().length > 0 && !slotValue.startsWith(" ") && !slotValue.endsWith(" ")) { | ||
} | ||
const slotName = this.samplePhrase.slotName(index); | ||
const slotType = this.intentSchema().intent(this.samplePhrase.intent).slotForName(slotName); | ||
var slotName = this.samplePhrase.slotName(index); | ||
var slotType = this.intentSchema().intent(this.samplePhrase.intent).slotForName(slotName); | ||
if (!slotType) { | ||
throw new Error("Invalid schema - not slot: " + slotName + " for intent: " + this.samplePhrase.intent); | ||
} | ||
const slotMatch = this.slotTypes().matchesSlot(slotType.type, slotValue); | ||
var slotMatch = this.slotTypes().matchesSlot(slotType.type, slotValue); | ||
if (!slotMatch.matches) { | ||
@@ -142,11 +148,12 @@ return undefined; | ||
return result; | ||
} | ||
intentSchema() { | ||
}; | ||
SamplePhraseTest.prototype.intentSchema = function () { | ||
return this.samplePhrase.sampleUtterances.interactionModel().intentSchema; | ||
} | ||
slotTypes() { | ||
}; | ||
SamplePhraseTest.prototype.slotTypes = function () { | ||
return this.samplePhrase.sampleUtterances.interactionModel().slotTypes; | ||
} | ||
} | ||
}; | ||
return SamplePhraseTest; | ||
}()); | ||
exports.SamplePhraseTest = SamplePhraseTest; | ||
//# sourceMappingURL=SampleUtterances.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class SlotTypes { | ||
constructor(slotTypes) { | ||
var SlotTypes = (function () { | ||
function SlotTypes(slotTypes) { | ||
this.types = []; | ||
for (const type of slotTypes) { | ||
for (var _i = 0, slotTypes_1 = slotTypes; _i < slotTypes_1.length; _i++) { | ||
var type = slotTypes_1[_i]; | ||
this.types.push(new SlotType(type.name, type.values)); | ||
} | ||
} | ||
addTypes(slotTypes) { | ||
SlotTypes.prototype.addTypes = function (slotTypes) { | ||
this.types = this.types.concat(slotTypes); | ||
} | ||
slotType(name) { | ||
let slotType; | ||
}; | ||
SlotTypes.prototype.slotType = function (name) { | ||
var slotType; | ||
name = name.toLowerCase(); | ||
for (const o of this.types) { | ||
for (var _i = 0, _a = this.types; _i < _a.length; _i++) { | ||
var o = _a[_i]; | ||
if (o.name.toLowerCase() === name) { | ||
@@ -23,7 +25,7 @@ slotType = o; | ||
return slotType; | ||
} | ||
matchesSlot(name, value) { | ||
const slotType = this.slotType(name); | ||
}; | ||
SlotTypes.prototype.matchesSlot = function (name, value) { | ||
var slotType = this.slotType(name); | ||
if (!slotType) { | ||
const match = new SlotMatch(true, value); | ||
var match = new SlotMatch(true, value); | ||
match.untyped = true; | ||
@@ -33,7 +35,8 @@ return match; | ||
return slotType.match(value); | ||
} | ||
} | ||
}; | ||
return SlotTypes; | ||
}()); | ||
exports.SlotTypes = SlotTypes; | ||
class SlotMatch { | ||
constructor(matches, value, enumeratedValue, slotValueSynonym) { | ||
var SlotMatch = (function () { | ||
function SlotMatch(matches, value, enumeratedValue, slotValueSynonym) { | ||
this.matches = matches; | ||
@@ -45,9 +48,11 @@ this.value = value; | ||
} | ||
} | ||
return SlotMatch; | ||
}()); | ||
exports.SlotMatch = SlotMatch; | ||
class SlotType { | ||
constructor(name, values) { | ||
var SlotType = (function () { | ||
function SlotType(name, values) { | ||
this.name = name; | ||
this.values = values; | ||
for (const value of values) { | ||
for (var _i = 0, values_1 = values; _i < values_1.length; _i++) { | ||
var value = values_1[_i]; | ||
if (value.builtin === undefined) { | ||
@@ -58,9 +63,10 @@ value.builtin = false; | ||
} | ||
isEnumerated() { | ||
SlotType.prototype.isEnumerated = function () { | ||
return !this.isBuiltin(); | ||
} | ||
isCustom() { | ||
let custom = false; | ||
}; | ||
SlotType.prototype.isCustom = function () { | ||
var custom = false; | ||
if (this.isBuiltin()) { | ||
for (const value of this.values) { | ||
for (var _i = 0, _a = this.values; _i < _a.length; _i++) { | ||
var value = _a[_i]; | ||
if (!value.builtin) { | ||
@@ -76,8 +82,8 @@ custom = true; | ||
return custom; | ||
} | ||
isBuiltin() { | ||
}; | ||
SlotType.prototype.isBuiltin = function () { | ||
return this.name.startsWith("AMAZON"); | ||
} | ||
match(value) { | ||
const matches = this.matchAll(value); | ||
}; | ||
SlotType.prototype.match = function (value) { | ||
var matches = this.matchAll(value); | ||
if (matches.length > 0) { | ||
@@ -90,7 +96,8 @@ return matches[0]; | ||
return new SlotMatch(false); | ||
} | ||
matchAll(value) { | ||
}; | ||
SlotType.prototype.matchAll = function (value) { | ||
value = value.trim(); | ||
const matches = []; | ||
for (const slotValue of this.values) { | ||
var matches = []; | ||
for (var _i = 0, _a = this.values; _i < _a.length; _i++) { | ||
var slotValue = _a[_i]; | ||
if (slotValue.name.value.toLowerCase() === value.toLowerCase()) { | ||
@@ -100,3 +107,4 @@ matches.push(new SlotMatch(true, value, slotValue)); | ||
else if (slotValue.name.synonyms) { | ||
for (const synonym of slotValue.name.synonyms) { | ||
for (var _b = 0, _c = slotValue.name.synonyms; _b < _c.length; _b++) { | ||
var synonym = _c[_b]; | ||
if (synonym.toLowerCase() === value.toLowerCase()) { | ||
@@ -109,5 +117,6 @@ matches.push(new SlotMatch(true, value, slotValue, synonym)); | ||
return matches; | ||
} | ||
} | ||
}; | ||
return SlotType; | ||
}()); | ||
exports.SlotType = SlotType; | ||
//# sourceMappingURL=SlotTypes.js.map |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
class Utterance { | ||
constructor(interactionModel, phrase) { | ||
var Utterance = (function () { | ||
function Utterance(interactionModel, phrase) { | ||
this.interactionModel = interactionModel; | ||
@@ -9,9 +9,9 @@ this.phrase = phrase; | ||
} | ||
intent() { | ||
Utterance.prototype.intent = function () { | ||
return this.matched() ? this.matchedSample.intent : undefined; | ||
} | ||
matched() { | ||
}; | ||
Utterance.prototype.matched = function () { | ||
return this.matchedSample !== undefined; | ||
} | ||
slot(index) { | ||
}; | ||
Utterance.prototype.slot = function (index) { | ||
if (!this.slots || index >= this.slots.length) { | ||
@@ -21,7 +21,7 @@ return undefined; | ||
return this.slots[index].trim(); | ||
} | ||
slotByName(name) { | ||
let slotValue; | ||
for (let i = 0; i < this.matchedSample.slotCount(); i++) { | ||
const slotName = this.matchedSample.slotName(i); | ||
}; | ||
Utterance.prototype.slotByName = function (name) { | ||
var slotValue; | ||
for (var i = 0; i < this.matchedSample.slotCount(); i++) { | ||
var slotName = this.matchedSample.slotName(i); | ||
if (slotName.toLowerCase() === name.toLowerCase()) { | ||
@@ -33,8 +33,8 @@ slotValue = this.slots[i].trim(); | ||
return slotValue; | ||
} | ||
toJSON() { | ||
const json = {}; | ||
}; | ||
Utterance.prototype.toJSON = function () { | ||
var json = {}; | ||
if (this.slots) { | ||
for (let i = 0; i < this.slots.length; i++) { | ||
const slotName = this.matchedSample.slotName(i); | ||
for (var i = 0; i < this.slots.length; i++) { | ||
var slotName = this.matchedSample.slotName(i); | ||
json[slotName] = this.slot(i); | ||
@@ -44,9 +44,11 @@ } | ||
return json; | ||
} | ||
matchIntent() { | ||
const matches = []; | ||
for (const intent of this.interactionModel.intentSchema.intents()) { | ||
const intentName = intent.name; | ||
for (const sample of this.interactionModel.sampleUtterances.samplesForIntent(intentName)) { | ||
const sampleTest = sample.matchesUtterance(this.phrase); | ||
}; | ||
Utterance.prototype.matchIntent = function () { | ||
var matches = []; | ||
for (var _i = 0, _a = this.interactionModel.intentSchema.intents(); _i < _a.length; _i++) { | ||
var intent = _a[_i]; | ||
var intentName = intent.name; | ||
for (var _b = 0, _c = this.interactionModel.sampleUtterances.samplesForIntent(intentName); _b < _c.length; _b++) { | ||
var sample = _c[_b]; | ||
var sampleTest = sample.matchesUtterance(this.phrase); | ||
if (sampleTest.matches()) { | ||
@@ -58,4 +60,5 @@ matches.push(sampleTest); | ||
if (matches.length > 0) { | ||
let topMatch; | ||
for (const match of matches) { | ||
var topMatch = void 0; | ||
for (var _d = 0, matches_1 = matches; _d < matches_1.length; _d++) { | ||
var match = matches_1[_d]; | ||
if (!topMatch || match.score() > topMatch.score()) { | ||
@@ -73,5 +76,6 @@ topMatch = match; | ||
} | ||
} | ||
} | ||
}; | ||
return Utterance; | ||
}()); | ||
exports.Utterance = Utterance; | ||
//# sourceMappingURL=Utterance.js.map |
@@ -5,7 +5,7 @@ { | ||
"private": false, | ||
"version": "0.0.12-0", | ||
"version": "0.0.12", | ||
"main": "./lib/src/Index.js", | ||
"typings": "./lib/src/Index.d.ts", | ||
"engines": { | ||
"node": "> 6.0.0" | ||
"node": "> 4.9.0" | ||
}, | ||
@@ -50,3 +50,3 @@ "files": [ | ||
"chai": "^4.1.2", | ||
"codecov": "^2.3.0", | ||
"codecov": "^3.0.2", | ||
"gulp": "^3.9.1", | ||
@@ -53,0 +53,0 @@ "gulp-typedoc": "^2.0.3", |
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
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
30799
509