forked from ChalmersGU-AI-course/shrdlite-course-project
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shrdlite-offline.ts
37 lines (31 loc) · 1 KB
/
shrdlite-offline.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
///<reference path="Shrdlite.ts"/>
///<reference path="TextWorld.ts"/>
///<reference path="ExampleWorlds.ts"/>
// Extract command line arguments:
var nodename = process.argv[0];
var jsfile = process.argv[1].replace(/^.*\//, "");
var worldname = process.argv[2];
var utterance = process.argv[3];
var usage = "Usage: " + nodename + " " + jsfile +
" (" + Object.keys(ExampleWorlds).join(" | ") + ")" +
" (utterance | example no.)";
if (process.argv.length != 4 || !ExampleWorlds[worldname]) {
console.error(usage);
process.exit(1);
}
var world = new TextWorld(ExampleWorlds[worldname]);
var example = parseInt(utterance);
if (!isNaN(example)) {
utterance = world.currentState.examples[example];
if (!utterance) {
console.error("Error: Cannot find example no. " + example);
process.exit(1);
}
}
world.printWorld(() => {
var plan = Shrdlite.parseUtteranceIntoPlan(world, utterance);
console.log();
world.performPlan(plan, () => {
world.printWorld();
});
});