| 
     
      
      
      From: <jom...@us...> - 2009-03-10 13:04:40
      
     
   | 
Revision: 1462
          http://jason.svn.sourceforge.net/jason/?rev=1462&view=rev
Author:   jomifred
Date:     2009-03-10 13:04:16 +0000 (Tue, 10 Mar 2009)
Log Message:
-----------
update .rel_plans to use plan terms and trigger terms
Modified Paths:
--------------
    trunk/demos/communication/bob.asl
    trunk/release-notes.txt
    trunk/src/asl/kqmlPlans.asl
    trunk/src/jason/asSyntax/Literal.java
    trunk/src/jason/asSyntax/Trigger.java
    trunk/src/jason/stdlib/list_plans.java
    trunk/src/jason/stdlib/relevant_plans.java
    trunk/src/jason/stdlib/remove_plan.java
Modified: trunk/demos/communication/bob.asl
===================================================================
--- trunk/demos/communication/bob.asl	2009-03-09 22:42:38 UTC (rev 1461)
+++ trunk/demos/communication/bob.asl	2009-03-10 13:04:16 UTC (rev 1462)
@@ -37,6 +37,16 @@
       .send(maria, askOne, fullname, FN);
       .println("Full name is ",FN);
       
+      // Ask maria plans to goto
+      .send(maria, askHow, {+!goto(_,_)[source(_)]});
+      .wait(500); // wait answer
+      .print("Received plans:");
+      .list_plans( {+!goto(_,_)[source(_)]} );
+      .print;
+      // another implementation (that do not include the received plans automaticaly in the PL)
+      .send(maria, askHow, {+!goto(_,_)[source(_)]}, ListOfPlans);
+      .print("Received plans by askHow: ", ListOfPlans);
+      
       // Send to maria a plan to achieve the goal hello
       .plan_label(Plan,hp); // get a plans based on a plan's label
       .println("Sending tell how: ",Plan);
Modified: trunk/release-notes.txt
===================================================================
--- trunk/release-notes.txt	2009-03-09 22:42:38 UTC (rev 1461)
+++ trunk/release-notes.txt	2009-03-10 13:04:16 UTC (rev 1462)
@@ -31,6 +31,7 @@
   not be used.
 - Some concurrent execution of .wait and .drop_desire/intention
   does not work (the intention isn't dropped)
+- send askHow with 4th argument blocks the intention
 
 
 ---------------------------
Modified: trunk/src/asl/kqmlPlans.asl
===================================================================
--- trunk/src/asl/kqmlPlans.asl	2009-03-09 22:42:38 UTC (rev 1461)
+++ trunk/src/asl/kqmlPlans.asl	2009-03-10 13:04:16 UTC (rev 1462)
@@ -112,7 +112,7 @@
 // the triggering event
 @kqmlReceivedAskHow
 +!kqml_received(Sender, askHow, Content, MsgId)
-   <- .relevant_plans(Content, ListOfPlans);
+   <- .relevant_plans(Content, ListOfPlans); 
       .send(Sender, tellHow, ListOfPlans, MsgId).
 
 /* general communication error handler */
Modified: trunk/src/jason/asSyntax/Literal.java
===================================================================
--- trunk/src/jason/asSyntax/Literal.java	2009-03-09 22:42:38 UTC (rev 1461)
+++ trunk/src/jason/asSyntax/Literal.java	2009-03-10 13:04:16 UTC (rev 1462)
@@ -117,8 +117,10 @@
     public List<Term> getTerms()  { return Structure.emptyTermList;   }
     /** returns all terms of this literal as an array */
     public Term[] getTermsArray() { return getTerms().toArray(Structure.emptyTermArray);  }
+    
+    private static final List<VarTerm> emptyListVar = new ArrayList<VarTerm>();
     /** returns all singleton vars (that appears once) in this literal */
-    public List<VarTerm> getSingletonVars() { return new ArrayList<VarTerm>(); }
+    public List<VarTerm> getSingletonVars() { return emptyListVar; }
 
     /** replaces all terms by unnamed variables (_). */
     public void makeTermsAnnon()  {}
Modified: trunk/src/jason/asSyntax/Trigger.java
===================================================================
--- trunk/src/jason/asSyntax/Trigger.java	2009-03-09 22:42:38 UTC (rev 1461)
+++ trunk/src/jason/asSyntax/Trigger.java	2009-03-10 13:04:16 UTC (rev 1462)
@@ -25,6 +25,8 @@
 package jason.asSyntax;
 
 import jason.asSemantics.Unifier;
+import jason.asSyntax.PlanBody.BodyType;
+import jason.asSyntax.parser.ParseException;
 import jason.asSyntax.parser.as2j;
 
 import java.io.StringReader;
@@ -190,6 +192,34 @@
         return operator.toString() + type + literal;
     }
     
