class AnswerHow_IntentionAction extends IntentionAction { canHandle(intention:Term, ai:RuleBasedAI) : boolean { if (intention.functor.is_a(ai.o.getSort("action.answer.how"))) return true; return false; } execute(ir:IntentionRecord, ai:RuleBasedAI) : boolean { this.ir = ir; let intention:Term = ir.action; let requester:TermAttribute = ir.requester; if (intention.attributes.length == 2) { if (intention.attributes[1] instanceof ConstantTermAttribute) { let targetID:string = (intention.attributes[1]).value; console.log(ai.selfID + " answer followup how to " + targetID); // this is a follow up question! see if we can reconstruct the question... let context:NLContext = ai.contextForSpeakerWithoutCreatingANewOne(targetID); if (context != null) { // get the last sentence we said: let lastPerf:NLContextPerformative = context.lastPerformativeBy(ai.selfID); let newIntention:Term = null; if (lastPerf != null) newIntention = this.convertPerformativeToHowQuestionAnswerIntention(lastPerf, ai, context); if (newIntention != null) { intention = newIntention; } else { let term:Term = Term.fromString("action.talk('"+ai.selfID+"'[#id], perf.inform.answer("+requester+",'unknown'[symbol]))", ai.o); ai.intentions.push(new IntentionRecord(term, intention.attributes[1], null, null, ai.timeStamp)); ir.succeeded = false; return true; } } else { // this should never happen let term:Term = Term.fromString("action.talk('"+ai.selfID+"'[#id], perf.inform.parseerror('"+context.speaker+"'[#id], #not(verb.understand('"+ai.selfID+"'[#id],#and(the(NOUN:'perf.question'[perf.question],S:[singular]),noun(NOUN,S))))))", ai.o); ai.intentions.push(new IntentionRecord(term, intention.attributes[1], null, null, ai.timeStamp)); ir.succeeded = false; return true; } } } if (intention.attributes.length>=3 && intention.attributes[2] instanceof TermTermAttribute) { let action:Term = (intention.attributes[2]).term; console.log(ai.selfID + " answer how: " + intention.attributes[2]); // we add the sentence with negative sign, to see if it introduces a contradiction let target1:Sentence[] = [new Sentence([new Term(ai.o.getSort("relation.howto"), [new TermTermAttribute(action), new VariableTermAttribute(ai.o.getSort("any"), "HOW")])],[false])]; ai.queuedInferenceProcesses.push(new InferenceRecord(ai, [], [target1], 1, 0, false, null, new AnswerHow_InferenceEffect(intention))); // TODO: this should have some temporary value (in all actions that require inference or continuous execution) // that is then replaced with true/false after inference/continuous is done ir.succeeded = true; /* if (requester != null) { let term:Term = Term.fromString("action.talk('"+ai.selfID+"'[#id], perf.inform.answer("+requester+",'unknown'[symbol]))", ai.o); ai.intentions.push(new IntentionRecord(term, requester, null, null, ai.timeStamp)); } */ } ir.succeeded = true; return true; } convertPerformativeToHowQuestionAnswerIntention(nlcp:NLContextPerformative, ai:RuleBasedAI, context:NLContext) : Term { if ((nlcp.performative.functor.is_a(ai.o.getSort("perf.request.action")) || nlcp.performative.functor.is_a(ai.o.getSort("perf.q.action"))) && (nlcp.performative.attributes[1] instanceof TermTermAttribute)) { console.log("convertPerformativeToHowQuestionAnswerIntention: perf.request.action/perf.q.action"); let predicate:Term = (nlcp.performative.attributes[1]).term; let newIntention:Term = new Term(ai.o.getSort("action.answer.how"), [new ConstantTermAttribute(nlcp.speaker, ai.o.getSort("#id")), nlcp.performative.attributes[0], new TermTermAttribute(predicate)]); console.log("convertPerformativeToHowQuestionAnswerIntention, newIntention: " + newIntention); return newIntention; } return null; } saveToXML(ai:RuleBasedAI) : string { return ""; } static loadFromXML(xml:Element, ai:RuleBasedAI) : IntentionAction { return new AnswerHow_IntentionAction(); } }