|
From: <jom...@us...> - 2016-03-07 13:22:13
|
Revision: 1876
http://sourceforge.net/p/jason/svn/1876
Author: jomifred
Date: 2016-03-07 13:22:11 +0000 (Mon, 07 Mar 2016)
Log Message:
-----------
fix .relevant_plans to work with vars
Modified Paths:
--------------
trunk/src/jason/asSyntax/ASSyntax.java
trunk/src/jason/asSyntax/PlanLibrary.java
trunk/src/jason/asSyntax/directives/NameSpace.java
trunk/src/jason/stdlib/desire.java
trunk/src/jason/stdlib/package.html
Modified: trunk/src/jason/asSyntax/ASSyntax.java
===================================================================
--- trunk/src/jason/asSyntax/ASSyntax.java 2016-03-02 10:22:16 UTC (rev 1875)
+++ trunk/src/jason/asSyntax/ASSyntax.java 2016-03-07 13:22:11 UTC (rev 1876)
@@ -121,6 +121,17 @@
}
/**
+ * Creates a new literal, the first argument is the namespace, the second is either Literal.LPos or Literal.LNeg,
+ * the third is the functor (a string),
+ * and the n remainder arguments are terms. see documentation of this
+ * class for examples of use.
+ */
+ public static Literal createLiteral(Atom namespace, boolean positive, String functor, Term... terms) {
+ return new LiteralImpl(namespace, positive, functor).addTerms(terms);
+ }
+
+
+ /**
* Creates a new structure (compound) term, the first argument is the functor (a string),
* and the n remainder arguments are terms.
*/
@@ -153,6 +164,11 @@
return new VarTerm(functor);
}
+ /** creates a new variable term in a namespace */
+ public static VarTerm createVar(Atom namespace, String functor) {
+ return new VarTerm(namespace, functor);
+ }
+
/** creates a new variable term (possibly negated) */
public static VarTerm createVar(boolean negated, String functor) {
VarTerm v = new VarTerm(functor);
Modified: trunk/src/jason/asSyntax/PlanLibrary.java
===================================================================
--- trunk/src/jason/asSyntax/PlanLibrary.java 2016-03-02 10:22:16 UTC (rev 1875)
+++ trunk/src/jason/asSyntax/PlanLibrary.java 2016-03-07 13:22:11 UTC (rev 1876)
@@ -354,14 +354,24 @@
}
public List<Plan> getCandidatePlans(Trigger te) {
- List<Plan> l = relPlans.get(te.getPredicateIndicator());
- if ((l == null || l.isEmpty()) && !varPlans.isEmpty() && te != TE_JAG_SLEEPING && te != TE_JAG_AWAKING) { // no rel plan, try varPlan
- for (Plan p: varPlans)
+ List<Plan> l = null;
+ if (te.getLiteral().isVar()) { // add all plans!
+ for (Plan p: this)
if (p.getTrigger().sameType(te)) {
if (l == null)
l = new ArrayList<Plan>();
l.add(p);
- }
+ }
+ } else {
+ l = relPlans.get(te.getPredicateIndicator());
+ if ((l == null || l.isEmpty()) && !varPlans.isEmpty() && te != TE_JAG_SLEEPING && te != TE_JAG_AWAKING) { // no rel plan, try varPlan
+ for (Plan p: varPlans)
+ if (p.getTrigger().sameType(te)) {
+ if (l == null)
+ l = new ArrayList<Plan>();
+ l.add(p);
+ }
+ }
}
return l; // if no rel plan, have to return null instead of empty list
}
Modified: trunk/src/jason/asSyntax/directives/NameSpace.java
===================================================================
--- trunk/src/jason/asSyntax/directives/NameSpace.java 2016-03-02 10:22:16 UTC (rev 1875)
+++ trunk/src/jason/asSyntax/directives/NameSpace.java 2016-03-07 13:22:11 UTC (rev 1876)
@@ -47,10 +47,14 @@
}
String type = ((Atom)directive.getTerm(1)).getFunctor();
if (!type.equals("local") && !type.equals("global")) {
- logger.log(Level.SEVERE, "The second parameter of the directive namespace should be local or global");
+ logger.log(Level.SEVERE, "The second parameter of the directive namespace should be either local or global");
return;
}
- if (type.equals("local")) {
+ if (type.equals("global") && isLocalNS(ns)) {
+ logger.warning("The namespace "+ns+" was previously defined as local, changing it to globall!");
+ localNSs.remove(ns);
+ }
+ if (type.equals("local")) {
ns = addLocalNS(ns);
}
}
@@ -79,9 +83,12 @@
static private int nsCounter = 0;
private synchronized Atom addLocalNS(Atom ns) {
- nsCounter++;
- Atom newNS = new Atom(LOCAL_PREFIX+nsCounter+ns);
- localNSs.put(ns,newNS);
+ Atom newNS = localNSs.get(ns);
+ if (newNS == null) {
+ nsCounter++;
+ newNS = new Atom(LOCAL_PREFIX+nsCounter+ns);
+ localNSs.put(ns,newNS);
+ }
return newNS;
}
}
Modified: trunk/src/jason/stdlib/desire.java
===================================================================
--- trunk/src/jason/stdlib/desire.java 2016-03-02 10:22:16 UTC (rev 1875)
+++ trunk/src/jason/stdlib/desire.java 2016-03-07 13:22:11 UTC (rev 1876)
@@ -118,10 +118,11 @@
Unifier solution = null; // the current response (which is an unifier)
Iterator<Event> evtIterator = null;
Iterator<Unifier> intendInterator = null;
+ {
+ find();
+ }
public boolean hasNext() {
- if (solution == null) // the first call of hasNext should find the first response
- find();
//if (solution == null)
// logger.info("* no more solution for "+teFromL+C);
return solution != null;
Modified: trunk/src/jason/stdlib/package.html
===================================================================
--- trunk/src/jason/stdlib/package.html 2016-03-02 10:22:16 UTC (rev 1875)
+++ trunk/src/jason/stdlib/package.html 2016-03-07 13:22:11 UTC (rev 1876)
@@ -34,7 +34,7 @@
<li>{@link jason.stdlib.findall findall}: find a list of beliefs of some kind.</li>
<li>{@link jason.stdlib.setof setof}: find a set of beliefs of some kind.</li>
<li>{@link jason.stdlib.count count}: count the number of beliefs of some kind.</li>
- <li>{@link jason.stdlib.name_space name_space}: checks whether an argument is a name space.</li>
+ <li>{@link jason.stdlib.namespace namespace}: checks whether an argument is a name space.</li>
</ul>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|