Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Merge a233a6d into 44e813e
Browse files Browse the repository at this point in the history
  • Loading branch information
ecruzado committed May 15, 2018
2 parents 44e813e + a233a6d commit 530bac6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
2 changes: 1 addition & 1 deletion bin/bst-launch.ts
Expand Up @@ -52,7 +52,7 @@ program

const speaker = new BSTVirtualAlexa(url, interactionModel, intentSchemaPath, samplesPath, applicationID, locale);
try {
speaker.start();
speaker.start(true);
} catch (error) {
process.exit(0);
return;
Expand Down
13 changes: 8 additions & 5 deletions lib/client/bst-virtual-alexa.ts
Expand Up @@ -16,6 +16,7 @@ export class BSTVirtualAlexa {
public static DefaultIntentSchemaLocation = "speechAssets/IntentSchema.json";
public static DefaultSampleUtterancesLocation = "speechAssets/SampleUtterances.txt";
public static DefaultInteractionModelLocation = "models/en-US.json";
static DefaultInteractionModel = { interactionModel: { languageModel: { invocationName: "", intents: [] }}};

private virtualAlexa: VirtualAlexa = null;
private interactionModelProvided: boolean = false;
Expand Down Expand Up @@ -132,7 +133,7 @@ export class BSTVirtualAlexa {
}
}

private validateFilesAndBuild(): VirtualAlexa {
private validateFilesAndBuild(createdEmptyInteractionModelIfNeeded: boolean): VirtualAlexa {
const builder = VirtualAlexa.Builder().applicationID(this.applicationID).skillURL(this.skillURL);
let usingInteractionModel = false;

Expand All @@ -144,11 +145,12 @@ export class BSTVirtualAlexa {
}
}


if (!(this.interactionModelProvided || this.intentSchemaProvided)) {
// No model provided, we check if default files exists
if (fs.existsSync(this.interactionModel)) {
usingInteractionModel = true;
} else if (!(fs.existsSync(this.intentSchemaFile) && fs.existsSync(this.sampleUtterancesFile))) {
} else if (!(fs.existsSync(this.intentSchemaFile) && fs.existsSync(this.sampleUtterancesFile)) && !createdEmptyInteractionModelIfNeeded) {
// Model don't exist in default locations
console.error("Error loading Interaction model, no file provided and none found in default locations");
throw new Error("Error loading Interaction model, no file provided and none found in default locations");
Expand All @@ -173,19 +175,20 @@ export class BSTVirtualAlexa {
if (usingInteractionModel) {
this.validateJsonFiles(this.interactionModel, BSTVirtualAlexa.FileTypes.InterationModel);
builder.interactionModelFile(this.interactionModel);
} else if (createdEmptyInteractionModelIfNeeded) {
builder.interactionModel(BSTVirtualAlexa.DefaultInteractionModel);
} else {
this.validateJsonFiles(this.intentSchemaFile, BSTVirtualAlexa.FileTypes.IntentSchema);
builder.intentSchemaFile(this.intentSchemaFile).sampleUtterancesFile(this.sampleUtterancesFile);
}

return builder.create();
}

/**
* Start the emulator
*/
public start(): void {
this.virtualAlexa = this.validateFilesAndBuild();
public start(createdEmptyInteractionModelIfNeeded?: boolean): void {
this.virtualAlexa = this.validateFilesAndBuild(createdEmptyInteractionModelIfNeeded);
}

/**
Expand Down
8 changes: 8 additions & 0 deletions test/client/bst-virtual-alexa-test.ts
Expand Up @@ -92,6 +92,14 @@ describe("BSTVirtualAlexa", async function() {
process.chdir("../..");
});

it("Start with defaults and non english model", function () {
process.chdir("test/resources/nonUSModel");
const speak = new BSTVirtualAlexa("http://localhost:9000");
speak.start(true);
assert(true, "Start processed without exceptions");
process.chdir("../../..");
});

it("Use provided models even when default is present in folder", function () {
process.chdir("test/resources/allSpeechModels");
const speak = new BSTVirtualAlexa("http://localhost:9000",
Expand Down

0 comments on commit 530bac6

Please sign in to comment.