+    /** try to convert the term t into a trigger, in case t is a trigger term, a string that can be parsed to a trigger, a var with value trigger, .... */
+    public static Trigger tryToGetTrigger(Term t) throws ParseException {
+        if (t instanceof Trigger) {
+            return (Trigger)t;
+        }
+        if (t instanceof VarTerm) {
+            VarTerm v = (VarTerm)t;
+            if (v.hasValue() && v.getValue() instanceof Trigger) {
+                return (Trigger)v.getValue();            
+            }
+            if (v.hasValue() && v.getValue() instanceof Plan) {
+                return ((Plan)v.getValue()).getTrigger();            
+            }
+        }
+        if (t.isString()) {
+            return ASSyntax.parseTrigger(((StringTerm)t).getString());
+        }
+        if (t.isPlanBody()) {
+            PlanBody p = (PlanBody)t;
+            if (p.getPlanSize() == 1) {
+                if (p.getBodyType() == BodyType.addBel)
+                    return new Trigger(TEOperator.add, TEType.belief, (Literal)p.getBodyTerm());
+                if (p.getBodyType() == BodyType.delBel)
+                    return new Trigger(TEOperator.del, TEType.belief, (Literal)p.getBodyTerm());
+            }
+        }
+        return null;
+    }
     
     /** get as XML */
     public Element getAsDOM(Document document) {
Modified: trunk/src/jason/stdlib/list_plans.java
===================================================================
--- trunk/src/jason/stdlib/list_plans.java	2009-03-09 22:42:38 UTC (rev 1461)
+++ trunk/src/jason/stdlib/list_plans.java	2009-03-10 13:04:16 UTC (rev 1462)
@@ -5,14 +5,21 @@
 import jason.asSemantics.Unifier;
 import jason.asSyntax.Plan;
 import jason.asSyntax.Term;
+import jason.asSyntax.Trigger;
 
 /** list all plans in PL */
 public class list_plans extends DefaultInternalAction {
 
     @Override public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
+        Trigger te = null;
+        if (args.length == 1 && args[0] instanceof Trigger)
+            te = Trigger.tryToGetTrigger(args[0]);
+        
         for (Plan p: ts.getAg().getPL()) {
             if (!p.getLabel().toString().startsWith("kqml")) { // do not list kqml plans
-                ts.getLogger().info(p.toString());
+                if (te == null || new Unifier().unifies(p.getTrigger(), te)) {
+                    ts.getLogger().info(p.toString());
+                }
             }
         }
         return true;
Modified: trunk/src/jason/stdlib/relevant_plans.java
===================================================================
--- trunk/src/jason/stdlib/relevant_plans.java	2009-03-09 22:42:38 UTC (rev 1461)
+++ trunk/src/jason/stdlib/relevant_plans.java	2009-03-10 13:04:16 UTC (rev 1462)
@@ -28,12 +28,9 @@
 import jason.asSemantics.Option;
 import jason.asSemantics.TransitionSystem;
 import jason.asSemantics.Unifier;
-import jason.asSyntax.ASSyntax;
 import jason.asSyntax.ListTerm;
 import jason.asSyntax.ListTermImpl;
 import jason.asSyntax.Plan;
-import jason.asSyntax.StringTerm;
-import jason.asSyntax.StringTermImpl;
 import jason.asSyntax.Term;
 import jason.asSyntax.Trigger;
 import jason.asSyntax.parser.ParseException;
@@ -48,10 +45,10 @@
 
   <p>Parameters:<ul>
   
-  <li>+ trigger (string): the string representing the triggering event.</li>
+  <li>+ trigger (trigger): the triggering event, enclosed by { and }.</li>
   
-  <li>- plans (list): the list of strings with the code of the relevant
-  plans.</li>
+  <li>- plans (list of plan terms): the list of plan terms corresponding to 
+  the code of the relevant plans.</li>
   
   <li><i>- labels</i> (list, optional): the list of labels of the plans.</li>
 
@@ -59,11 +56,11 @@
   
   <p>Example:<ul> 
 
-  <li> <code>.relevant_plans("+!go(X,Y)",LP)</code>: unifies LP with a list of
+  <li> <code>.relevant_plans({+!go(X,Y)},LP)</code>: unifies LP with a list of
   all plans in the agent's plan library that are relevant for the triggering
   event <code>+!go(X,Y)</code>.</li>
 
-  <li> <code>.relevant_plans("+!go(X,Y)",LP, LL)</code>: same as above but also 
+  <li> <code>.relevant_plans({+!go(X,Y)},LP, LL)</code>: same as above but also 
   unifies LL with a list of labels of plans in LP.</li>
 
   </ul>
@@ -78,24 +75,18 @@
 
     @Override public int getMinArgs() { return 2; }
     @Override public int getMaxArgs() { return 3; }
-
-    @Override
-    protected void checkArguments(Term[] args) throws JasonException {
-        super.checkArguments(args);
-        if (!args[0].isString())
-            throw JasonException.createWrongArgument(this,"first argument must be a string");
-    }
     
     @Override
 	public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
         checkArguments(args);
         
-		Trigger te;
+		Trigger te = null;
 		try {
-		    te = ASSyntax.parseTrigger(((StringTerm) args[0]).getString());
-		} catch (ParseException e) {
+		    te = Trigger.tryToGetTrigger(args[0]);
+        } catch (ParseException e) {}
+        if (te == null)
             throw JasonException.createWrongArgument(this,"first argument '"+args[0]+"' must follow the syntax of a trigger.");
-		}
+        
 		ListTerm labels = new ListTermImpl();
 		ListTerm lt = new ListTermImpl();
 		ListTerm last = lt;
@@ -107,9 +98,11 @@
                 if (np.getLabel() != null) {
                     np.getLabel().delSources();
                 }
-                StringTerm stplan = new StringTermImpl(np.toASString().replaceAll("\\\"", "\\\\\""));
-                last = last.append(stplan);
-                if (args.length == 3) labels.add(np.getLabel());
+                //StringTerm stplan = new StringTermImpl(np.toASString().replaceAll("\\\"", "\\\\\""));
+                //last = last.append(stplan);
+                last = last.append(np);
+                if (args.length == 3) 
+                    labels.add(np.getLabel());
             }
 		}
 
Modified: trunk/src/jason/stdlib/remove_plan.java
===================================================================
--- trunk/src/jason/stdlib/remove_plan.java	2009-03-09 22:42:38 UTC (rev 1461)
+++ trunk/src/jason/stdlib/remove_plan.java	2009-03-10 13:04:16 UTC (rev 1462)
@@ -66,9 +66,10 @@
   by labels <code>l1[source(bob)]</code>, <code>l2[source(bob)]</code>, and
   <code>l3[source(bob)]</code>.</li>
 
+  <li> <code>.relevant_plans({ +!g }, _, L); .remove_plan(LL)</code>: 
+  removes all plans with trigger event <code>+!g</code>.</li>
   </ul>
 
-
   @see jason.stdlib.add_plan
   @see jason.stdlib.plan_label
   @see jason.stdlib.relevant_plans
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
 |