How to use the thingpedia.FileClient function in thingpedia

To help you get started, we’ve selected a few thingpedia examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github stanford-oval / almond-cloud / tests / unit / test_example_names.js View on Github external
// This file is part of Almond
//
// Copyright 2019 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna 
//
// See COPYING for details
"use strict";

const Tp = require('thingpedia');
const ThingTalk = require('thingtalk');
const path = require('path');

const getExampleName = require('../../util/example_names');

const _schemaRetriever = new ThingTalk.SchemaRetriever(new Tp.FileClient({
    thingpedia: path.resolve(path.dirname(module.filename), './thingpedia.tt')
}), null, true);

const TEST_CASES = [
    [`query := @com.twitter.search();`, `Search`],

    [`query (p_hashtag : Entity(tt:hashtag)) := @com.twitter.search(), contains(hashtags, p_hashtag);`, `SearchByHashtags`],

    [`query (p_author : Entity(tt:username)) := @com.twitter.search(), author == p_author;`, `SearchByAuthor`],

    [`query (p_author1 : Entity(tt:username), p_author2 : Entity(tt:username)) := @com.twitter.search(), in_array(author, [p_author1, p_author2]);`,
    `SearchByAuthor`],

    [`query () := @thermostat.get_temperature();`, 'GetTemperature'],
    [`query (p_value : Measure(C)) := @thermostat.get_temperature(), value >= p_value;`, 'GetTemperatureByValueGreaterThan'],
    [`query (p_value : Measure(C)) := @thermostat.get_temperature(), value <= p_value;`, 'GetTemperatureByValueLessThan'],
github stanford-oval / genie-toolkit / tool / lib / thingtalk-dataset.js View on Github external
async read(locale, thingpedia, dataset) {
        const tpClient = new Tp.FileClient({ locale, thingpedia, dataset });
        const parsed = await this._loadDataset(tpClient);

        if (this._options.debug)
            console.log('Loaded ' + parsed.examples.length + ' templates');
        this._locale = locale;
        this._dataset = parsed;
    }
github stanford-oval / genie-toolkit / tool / sample-constants.js View on Github external
async execute(args) {
        const options = {
            locale: args.locale,
            rng: seedrandom.alea(args.random_seed),
            thingpedia_url: args.thingpedia_url,
            developer_key: args.developer_key,
            devices: args.devices,
            sample_size: args.sample_size
        };
        const tpClient = new Tp.FileClient(args);
        const schemaRetriever = new ThingTalk.SchemaRetriever(tpClient, null, !args.debug);
        const sampler = new ConstantSampler(schemaRetriever, options);
        const constants = await sampler.sample();
        args.output.end(constants.map((c) => c.join('\t')).join('\n'));

        StreamUtils.waitFinish(args.output);
    }
};
github stanford-oval / genie-toolkit / tool / mturk-validate.js View on Github external
async execute(args) {
        const tpClient = new Tp.FileClient(args);
        const schemaRetriever = new ThingTalk.SchemaRetriever(tpClient, null, !args.debug);
        const tokenizer = TokenizerService.get(process.env.GENIE_USE_TOKENIZER, true);

        let validationRejects = Promise.resolve();
        let validationCounts;

        if (args.validation_threshold > 0) {
            if (!args.validation_input)
                throw new Error(`Argument --validation-input is required when performing manual validation`);
            const validationInput = fs.createReadStream(args.validation_input)
                .pipe(csvparse({
                    columns: true,
                    delimiter: ',',
                    relax_column_count: true
                }))
                .pipe(new MT.ValidationRejecter({
github stanford-oval / almond-cloud / util / dataset.js View on Github external
async function loadCheatsheetFromFile(language, thingpedia, dataset, random = true, options = {}) {
    const tpClient = new Tp.FileClient({
        locale: language,
        thingpedia, dataset
    });
    const deviceNames = await tpClient.getAllDeviceNames(null);
    const devices = [];
    const devices_rev = {};
    for (let dev of deviceNames) {
        devices.push({
            primary_kind: dev.kind,
            name: dev.kind_canonical
        });
        devices_rev[dev.kind] = true;
    }

    let parsedExamples = ThingTalk.Grammar.parse(await tpClient.getAllExamples()).datasets[0].examples;
    const examples = parsedExamples.map((e) => {
github stanford-oval / genie-toolkit / tool / manual-annotate.js View on Github external
constructor(rl, lines, options) {
        super();

        this._rl = rl;

        const tpClient = new Tp.FileClient(options);
        this._schemas = new ThingTalk.SchemaRetriever(tpClient, null, true);
        this._parser = ParserClient.get(options.server, 'en-US');

        this._nextLine = lines[Symbol.iterator]();

        this._state = 'loading';
        this._candidates = undefined;
        this._utterance = undefined;
        this._preprocessed = undefined;
        this._entities = undefined;
        this._serial = options.offset - 2;
        this._id = undefined;

        rl.on('line', async (line) => {
            if (line.trim().length === 0 || this._state === 'loading') {
                rl.prompt();
github stanford-oval / genie-toolkit / tool / dialog-to-contextual.js View on Github external
async execute(args) {
        const tpClient = new Tp.FileClient(args);
        const schemas = new ThingTalk.SchemaRetriever(tpClient, null, true);
        const tokenizer = TokenizerService.get('local');

        readAllLines(args.input_file, '====')
            .pipe(new DialogParser())
            .pipe(new DialogToTurnStream({
                locale: args.locale,
                tokenizer,
                schemas,
                tokenized: args.tokenized,
                debug: args.debug
            }))
            .pipe(new DatasetStringifier())
            .pipe(args.output);

        await StreamUtils.waitFinish(args.output);
github stanford-oval / genie-toolkit / tool / sample.js View on Github external
let contexts;
        if (args.contextual) {
            if (!args.context_source)
                throw new Error(`--context-source is required if --contextual`);

            contexts = await readAllLines([fs.createReadStream(args.context_source)])
                .pipe(new DatasetParser({ preserveId: true }))
                .pipe(new ContextSourceLoader())
                .read();
        }

        const constants = await parseConstantFile(args.locale, args.constants);
        const [functionBlackList, deviceBlackList, functionHighValueList, functionWhiteList, deviceWhiteList] =
            await parseSamplingControlFile(args.sampling_control);

        const tpClient = new Tp.FileClient(args.locale, args.thingpedia, null);
        const schemaRetriever = new ThingTalk.SchemaRetriever(tpClient, null, !args.debug);

        const options = {
            rng: seedrandom.alea(args.random_seed),
            locale: args.locale,

            samplingStrategy: args.sampling_strategy,
            functionBlackList,
            deviceBlackList,
            functionHighValueList,
            functionWhiteList,
            deviceWhiteList,
            contexts,

            compoundOnly: !!args.compound_only,
            debug: args.debug
github stanford-oval / genie-toolkit / tool / manual-annotate-dialog.js View on Github external
constructor(rl, options) {
        super({ objectMode: true });

        this._rl = rl;

        const tpClient = new Tp.FileClient(options);
        this._schemas = new ThingTalk.SchemaRetriever(tpClient, null, true);
        this._parser = ParserClient.get(options.server, 'en-US');

        this._state = 'loading';

        this._serial = 0;

        this._currentDialog = [];

        this._dialogState = undefined;
        this._context = undefined;
        this._utterance = undefined;
        this._preprocessed = undefined;
        this._entities = undefined;
        this._candidates = undefined;