Skip to content

Commit

Permalink
Remove more unused code
Browse files Browse the repository at this point in the history
From codepaths that can no longer be triggered
  • Loading branch information
gcampax committed Feb 22, 2022
1 parent 8171e17 commit 27827c8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 113 deletions.
45 changes: 4 additions & 41 deletions lib/templates/dialogue_acts/empty-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,9 @@ import {
ContextInfo,
makeAgentReply,
makeSimpleState,
addNewStatement,
} from '../state_manip';
import {
isValidSearchQuestion
} from './common';

type EmptySearch = [Ast.Expression|null, C.ParamSlot|null, boolean];
type EmptySearch = [Ast.Expression|null];

/**
* Agent dialogue act: a search command returned no result.
Expand All @@ -41,43 +37,10 @@ type EmptySearch = [Ast.Expression|null, C.ParamSlot|null, boolean];
* @param base - the base table used in the reply
* @param question - a search question used in the reply
*/
export function makeEmptySearchError(ctx : ContextInfo, [base, question, offerMonitor] : EmptySearch) {
export function makeEmptySearchError(ctx : ContextInfo, [base] : EmptySearch) {
if (base !== null && !C.isSameFunction(base.schema!, ctx.currentTableFunction!))
return null;
if (question !== null && !C.isSameFunction(ctx.currentTableFunction!, question.schema))
return null;

let type, state;
if (question !== null) {
if (!isGoodEmptySearchQuestion(ctx, question))
return null;

const arg = ctx.currentTableFunction!.getArgument(question.name);
if (!arg)
return null;
type = arg.type;
state = makeSimpleState(ctx, 'sys_empty_search_question', [question.name]);
} else if (offerMonitor) {
const monitor = C.tableToStream(ctx.current!.stmt.lastQuery!, { monitorItemID : true });
if (!monitor)
return null;
state = addNewStatement(ctx, 'sys_empty_search', null, 'proposed', monitor);
} else {
type = null;
state = makeSimpleState(ctx, 'sys_empty_search', null);
}
return makeAgentReply(ctx, state, [base, question], type);
}

function isGoodEmptySearchQuestion(ctx : ContextInfo, question : C.ParamSlot) {
const currentStmt = ctx.current!.stmt;
const currentTable = currentStmt.expression;
if (!isValidSearchQuestion(currentTable, [question]))
return false;

const ctxFilterTable = C.findFilterExpression(currentTable);
if (!ctxFilterTable || !C.filterUsesParam(ctxFilterTable.filter, question.name))
return false;

return true;
const state = makeSimpleState(ctx, 'sys_empty_search', null);
return makeAgentReply(ctx, state, [base]);
}
30 changes: 6 additions & 24 deletions lib/templates/dialogue_acts/list-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
// Author: Giovanni Campagna <gcampagn@cs.stanford.edu>


import assert from 'assert';

import { Ast, } from 'thingtalk';

import * as C from '../ast_manip';
Expand All @@ -31,7 +29,6 @@ import {
NameList,
makeAgentReply,
makeSimpleState,
addAction,
} from '../state_manip';
import {
isInfoPhraseCompatibleWithResult,
Expand All @@ -46,24 +43,16 @@ import {
export interface ListProposal {
results : Ast.DialogueHistoryResultItem[];
info : SlotBag|null;
action : Ast.Invocation|null;
hasLearnMore : boolean;
}

export function listProposalKeyFn({ results, info, action, hasLearnMore } : ListProposal) {
export function listProposalKeyFn({ results, info } : ListProposal) {
return {
idType: results[0].value.id ? results[0].value.id.getType() : null,
queryName: info ? info.schema!.qualifiedName : null,
actionName: action ? action.schema!.qualifiedName : null,
length: results.length
};
}

function checkInvocationCast(x : Ast.Invocation|Ast.FunctionCallExpression) : Ast.Invocation {
assert(x instanceof Ast.Invocation);
return x;
}

function checkListProposal(nameList : NameList, info : SlotBag|null, hasLearnMore : boolean) : ListProposal|null {
const { ctx, results } = nameList;
const resultType = results[0].value.id.getType();
Expand Down Expand Up @@ -102,8 +91,7 @@ function checkListProposal(nameList : NameList, info : SlotBag|null, hasLearnMor
}


const action = ctx.nextInfo && ctx.nextInfo.isAction ? checkInvocationCast(C.getInvocation(ctx.next!)) : null;
return { results, info, action, hasLearnMore };
return { results, info };
}

export type ThingpediaListProposal = [ContextInfo, SlotBag];
Expand Down Expand Up @@ -133,8 +121,7 @@ export function checkThingpediaListProposal(proposal : ThingpediaListProposal, a
if (!mergedInfo)
return null;

const action = ctx.nextInfo && ctx.nextInfo.isAction ? checkInvocationCast(C.getInvocation(ctx.next!)) : null;
return { results: ctx.results!, info: mergedInfo, action, hasLearnMore: false };
return { results: ctx.results!, info: mergedInfo };
}

export function makeListProposalFromDirectAnswers(...phrases : DirectAnswerPhrase[]) : ListProposal|null {
Expand Down Expand Up @@ -181,16 +168,14 @@ export function makeListProposalFromDirectAnswers(...phrases : DirectAnswerPhras

const results = ctx.results!.slice(0, phrases.length);

return { results, info: null, action: null, hasLearnMore: false };
return { results, info: null };
}

function makeListProposalReply(ctx : ContextInfo, proposal : ListProposal) {
const { results, action, hasLearnMore } = proposal;
const { results } = proposal;
const options : AgentReplyOptions = {
numResults: results.length
};
if (action || hasLearnMore)
options.end = false;
let dialogueAct;
switch (results.length) {
case 2:
Expand All @@ -205,10 +190,7 @@ function makeListProposalReply(ctx : ContextInfo, proposal : ListProposal) {
default:
dialogueAct = 'sys_recommend_many';
}
if (action === null)
return makeAgentReply(ctx, makeSimpleState(ctx, dialogueAct, null), proposal, null, options);
else
return makeAgentReply(ctx, addAction(ctx, dialogueAct, action, 'proposed'), proposal, null, options);
return makeAgentReply(ctx, makeSimpleState(ctx, dialogueAct, null), proposal, null, options);
}

export {
Expand Down
45 changes: 2 additions & 43 deletions lib/templates/dialogue_acts/recommendation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,17 @@ import {
ContextInfo,
makeAgentReply,
makeSimpleState,
addActionParam,
addNewItem,
} from '../state_manip';
import {
isInfoPhraseCompatibleWithResult,
findChainParam
} from './common';
import type { ListProposal } from './list-proposal';

export interface Recommendation {
ctx : ContextInfo;
topResult : Ast.DialogueHistoryResultItem;
info : SlotBag|null;
action : Ast.Invocation|null;
hasLearnMore : boolean;
hasAnythingElse : boolean;
}

export function recommendationKeyFn(rec : Recommendation) {
Expand All @@ -55,11 +50,6 @@ export function recommendationKeyFn(rec : Recommendation) {
};
}

function checkInvocationCast(x : Ast.Invocation|Ast.FunctionCallExpression) : Ast.Invocation {
assert(x instanceof Ast.Invocation);
return x;
}

function makeArgMinMaxRecommendation(ctx : ContextInfo, name : Ast.Value, base : Ast.Expression, param : C.ParamSlot, direction : 'asc'|'desc') {
const resultInfo = ctx.resultInfo!;
if (!resultInfo.argMinMaxField)
Expand Down Expand Up @@ -95,9 +85,6 @@ function makeRecommendation(ctx : ContextInfo, name : Ast.Value) : Recommendatio
return {
ctx, topResult,
info: null,
action: ctx.nextInfo && ctx.nextInfo.isAction ? checkInvocationCast(C.getInvocation(ctx.next!)) : null,
hasLearnMore: false,
hasAnythingElse: false
};
}

Expand All @@ -119,9 +106,6 @@ function makeThingpediaRecommendation(ctx : ContextInfo, info : SlotBag) : Recom
return {
ctx, topResult,
info,
action: ctx.nextInfo && ctx.nextInfo.isAction ? checkInvocationCast(C.getInvocation(ctx.next!)) : null,
hasLearnMore: false,
hasAnythingElse: false
};
}

Expand All @@ -145,9 +129,6 @@ function checkRecommendation(rec : Recommendation, info : SlotBag|null) : Recomm
return {
ctx: rec.ctx, topResult: rec.topResult,
info: merged,
action: rec.action,
hasLearnMore: rec.hasLearnMore,
hasAnythingElse: rec.hasAnythingElse
};
}

Expand All @@ -165,9 +146,6 @@ function makeDisplayResult(ctx : ContextInfo, info : SlotBag) : Recommendation|
return {
ctx, topResult,
info,
action: ctx.nextInfo && ctx.nextInfo.isAction ? checkInvocationCast(C.getInvocation(ctx.next!)) : null,
hasLearnMore: false,
hasAnythingElse: false
};
}

Expand All @@ -192,9 +170,6 @@ function combineDisplayResult(proposal : Recommendation, newInfo : SlotBag) {
ctx: proposal.ctx,
topResult: proposal.topResult,
info: maybeNewInfo,
action: proposal.action,
hasLearnMore: false,
hasAnythingElse: proposal.hasAnythingElse,
};
return newProposal;
}
Expand All @@ -216,40 +191,24 @@ function checkDisplayResult(proposal : Recommendation|null) {
}

function makeRecommendationReply(ctx : ContextInfo, proposal : Recommendation) {
const { topResult, action, hasLearnMore } = proposal;
const options : AgentReplyOptions = {
numResults: 1
};
if (action || hasLearnMore)
options.end = false;
if (action === null) {
return makeAgentReply(ctx, makeSimpleState(ctx, 'sys_recommend_one', null), proposal, null, options);
} else {
const chainParam = findChainParam(topResult, action);
if (!chainParam)
return null;
return makeAgentReply(ctx, addActionParam(ctx, 'sys_recommend_one', action, chainParam, topResult.value.id, 'proposed'),
proposal, null, options);
}
return makeAgentReply(ctx, makeSimpleState(ctx, 'sys_recommend_one', null), proposal, null, options);
}

function makeDisplayResultReply(ctx : ContextInfo, proposal : Recommendation) {
const { action, hasAnythingElse } = proposal;
const options : AgentReplyOptions = {
numResults: 1
};
if (action || hasAnythingElse)
options.end = false;
return makeAgentReply(ctx, makeSimpleState(ctx, 'sys_display_result', null), proposal, null, options);
}

export function makeDisplayResultReplyFromList(ctx : ContextInfo, proposal : ListProposal) {
const { results, action, hasLearnMore } = proposal;
const { results, } = proposal;
const options : AgentReplyOptions = {
numResults: results.length
};
if (action || hasLearnMore)
options.end = false;
return makeAgentReply(ctx, makeSimpleState(ctx, 'sys_display_result', null), proposal, null, options);
}

Expand Down
10 changes: 5 additions & 5 deletions lib/templates/dlg/empty-search.genie
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,17 @@ import * as C from '../ast_manip';
import ThingpediaLoader from '../load-thingpedia';
import { SlotBag } from '../slot_bag';

empty_search_error : [Ast.InvocationExpression|null, C.ParamSlot|null, boolean] = {
empty_search_error : [Ast.InvocationExpression|null] = {
["${sorry_preamble} {there are no ${base[plural=other]}|i cannot find any ${base[plural=one]}} {matching your request|with those characteristics|like that}."]:
(sorry_preamble, base:base_table) => [base, null, false],
(sorry_preamble, base:base_table) => [base],

["${sorry_preamble} {there are no ${base[plural=other]}|i cannot find any ${base[plural=one]}} at the moment {matching your request|with those characteristics|like that}. would you like to be notified when {there are|i have|you have} new ${base[plural=other]}?", priority=1]:
(sorry_preamble, base:base_table<is_monitorable=true>) => [base, null, true],
(sorry_preamble, base:base_table<is_monitorable=true>) => [base],

?inference {
["${sorry_preamble} i cannot find any result for your search. ", priority=-1]: (sorry_preamble) => [null, null, false];
["${sorry_preamble} i cannot find any result for your search. ", priority=-1]: (sorry_preamble) => [null];
}

["${sorry_preamble} ${message}.", priority=5]: (sorry_preamble, message: ctx_thingpedia_empty_result)
=> [null, null, false],
=> [null],
}

0 comments on commit 27827c8

Please sign in to comment.