|
From: <jom...@us...> - 2008-07-17 09:16:31
|
Revision: 1352
http://jason.svn.sourceforge.net/jason/?rev=1352&view=rev
Author: jomifred
Date: 2008-07-17 09:16:19 +0000 (Thu, 17 Jul 2008)
Log Message:
-----------
copy var annots to its value (see TestVarInContext example)
Modified Paths:
--------------
trunk/applications/as-unit-test/src/jason/tests/TestVarInContext.java
trunk/build.xml
trunk/src/jason/asSemantics/Unifier.java
trunk/src/jason/asSemantics/VarsCluster.java
trunk/src/jason/asSyntax/VarTerm.java
trunk/src/jason/asSyntax/directives/Include.java
trunk/src/jason/bb/DefaultBeliefBase.java
trunk/src/jason/jeditplugin/AboutGUI.java
trunk/src/test/VarTermTest.java
Modified: trunk/applications/as-unit-test/src/jason/tests/TestVarInContext.java
===================================================================
--- trunk/applications/as-unit-test/src/jason/tests/TestVarInContext.java 2008-07-11 12:37:27 UTC (rev 1351)
+++ trunk/applications/as-unit-test/src/jason/tests/TestVarInContext.java 2008-07-17 09:16:19 UTC (rev 1352)
@@ -17,13 +17,17 @@
// defines the agent's AgentSpeak code
ag.parseAScode(
- "b1[b]. b2[c]. b3[d]. b4[a,d]. "+
+ "b1[b]. b2[c]. b3[d]. b4[a,d]. step(5). b(8)[step(3)]. b(9)[step(0)]."+
"+!test1 : P[e] | P[c] <- jason.asunit.print(P). " +
"+!test2 : P[e] & P[c] <- jason.asunit.print(P). " +
"-!test2 <- jason.asunit.print(\"error\"). " +
- "+!test3 : P[a] & P[d] <- jason.asunit.print(P). "
+ "+!test3 : P[a] & P[d] <- jason.asunit.print(P). " +
+
+ "is_old(P) :- (not P | (step(Current) & P[step(N)] & Current - N > 3)). " +
+ "+!test4(X) : is_old(X) <- jason.asunit.print(1). "+
+ "+!test4(_) <- jason.asunit.print(2). "
);
}
@@ -39,6 +43,12 @@
ag.addGoal("test3");
ag.assertPrint("b4", 5);
+
+ ag.addGoal("test4(b(8))");
+ ag.assertPrint("2", 5);
+
+ ag.addGoal("test4(b(9))");
+ ag.assertPrint("1", 5);
}
}
Modified: trunk/build.xml
===================================================================
--- trunk/build.xml 2008-07-11 12:37:27 UTC (rev 1351)
+++ trunk/build.xml 2008-07-17 09:16:19 UTC (rev 1352)
@@ -146,6 +146,14 @@
</target>
<target name="plugin" depends="compile, jar">
+ <propertyfile file="${dist.properties}">
+ <entry key="version" value="${version}" />
+ <entry key="release" value="${release}" />
+ <!-- entry default="0" key="build" operation="+" type="int" /-->
+ <entry key="build.date" type="date" value="now" />
+ </propertyfile>
+ <property file="${dist.properties}" />
+
<jar jarfile="${jedit.install.dir}/jars/${plugin.jar.name}">
<fileset dir="${basedir}/src/jeditPlugin">
<include name="Jason.props" />
@@ -221,16 +229,6 @@
<echo message="Generating Jason ${version}.${release}" />
- <propertyfile file="${dist.properties}">
- <entry key="version" value="${version}" />
- <entry key="release" value="${release}" />
- <!-- entry default="0" key="build" operation="+" type="int" /-->
- <entry key="build.date" type="date" value="now" />
- </propertyfile>
- <property file="${dist.properties}" />
-
- <antcall target="plugin" />
-
<fixcrlf eol="crlf" includes="**/*.txt,**/*.bat" srcdir="${basedir}" />
<delete failonerror="no" includeEmptyDirs="true">
Modified: trunk/src/jason/asSemantics/Unifier.java
===================================================================
--- trunk/src/jason/asSemantics/Unifier.java 2008-07-11 12:37:27 UTC (rev 1351)
+++ trunk/src/jason/asSemantics/Unifier.java 2008-07-17 09:16:19 UTC (rev 1352)
@@ -195,30 +195,28 @@
t2vl = null;
// both has value, their values should unify
- if (t1vl != null && t2vl != null) {
+ if (t1vl != null && t2vl != null)
return unifiesNoUndo(t1vl, t2vl);
- }
+
// only t1 has value, t1's value should unify with var t2
- if (t1vl != null) {
+ if (t1vl != null)
return unifiesNoUndo(t2gv, t1vl);
- }
+
// only t2 has value, t2's value should unify with var t1
- if (t2vl != null) {
+ if (t2vl != null)
return unifiesNoUndo(t1gv, t2vl);
- }
// both are var with no value, like X=Y
// we must ensure that these vars will form a cluster
//if (! t1gv.isUnnamedVar() && ! t2gv.isUnnamedVar()) {
- VarTerm t1c = (VarTerm) t1gv.clone();
- VarTerm t2c = (VarTerm) t2gv.clone();
- VarsCluster cluster = new VarsCluster(t1c, t2c, this);
- if (cluster.hasValue()) {
- // all vars of the cluster should have the same value
- for (VarTerm vtc : cluster) {
- function.put(vtc, cluster);
- }
- }
+ VarTerm t1c = (VarTerm) t1gv.clone();
+ VarTerm t2c = (VarTerm) t2gv.clone();
+ VarsCluster cluster = new VarsCluster(t1c, t2c, this);
+ if (cluster.hasValue()) {
+ // all vars of the cluster should have the same value
+ for (VarTerm vtc : cluster)
+ function.put(vtc, cluster);
+ }
//}
return true;
}
Modified: trunk/src/jason/asSemantics/VarsCluster.java
===================================================================
--- trunk/src/jason/asSemantics/VarsCluster.java 2008-07-11 12:37:27 UTC (rev 1351)
+++ trunk/src/jason/asSemantics/VarsCluster.java 2008-07-17 09:16:19 UTC (rev 1352)
@@ -77,18 +77,16 @@
private void add(VarTerm vt) {
Term vl = u.get(vt);
- if (vl == null) {
- // v1 has no value
- if (vars == null) {
+ if (vl == null) { // vt is not in a VarsCluster
+ if (vars == null)
vars = new TreeSet<VarTerm>();
- }
vars.add(vt);
} else if (vl instanceof VarsCluster) {
- if (vars == null) {
+ // since vt is in a VarsCluster, join the two sets here
+ if (vars == null)
vars = ((VarsCluster) vl).vars;
- } else {
+ else
vars.addAll(((VarsCluster) vl).vars);
- }
} else {
logger.warning("joining var that has value!");
}
Modified: trunk/src/jason/asSyntax/VarTerm.java
===================================================================
--- trunk/src/jason/asSyntax/VarTerm.java 2008-07-11 12:37:27 UTC (rev 1351)
+++ trunk/src/jason/asSyntax/VarTerm.java 2008-07-17 09:16:19 UTC (rev 1352)
@@ -42,7 +42,12 @@
/**
* Represents a variable Term: like X (starts with upper case). It may have a
- * value, after {@link Unifier}.apply.
+ * value, after {@link VarTerm}.apply.
+ *
+ * An object of this class can be used in place of a
+ * Literal, Number, List, String, .... It behaves like a
+ * Literal, Number, .... just in case its value is a Literal,
+ * Number, ...
*
* @author jomi
*/
@@ -110,15 +115,17 @@
}
vl = (Term)vl.clone(); // should clone here, since there is no cloning in unify
- // TODO: decide whether to use var annots in apply
+ // decide whether to use var annots in apply
// X = p[a]
// !X[b]
// what's the event:
// +!p[a]
// or
// +!p[a,b]
- //if (vl.isPred() && this.hasAnnot()) // if this var has annots, add them in the value's annots (Experimental)
- // ((Pred)vl).addAnnots(this.getAnnots());
+ // Answer: use annots of var, useful for meta-programming like
+ // P[step(N)]
+ 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();
@@ -147,8 +154,9 @@
protected UnnamedVar preferredUnnamedVar(Unifier un) {
if (un != null) {
- // check if I have a var cluster with another unnamed var there
- // and then prefer that unnamed var instead of a new one
+ // check if I am in a var cluster with another unnamed var,
+ // i.e. I am unified with an unnamed var,
+ // then prefer that unnamed var instead of a new one
Term vl = un.get(this);
if (vl != null && vl instanceof VarsCluster)
for (VarTerm v: (VarsCluster)vl)
Modified: trunk/src/jason/asSyntax/directives/Include.java
===================================================================
--- trunk/src/jason/asSyntax/directives/Include.java 2008-07-11 12:37:27 UTC (rev 1351)
+++ trunk/src/jason/asSyntax/directives/Include.java 2008-07-17 09:16:19 UTC (rev 1352)
@@ -56,7 +56,8 @@
// or in the source paths
List<String> newpath = new ArrayList<String>();
newpath.add(new File(outerPrefix).getAbsoluteFile().getParent());
- newpath.addAll(aslSourcePath);
+ if (aslSourcePath != null)
+ newpath.addAll(aslSourcePath);
file = checkPathAndFixWithSourcePath(file, newpath, null);
in = new FileInputStream(file);
}
Modified: trunk/src/jason/bb/DefaultBeliefBase.java
===================================================================
--- trunk/src/jason/bb/DefaultBeliefBase.java 2008-07-11 12:37:27 UTC (rev 1351)
+++ trunk/src/jason/bb/DefaultBeliefBase.java 2008-07-17 09:16:19 UTC (rev 1352)
@@ -62,7 +62,9 @@
protected Set<Literal> percepts = new HashSet<Literal>();
public void init(Agent ag, String[] args) {
- logger = Logger.getLogger(ag.getTS().getUserAgArch().getAgName() + "-"+DefaultBeliefBase.class.getSimpleName());
+ if (ag != null) {
+ logger = Logger.getLogger(ag.getTS().getUserAgArch().getAgName() + "-"+DefaultBeliefBase.class.getSimpleName());
+ }
}
public void stop() {
Modified: trunk/src/jason/jeditplugin/AboutGUI.java
===================================================================
--- trunk/src/jason/jeditplugin/AboutGUI.java 2008-07-11 12:37:27 UTC (rev 1351)
+++ trunk/src/jason/jeditplugin/AboutGUI.java 2008-07-17 09:16:19 UTC (rev 1352)
@@ -18,12 +18,12 @@
Properties p = new Properties();
p.load(JasonID.class.getResource("/dist.properties").openStream());
version = "Jason " + p.get("version") + "." + p.get("release");
- build = " build " + p.get("build") + " on " + p.get("build.date") + "\n\n";
+ build = " build on " + p.get("build.date") + "\n\n";
} catch (Exception ex) { }
JOptionPane.showMessageDialog(parent,
version + build+
- "Copyright (C) 2003-2005 Rafael H. Bordini, Jomi F. Hubner, et al.\n\n"+
+ "Copyright (C) 2003-2008 Rafael H. Bordini, Jomi F. Hubner, et al.\n\n"+
"This library is free software; you can redistribute it and/or\n"+
"modify it under the terms of the GNU Lesser General Public\n"+
"License as published by the Free Software Foundation; either\n"+
@@ -40,7 +40,7 @@
"Musees Nationaux, France). Photograph by Herve Lewandowski.\n\n"+
"To contact the authors:\n"+
"http://www.dur.ac.uk/r.bordini\n"+
- "http://www.inf.furb.br/~jomi",
+ "http://www.emse.fr/~hubner",
"JasonID - About",
JOptionPane.INFORMATION_MESSAGE,
new ImageIcon(JasonID.class.getResource("/images/Jason-GMoreau-Small.jpg")));
Modified: trunk/src/test/VarTermTest.java
===================================================================
--- trunk/src/test/VarTermTest.java 2008-07-11 12:37:27 UTC (rev 1351)
+++ trunk/src/test/VarTermTest.java 2008-07-17 09:16:19 UTC (rev 1352)
@@ -261,7 +261,7 @@
assertTrue(u.unifies(v1, p1));
assertEquals(u.get("X").toString(), "p(t1,t2)");
v1.apply(u);
- assertEquals("p(t1,t2)",v1.toString());
+ assertEquals("p(t1,t2)[a,b,c]",v1.toString());
}
public void testVarWithAnnots2() {
@@ -280,7 +280,7 @@
assertTrue(u.unifies(v1, v2));
assertTrue(u.unifies(new Literal("vvv"), v1));
v1.apply(u);
- assertEquals("vvv", v1.toString());
+ assertEquals("vvv[a]", v1.toString());
}
public void testVarWithAnnots3() {
@@ -315,7 +315,7 @@
assertEquals("a", u.get("A").toString());
assertEquals("p(1)", u.get(v).toString());
v.apply(u);
- assertEquals("p(1)", v.toString());
+ assertEquals("p(1)[a]", v.toString());
}
/*
@@ -348,7 +348,7 @@
assertTrue(i.hasNext());
u = i.next(); // u = {P[d]=b2}
v1.apply(u);
- assertEquals("b2",v1.toString());
+ assertEquals("b2[d]",v1.toString());
}
@SuppressWarnings("unchecked")
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|