From 92cc9f45604d1d47c4a661cc428ee7529e51d7d9 Mon Sep 17 00:00:00 2001 From: anurni Date: Mon, 30 Sep 2024 14:35:43 +0200 Subject: [PATCH] part 2 works partly, issue with combining noNLU with QUD(?) --- src/dme.ts | 1 + src/nlug.ts | 21 ++++++++++++-- src/rules.ts | 73 +++++++++++++++++++++++++++++++++++++++++++++--- src/types.ts | 8 ++++-- test/dme.test.ts | 13 +++++++++ 5 files changed, 107 insertions(+), 9 deletions(-) diff --git a/src/dme.ts b/src/dme.ts index 21a2c6b..6e7f11e 100644 --- a/src/dme.ts +++ b/src/dme.ts @@ -75,6 +75,7 @@ export const dme = setup({ always: [ isuTransition("SelectMove", "select_respond"), isuTransition("SelectMove", "select_from_plan"), + isuTransition("SelectMove", "selectIcmSemNeg"), { target: "SelectMove" }, // TODO check it -- needed for greeting ], }, diff --git a/src/nlug.ts b/src/nlug.ts index 541d1cf..513013b 100644 --- a/src/nlug.ts +++ b/src/nlug.ts @@ -37,6 +37,7 @@ const nluMapping: NLUMapping = { }], }; const nlgMapping: NLGMapping = [ + [{ type: "noNLU", content: null }, "Sorry, I don't understand."], [{ type: "ask", content: WHQ("booking_course") }, "Which course?"], [{ type: "ask", content: WHQ("course_day")}, "Which day?"], [{ type: "greet", content: null }, "Hello! You can ask me anything!"], @@ -64,16 +65,32 @@ const nlgMapping: NLGMapping = [ ]; export function nlg(moves: Move[]): string { + // if ( moves.length === 0) { + // return "no moves" + // } console.log("generating moves", moves); function generateMove(move: Move): string { const mapping = nlgMapping.find((x) => objectsEqual(x[0], move)); + //console.log(`This is the the value for const mapping ${mapping}`) if (mapping) { + //console.log(`This is the value of mapping[0] ${mapping[0]}`) + //console.log(`This is the move ${move}`) + //console.log(`This is the value of mapping[1] ${mapping[1]}`) + //console.log(`Mapping of move type : ${move.type}`) + //console.log(`This is the move stringified ${JSON.stringify(move)}`) return mapping[1]; } - throw new Error(`Failed to generate move ${JSON.stringify(move)}`); + if (mapping !== undefined) { + //console.log(`Mapping of ${move.type} is undefined`); + return mapping[1]; + } + else { + //console.log(`Mapping of ${move.type} not found`) + throw new Error(`Failed to generate move ${JSON.stringify(move)}`); + } } const utterance = moves.map(generateMove).join(' '); - console.log("generated utterance:", utterance); + //console.log("generated utterance:", utterance); return utterance; } diff --git a/src/rules.ts b/src/rules.ts index 9c24cc0..812e5f1 100644 --- a/src/rules.ts +++ b/src/rules.ts @@ -5,7 +5,7 @@ import { Move, Action, } from "./types"; -import { objectsEqual } from "./utils"; +import { consultDB, objectsEqual } from "./utils"; type Rules = { [index: string]: ( @@ -266,7 +266,8 @@ export const rules: Rules = { next_moves: [ ...is.next_moves, { type: "ask", content: q } ], private: { ...is.private, plan: [...is.private.plan.slice(1)] }, }; - } else { + } + else { newIS = { ...is, next_moves: [ ...is.next_moves, { type: "ask", content: q } ], @@ -320,13 +321,77 @@ export const rules: Rules = { } }, - /** only for greet for now */ + /** for greeting */ select_other: ({ is }) => { if (is.private.agenda[0] && is.private.agenda[0].type === "greet") { + //console.log(`this is is.private.agenda ${is.private.agenda[0].content}`) + //console.log(`this is is.private.agenda's type ${is.private.agenda[0].type}`) + //console.log(`this is is.shared.lu?.moves.length ${is.shared.lu?.moves.length}`) + //console.log(`this is is.shared.lu? ${Array.isArray(is.shared.lu?.moves[0])}`) + //console.log(`this is is.shared.lu?.moves.length ${is.shared.lu?.moves.length}`) return () => ({ ...is, - next_moves: [ ...is.next_moves, is.private.agenda[0] as Move ] + next_moves: [ ...is.next_moves, is.private.agenda[0] as Move ], }); } }, + + + + /** for no NLU situations - rule 3.12*/ + // selectIcmSemNeg: ({ is }) => { + // if(Array.isArray(is.shared.lu?.moves) && is.shared.lu.moves.length === 0) { + // const noNLU = {type: "noNLU", content: null} + // //console.log(`------------------->this is is.shared.qud ${is.shared.qud[0]}`) + // //console.log(`------------------->this is is.shared.qud ${is.shared.qud}`) + // return () => ({ + // ...is, + // next_moves: [ ...is.next_moves, noNLU as Move ] + // }); + // } + // }, + +/** for no NLU situations - rule 3.12 */ +selectIcmSemNeg: ({ is }) => { + // Check if NLU moves are empty + if (Array.isArray(is.shared.lu?.moves) && is.shared.lu.moves.length === 0) { + + let noNLU; + console.log(`----------------------this is the else working-------------------------------------`) + console.log(`--------------------------${is.shared.lu.moves}--------------------------------`) + console.log(`----------------${is.domain.plans[0].plan[0].content?.predicate}----------------------------------------------------------------`) + noNLU = { + type: "noNLU", + content: null + }; + + + // Update next_moves with noNLU move + return () => ({ + ...is, + next_moves: [...is.next_moves, noNLU as Move] + }); + } +}, + +//checkLastMove: ({ is }) => { + //if (is.shared.lu?.moves.) + + + + + // repeatQuestion: ({ is }) => { + // if(Array.isArray(is.shared.lu?.moves) && is.shared.lu.moves.length === 0 && is.shared.qud) { + // const noNLU = {type: "noNLU", content: null} + // const q = is.private.agenda[0].content as Question; + // console.log(`------------------->this is is.shared.qud ${is.shared.qud[0]}`) + // console.log(`------------------->this is is.shared.qud ${is.shared.qud}`) + // return () => ({ + // ...is, + // next_moves: [ ...is.next_moves, noNLU { type: "ask", content: q } as Move ] + // }); + // } + // } + + }; diff --git a/src/types.ts b/src/types.ts index 127ab86..3528013 100644 --- a/src/types.ts +++ b/src/types.ts @@ -33,7 +33,8 @@ type WhQuestion = { type: "whq"; predicate: string }; interface OtherMove { type: | "greet" - | "request"; + | "request" + | "noNLU"; content: null | string; } interface AnswerMove { @@ -45,7 +46,8 @@ interface AskMove { content: Question; } -export type Move = OtherMove | AnswerMove | AskMove; + +export type Move = OtherMove | AnswerMove | AskMove ; export type Action = { type: @@ -54,7 +56,7 @@ export type Action = { | "raise" | "findout" | "consultDB"; - content: null | Question; + content: null | Question ; } type Speaker = "usr" | "sys"; diff --git a/test/dme.test.ts b/test/dme.test.ts index 509be52..d7a704b 100644 --- a/test/dme.test.ts +++ b/test/dme.test.ts @@ -143,4 +143,17 @@ describe("DME tests", () => { { speaker: "sys", message: "The lecture is in J440." }, ]); }); + + describe("system answer in case of no NLU", () => { + runTest([ + { speaker: "sys", message: "Hello! You can ask me anything!" }, + { speaker: "usr", message: "blablablablaaaaa" }, + { speaker: "sys", message: "Sorry, I don't understand." }, + { speaker: "usr", message: "Where is the lecture?" }, + { speaker: "sys", message: "Which course?" }, + { speaker: "usr", message: "blablablablaaaaa" }, + { speaker: "sys", message: "Sorry, I don't understand. Which course?" }, + + ]); + }); });