Skip to content

Commit

Permalink
part 2 works partly, issue with combining noNLU with QUD(?)
Browse files Browse the repository at this point in the history
  • Loading branch information
anurni committed Sep 30, 2024
1 parent b6a8689 commit 92cc9f4
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/dme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
],
},
Expand Down
21 changes: 19 additions & 2 deletions src/nlug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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!"],
Expand Down Expand Up @@ -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;
}

Expand Down
73 changes: 69 additions & 4 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
Move,
Action,
} from "./types";
import { objectsEqual } from "./utils";
import { consultDB, objectsEqual } from "./utils";

type Rules = {
[index: string]: (
Expand Down Expand Up @@ -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 } ],
Expand Down Expand Up @@ -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 ]
// });
// }
// }


};
8 changes: 5 additions & 3 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ type WhQuestion = { type: "whq"; predicate: string };
interface OtherMove {
type:
| "greet"
| "request";
| "request"
| "noNLU";
content: null | string;
}
interface AnswerMove {
Expand All @@ -45,7 +46,8 @@ interface AskMove {
content: Question;
}

export type Move = OtherMove | AnswerMove | AskMove;

export type Move = OtherMove | AnswerMove | AskMove ;

export type Action = {
type:
Expand All @@ -54,7 +56,7 @@ export type Action = {
| "raise"
| "findout"
| "consultDB";
content: null | Question;
content: null | Question ;
}

type Speaker = "usr" | "sys";
Expand Down
13 changes: 13 additions & 0 deletions test/dme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?" },

]);
});
});

0 comments on commit 92cc9f4

Please sign in to comment.