|
From: <jom...@us...> - 2008-09-27 15:39:24
|
Revision: 1382
http://jason.svn.sourceforge.net/jason/?rev=1382&view=rev
Author: jomifred
Date: 2008-09-27 15:39:20 +0000 (Sat, 27 Sep 2008)
Log Message:
-----------
optimise Unifier for the new hierarchy of classes
Modified Paths:
--------------
trunk/src/jason/asSemantics/Unifier.java
trunk/src/jason/asSyntax/ArithFunctionTerm.java
trunk/src/jason/asSyntax/LogExpr.java
trunk/src/jason/asSyntax/PlanBodyImpl.java
trunk/src/jason/asSyntax/Structure.java
trunk/src/test/TermTest.java
Modified: trunk/src/jason/asSemantics/Unifier.java
===================================================================
--- trunk/src/jason/asSemantics/Unifier.java 2008-09-27 13:56:22 UTC (rev 1381)
+++ trunk/src/jason/asSemantics/Unifier.java 2008-09-27 15:39:20 UTC (rev 1382)
@@ -23,10 +23,8 @@
package jason.asSemantics;
-import jason.asSyntax.Atom;
import jason.asSyntax.Literal;
import jason.asSyntax.Pred;
-import jason.asSyntax.Structure;
import jason.asSyntax.Term;
import jason.asSyntax.Trigger;
import jason.asSyntax.VarTerm;
@@ -215,50 +213,27 @@
// both terms are not vars
- // if the first is an Atom and the second pred, they must have the same functor
- // and no terms in the pred
- if (t1g.isAtom() && t2g.isPred()) {
- Atom t1a = (Atom)t1g;
- Pred t2p = (Pred)t2g;
- return t2p.getArity() == 0 && t1a.getFunctor().equals(t2p.getFunctor());
- }
-
- // if any of the terms is not a structure (is a number or a
+ // if any of the terms is not a literal (is a number or a
// string), they must be equal
- if (!t1g.isStructure() || !t2g.isStructure())
+ if (!t1g.isLiteral() || !t2g.isLiteral())
return t1g.equals(t2g);
- // both terms are structures
+ // both terms are literal
- Structure t1s = (Structure)t1g;
- Structure t2s = (Structure)t2g;
+ Literal t1s = (Literal)t1g;
+ Literal t2s = (Literal)t2g;
// different arities
final int ts = t1s.getArity();
if (ts != t2s.getArity())
return false;
- final boolean t1islit = t1g.isLiteral();
- final boolean t2islit = t2g.isLiteral();
- final boolean t1isneg = t1islit && ((Literal)t1g).negated();
- final boolean t2isneg = t2islit && ((Literal)t2g).negated();
-
// if both are literal, they must have the same negated
- if (t1islit && t2islit && t1isneg != t2isneg)
+ if (t1s.negated() != t2s.negated())
return false;
- // if one term is literal and the other not, the literal should not be negated
- if (t1islit && !t2islit && t1isneg)
- return false;
- if (t2islit && !t1islit && t2isneg)
- return false;
-
- // if the first term is a predicate and the second not, the first should not have annots
- if (t1g.isPred() && !t2g.isPred() && ((Pred)t1g).hasAnnot())
- return false;
-
// different functor
- if (!t1s.getFunctor().equals(t2s.getFunctor())) // t1a.getFunctor() != null &&
+ if (!t1s.getFunctor().equals(t2s.getFunctor()))
return false;
// unify inner terms
@@ -267,10 +242,9 @@
if (!unifiesNoUndo(t1s.getTerm(i), t2s.getTerm(i)))
return false;
- // if both are predicates, the first's annots must be subset of the second's annots
- if (t1g.isPred() && t2g.isPred())
- if ( ! ((Pred)t1g).hasSubsetAnnot((Pred)t2g, this))
- return false;
+ // the first's annots must be subset of the second's annots
+ if ( ! t1s.hasSubsetAnnot(t2s, this))
+ return false;
return true;
}
Modified: trunk/src/jason/asSyntax/ArithFunctionTerm.java
===================================================================
--- trunk/src/jason/asSyntax/ArithFunctionTerm.java 2008-09-27 13:56:22 UTC (rev 1381)
+++ trunk/src/jason/asSyntax/ArithFunctionTerm.java 2008-09-27 15:39:20 UTC (rev 1382)
@@ -14,6 +14,8 @@
* Represents an arithmetic function, like math.max(arg1,arg2) -- a functor (math.max) and two arguments.
* A Structure is thus used to store the data.
*
+ * @composed - "arguments (from Structure.terms)" 0..* Term
+ *
* @author Jomi
*
*/
Modified: trunk/src/jason/asSyntax/LogExpr.java
===================================================================
--- trunk/src/jason/asSyntax/LogExpr.java 2008-09-27 13:56:22 UTC (rev 1381)
+++ trunk/src/jason/asSyntax/LogExpr.java 2008-09-27 15:39:20 UTC (rev 1382)
@@ -44,10 +44,6 @@
@navassoc - op - LogicalOp
- //@view
- //@match class jason.asSyntax.Term
- //@opt !hide
-
*/
public class LogExpr extends BinaryStructure implements LogicalFormula {
Modified: trunk/src/jason/asSyntax/PlanBodyImpl.java
===================================================================
--- trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-09-27 13:56:22 UTC (rev 1381)
+++ trunk/src/jason/asSyntax/PlanBodyImpl.java 2008-09-27 15:39:20 UTC (rev 1382)
@@ -15,7 +15,7 @@
*
*
* @navassoc - next - PlanBody
- * @navassoc - type - BodyType
+ * @navassoc - type - PlanBody.BodyType
*
* @author Jomi
*/
Modified: trunk/src/jason/asSyntax/Structure.java
===================================================================
--- trunk/src/jason/asSyntax/Structure.java 2008-09-27 13:56:22 UTC (rev 1381)
+++ trunk/src/jason/asSyntax/Structure.java 2008-09-27 15:39:20 UTC (rev 1382)
@@ -44,7 +44,7 @@
* e.g.: val(10,x(3)).
* <i>n</i> can be 0, so this class also represents atoms.
*
- * @composed - - 0..* Term
+ * @composed - terms 0..* Term
*
*/
public class Structure extends Atom {
Modified: trunk/src/test/TermTest.java
===================================================================
--- trunk/src/test/TermTest.java 2008-09-27 13:56:22 UTC (rev 1381)
+++ trunk/src/test/TermTest.java 2008-09-27 15:39:20 UTC (rev 1382)
@@ -335,7 +335,7 @@
assertTrue(u.unifies(t1, t3));
assertEquals(u.get("H").toString(),"a");
assertEquals(u.get("R").toString(),"[b,c,d]");
- }
+ }
public void testApplyAnnots() {
Term t1 = DefaultTerm.parse("p[a,X,c,d]");
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|