Skip to content

Commit

Permalink
fix: reason of the desire
Browse files Browse the repository at this point in the history
  • Loading branch information
yan-elena committed May 14, 2024
1 parent 568a629 commit 621400b
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 28 deletions.
9 changes: 4 additions & 5 deletions src/component/event/design/DesireCommitted.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,20 @@ function DesireCommitted(props) {
const type = "Desire committed";

const intention = props.event.message.event
const desire = intention.intentionInfo.intendedMeansInfo[0].plan.trigger
const selectedPlan = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "SelectPlanEvent" && e.message.event.selectedPlan.trigger === desire)
const desire = intention.intentionInfo.trigger
const selectedPlan = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "SelectPlanEvent" && e.message.event.selectedPlan.trigger === desire).message.event.selectedPlan
const planSelected = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "PlanSelected" && e.message.event.goalInfo.goalFunctor === desire)

const explanation = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "GoalCreated" && e.message.event.goalInfo.goalFunctor === desire)

if (selectedPlan && planSelected) {
const context = selectedPlan.context ? " because I believe " + selectedPlan.context.replace("&", "and").replace("|", "or") : ""
const body = selectedPlan.body ? "Plan body: " + selectedPlan.body : ""
const im = intention.intentionInfo.intendedMeansInfo
const id = intention.intentionInfo.id
const description = "I committed to desire " + desire + context + ", and it became a new intention " + id + " " + im[0].trigger
const description = "I committed to desire " + desire + context + ", and it became a new intention " + id + " " + intention.intentionInfo.trigger

let reason = getIntentionReason(desire, intention.intentionInfo)
let parentDesire = reason ? ["Intention " + id + " " + desire + " is an intention" + reason, <br/>] : []
let parentDesire = reason ? ["Intention " + id + " " + desire + " is an intention " + reason, <br/>] : []

if (agentState.intention[id]) {
agentState.intention[id].push(desire)
Expand Down
2 changes: 1 addition & 1 deletion src/component/event/design/DesireRemoved.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function DesireRemoved(props) {
let intentionInfo = "intention " + id + " " + functor.split('(')[0]
if (result === "achieved") {
type = "Desire satisfied";
description = "I have satisfied my desire " + functor + " because its " + intentionInfo + " has finished"
description = "I have satisfied my desire " + functor + " because its " + intentionInfo + " finished"
} else if (result === "failed") {
type = "Desire dropped";
description = "I gave up desire " + functor + " because its " + intentionInfo + " failed"
Expand Down
43 changes: 24 additions & 19 deletions src/component/event/design/NewDesire.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import React from "react";
import Event from "../Event";
import {agentState} from "../../../model/agentState";
import {Level} from "../../../model/Level";

function NewDesire(props) {
Expand All @@ -13,27 +12,33 @@ function NewDesire(props) {
const info = "State: " + state

let description = "I have a new desire " + functor
let reason = " because it is an initial desire"
let reason = ""
let explanation
if (intention) {
let im = intention.intendedMeansInfo
if (im.length > 0) {
const parent = im[0].trigger
if (agentState.speechAct.signal.includes(parent)) {
reason = " because it is created from the signal " + parent
} else if (agentState.speechAct.tell.includes(parent)) {
reason = " because it is created from " + parent + " tell message"
} else if (agentState.belief.self.includes(parent)) {
reason = " because it is formed on the addition of a belief " + parent
} else if (agentState.belief.percept.includes(parent)) {
reason = " because it is created from the perception of " + parent
} else { // parent-goal
explanation = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "GoalCreated" && e.message.event.goalInfo.intention.value && e.message.event.goalInfo.intention.value.id === intention.id)
reason = " because it is created from " + parent

if (source) {
if (source.includes("self")) {
if (intention) {
let im = intention.intendedMeansInfo
if (im.length > 0) {
const parent = im[0].trigger
const type = im[0].type

if (type === "belief") {
reason = " because I believe " + parent
} else if (type === "achieve") {
explanation = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "GoalCreated" && e.message.event.goalInfo.intention.value && e.message.event.goalInfo.intention.value.id === intention.id)
reason = " because it is created from " + parent
}
} else {
reason = " because it is an initial desire "
}
}
} else { //speech act message
const speechAct = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "NewSpeechActMessage" && e.message.event.message.sender === source[0] && e.message.event.message.message === goalInfo.goalFunctor)
if (speechAct) {
reason = " because I received a " + speechAct.message.event.message.type + " message " + speechAct.message.event.message.message + " from the agent " + speechAct.message.event.message.sender
}
}
} else if (source && source !== "self" && agentState.speechAct.achieve.includes(functor)) {
reason = " created from agent " + source + " by an achieved message "
}

return (
Expand Down
3 changes: 1 addition & 2 deletions src/component/event/implementation/goalEvent/GoalCreated.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,13 @@ function GoalCreated(props) {
const type = "Goal Created"
const functor = props.event.message.event.goalInfo.goalFunctor
const state = props.event.message.event.goalStates
// const intention = props.event.message.event.intention.value
const info = "State: " + state

let description = "Goal " + functor + " created"
const intention = props.event.message.event.goalInfo.intention.value
let explanation
if (intention) {
explanation = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "GoalCreated" && e.message.event.goalInfo.goalFunctor.split("(")[0] === intention.intendedMeansInfo[0].trigger)
explanation = props.log.slice(0, props.log.indexOf(props.event)).findLast(e => e.message.type === "GoalCreated" && intention.intendedMeansInfo[0] && e.message.event.goalInfo.goalFunctor.split("(")[0] === intention.intendedMeansInfo[0].trigger)
description += " from " + intention.trigger
}

Expand Down
2 changes: 1 addition & 1 deletion src/model/agentState.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ export function getIntentionReason(desire, intentionInfo) {
let reason = ""

if (im.length > 0) {
let parent = im[0].trigger !== desire ? im[0].trigger : (im[1] ? im[1].trigger : "")
let parent = intentionInfo.trigger

if (parent) {
if (agentState.speechAct.signal.includes(parent)) {
Expand Down

0 comments on commit 621400b

Please sign in to comment.