From: <jom...@us...> - 2008-09-09 08:57:25
|
Revision: 1361 http://jason.svn.sourceforge.net/jason/?rev=1361&view=rev Author: jomifred Date: 2008-09-09 08:57:21 +0000 (Tue, 09 Sep 2008) Log Message: ----------- the source of beliefs can now be strings Modified Paths: -------------- trunk/applications/jason-moise/src/jmoise/OrgAgent.java trunk/src/jason/asSyntax/Pred.java trunk/src/jason/asSyntax/VarTerm.java trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc trunk/src/jason/asSyntax/parser/as2j.java trunk/src/jason/bb/BeliefBase.java trunk/src/jason/bb/DefaultBeliefBase.java trunk/src/jason/functions/time.java trunk/src/jason/stdlib/time.java Modified: trunk/applications/jason-moise/src/jmoise/OrgAgent.java =================================================================== --- trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-09-07 11:13:09 UTC (rev 1360) +++ trunk/applications/jason-moise/src/jmoise/OrgAgent.java 2008-09-09 08:57:21 UTC (rev 1361) @@ -53,7 +53,7 @@ */ public class OrgAgent extends AgArch { - private static final Term managerSource = Pred.createSource("orgManager"); + private static final Term managerSource = Pred.createSource(new Atom("orgManager")); private static final Atom rootAtom = new Atom("root"); private Logger logger = Logger.getLogger(OrgAgent.class.getName()); Modified: trunk/src/jason/asSyntax/Pred.java =================================================================== --- trunk/src/jason/asSyntax/Pred.java 2008-09-07 11:13:09 UTC (rev 1360) +++ trunk/src/jason/asSyntax/Pred.java 2008-09-09 08:57:21 UTC (rev 1361) @@ -230,6 +230,27 @@ return removed; } + /** + * returns all annots with the specified functor e.g.: from annots + * [t(a), t(b), source(tom)] + * and functor "t", + * it returns [t(a),t(b)] + */ + public ListTerm getAnnots(String functor) { + ListTerm ls = new ListTermImpl(); + if (annots != null) { + ListTerm tail = ls; + for (Term ta : annots) { + if (ta.isStructure()) { + if (((Structure)ta).getFunctor().equals(functor)) { + tail = tail.append(ta); + } + } + } + } + return ls; + } + /** returns true if all this predicate annots are in p's annots */ public boolean hasSubsetAnnot(Pred p) { if (annots == null) return true; @@ -307,26 +328,21 @@ /** * Adds a source annotation like "source(<i>agName</i>)". */ - public void addSource(Structure agName) { + public void addSource(Term agName) { if (agName != null) addAnnot(createSource(agName)); } /** deletes "source(<i>agName</i>)" */ - public boolean delSource(Structure agName) { + public boolean delSource(Term agName) { if (annots != null) return annots.remove(createSource(agName)); else return false; } - public static Term createSource(String source) { + public static Term createSource(Term source) { Structure s = new Structure("source",1); - s.addTerm(new Atom(source)); - return s; - } - public static Term createSource(Structure source) { - Structure s = new Structure("source",1); s.addTerm(source); return s; } @@ -351,27 +367,6 @@ return ls; } - /** - * returns all annots with the specified functor e.g.: from annots - * [t(a), t(b), source(tom)] - * and functor "t", - * it returns [t(a),t(b)] - */ - public ListTerm getAnnots(String functor) { - ListTerm ls = new ListTermImpl(); - if (annots != null) { - ListTerm tail = ls; - for (Term ta : annots) { - if (ta.isStructure()) { - if (((Structure)ta).getFunctor().equals(functor)) { - tail = tail.append(ta); - } - } - } - } - return ls; - } - /** deletes all sources annotations */ public void delSources() { if (annots != null) { @@ -401,11 +396,9 @@ } /** returns true if this pred has a "source(<i>agName</i>)" */ - public boolean hasSource(Structure agName) { + public boolean hasSource(Term agName) { if (annots != null) { - Structure ts = new Structure("source"); - ts.addTerm(agName); - return annots.contains(ts); + return annots.contains(createSource(agName)); } return false; } @@ -414,7 +407,7 @@ /** * Replaces all variables of the term for unnamed variables (_). * - * @param un is the unifier that containt the map of replacements + * @param un is the unifier that contains the map of replacements */ @Override public void makeVarsAnnon(Unifier un) { Modified: trunk/src/jason/asSyntax/VarTerm.java =================================================================== --- trunk/src/jason/asSyntax/VarTerm.java 2008-09-07 11:13:09 UTC (rev 1360) +++ trunk/src/jason/asSyntax/VarTerm.java 2008-09-09 08:57:21 UTC (rev 1361) @@ -512,7 +512,7 @@ } @Override - public void addSource(Structure t) { + public void addSource(Term t) { if (value != null && getValue().isPred()) ((Pred) getValue()).addSource(t); else @@ -521,7 +521,7 @@ } @Override - public boolean delSource(Structure s) { + public boolean delSource(Term s) { if (value != null && getValue().isPred()) return ((Pred) getValue()).delSource(s); else @@ -553,7 +553,7 @@ } @Override - public boolean hasSource(Structure s) { + public boolean hasSource(Term s) { if (value != null && getValue().isPred()) return ((Pred) getValue()).hasSource(s); else Modified: trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc =================================================================== --- trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-09-07 11:13:09 UTC (rev 1360) +++ trunk/src/jason/asSyntax/parser/AS2JavaParser.jcc 2008-09-09 08:57:21 UTC (rev 1361) @@ -460,12 +460,14 @@ /* List of terms */ -List terms() : { List listTerms = new ArrayList(); Term v; PlanBody o; } +List terms() : { ArrayList listTerms = new ArrayList(); Term v; PlanBody o; } { v=term() { listTerms.add(v); } ( "," v=term() { listTerms.add(v); } )* - { return listTerms; } + { listTerms.trimToSize(); + return listTerms; + } } Modified: trunk/src/jason/asSyntax/parser/as2j.java =================================================================== --- trunk/src/jason/asSyntax/parser/as2j.java 2008-09-07 11:13:09 UTC (rev 1360) +++ trunk/src/jason/asSyntax/parser/as2j.java 2008-09-09 08:57:21 UTC (rev 1361) @@ -647,7 +647,7 @@ /* List of terms */ final public List terms() throws ParseException { - List listTerms = new ArrayList(); Term v; PlanBody o; + ArrayList listTerms = new ArrayList(); Term v; PlanBody o; v = term(); listTerms.add(v); label_10: @@ -664,6 +664,7 @@ v = term(); listTerms.add(v); } + listTerms.trimToSize(); {if (true) return listTerms;} throw new Error("Missing return statement in function"); } @@ -1233,13 +1234,13 @@ return false; } - final private boolean jj_3R_13() { - if (jj_scan_token(39)) return true; + final private boolean jj_3R_17() { + if (jj_scan_token(42)) return true; return false; } - final private boolean jj_3R_17() { - if (jj_scan_token(42)) return true; + final private boolean jj_3R_13() { + if (jj_scan_token(39)) return true; return false; } Modified: trunk/src/jason/bb/BeliefBase.java =================================================================== --- trunk/src/jason/bb/BeliefBase.java 2008-09-07 11:13:09 UTC (rev 1360) +++ trunk/src/jason/bb/BeliefBase.java 2008-09-09 08:57:21 UTC (rev 1361) @@ -25,6 +25,7 @@ import jason.asSemantics.Agent; import jason.asSemantics.Unifier; +import jason.asSyntax.Atom; import jason.asSyntax.Literal; import jason.asSyntax.Pred; import jason.asSyntax.PredicateIndicator; @@ -42,8 +43,8 @@ */ public interface BeliefBase extends Iterable<Literal>, Cloneable { - public static final Term TPercept = Pred.createSource("percept"); - public static final Term TSelf = Pred.createSource("self"); + public static final Term TPercept = Pred.createSource(new Atom("percept")); + public static final Term TSelf = Pred.createSource(new Atom("self")); /** * Called before the MAS execution with the agent that uses this Modified: trunk/src/jason/bb/DefaultBeliefBase.java =================================================================== --- trunk/src/jason/bb/DefaultBeliefBase.java 2008-09-07 11:13:09 UTC (rev 1360) +++ trunk/src/jason/bb/DefaultBeliefBase.java 2008-09-09 08:57:21 UTC (rev 1361) @@ -272,10 +272,11 @@ @SuppressWarnings("unchecked") public void add(Literal l, boolean addInEnd) { - try { + //try { // minimise the allocation space of terms - if (!l.isAtom()) ((ArrayList) l.getTerms()).trimToSize(); - } catch (Exception e) {} + // Moved to the parser. + // if (!l.isAtom()) ((ArrayList) l.getTerms()).trimToSize(); + //} catch (Exception e) {} map.put(new LiteralWrapper(l), l); if (addInEnd) { Modified: trunk/src/jason/functions/time.java =================================================================== --- trunk/src/jason/functions/time.java 2008-09-07 11:13:09 UTC (rev 1360) +++ trunk/src/jason/functions/time.java 2008-09-09 08:57:21 UTC (rev 1361) @@ -8,7 +8,7 @@ <p>Function: <b><code>system.time</code></b>: encapsulates java System.currentTimeMillis(), returns the current time in milliseconds. - @see jason.stdlib.time + @see jason.stdlib.time internal action time @author Jomi */ Modified: trunk/src/jason/stdlib/time.java =================================================================== --- trunk/src/jason/stdlib/time.java 2008-09-07 11:13:09 UTC (rev 1360) +++ trunk/src/jason/stdlib/time.java 2008-09-09 08:57:21 UTC (rev 1361) @@ -36,7 +36,7 @@ </ul> @see jason.stdlib.date - @see jason.functions.time + @see jason.functions.time function time */ public class time extends DefaultInternalAction { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |