From 8d4aeffff777bc9f49809cffe549f2f16796b903 Mon Sep 17 00:00:00 2001 From: Bora-Valar-Kara Date: Thu, 23 Oct 2025 23:09:30 +0200 Subject: [PATCH] lab1 --- src/dme.ts | 1 + src/is.ts | 10 +++++++++- src/nlug.ts | 25 +++++++++++++++++++++++++ src/rules.ts | 11 +++++++++++ src/types.ts | 2 +- test/dme.test.ts | 45 +++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 92 insertions(+), 2 deletions(-) diff --git a/src/dme.ts b/src/dme.ts index 43dcf61..582598d 100644 --- a/src/dme.ts +++ b/src/dme.ts @@ -122,6 +122,7 @@ export const dme = setup({ isuTransition("DowndateQUD", "integrate_usr_ask"), isuTransition("DowndateQUD", "integrate_answer"), isuTransition("DowndateQUD", "integrate_greet"), + isuTransition("DowndateQUD", "integrate_no_input"), { target: "DowndateQUD" }, ], }, diff --git a/src/is.ts b/src/is.ts index d04611d..25ff6d6 100644 --- a/src/is.ts +++ b/src/is.ts @@ -12,11 +12,14 @@ export const initialIS = (): InformationState => { // Mapping from predicate to sort favorite_food: "food", booking_course: "course", + booking_day: "day", }; const individuals: { [index: string]: string } = { // Mapping from individual to sort pizza: "food", LT2319: "course", + friday: "day", + tuesday: "day", }; return { domain: { @@ -27,6 +30,7 @@ export const initialIS = (): InformationState => { type: "issue", content: WHQ("booking_room"), plan: [ + findout(WHQ("booking_day")), findout(WHQ("booking_course")), consultDB(WHQ("booking_room")), ], @@ -37,9 +41,13 @@ export const initialIS = (): InformationState => { consultDB: (question, facts) => { if (objectsEqual(question, WHQ("booking_room"))) { const course = getFactArgument(facts, "booking_course"); - if (course == "LT2319") { + const day = getFactArgument(facts, "booking_day"); + if (course == "LT2319" && day == "friday") { return { predicate: "booking_room", argument: "G212" }; } + if (course == "LT2319" && day == "tuesday") { + return { predicate: "booking_room", argument: "J440" }; + } } return null; }, diff --git a/src/nlug.ts b/src/nlug.ts index eb1f618..8c1a890 100644 --- a/src/nlug.ts +++ b/src/nlug.ts @@ -37,6 +37,19 @@ const nluMapping: NLUMapping = { content: "LT2319", }, ], + friday: [ + { + type: "answer", + content: "friday", + }, + ], + tuesday: [ + { + type: "answer", + content: "tuesday", + }, + ], + "*no_input*": [], }; const nlgMapping: NLGMapping = [ [{ type: "ask", content: WHQ("booking_course") }, "Which course?"], @@ -55,6 +68,18 @@ const nlgMapping: NLGMapping = [ }, "The lecture is in G212.", ], + [{ type: "ask", content: WHQ("booking_day") }, "Which day?"], + [ + { + type: "answer", + content: { predicate: "booking_room", argument: "J440" }, + }, + "The lecture is in J440.", + ], + [ + { type: "icm:per:neg", content: null }, + "I didn't hear anything from you.", + ], ]; export function nlg(moves: Move[]): string { diff --git a/src/rules.ts b/src/rules.ts index a067b0e..3f6af70 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -144,6 +144,17 @@ export const rules: Rules = { /** TODO rule 2.8 integrate_sys_quit */ + /** negative perception feedback - when no user input */ + integrate_no_input: ({ is }) => { + // check if latest utterance is from user and has no moves (empty) + if (is.shared.lu!.speaker === "usr" && is.shared.lu!.moves.length === 0) { + return () => ({ + ...is, + next_moves: [{ type: "icm:per:neg", content: null }, ...is.next_moves], + }); + } + }, + /** * DowndateQUD */ diff --git a/src/types.ts b/src/types.ts index 067f8fc..6664d71 100644 --- a/src/types.ts +++ b/src/types.ts @@ -28,7 +28,7 @@ export type Question = WhQuestion; type WhQuestion = { type: "whq"; predicate: string }; interface OtherMove { - type: "greet" | "request"; + type: "greet" | "request" | "icm:per:neg"; content: null | string; } interface AnswerMove { diff --git a/test/dme.test.ts b/test/dme.test.ts index 442db45..1661408 100644 --- a/test/dme.test.ts +++ b/test/dme.test.ts @@ -137,9 +137,54 @@ describe("DME tests", () => { runTest([ { speaker: "sys", message: "Hello! You can ask me anything!" }, { speaker: "usr", message: "Where is the lecture?" }, + { speaker: "sys", message: "Which day?" }, + { speaker: "usr", message: "Friday" }, { speaker: "sys", message: "Which course?" }, { speaker: "usr", message: "Dialogue Systems 2" }, { speaker: "sys", message: "The lecture is in G212." }, ]); }); + + describe("system answer from database - Friday", () => { + runTest([ + { speaker: "sys", message: "Hello! You can ask me anything!" }, + { speaker: "usr", message: "Where is the lecture?" }, + { speaker: "sys", message: "Which day?" }, + { speaker: "usr", message: "Friday" }, + { speaker: "sys", message: "Which course?" }, + { speaker: "usr", message: "Dialogue Systems 2" }, + { speaker: "sys", message: "The lecture is in G212." }, + ]); + }); + + describe("system answer from database - Tuesday", () => { + runTest([ + { speaker: "sys", message: "Hello! You can ask me anything!" }, + { speaker: "usr", message: "Where is the lecture?" }, + { speaker: "sys", message: "Which day?" }, + { speaker: "usr", message: "Tuesday" }, + { speaker: "sys", message: "Which course?" }, + { speaker: "usr", message: "Dialogue Systems 2" }, + { speaker: "sys", message: "The lecture is in J440." }, + ]); + }); + + describe("Negative system contact feedback", () => { + runTest([ + { speaker: "sys", message: "Hello! You can ask me anything!" }, + { speaker: "usr", message: "*no_input*" }, + { speaker: "sys", message: "I didn't hear anything from you." }, + ]); + }); + + describe("Negative feedback followed by repeated question", () => { + runTest([ + { speaker: "sys", message: "Hello! You can ask me anything!" }, + { speaker: "usr", message: "Where is the lecture?" }, + { speaker: "sys", message: "Which day?" }, + { speaker: "usr", message: "*no_input*" }, + { speaker: "sys", message: "I didn't hear anything from you. Which day?" }, + ]); + }); + });