Skip to content

Commit

Permalink
Lab 1 (Some comments are the methods I tried but they didn't work)
Browse files Browse the repository at this point in the history
  • Loading branch information
Braveoneone committed Sep 25, 2024
1 parent af22e0a commit 4acc5bf
Show file tree
Hide file tree
Showing 6 changed files with 155 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/azure.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export const KEY = "<INSERT AZURE KEY HERE>";
export const KEY = "4e763d7012be49e5a48c5db78d8c33b5";
3 changes: 3 additions & 0 deletions src/dme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
],
},
Expand Down Expand Up @@ -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" },
],
Expand Down
22 changes: 18 additions & 4 deletions src/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: {
Expand Down Expand Up @@ -56,20 +59,31 @@ 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")),
],
},
],
},
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;
},
Expand Down
19 changes: 18 additions & 1 deletion src/nlug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ interface NLUMapping {
[index: string]: Move[];
}
type NLGMapping = [Move, string][];

const nluMapping: NLUMapping = {
"where is the lecture?": [{
type: "ask",
Expand All @@ -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",
Expand All @@ -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 {
Expand Down
79 changes: 76 additions & 3 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ type Rules = {
context: TotalInformationState,
) => ((x: void) => InformationState) | undefined;
};

let answerMove: Question = { type: "whq", predicate: "" };

Check failure on line 15 in src/rules.ts

View workflow job for this annotation

GitHub Actions / build

'answerMove' is declared but its value is never read.
export const rules: Rules = {
clear_agenda: ({ is }) => {
return () => ({
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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 ]
Expand Down
40 changes: 39 additions & 1 deletion test/dme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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." },
]);
});
});

0 comments on commit 4acc5bf

Please sign in to comment.