Skip to content

Commit

Permalink
Fix LGTM warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
gcampax committed Oct 7, 2021
1 parent 6a18381 commit c1112b6
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
21 changes: 15 additions & 6 deletions lib/thingtalk-dialogues/synthesis-dialogue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ const enum PartialDialogueState {
*/
let partialDialogueID = 0;

/**
* Combine the id of the dialogue with the "tag" of the non-deterministic
* agent choice to form a single tag, used to identify contexts in the
* synthesis templates.
*/
function combineDialogueAgentTags(dialogueTag : number, agentTag : number) {
if (agentTag > 65535)
throw new Error('OVERFLOW: too many agent either choices');
return dialogueTag << 16 | agentTag;
}

/**
* A partial dialogue, during synthesis.
*
Expand Down Expand Up @@ -199,7 +210,7 @@ export default class SynthesisDialogue implements AbstractCommandIO, Synthesizer
context: this,
key: {
dialogue: this,
tag: this._id << 65536 | agentTurn.tag
tag: combineDialogueAgentTags(this._id, agentTurn.tag),
}
};
}
Expand Down Expand Up @@ -278,12 +289,10 @@ export default class SynthesisDialogue implements AbstractCommandIO, Synthesizer
placeholders : TemplatePlaceholderMap,
semantics : SemanticAction<[Ast.DialogueState, ...any[]], Ast.DialogueState>) {
let ctxNonTerm;
if (tag === null) {
if (tag === null)
ctxNonTerm = new NonTerminal('ctx_sys_dynamic_any', undefined, ['dialogue', this]);
} else {
assert(tag < 65536);
ctxNonTerm = new NonTerminal('ctx_sys_dynamic_any', undefined, ['tag', this._id << 65536 | tag]);
}
else
ctxNonTerm = new NonTerminal('ctx_sys_dynamic_any', undefined, ['tag', combineDialogueAgentTags(this._id, tag)]);

addTemplate(this._userGenerator, [ctxNonTerm], tmpl, placeholders, (ctx : AgentTurn, ...args : any[]) : UserReplyRecord|null => {
const result = semantics(ctx.state, ...args);
Expand Down
2 changes: 1 addition & 1 deletion lib/transaction-dialogues/context-phrases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ export class ContextPhraseCreator {
utterance.push(piece);
}

if (utterance && utterance.length) {
if (utterance.length) {
const value = [this.ctx, bag];
output.push({
symbol: this.contextTable.ctx_thingpedia_list_result,
Expand Down
1 change: 0 additions & 1 deletion lib/transaction-dialogues/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -290,7 +290,6 @@ export async function policy(dlg : DialogueInterface, startMode : PolicyStartMod
switch (cmd.type) {
case POLICY_NAME + '.end':
dlg.say(dlg._("alright, {bye|good bye}!"), StateM.makeSimpleState(ctx.state, POLICY_NAME, 'sys_end'));
lastReply = await dlg.flush();
return;

case POLICY_NAME + '.greet':
Expand Down

0 comments on commit c1112b6

Please sign in to comment.