Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
// See COPYING for details
"use strict";
const Tp = require('thingpedia');
const { getBestEntityMatch } = require('../lib/dialogs/entity_lookup');
const THINGPEDIA_URL = 'https://almond-dev.stanford.edu/thingpedia';
const _mockPlatform = {
locale: 'en-US',
getDeveloperKey() {
return null;
}
};
const _thingpediaClient = new Tp.HttpClient(_mockPlatform, THINGPEDIA_URL);
const TEST_CASES = [
['tt:cryptocurrency_code', 'bitcoin', 'btc', 'Bitcoin'],
['tt:cryptocurrency_code', 'bitcoin cash', 'bch', 'Bitcoin Cash'],
['tt:cryptocurrency_code', 'ethereum', 'eth', 'Ethereum'],
['sportradar:eu_soccer_team', 'juventus', 'juv', 'Juventus Turin'],
['sportradar:eu_soccer_team', 'inter', 'int', 'Inter Milan'],
['sportradar:eu_soccer_team', 'arsenal', 'ars', 'Arsenal FC'],
['sportradar:eu_soccer_team', 'barcelona', 'bar', 'FC Barcelona'],
['sportradar:us_soccer_team', 'san jose earthquakes', 'sje', "San Jose Earthquakes"],
['sportradar:us_soccer_team', 'sj earthquakes', 'sje', "San Jose Earthquakes"],
['sportradar:ncaafb_team', 'stanford cardinals', 'sta', 'Stanford Cardinal'],
this.tag = spec.tag;
this.locale = spec.language;
this.trained = spec.trained;
if (spec.use_exact)
this.exact = service.getExact(spec.language);
else
this.exact = new DummyExactMatcher(); // non default models don't get any exact match
this._modeldir = AbstractFS.resolve(Config.NL_MODEL_DIR, `./${spec.tag}:${spec.language}`);
if (Config.WITH_THINGPEDIA === 'embedded') {
const org = (spec.owner === null || spec.owner === 1) ? { is_admin: true, id: 1 } : { is_admin: false, id: spec.owner };
this.tpClient = new OrgThingpediaClient(spec.language, org);
} else {
this.tpClient = new Tp.HttpClient({
getDeveloperKey() {
return Config.NL_THINGPEDIA_DEVELOPER_KEY;
},
locale: spec.language,
}, Config.THINGPEDIA_URL);
}
}
const ThingTalk = require('thingtalk');
const Gettext = require('node-gettext');
const Tp = require('thingpedia');
const Almond = require('almond-dialog-agent');
const Intent = Almond.Intent;
const ParserClient = require('./parserclient');
const db = require('../../util/db');
const Config = require('../../config');
assert.strictEqual(Config.WITH_THINGPEDIA, 'external');
const gettext = new Gettext();
gettext.setLocale('en-US');
const schemas = new ThingTalk.SchemaRetriever(new Tp.HttpClient({
getDeveloperKey() {
return null;
},
locale: 'en-US',
}, Config.THINGPEDIA_URL), null, true);
function candidateToString(cand) {
if (cand.isProgram)
return `Program(${cand.program.prettyprint(true)})`;
else if (cand.isSetup)
return `Setup(${cand.program.prettyprint(true)})`;
else if (cand.isPermissionRule)
return `PermissionRule(${cand.rule.prettyprint(true)})`;
else
return String(cand);
}
module.exports.createMockEngine = function(thingpediaUrl) {
var thingpedia;
if (thingpediaUrl === 'mock')
thingpedia = _mockThingpediaClient;
else
thingpedia = new Tp.HttpClient(_mockPlatform, thingpediaUrl || THINGPEDIA_URL);
var schemas = new ThingTalk.SchemaRetriever(thingpedia, null, true);
return {
platform: _mockPlatform,
thingpedia: thingpedia,
schemas: schemas,
devices: new MockDeviceDatabase(),
apps: new MockAppDatabase(schemas),
discovery: new MockDiscoveryClient(),
messaging: new MockMessagingManager(),
remote: new MockRemote(schemas),
permissions: new MockPermissionManager(schemas)
};
};