|
From: <jom...@us...> - 2008-04-13 10:45:13
|
Revision: 1214
http://jason.svn.sourceforge.net/jason/?rev=1214&view=rev
Author: jomifred
Date: 2008-04-13 03:45:08 -0700 (Sun, 13 Apr 2008)
Log Message:
-----------
fix bug in communication: use nested source annotation
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/asunit/TestArch.java
trunk/applications/as-unit-test/src/jason/tests/TestKQML.java
trunk/release-notes.txt
trunk/src/asl/kqmlPlans.asl
trunk/src/jason/asSyntax/Pred.java
trunk/src/jason/asSyntax/VarTerm.java
trunk/src/jason/stdlib/add_annot.java
trunk/src/jason/stdlib/package.html
trunk/src/jason/stdlib/send.java
trunk/src/test/ListTermTest.java
trunk/src/test/VarTermTest.java
Added Paths:
-----------
trunk/src/jason/stdlib/add_nested_source.java
Modified: trunk/applications/as-unit-test/src/jason/asunit/TestArch.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/asunit/TestArch.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/applications/as-unit-test/src/jason/asunit/TestArch.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -93,7 +93,7 @@
}
public void print(String s) {
- System.out.println(s);
+ //System.out.println(s);
output.append(s+"\n");
}
Modified: trunk/applications/as-unit-test/src/jason/tests/TestKQML.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestKQML.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/applications/as-unit-test/src/jason/tests/TestKQML.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -19,7 +19,8 @@
// defines the agent's AgentSpeak code
bob.parseAScode(
"+!simple_send <- .send(maria, tell, vl(10)); "+
- " .send(maria, achieve, goto(10,2)). " +
+ " .send(maria, achieve, goto(10,2)); " +
+ " .send(maria, tell, loves(maria,bob)[source(maria), source(mog)]). " +
"+!send_ask1 <- .send(maria, askOne, vl(_), vl(X)); " +
" .send(maria, askOne, vl(_)); " +
@@ -56,9 +57,10 @@
@Test
public void testSend() {
bob.addGoal("simple_send");
- bob.assertIdle(5); // bob sent the messages
- maria.assertBel("vl(10)", 5); // maria received tell
- maria.assertAct("act(10,2,bob)", 5); // maria received achieved
+ bob.assertIdle(5); // bob sent the messages
+ maria.assertBel("vl(10)[source(bob)]", 5); // maria received tell
+ maria.assertAct("act(10,2,bob)", 5); // maria received achieved
+ maria.assertBel("loves(maria,bob)[source(bob)[source(maria),source(mog)]]", 5);
}
@Test
@@ -92,7 +94,7 @@
bob.addGoal("simple_send");
bob.addGoal("send_askAll1");
bob.assertIdle(10);
- maria.assertIdle(10);
+ maria.assertIdle(15);
bob.assertPrint("[vl(10),vl(1),vl(2)]", 5);
bob.addGoal("send_askAll2");
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/release-notes.txt 2008-04-13 10:45:08 UTC (rev 1214)
@@ -1,7 +1,14 @@
------------
-version 1.1
------------
+-------------
+version 1.1.1
+-------------
+Bugs fixed:
+. use nested source annotations in communication
+
+-------------
+version 1.1.0
+-------------
+
New features
. Performance improvements: in general, applications run 30%
faster.
Modified: trunk/src/asl/kqmlPlans.asl
===================================================================
--- trunk/src/asl/kqmlPlans.asl 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/asl/kqmlPlans.asl 2008-04-13 10:45:08 UTC (rev 1214)
@@ -15,7 +15,7 @@
: .structure(Content) &
.ground(Content) &
not .list(Content)
- <- .add_annot(Content, source(Sender), CA);
+ <- .add_nested_source(Content, Sender, CA);
+CA.
@kqmlReceivedTellList
+!kqml_received(Sender, tell, Content, _)
@@ -29,7 +29,7 @@
+!add_all_kqml_received(S,[H|T])
: .structure(H) &
.ground(H)
- <- .add_annot(H, source(S), CA);
+ <- .add_nested_source(H, Sender, CA);
+CA;
!add_all_kqml_received(S,T).
@@ -39,7 +39,7 @@
@kqmlReceivedUnTell
+!kqml_received(Sender, untell, Content, _)
- <- .add_annot(Content, source(Sender), CA);
+ <- .add_nested_source(Content, Sender, CA);
-CA.
@@ -48,7 +48,7 @@
@kqmlReceivedAchieve
+!kqml_received(Sender, achieve, Content, _)
: not .list(Content)
- <- .add_annot(Content, source(Sender), CA);
+ <- .add_nested_source(Content, Sender, CA);
!!CA.
@kqmlReceivedAchieveList
+!kqml_received(Sender, achieve, Content, _)
@@ -61,7 +61,7 @@
@kqmlReceivedAchieveList2
+!add_all_kqml_achieve(Sender,[H|T])
- <- .add_annot(H, source(Sender), CA);
+ <- .add_nested_source(H, Sender, CA);
!!CA;
!add_all_kqml_achieve(Sender,T).
Modified: trunk/src/jason/asSyntax/Pred.java
===================================================================
--- trunk/src/jason/asSyntax/Pred.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/jason/asSyntax/Pred.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -65,7 +65,7 @@
}
/** to be used by atom */
- protected Pred(String functor, int termsSize) {
+ public Pred(String functor, int termsSize) {
super(functor, termsSize);
}
@@ -123,7 +123,7 @@
}
public void addAnnots(List<Term> l) {
- if (l == null) return;
+ if (l == null || l.isEmpty()) return;
ListTerm tail;
if (annots == null) {
annots = new ListTermImpl();
@@ -309,7 +309,7 @@
*/
public void addSource(Structure agName) {
if (agName != null) {
- Structure ts = new Structure("source");
+ Structure ts = new Structure("source", 1);
ts.addTerm(agName);
addAnnot(ts);
}
Modified: trunk/src/jason/asSyntax/VarTerm.java
===================================================================
--- trunk/src/jason/asSyntax/VarTerm.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/jason/asSyntax/VarTerm.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -111,9 +111,8 @@
vl = (Term)vl.clone(); // should clone here, since there is no cloning in unify
// The below does not conform the rules in manual
- //if (vl.isPred() && this.hasAnnot()) { // if this var has annots, add them in the value's annots (Experimental)
- // ((Pred)vl).addAnnots(this.getAnnots());
- //}
+ //if (vl.isPred() && this.hasAnnot()) // if this var has annots, add them in the value's annots (Experimental)
+ // ((Pred)vl).addAnnots(this.getAnnots());
value = vl;
resetHashCodeCache();
@@ -128,7 +127,7 @@
public boolean apply(Unifier u) {
if (value == null) {
Term vl = u.get(this);
- // System.out.println("applying="+t+"="+vl+" un="+this);
+ //System.out.println("applying "+this+"="+vl+" un="+u);
if (vl != null && !(vl instanceof VarsCluster)) {
setValue(vl);
value.apply(u); // in case t has var args
@@ -153,7 +152,7 @@
if (t == this) return true;
if (t instanceof Term) {
Term vl = getValue();
- // System.out.println("cheking equals form "+tAsTerm.getFunctor()+"
+ // System.out.println("checking equals form "+tAsTerm.getFunctor()+"
// and this "+this.getFunctor()+" my value "+vl);
if (vl != null) {
// compare the values
Modified: trunk/src/jason/stdlib/add_annot.java
===================================================================
--- trunk/src/jason/stdlib/add_annot.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/jason/stdlib/add_annot.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -64,6 +64,8 @@
unifies with <code>[a1[source(jomi)], a2[source(jomi)]]</code>.</li>
</ul>
+
+ @see jason.stdlib.add_nested_source
*/
public class add_annot extends DefaultInternalAction {
Added: trunk/src/jason/stdlib/add_nested_source.java
===================================================================
--- trunk/src/jason/stdlib/add_nested_source.java (rev 0)
+++ trunk/src/jason/stdlib/add_nested_source.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -0,0 +1,118 @@
+//----------------------------------------------------------------------------
+// Copyright (C) 2003 Rafael H. Bordini, Jomi F. Hubner, et al.
+//
+// This library is free software; you can redistribute it and/or
+// modify it under the terms of the GNU Lesser General Public
+// License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// Lesser General Public License for more details.
+//
+// You should have received a copy of the GNU Lesser General Public
+// License along with this library; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// To contact the authors:
+// http://www.dur.ac.uk/r.bordini
+// http://www.inf.furb.br/~jomi
+//
+//----------------------------------------------------------------------------
+
+
+package jason.stdlib;
+
+import jason.JasonException;
+import jason.asSemantics.DefaultInternalAction;
+import jason.asSemantics.TransitionSystem;
+import jason.asSemantics.Unifier;
+import jason.asSyntax.ListTerm;
+import jason.asSyntax.ListTermImpl;
+import jason.asSyntax.Literal;
+import jason.asSyntax.Pred;
+import jason.asSyntax.Structure;
+import jason.asSyntax.Term;
+
+/**
+ <p>Internal action: <b><code>.add_nested_source</code></b>.
+
+ <p>Description: adds a source annotation to a literal (used in communication).
+
+ <p>Parameters:<ul>
+
+ <li>+ belief(s) (literal or list): the literal where the source annotation
+ is to be added. If this parameter is a list, all literals in the list
+ will have the source added.<br/>
+
+ <li>+ source (atom): the source.<br/>
+
+ <li>+/- annotated beliefs(s) (literal or list): this argument
+ unifies with the result of the source addition.<br/>
+
+ </ul>
+
+ <p>Examples:<ul>
+
+ <li> <code>.add_nested_source(a,jomi,B)</code>: <code>B</code>
+ unifies with <code>a[source(jomi)]</code>.</li>
+
+ <li> <code>.add_nested_source(a[source(bob)],jomi,B)</code>: <code>B</code>
+ unifies with <code>a[source(jomi)[source(bob)]]</code>.</li>
+
+ <li> <code>.add_annot([a1,a2], jomi, B)</code>: <code>B</code>
+ unifies with <code>[a1[source(jomi)], a2[source(jomi)]]</code>.</li>
+
+ </ul>
+
+ @see jason.stdlib.add_annot
+
+ */
+public class add_nested_source extends DefaultInternalAction {
+
+ @Override
+ public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+ try {
+ Term result = addAnnotToList(un, args[0], (Structure)args[1].clone());
+ return un.unifies(result,args[2]);
+ } catch (ArrayIndexOutOfBoundsException e) {
+ throw new JasonException("The internal action 'add_nested_source' requires three arguments.");
+ }
+ }
+
+ public Term addAnnotToList(Unifier unif, Term l, Structure source) {
+ if (l.isList()) {
+ ListTerm result = new ListTermImpl();
+ for (Term lTerm: (ListTerm)l) {
+ Term t = addAnnotToList( unif, lTerm, source);
+ if (t != null) {
+ result.add(t);
+ }
+ }
+ return result;
+ } else {
+ try {
+ // if it can be parsed as a literal and is not an atom, OK to add annot
+ Literal result;
+ if (l.isAtom())
+ result = new Literal(((Structure)l).getFunctor());
+ else
+ result = Literal.parseLiteral(l.toString());
+
+ // create the source annots
+ Pred ts = new Pred("source",1);
+ ts.addTerm(source);
+ ts.addAnnots(result.getAnnots("source"));
+
+ result.delSources();
+ result.addAnnot(ts);
+ return result;
+ } catch (Exception e) {
+ // no problem, the content is not a pred (it is a number,
+ // string, ....) received in a message, for instance
+ }
+ }
+ return null;
+ }
+}
Modified: trunk/src/jason/stdlib/package.html
===================================================================
--- trunk/src/jason/stdlib/package.html 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/jason/stdlib/package.html 2008-04-13 10:45:08 UTC (rev 1214)
@@ -90,6 +90,7 @@
<li>{@link jason.stdlib.string}: check whether an argument is a string.</li>
<li>{@link jason.stdlib.ground}: check whether an argument is ground.</li>
<li>{@link jason.stdlib.add_annot}: add an annotation in a literal.</li>
+ <li>{@link jason.stdlib.add_nested_source}: add a source in a literal.</li>
</ul>
Modified: trunk/src/jason/stdlib/send.java
===================================================================
--- trunk/src/jason/stdlib/send.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/jason/stdlib/send.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -33,7 +33,6 @@
import jason.asSemantics.Unifier;
import jason.asSyntax.ListTerm;
import jason.asSyntax.NumberTerm;
-import jason.asSyntax.Pred;
import jason.asSyntax.StringTerm;
import jason.asSyntax.Structure;
import jason.asSyntax.Term;
@@ -141,9 +140,10 @@
}
// remove source annots in the content (in case it is a pred)
- try {
- ((Pred)pcnt).delSources();
- } catch (Exception e) {}
+ // -- CHANGE: use nested annots
+ //try {
+ // ((Pred)pcnt).delSources();
+ //} catch (Exception e) {}
} catch (ArrayIndexOutOfBoundsException e) {
throw new JasonException("The internal action 'send' to '"+to+"' has not received three arguments.");
Modified: trunk/src/test/ListTermTest.java
===================================================================
--- trunk/src/test/ListTermTest.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/test/ListTermTest.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -1,6 +1,7 @@
package test;
import jason.asSemantics.Unifier;
+import jason.asSyntax.Atom;
import jason.asSyntax.ListTerm;
import jason.asSyntax.ListTermImpl;
import jason.asSyntax.Structure;
@@ -177,6 +178,15 @@
assertEquals(lt5.getTail(), null);
}
+ public void testTailUnify() {
+ ListTerm lt5 = ListTermImpl.parseList("[H|T]");
+ Unifier u = new Unifier();
+ u.unifies(new VarTerm("H"), new Atom("a"));
+ u.unifies(new VarTerm("T"), ListTermImpl.parseList("[b,c]"));
+ lt5.apply(u);
+ assertEquals("[a,b,c]",lt5.toString());
+ }
+
public void testGround() {
ListTerm l = ListTermImpl.parseList("[c,b,a,x,y,d]");
assertTrue(l.isGround());
Modified: trunk/src/test/VarTermTest.java
===================================================================
--- trunk/src/test/VarTermTest.java 2008-04-10 21:40:07 UTC (rev 1213)
+++ trunk/src/test/VarTermTest.java 2008-04-13 10:45:08 UTC (rev 1214)
@@ -6,7 +6,6 @@
import jason.asSemantics.TransitionSystem;
import jason.asSemantics.Unifier;
import jason.asSyntax.ArithExpr;
-import jason.asSyntax.Atom;
import jason.asSyntax.DefaultTerm;
import jason.asSyntax.ListTerm;
import jason.asSyntax.ListTermImpl;
@@ -255,11 +254,13 @@
// X[a,b,c] = p[a,c,b,d] ok (X is p)
assertTrue(u.unifies(v1, p1));
assertEquals(u.get("X").toString(), "p(t1,t2)");
+ v1.apply(u);
+ assertEquals("p(t1,t2)",v1.toString());
}
public void testVarWithAnnots2() {
// test vars annots
-
+
// X[a] = Y[a,b] - ok
VarTerm v1 = VarTerm.parseVar("X[a]");
VarTerm v2 = VarTerm.parseVar("Y[a,b]");
@@ -271,7 +272,7 @@
assertFalse(u.unifies(v2, v1));
assertTrue(u.unifies(v1, v2));
- assertTrue(u.unifies(new Atom("vvv"), v1));
+ assertTrue(u.unifies(new Literal("vvv"), v1));
v1.apply(u);
assertEquals("vvv", v1.toString());
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|