Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
return Q.try(() => {
// get the name, description and icon before we factor the remote rules out
var name = this._getName();
var description = this.describe();
var appMeta = { $icon: this.icon };
if (!this._hasTrigger)
appMeta.$conversation = this.manager.id;
[newprogram, sendprograms] = ThingTalk.Generate.factorProgram(this.manager.messaging, this.program);
if (newprogram !== null) {
var code = Ast.prettyprint(newprogram);
return this.manager.apps.loadOneApp(code, appMeta, undefined, undefined,
name, description, true);
}
}).then((app) => {
return Helpers.sendRules(this, sendprograms, app);
// Copyright 2017 The Board of Trustees of the Leland Stanford Junior University
//
// Author: Giovanni Campagna
//
// See COPYING for details
"use strict";
require('thingengine-core/lib/polyfill');
const Q = require('q');
const fs = require('fs');
const csv = require('csv');
const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Generate = ThingTalk.Generate;
const Type = ThingTalk.Type;
const SchemaRetriever = require('./deps/schema_retriever');
const db = require('../util/db');
const i18n = require('../util/i18n');
const STRICTLY_CHEATSHEET = false;
function getAllThingpediaSentences(dbClient, language) {
let target_jsons = new Set;
return db.selectAll(dbClient, "select * from example_utterances where type = 'thingpedia' and is_base = 1 and language = ? order by id asc", [language]).then((rows) => {
if (!STRICTLY_CHEATSHEET)
return rows;
return rows.filter((row) => {
if (target_jsons.has(row.target_json))
// -*- mode: js; indent-tabs-mode: nil; js-basic-offset: 4 -*-
//
// This file is part of Almond
//
// Copyright 2016 Giovanni Campagna
//
// See COPYING for details
"use strict";
const Q = require('q');
const assert = require('assert');
const ThingTalk = require('thingtalk');
const Ast = ThingTalk.Ast;
const Generate = ThingTalk.Generate;
const Describe = ThingTalk.Describe;
const Dialog = require('./dialog');
const DeviceChoiceDialog = require('./device_choice_dialog');
const SlotFillingDialog = require('./slot_filling_dialog');
const ValueCategory = require('./semantic').ValueCategory;
const Helpers = require('./helpers');
module.exports = class RuleDialog extends Dialog {
constructor() {
super();
this.program = null;
this._hasTrigger = false;
this._primitiveQuery = null;
this._primitiveAction = null;
return ThingTalk.Grammar.parseAndTypecheck(`now => @org.thingpedia.builtin.test.get_data(count=1,size=1byte), v_data := data => return;`, engine1.schemas).then((prog) => {
prog.principal = ThingTalk.Ast.Value.Entity(engine2.messaging.type + '-account:' + engine2.messaging.account, 'tt:contact', null);
for (let param of prog.rules[0].queries[0].in_params) {
if (param.name === 'size') {
param.value.value = sz;
break;
}
}
let [engine1prog] = ThingTalk.Generate.lowerReturn(engine1.messaging, prog);
prog.principal = null;
let uniqueId = uuid.v4();
console.log(`RTT test begin, size ${sz}, iteration ${i+1}`);
logfile.write(`${Date.now()}\ttest-begin\trtt ${sz} ${i+1}/3\n`);
return Q.Promise((resolve, reject) => {
let added = (newId) => {
if (newId !== uniqueId)
return;
conversation.removeListener('notify', added);
resolve();
}
let assistant = engine1.platform.getCapability('assistant');
let conversation = assistant.getConversation();
conversation.on('notify', added);
}).then((schema) => {
this.action.schema = schema;
this._slotFill(this.trigger, false);
this._slotFill(this.action, true);
return ThingTalk.Generate.codegenRule(schemas, this.trigger, this.action);
});
}
return db.selectAll(dbClient, "select kind from device_schema where approved_version is not null and kind_type <> 'global'", []).then((rows) => {
let kinds = rows.map(r => r.kind);
let schemaRetriever = new SchemaRetriever(dbClient, language);
let stream = ThingTalk.Generate.genRandomRules(kinds, schemaRetriever, N, {
applyHeuristics: true,
allowUnsynthesizable: false,
strictParameterPassing: true,
samplingPolicy: 'uniform',
actionArgConstantProbability: 0.7,
argConstantProbability: 0.3,
requiredArgConstantProbability: 0.9,
applyFiltersToInputs: false,
filterClauseProbability: 0.3
});
stream.on('data', (r) => {
//console.log('Rule #' + (i+1));
//i++;
if (format === 'turk') {
row = row.concat([makeId(), Ast.prettyprint(r, true).trim(), postprocess(describeProgram(gettext, r))]);
if (row.length === sentences_per_hit * 3) {
constructor(prim, scope) {
super();
this.prim = prim;
this._scope = scope;
this.icon = Helpers.getIcon(prim);
this._resolving = null;
this._paring = false;
this._options = null;
this._aux = null;
let [toFill, toConcretize] = ThingTalk.Generate.computeSlots(prim);
this.toFill = toFill;
this.toConcretize = toConcretize;
}
function makeProgram(stream, query, action, executor=null) {
let rule;
if (action)
action = new ThingTalk.Ast.Action.Invocation(action, null);
else
action = ThingTalk.Generate.notifyAction(executor ? 'return' : 'notify');
if (stream && query)
rule = new Ast.Statement.Rule(new Ast.Stream.Join(stream, query, [], null), [action]);
else if (stream)
rule = new Ast.Statement.Rule(stream, [action]);
else
rule = new Ast.Statement.Command(query, [action]);
return new Ast.Program([], [], [rule], executor);
}
var copy = {};
Object.assign(copy, assignments);
return into.push({ utterance: expanded,
assignments: copy });
}
let argname = argnames[i];
let argtype = argtypes[argname];
if (!argtype)
throw new TypeError('Invalid placeholder $' + argname);
let type = argtype;
if (argtype.isArray)
type = argtype.elem;
let choices = chooseValues(ThingTalk.Generate.genRandomValue(argname, type, true), usedValues);
let placeholder = getPlaceholder(type);
if (!choices)
throw new TypeError('Cannot expand placeholder $' + argname + ' of type ' + argtype);
var argnameRegex = '\\$' + argname;
if (!forcePlaceholder) {
choices.forEach(function(c) {
assignments[argname] = c;
let description = ThingTalk.Describe.describeArg(gettext, c, true);
expandRecursively(expanded.replace(new RegExp(argnameRegex, 'g'), description), i+1, false);
assignments[argname] = undefined;
});
}
_prettyprint() {
let rule;
if (!this._stream && !this._query && !this._action)
return 'Please choose at least one function.';
let stream = this._stream;
let query = this._query;
let action = this._action ? this._action : ThingTalk.Generate.notifyAction();
if (stream && query) {
rule = new Ast.Statement.Rule(
new Ast.Stream.Join(stream, query, [], null), [action]
);
} else if (stream) {
rule = new Ast.Statement.Rule(stream, [action]);
} else {
rule = new Ast.Statement.Command(query, [action]);
}
return new Ast.Input.Program([], [], [rule]).prettyprint();
}