From 4acc5bf6d55d9b7bb5902be35ae38392f74a9820 Mon Sep 17 00:00:00 2001 From: braveoneone <3282424963@qq.com> Date: Wed, 25 Sep 2024 04:13:00 +0200 Subject: [PATCH 1/2] Lab 1 (Some comments are the methods I tried but they didn't work) --- src/azure.ts | 2 +- src/dme.ts | 3 ++ src/is.ts | 22 +++++++++++--- src/nlug.ts | 19 +++++++++++- src/rules.ts | 79 ++++++++++++++++++++++++++++++++++++++++++++++-- test/dme.test.ts | 40 +++++++++++++++++++++++- 6 files changed, 155 insertions(+), 10 deletions(-) diff --git a/src/azure.ts b/src/azure.ts index f232e1d..2a89a5f 100644 --- a/src/azure.ts +++ b/src/azure.ts @@ -1 +1 @@ -export const KEY = ""; +export const KEY = "4e763d7012be49e5a48c5db78d8c33b5"; diff --git a/src/dme.ts b/src/dme.ts index 21a2c6b..47084d1 100644 --- a/src/dme.ts +++ b/src/dme.ts @@ -83,6 +83,8 @@ export const dme = setup({ isuTransition("SelectionDone", "select_ask"), isuTransition("SelectionDone", "select_answer"), isuTransition("SelectionDone", "select_other"), + isuTransition("SelectionDone", "select_icm_semneg"),// add select_icm_semneg transition + { target: "SelectionDone" }, ], }, @@ -121,6 +123,7 @@ export const dme = setup({ isuTransition("DowndateQUD", "integrate_sys_ask"), isuTransition("DowndateQUD", "integrate_usr_ask"), isuTransition("DowndateQUD", "integrate_answer"), + //isuTransition("DowndateQUD", "integrate_other_icm"), isuTransition("DowndateQUD", "integrate_greet"), { target: "DowndateQUD" }, ], diff --git a/src/is.ts b/src/is.ts index 0975cb1..0dfc71c 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", + course_day: "day", // weekday type }; const individuals: { [index: string]: string } = { // Mapping from individual to sort pizza: "food", LT2319: "course", + Monday: "day", + Thursday: "day", }; return { domain: { @@ -56,8 +59,9 @@ export const initialIS = (): InformationState => { { type: "issue", content: WHQ("booking_room"), - plan: [ - findout(WHQ("booking_course")), + plan: [//add question in plan orderly + findout(WHQ("booking_course")), + findout(WHQ("course_day")), consultDB(WHQ("booking_room")), ], }, @@ -65,11 +69,21 @@ export const initialIS = (): InformationState => { }, database: { consultDB: (question, facts) => { + // if (objectsEqual(question, WHQ("booking_room"))) { + // const course = getFactArgument(facts, "booking_course"); + // if (course == "LT2319") { + // return { predicate: "booking_room", argument: "G212" }; + // } + // } if (objectsEqual(question, WHQ("booking_room"))) { - const course = getFactArgument(facts, "booking_course"); - if (course == "LT2319") { + const day = getFactArgument(facts, "course_day"); + console.log(day); + if (day == "Monday") { return { predicate: "booking_room", argument: "G212" }; } + else if (day == "Thursday") { + return { predicate: "booking_room", argument: "J440" }; + } } return null; }, diff --git a/src/nlug.ts b/src/nlug.ts index dfd3741..c6374e3 100644 --- a/src/nlug.ts +++ b/src/nlug.ts @@ -5,7 +5,6 @@ interface NLUMapping { [index: string]: Move[]; } type NLGMapping = [Move, string][]; - const nluMapping: NLUMapping = { "where is the lecture?": [{ type: "ask", @@ -27,10 +26,21 @@ const nluMapping: NLUMapping = { type: "answer", content: "LT2319", }], + "monday": [{// answer in lowerCase + type: "answer", + content: "Monday", + }], + "thursday": [{ + type: "answer", + content: "Thursday", + }], }; const nlgMapping: NLGMapping = [ [{ type: "ask", content: WHQ("booking_course") }, "Which course?"], + [{ type: "ask", content: WHQ("course_day") }, "Which day?"], + [{ type: "ask", content: WHQ("sorry") }, "Sorry, I don’t understand."], [{ type: "greet", content: null }, "Hello! You can ask me anything!"], + //[{ type: "request", content: null }, "Sorry, I don’t understand."], [ { type: "answer", @@ -45,6 +55,13 @@ const nlgMapping: NLGMapping = [ }, "The lecture is in G212.", ], + [ + { + type: "answer", + content: { predicate: "booking_room", argument: "J440" }, + }, + "The lecture is in J440.", + ], ]; export function nlg(moves: Move[]): string { diff --git a/src/rules.ts b/src/rules.ts index 9c24cc0..561a4a1 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -12,7 +12,7 @@ type Rules = { context: TotalInformationState, ) => ((x: void) => InformationState) | undefined; }; - +let answerMove: Question = { type: "whq", predicate: "" }; export const rules: Rules = { clear_agenda: ({ is }) => { return () => ({ @@ -80,6 +80,27 @@ export const rules: Rules = { } }, + // integrate_other_icm: ({ is }) => { + + // if (Array.isArray(is.shared.lu!.moves) && is.shared.lu!.moves.length === 0) { + // // const a = move.content; + // // if (is.domain.relevant(a, topQUD)) { + // // let proposition = is.domain.combine(topQUD, a); + // // return () => ({ + // // ...is, + // // shared: { + // // ...is.shared, + // // com: [proposition, ...is.shared.com], + // // }, + // // }); + + // // } + // return () => ({ + // ...is, + // }); + // } + + // }, /** rule 2.3 */ integrate_usr_ask: ({ is }) => { if (is.shared.lu!.speaker === "usr") { @@ -257,7 +278,7 @@ export const rules: Rules = { let newIS = is; if ( is.private.agenda[0] && - ["findout", "raise"].includes(is.private.agenda[0].type) + ["findout", "raise"].includes(is.private.agenda[0].type) && is.shared.lu!.moves.length !== 0 ) { const q = is.private.agenda[0].content as Question; if (is.private.plan[0] && is.private.plan[0].type === "raise") { @@ -319,10 +340,62 @@ export const rules: Rules = { } } }, + //&& is.private.agenda[0] && ["findout", "raise"].includes(is.private.agenda[0].type) + // Negative system semantic understanding feedback + select_icm_semneg: ({ is }) => { + if (Array.isArray(is.shared.lu!.moves) && is.shared.lu!.moves.length === 0 && is.private.agenda[0]) { + const q = is.private.agenda[0].content as Question; + console.log("====================type====================",is.private.agenda[0]); + //const askMove: Move = { type: "request", content: "Sorry, I don’t understand." }; + return () => ({ + ...is, + next_moves: [ ...is.next_moves, { type: "ask", content: { type: 'whq', predicate: 'sorry' } }, { type: "ask", content: q } ] + });} + else if (Array.isArray(is.shared.lu!.moves) && is.shared.lu!.moves.length === 0 && !is.private.agenda[0]) { + console.log("====================type====================",is.private.agenda[0]); + return () => ({ + ...is, + next_moves: [ ...is.next_moves, { type: "ask", content: { type: 'whq', predicate: 'sorry' } } ] + }); + + } + // let newIS = is; + // const content_usr = newIS.shared.lu!.moves;// moves:[Array] + // //const q = newIS.private.agenda[0].content as Question; + // // const bell = [{ + // // predicate: "answer", + // // argument: "Sorry, I don’t understand.", + // // }]; + // //for (const bel of bell) { + // const answerMove: Move = { type: "answer", content: "Sorry, I don’t understand." }; + // if (Array.isArray(content_usr) && content_usr.length === 0 ) { + // newIS = { + // ...is, + // next_moves: [ ...is.next_moves, answerMove ], + // private: { + // ...is.private, + // agenda: [...is.private.agenda], + // } + // //private: { ...is.private, plan: [...is.private.plan.slice(1)] }, + // }; + // // return () => ({ + // // ...is, + // // next_moves: [ ...is.next_moves, answerMove, { type: "ask", content: q } ], + // // }); + + // // } else { + // // newIS = { + // // ...is, + // // next_moves: [ ...is.next_moves, { type: "ask", content: q } ], + // // }; + // } + // //} + // return () => newIS; + }, /** only for greet for now */ select_other: ({ is }) => { - if (is.private.agenda[0] && is.private.agenda[0].type === "greet") { + if (is.private.agenda[0] && is.private.agenda[0].type === "greet" ) { return () => ({ ...is, next_moves: [ ...is.next_moves, is.private.agenda[0] as Move ] diff --git a/test/dme.test.ts b/test/dme.test.ts index de53be1..04388f0 100644 --- a/test/dme.test.ts +++ b/test/dme.test.ts @@ -132,13 +132,51 @@ describe("DME tests", () => { ]); }); - describe("system answer from database", () => { + describe("system answer from database", () => {// change the describe run test content runTest([ { speaker: "sys", message: "Hello! You can ask me anything!" }, { speaker: "usr", message: "Where is the lecture?" }, { speaker: "sys", message: "Which course?" }, { speaker: "usr", message: "Dialogue Systems 2" }, + { speaker: "sys", message: "Which day?" }, + { speaker: "usr", message: "Monday" }, { speaker: "sys", message: "The lecture is in G212." }, ]); }); + + describe("system answer from database", () => {// change the describe run test content + runTest([ + { speaker: "sys", message: "Hello! You can ask me anything!" }, + { speaker: "usr", message: "Where is the lecture?" }, + { speaker: "sys", message: "Which course?" }, + { speaker: "usr", message: "Apple" }, + { speaker: "sys", message: "Sorry, I don’t understand. Which course?" }, + ]); + }); + + describe("system answer from database", () => {// change the describe run test content + runTest([ + { speaker: "sys", message: "Hello! You can ask me anything!" }, + { speaker: "usr", message: "Where is the lecture?" }, + { speaker: "sys", message: "Which course?" }, + { speaker: "usr", message: "Dialogue Systems" }, + { speaker: "sys", message: "Which day?" }, + { speaker: "usr", message: "banana" }, + { speaker: "sys", message: "Sorry, I don’t understand. Which day?" }, + ]); + }); + + describe("system answer from database", () => {// change the describe run test content + runTest([ + { speaker: "sys", message: "Hello! You can ask me anything!" }, + { speaker: "usr", message: "Orange" }, + { speaker: "sys", message: "Sorry, I don’t understand." }, + { speaker: "usr", message: "Where is the lecture?" }, + { speaker: "sys", message: "Which course?" }, + { speaker: "usr", message: "Dialogue Systems 2" }, + { speaker: "sys", message: "Which day?" }, + { speaker: "usr", message: "Thursday" }, + { speaker: "sys", message: "The lecture is in J440." }, + ]); + }); }); From c37a8a90ea6890087c89dc70a4e1231ae4e2cf46 Mon Sep 17 00:00:00 2001 From: braveoneone <3282424963@qq.com> Date: Wed, 16 Oct 2024 14:36:15 +0200 Subject: [PATCH 2/2] update type.ts --- src/nlug.ts | 2 +- src/rules.ts | 5 ++--- src/types.ts | 1 + 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/nlug.ts b/src/nlug.ts index c6374e3..1f004f1 100644 --- a/src/nlug.ts +++ b/src/nlug.ts @@ -38,7 +38,7 @@ const nluMapping: NLUMapping = { const nlgMapping: NLGMapping = [ [{ type: "ask", content: WHQ("booking_course") }, "Which course?"], [{ type: "ask", content: WHQ("course_day") }, "Which day?"], - [{ type: "ask", content: WHQ("sorry") }, "Sorry, I don’t understand."], + [{ type: "sorry", content: null }, "Sorry, I don’t understand."], [{ type: "greet", content: null }, "Hello! You can ask me anything!"], //[{ type: "request", content: null }, "Sorry, I don’t understand."], [ diff --git a/src/rules.ts b/src/rules.ts index 561a4a1..5ea12eb 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -12,7 +12,6 @@ type Rules = { context: TotalInformationState, ) => ((x: void) => InformationState) | undefined; }; -let answerMove: Question = { type: "whq", predicate: "" }; export const rules: Rules = { clear_agenda: ({ is }) => { return () => ({ @@ -349,13 +348,13 @@ export const rules: Rules = { //const askMove: Move = { type: "request", content: "Sorry, I don’t understand." }; return () => ({ ...is, - next_moves: [ ...is.next_moves, { type: "ask", content: { type: 'whq', predicate: 'sorry' } }, { type: "ask", content: q } ] + next_moves: [ ...is.next_moves, { type: "sorry", content: null}, { type: "ask", content: q } ] });} else if (Array.isArray(is.shared.lu!.moves) && is.shared.lu!.moves.length === 0 && !is.private.agenda[0]) { console.log("====================type====================",is.private.agenda[0]); return () => ({ ...is, - next_moves: [ ...is.next_moves, { type: "ask", content: { type: 'whq', predicate: 'sorry' } } ] + next_moves: [ ...is.next_moves, { type: "sorry", content: null } ] }); } diff --git a/src/types.ts b/src/types.ts index 127ab86..e0cd49b 100644 --- a/src/types.ts +++ b/src/types.ts @@ -33,6 +33,7 @@ type WhQuestion = { type: "whq"; predicate: string }; interface OtherMove { type: | "greet" + | "sorry" | "request"; content: null | string; }