Skip to content

Commit

Permalink
FileThingpediaClient: fix getExamplesByKinds
Browse files Browse the repository at this point in the history
It should take an array of kinds, not a single string separated
by commas
  • Loading branch information
gcampax committed Oct 22, 2019
1 parent 592f3f2 commit 9ff085c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/file_thingpedia_client.js
Expand Up @@ -9,6 +9,7 @@
// See COPYING for details
"use strict";

const assert = require('assert');
const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const fs = require('fs');
Expand Down Expand Up @@ -111,16 +112,16 @@ class FileClient extends BaseClient {
}

async getExamplesByKinds(kinds) {
assert(Array.isArray(kinds));
await this._ensureLoaded();
const devices = kinds.split(',');

let examples = [];
for (let device of devices) {
for (let device of kinds) {
if (device in this._examples)
examples = examples.concat(this._examples[device]);
}

const name = `@org.thingpedia.dynamic.by_kinds.${devices.join('__')}`;
const name = `@org.thingpedia.dynamic.by_kinds.${kinds.join('__')}`;
let dataset = new Ast.Dataset(name, 'en', examples, {});
let library = new Ast.Input.Library([], [dataset]);
return library.prettyprint();
Expand Down
2 changes: 1 addition & 1 deletion test/test_file_client.js
Expand Up @@ -116,7 +116,7 @@ async function testGetExamples() {
ex.preprocessed.forEach((p) => assertNonEmptyString(p));
}

const bing = ThingTalk.Grammar.parse(await _fileClient.getExamplesByKinds('com.bing,com.google'));
const bing = ThingTalk.Grammar.parse(await _fileClient.getExamplesByKinds(['com.bing', 'com.google']));
assert(bing.isLibrary);
assert.strictEqual(bing.classes.length, 0);
assert.strictEqual(bing.datasets.length, 1);
Expand Down

0 comments on commit 9ff085c

Please sign in to comment.