Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lab 1 #7

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 13 additions & 1 deletion src/is.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ 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",
thursday : "day",
monday : "day",

};
return {
domain: {
Expand Down Expand Up @@ -58,6 +62,7 @@ export const initialIS = (): InformationState => {
content: WHQ("booking_room"),
plan: [
findout(WHQ("booking_course")),
findout(WHQ("booking_day")),
consultDB(WHQ("booking_room")),
],
},
Expand All @@ -67,12 +72,19 @@ export const initialIS = (): InformationState => {
consultDB: (question, facts) => {
if (objectsEqual(question, WHQ("booking_room"))) {
const course = getFactArgument(facts, "booking_course");
if (course == "LT2319") {
const booking_day = getFactArgument(facts, "booking_day");
if (course == "LT2319" && booking_day == "monday") {
return { predicate: "booking_room", argument: "G212" };
}
if (course == "LT2319" && booking_day == "thursday") {
return { predicate: "booking_room", argument: "J440" };
}
}

return null;
},


},
next_moves: [],
private: {
Expand Down
55 changes: 54 additions & 1 deletion src/nlug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,34 @@ const nluMapping: NLUMapping = {
type: "ask",
content: WHQ("booking_room"),
}],
"which day is the lecture": [{
type: "ask",
content: WHQ("booking_day"),
}],

"what's your favorite food?": [{
type: "ask",
content: WHQ("favorite_food"),
}],

/* "I am sorry, I don't understand you.": [{
type: "FailedNlu",
content: null,
}], */

monday: [{
type: "answer",
content: "monday",
}],

thursday: [{
type: "answer",
content: "thursday",
}],




pizza: [{
type: "answer",
content: "pizza",
Expand All @@ -27,10 +51,25 @@ const nluMapping: NLUMapping = {
type: "answer",
content: "LT2319",
}],



};


const nlgMapping: NLGMapping = [
[{ type: "ask", content: WHQ("booking_course") }, "Which course?"],
[{type: "ask", content: WHQ("booking_course") }, "Which course?"],
[{ type: "ask", content: WHQ("booking_day") }, "Which day is the lecture?"],
[{type: "greet", content: null }, "Hello! You can ask me anything!"],
[{type : "FailedNlu", content: null}, "I am sorry, I don't understand you."],

/* [{ type: "ask", content: WHQ("booking_course") }, "Which course?"],
[{ type: "greet", content: null }, "Hello! You can ask me anything!"],
[{ type: "ask", content: WHQ("booking_day") }, "Which day is the lecture?"], */




[
{
type: "answer",
Expand All @@ -45,6 +84,20 @@ 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
35 changes: 34 additions & 1 deletion src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,17 @@ export const rules: Rules = {
next_moves: [ ...is.next_moves, { type: "ask", content: q } ],
private: { ...is.private, plan: [...is.private.plan.slice(1)] },
};
} else {
}
if (is.shared.qud.length >0 && Array.isArray(is.shared.lu?.moves) && is.shared.lu?.moves.length === 0) {
const FailedNlu = {type: "FailedNlu", content : null } as Move ;
newIS = {
...is,
next_moves: [ ...is.next_moves, FailedNlu, { type: "ask", content: q } ],
};

}
else {

newIS = {
...is,
next_moves: [ ...is.next_moves, { type: "ask", content: q } ],
Expand All @@ -276,6 +286,24 @@ export const rules: Rules = {
}
},

/**rule 3.12 Implement here*/



selectIcmSemNeg : ({is}) => {
if (Array.isArray(is.shared.lu?.moves) && is.shared.lu?.moves.length === 0) {
const FailedNlu = {type: "FailedNlu", content : null } as Move ;
return () => ({
...is,
next_moves : [...is.next_moves, FailedNlu]
})
}
},





/** rule 2.14 */
select_respond: ({ is }) => {
if (
Expand Down Expand Up @@ -320,6 +348,11 @@ export const rules: Rules = {
}
},






/** only for greet for now */
select_other: ({ is }) => {
if (is.private.agenda[0] && is.private.agenda[0].type === "greet") {
Expand Down
14 changes: 14 additions & 0 deletions test/dme.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,21 @@ describe("DME tests", () => {
{ speaker: "usr", message: "Where is the lecture?" },
{ speaker: "sys", message: "Which course?" },
{ speaker: "usr", message: "Dialogue Systems 2" },
{ speaker: "sys", message: "Which day is the lecture?" },
{ speaker: "usr", message: "monday" },
{ speaker: "sys", message: "The lecture is in G212." },
]);
});
describe("system answer in NLU", () => {
runTest([
{ speaker: "sys", message: "Hello! You can ask me anything!" },
{ speaker: "usr", message: "blabla" },
{ speaker: "sys", message: "I am sorry, I don't understand you." },
{ speaker: "usr", message: "Where is the lecture?" },
{ speaker: "sys", message: "Which course?" },
{ speaker: "usr", message: "blabla" },
{ speaker: "sys", message: "I am sorry, I don't understand you. Which course?" },
]);
});

});