Changeset 719
- Timestamp:
- 11/16/2010 12:22:38 AM (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
AgentMind/branches/FAtiMA-Modular/FAtiMA.SocialRelations/src/FAtiMA/socialRelations/RelationsLoaderHandler.java
r717 r719 3 3 import org.xml.sax.Attributes; 4 4 5 import FAtiMA.Core.AgentCore; 5 import FAtiMA.Core.AgentModel; 6 import FAtiMA.Core.deliberativeLayer.goals.Goal; 6 7 import FAtiMA.Core.deliberativeLayer.plan.Effect; 8 import FAtiMA.Core.deliberativeLayer.plan.Step; 7 9 import FAtiMA.Core.exceptions.ContextParsingException; 8 10 import FAtiMA.Core.exceptions.InvalidEmotionTypeException; 9 11 import FAtiMA.Core.util.Constants; 10 import FAtiMA.Core.util.parsers.LikeCondition;11 12 import FAtiMA.Core.util.parsers.ReflectXMLHandler; 13 import FAtiMA.Core.wellFormedNames.Name; 14 import FAtiMA.Core.wellFormedNames.Substitution; 15 import FAtiMA.Core.wellFormedNames.Symbol; 12 16 13 17 public class RelationsLoaderHandler extends ReflectXMLHandler{ 18 19 private String _currentGoalKey; 20 private String _currentActionKey; 21 private String _conditionType; 22 private boolean _precondition; 23 private AgentModel _aM; 24 private float _probability; 25 private Substitution _self = new Substitution(new Symbol("[SELF]"), new Symbol(Constants.SELF)); 26 14 27 15 private AgentCore _ag;16 28 17 public RelationsLoaderHandler(AgentCore ag) 18 { 19 this._ag = ag; 29 public RelationsLoaderHandler(AgentModel aM){ 30 _aM = aM; 20 31 } 21 32 33 22 34 //parsed from the role file 23 35 public void Relation(Attributes attributes) … … 26 38 String target = attributes.getValue("target"); 27 39 float like = Float.parseFloat(attributes.getValue("like")); 28 LikeRelation.getRelation(Constants.SELF, target).setValue(_a g.getMemory(),like);40 LikeRelation.getRelation(Constants.SELF, target).setValue(_aM.getMemory(),like); 29 41 30 42 String auxRespect = attributes.getValue("respect"); … … 37 49 respect = Float.parseFloat(auxRespect); 38 50 } 39 RespectRelation.getRelation(Constants.SELF, target).setValue(_a g.getMemory(),respect);51 RespectRelation.getRelation(Constants.SELF, target).setValue(_aM.getMemory(),respect); 40 52 } 41 53 54 42 55 43 56 //used in goals … … 45 58 { 46 59 LikeCondition lc; 47 60 Goal g; 61 48 62 try 49 63 { 50 64 lc = LikeCondition.ParseSocialCondition(attributes); 51 52 65 lc.MakeGround(_self); 53 _currentGoal.AddCondition(_conditionType, lc); 66 g = _aM.getDeliberativeLayer().getGoalLibrary().GetGoal(Name.ParseName(_currentGoalKey)); 67 g.AddCondition(_conditionType, lc); 54 68 } 55 69 catch(Exception e) … … 63 77 public void LikeCondition(Attributes attributes) throws InvalidEmotionTypeException, ContextParsingException { 64 78 LikeCondition l; 79 l = LikeCondition.ParseSocialCondition(attributes); 80 l.MakeGround(_self); 65 81 66 l = LikeCondition.ParseSocialCondition(attributes); 67 //l.MakeGround(_self); 68 69 if(_precondition) 70 _currentOperator.AddPrecondition(l); 82 Step action = _aM.getDeliberativeLayer().getEmotionalPlanner().GetStep(Name.ParseName(_currentActionKey)); 83 if(_precondition) 84 action.AddPrecondition(l); 71 85 else { 72 String operatorName = _currentOperator.getName().GetFirstLiteral().toString();73 _currentOperator.AddEffect(new Effect(_am, operatorName,_probability, l));86 String operatorName = action.getName().GetFirstLiteral().toString(); 87 action.AddEffect(new Effect(_aM, operatorName,_probability, l)); 74 88 } 75 89 } 90 91 92 93 public void ActivePursuitGoal(Attributes attributes) { 94 _currentGoalKey = attributes.getValue("name"); 95 } 96 97 public void Action(Attributes attributes){ 98 _currentActionKey = attributes.getValue("name"); 99 } 100 101 public void SuccessConditions(Attributes attributes) { 102 _conditionType = "SuccessConditions"; 103 } 104 105 public void FailureConditions(Attributes attributes) { 106 _conditionType = "FailureConditions"; 107 } 108 109 public void PreConditions(Attributes attributes) { 110 _conditionType = "PreConditions"; 111 _precondition = true; 112 } 113 114 public void Effects(Attributes attributes) { 115 _precondition = false; 116 } 117 118 public void Effect(Attributes attributes) { 119 _probability = Float.parseFloat(attributes.getValue("probability")); 120 } 121 122 76 123 } 77 124
Note: See TracChangeset
for help on using the changeset viewer.