|
From: <jom...@us...> - 2009-02-14 18:08:52
|
Revision: 1444
http://jason.svn.sourceforge.net/jason/?rev=1444&view=rev
Author: jomifred
Date: 2009-02-14 18:08:49 +0000 (Sat, 14 Feb 2009)
Log Message:
-----------
fix bug of var unified with atom an then add in BB, as in X = p; +X;
Modified Paths:
--------------
trunk/src/jason/asSemantics/TransitionSystem.java
trunk/src/jason/asSyntax/VarTerm.java
trunk/src/templates/ia
trunk/src/test/VarTermTest.java
Modified: trunk/src/jason/asSemantics/TransitionSystem.java
===================================================================
--- trunk/src/jason/asSemantics/TransitionSystem.java 2009-02-13 18:17:30 UTC (rev 1443)
+++ trunk/src/jason/asSemantics/TransitionSystem.java 2009-02-14 18:08:49 UTC (rev 1444)
@@ -23,6 +23,7 @@
package jason.asSemantics;
+import jade.domain.introspection.GetValue;
import jason.JasonException;
import jason.RevisionFailedException;
import jason.architecture.AgArch;
@@ -41,6 +42,7 @@
import jason.asSyntax.Structure;
import jason.asSyntax.Term;
import jason.asSyntax.Trigger;
+import jason.asSyntax.VarTerm;
import jason.asSyntax.Trigger.TEOperator;
import jason.asSyntax.Trigger.TEType;
import jason.asSyntax.parser.ParseException;
@@ -543,10 +545,7 @@
case delAddBel:
// -+a(1,X) ===> remove a(_,_), add a(1,X)
// change all vars to anon vars to remove it
- if (!body.hasSource()) {
- // do not add source(self) in case the programmer set a source
- body.addAnnot(BeliefBase.TSelf);
- }
+ body = addSelfSource(body);
Literal bc = (Literal)body.clone();
bc.makeTermsAnnon();
// to delete, create events as external to avoid that
@@ -567,11 +566,7 @@
// Rule AddBel
case addBel:
- if (!body.hasSource()) {
- // do not add source(self) in case the
- // programmer set the source
- body.addAnnot(BeliefBase.TSelf);
- }
+ body = addSelfSource(body);
// calculate focus
Intention newfocus = Intention.EmptyInt;
@@ -599,10 +594,7 @@
break;
case delBel:
- if (!body.hasSource()) {
- // do not add source(self) in case the programmer set a source
- body.addAnnot(BeliefBase.TSelf);
- }
+ body = addSelfSource(body);
newfocus = Intention.EmptyInt;
if (setts.sameFocus())
@@ -626,6 +618,22 @@
break;
}
}
+
+ // add the self source in the body in case no other source was given
+ private Literal addSelfSource(Literal body) {
+ // manage the case of var unified with atom
+ if (body instanceof VarTerm) {
+ Term v = ((VarTerm)body).getValue();
+ if (v != null && v instanceof Atom)
+ body = new LiteralImpl((Atom)v);
+ }
+ if (!body.hasSource()) {
+ // do not add source(self) in case the
+ // programmer set the source
+ body.addAnnot(BeliefBase.TSelf);
+ }
+ return body;
+ }
public void applyClrInt(Intention i) throws JasonException {
while (true) { // quit the method by return
Modified: trunk/src/jason/asSyntax/VarTerm.java
===================================================================
--- trunk/src/jason/asSyntax/VarTerm.java 2009-02-13 18:17:30 UTC (rev 1443)
+++ trunk/src/jason/asSyntax/VarTerm.java 2009-02-14 18:08:49 UTC (rev 1444)
@@ -422,42 +422,50 @@
@Override
public void setAnnots(ListTerm l) {
- if (value != null && value.isPred())
- ((Pred) value).setAnnots(l);
+ if (value != null)
+ if (getValue().isPred())
+ ((Pred) value).setAnnots(l);
+ else
+ logger.log(Level.WARNING, "The setAnnots '"+l+"' in "+this+" was lost, since this var value is not a Pred. The value's class is "+getValue().getClass().getName(), new Exception());
else
super.setAnnots(l);
}
- /*
@Override
- public void addAnnot(int index, Term t) {
- if (value != null && getValue().isPred())
- ((Pred) getValue()).addAnnot(index, t);
- else
- super.addAnnot(index, t);
- }
- */
-
- @Override
public boolean importAnnots(Literal p) {
- if (value != null && getValue().isPred())
- return ((Pred) getValue()).importAnnots(p);
+ if (value != null)
+ if (getValue().isPred()) {
+ return ((Pred) getValue()).importAnnots(p);
+ } else {
+ logger.log(Level.WARNING, "The importAnnots '"+p+"' in "+this+" was lost, since this var value is not a Pred. The value's class is "+getValue().getClass().getName(), new Exception());
+ return false;
+ }
else
return super.importAnnots(p);
}
@Override
public boolean addAnnot(Term t) {
- if (value != null && getValue().isPred())
- return ((Pred) getValue()).addAnnot(t);
+ if (value != null)
+ if (getValue().isPred()) {
+ return ((Pred) getValue()).addAnnot(t);
+ } else {
+ logger.log(Level.WARNING, "The add of annotation '"+t+"' in "+this+" was lost, since this var value is not a Pred. The value's class is "+getValue().getClass().getName(), new Exception());
+ return false;
+ }
else
return super.addAnnot(t);
}
@Override
public Literal addAnnots(List<Term> l) {
- if (value != null && getValue().isPred())
- return ((Pred) getValue()).addAnnots(l);
+ if (value != null)
+ if (getValue().isPred()) {
+ return ((Pred) getValue()).addAnnots(l);
+ } else {
+ logger.log(Level.WARNING, "The addAnnots '"+l+"' in "+this+" was lost, since this var value is not a Pred. The value's class is "+getValue().getClass().getName(), new Exception());
+ return null;
+ }
else
return super.addAnnots(l);
}
@@ -531,11 +539,13 @@
@Override
public void addSource(Term t) {
- if (value != null && getValue().isPred())
- ((Pred) getValue()).addSource(t);
+ if (value != null)
+ if (getValue().isPred())
+ ((Pred) getValue()).addSource(t);
+ else
+ logger.log(Level.WARNING, "The addSource '"+t+"' in "+this+" was lost, since this var value is not a Pred. The value's class is "+getValue().getClass().getName(), new Exception());
else
super.addSource(t);
-
}
@Override
Modified: trunk/src/templates/ia
===================================================================
--- trunk/src/templates/ia 2009-02-13 18:17:30 UTC (rev 1443)
+++ trunk/src/templates/ia 2009-02-14 18:08:49 UTC (rev 1444)
@@ -5,29 +5,11 @@
import jason.*;
import jason.asSemantics.*;
import jason.asSyntax.*;
-import java.util.logging.*;
public class <IA_NAME> extends DefaultInternalAction {
- private Logger logger = Logger.getLogger("<PROJECT_NAME>."+<IA_NAME>.class.getName());
-
- // Example of that must receive one literal and one number as arguments
- @Override public int getMinArgs() { return 1; }
- @Override public int getMaxArgs() { return 2; }
-
- // improve the check of the arguments to also check the type of the arguments
- @Override protected void checkArguments(Term[] args) throws JasonException {
- super.checkArguments(args); // check number of arguments
- if (!args[0].isLiteral())
- throw JasonException.createWrongArgument(this,"first argument must be a literal");
- if (args.length == 2 && !args[1].isNumeric())
- throw JasonException.createWrongArgument(this,"second argument must be a number");
- }
-
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
- checkArguments(args);
-
// execute the internal action
ts.getAg().getLogger().info("executing internal action '<PCK>.<IA_NAME>'");
if (true) { // just to show how to throw another kind of exception
Modified: trunk/src/test/VarTermTest.java
===================================================================
--- trunk/src/test/VarTermTest.java 2009-02-13 18:17:30 UTC (rev 1443)
+++ trunk/src/test/VarTermTest.java 2009-02-14 18:08:49 UTC (rev 1444)
@@ -7,6 +7,7 @@
import jason.asSemantics.Unifier;
import jason.asSyntax.ASSyntax;
import jason.asSyntax.ArithExpr;
+import jason.asSyntax.Atom;
import jason.asSyntax.ListTerm;
import jason.asSyntax.ListTermImpl;
import jason.asSyntax.Literal;
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|