Skip to content

Commit

Permalink
Optimise some type inferences
Browse files Browse the repository at this point in the history
  • Loading branch information
vladmaraev committed Sep 10, 2024
1 parent 44a621c commit 996a88a
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
11 changes: 6 additions & 5 deletions src/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,12 @@ export const rules: Rules = {
/** rule 2.2 */
integrate_sys_ask: ({ is }) => {
if (is.shared.lu!.speaker === "sys" && is.shared.lu!.move.type === "ask") {
const q = is.shared.lu!.move.content;
return () => ({
...is,
shared: {
...is.shared,
qud: [is.shared.lu!.move.content as Question, ...is.shared.qud],
qud: [q, ...is.shared.qud],
},
});
}
Expand All @@ -76,7 +77,7 @@ export const rules: Rules = {
/** rule 2.3 */
integrate_usr_ask: ({ is }) => {
if (is.shared.lu!.speaker === "usr" && is.shared.lu!.move.type === "ask") {
const question = is.shared.lu!.move.content as Question;
const question = is.shared.lu!.move.content;
const respondAction: { type: "respond"; content: Question } = {
type: "respond",
content: question,
Expand All @@ -98,8 +99,8 @@ export const rules: Rules = {
/** rule 2.4 */
integrate_answer: ({ is }) => {
const topQUD = is.shared.qud[0];
const a = is.shared.lu!.move.content;
if (topQUD && is.shared.lu!.move.type === "answer") {
const a = is.shared.lu!.move.content;
if (is.domain.relevant(a, topQUD)) {
let proposition = is.domain.combine(topQUD, a);
return () => ({
Expand Down Expand Up @@ -153,7 +154,7 @@ export const rules: Rules = {
if (is.private.agenda.length > 0) {
const action = is.private.agenda[0];
if (action.type === "respond") {
const question = action.content as Question;
const question = action.content;
for (const planInfo of is.domain.plans) {
if (
planInfo.type == "issue" &&
Expand Down Expand Up @@ -237,7 +238,7 @@ export const rules: Rules = {
is.private.agenda[0] &&
["findout", "raise"].includes(is.private.agenda[0].type)
) {
const q = is.private.agenda[0].content;
const q = is.private.agenda[0].content as Question;
if (is.private.plan[0] && is.private.plan[0].type === "raise") {
newIS = {
...is,
Expand Down
18 changes: 13 additions & 5 deletions src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,18 @@ export type Database = {
consultDB: (q: Question, p: Proposition[]) => Proposition | null;
};

type ShortAnswer = string;
type Proposition = {
export type ShortAnswer = string;
export type Proposition = {
predicate: string;
argument: string;
};

export type Question = WhQuestion;
type WhQuestion = { type: "whq"; predicate: string };

export interface Move {
interface OtherMove {
// no difference between Move and Action for now
type:
| "ask"
| "answer"
| "respond"
| "greet"
| "unknown"
Expand All @@ -40,6 +38,16 @@ export interface Move {
| "request";
content: null | Proposition | ShortAnswer | Question;
}
interface AnswerMove {
type: "answer";
content: Proposition | ShortAnswer;
}
interface AskMove {
type: "ask";
content: Question;
}

export type Move = OtherMove | AnswerMove | AskMove;

type Speaker = "usr" | "sys";

Expand Down

0 comments on commit 996a88a

Please sign in to comment.