How to use the thingtalk.Type function in thingtalk

To help you get started, we’ve selected a few thingtalk 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-dialog-agent / test / auto_test_almond.js View on Github external
[(almond) => {
        almond.askQuestion(null, 'org.thingpedia.builtin.test', ThingTalk.Type.Number, 'What is the answer to life the universe and everything?').then((v) => {
            assert.strictEqual(v, 42);
        });

        // inject a meaningless intent so we synchronize the two concurrent tasks
        return almond.handleParsedCommand({ code: ['bookkeeping', 'special', 'special:wakeup'], entities: {} });
    },
`>> What is the answer to life the universe and everything?
github stanford-oval / genie-toolkit / lib / sentence-generator / index.js View on Github external
//
// Copyright 2017-2018 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna 
//
// See COPYING for details
"use strict";

const assert = require('assert');
const stream = require('stream');
const path = require('path');
const events = require('events');

const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;
const Grammar = ThingTalk.Grammar;
const SchemaRetriever = ThingTalk.SchemaRetriever;
const NNSyntax = ThingTalk.NNSyntax;
const Units = ThingTalk.Units;

const { clean, makeDummyEntities } = require('../utils');

const $runtime = require('./runtime');
const importGenie = require('../genie-compiler');
const { typeToStringSafe } = require('../../languages/ast_manip');
const i18n = require('../i18n');

function identity(x) {
    return x;
}
github stanford-oval / almond-cloud / util / gen_random_rule.js View on Github external
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of ThingEngine
//
// Copyright 2016 Giovanni Campagna 
//
// See COPYING for details
"use strict";

const Q = require('q');
const stream = require('stream');

const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Type = ThingTalk.Type;
// FIXME
const ThingTalkUtils = require('thingtalk/lib/utils');

const db = require('./db');
const genValueList = require('./gen_random_value');

function sample(distribution) {
    var keys = Object.keys(distribution);
    var sums = new Array(keys.length);
    var rolling = 0;
    for (var i = 0; i < keys.length; i++) {
        sums[i] = rolling + distribution[keys[i]];
        rolling = sums[i];
    }

    var total = sums[keys.length-1];
github stanford-oval / genie-toolkit / tool / webqa-process-schemaorg.js View on Github external
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of Genie
//
// Copyright 2019 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna 
//
// See COPYING for details
"use strict";

const assert = require('assert');
const POS = require("en-pos");
const Tp = require('thingpedia');
const ThingTalk = require('thingtalk');
const Type = ThingTalk.Type;
const Ast = ThingTalk.Ast;
const fs = require('fs');
const util = require('util');

const { clean, pluralize } = require('../lib/utils');
const StreamUtils = require('../lib/stream-utils');

const keepAnnotation = false;

function getId(id) {
    assert(id.startsWith('http://schema.org/'));
    return id.substring('http://schema.org/'.length);
}

function getIncludes(includes) {
    if (Array.isArray(includes))
github stanford-oval / almond-cloud / browser / deps / intent.js View on Github external
Intent.parse = async function parse(json, schemaRetriever, context) {
    if ('program' in json)
        return Intent.fromThingTalk(await ThingTalk.Grammar.parseAndTypecheck(json.program, schemaRetriever, true), context);

    let { code, entities } = json;
    for (let name in entities) {
        if (name.startsWith('SLOT_')) {
            let slotname = json.slots[parseInt(name.substring('SLOT_'.length))];
            let slotType = ThingTalk.Type.fromString(json.slotTypes[slotname]);
            let value = ThingTalk.Ast.Value.fromJSON(slotType, entities[name]);
            entities[name] = value;
        }
    }

    const thingtalk = ThingTalk.NNSyntax.fromNN(code, entities);
    await thingtalk.typecheck(schemaRetriever, true);
    return Intent.fromThingTalk(thingtalk, context);
};
github stanford-oval / thingengine-core / node_modules / sabrina / lib / sabrina.js View on Github external
'show': [],
    },
    DeviceVerbToActionMap: {
        'scale': {},
        'tv': {
            'turn on': ['setpower', Parameter.Constant(true)],
            'turn off': ['setpower', Parameter.Constant(false)]
        },
        'lightbulb': {
            'turn on': ['setpower', Parameter.Constant(true)],
            'turn off': ['setpower', Parameter.Constant(false)]
        },
    },
    AbsoluteVerbToActionMap: {
        'tweet': ['twitter', 'sink', Parameter.Input("What do you want me to tweet?",
                                                     ThingTalk.Type.String)]
    },

    VerbToActionMap: {
        'tt:device.action.post': {
            'tt:missing': ['twitter', 'facebook'],
            'tt:device.twitter': ['twitter', 'sink', Parameter.Input("What do you want me to tweet?",
                                                                     ThingTalk.Type.String)],
            'tt:device.facebook': ['facebook', 'post', Parameter.Input("What do you want me to post on Facebook?",
                                                                       ThingTalk.Type.String)]
        }
    },
};

const LambdaForm = adt.data(function() {
    return {
        Atom: { name: adt.only(String) },
github stanford-oval / almond-cloud / scripts / gen_primitive.js View on Github external
meta.schema.forEach((typestr, i) => {
        var type = ThingTalk.Type.fromString(typestr);
        var argname = meta.args[i];
        var argcanonical = meta.argcanonicals[i];
        var argrequired = channelType === 'action' || meta.required[i];

        if (PARAMS_BLACK_LIST.indexOf(argname) > -1) {
            return;
        }
        else if (type.isEntity && type.type == 'tt:picture')
            return;
        else if (type.isTime)
            return;
        else if (!argrequired && !type.isEnum && !coin(0.2))
            return;
        else 
            var [sempreType, value] = chooseRandomValue(argname, type);
        if (!sempreType)
github stanford-oval / almond-dialog-agent / lib / semantic.js View on Github external
Intent.parse = async function parse(json, schemaRetriever, context) {
    if ('program' in json)
        return Intent.fromThingTalk(await ThingTalk.Grammar.parseAndTypecheck(json.program, schemaRetriever, true), context);

    let { code, entities } = json;
    for (let name in entities) {
        if (name.startsWith('SLOT_')) {
            let slotname = json.slots[parseInt(name.substring('SLOT_'.length))];
            let slotType = ThingTalk.Type.fromString(json.slotTypes[slotname]);
            let value = ThingTalk.Ast.Value.fromJSON(slotType, entities[name]);
            entities[name] = value;
        }
    }

    const thingtalk = ThingTalk.NNSyntax.fromNN(code, entities);
    await thingtalk.typecheck(schemaRetriever, true);
    return Intent.fromThingTalk(thingtalk, context);
};
github stanford-oval / almond-cloud / scripts / verify_all.js View on Github external
_parseMetaTypes(channels) {
        for (var name in channels)
            channels[name].schema = channels[name].schema.map(ThingTalk.Type.fromString);
    }