本文整理汇总了Java中jason.asSyntax.Term.equals方法的典型用法代码示例。如果您正苦于以下问题:Java Term.equals方法的具体用法?Java Term.equals怎么用?Java Term.equals使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jason.asSyntax.Term
的用法示例。
在下文中一共展示了Term.equals方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getVarFromValue
import jason.asSyntax.Term; //导入方法依赖的package包/类
public VarTerm getVarFromValue(Term vl) {
for (VarTerm v: function.keySet()) {
Term vvl = function.get(v);
if (vvl.equals(vl)) {
return v;
}
}
return null;
}
示例2: testAddRemove
import jason.asSyntax.Term; //导入方法依赖的package包/类
public void testAddRemove() {
l1.add(new Structure("d"));
l1.add(0, new Structure("a1"));
l1.add(1, new Structure("a2"));
assertEquals(new Structure("a2"), l1.get(1));
assertEquals(l1.size(), 6);
List<Term> lal = new ArrayList<Term>();
lal.add(new Structure("b1"));
lal.add(new Structure("b2"));
l1.addAll(4, lal);
assertEquals(l1.size(), 8);
//System.out.println(l1);
assertEquals(new Structure("a1"), l1.remove(0));
assertEquals(new Structure("b"), l1.remove(2));
assertTrue(l1.remove(new Structure("b1")));
assertTrue(l1.remove(new Structure("d")));
assertTrue(l1.remove(new Structure("a2")));
assertEquals(l1.size(), 3);
Iterator<Term> i = l1.iterator();
while (i.hasNext()) {
Term t = i.next();
//System.out.println("-"+t);
if (t.equals(new Structure("a"))) {
i.remove();
}
}
assertEquals("[b2,c]", l1.toString());
i = l1.iterator();
i.next(); i.next(); // c is the current
i.remove(); // remove c
assertEquals("[b2]", l1.toString());
}
示例3: unifyTerms
import jason.asSyntax.Term; //导入方法依赖的package包/类
protected boolean unifyTerms(Term t1g, Term t2g) {
// if args are expressions, apply them and use their values
if (t1g.isArithExpr())
t1g = t1g.capply(this);
if (t2g.isArithExpr())
t2g = t2g.capply(this);
final boolean t1gisvar = t1g.isVar();
final boolean t2gisvar = t2g.isVar();
// one of the args is a var
if (t1gisvar || t2gisvar) {
final VarTerm t1gv = t1gisvar ? (VarTerm)t1g : null;
final VarTerm t2gv = t2gisvar ? (VarTerm)t2g : null;
// get their values
final Term t1vl = t1gisvar ? get(t1gv) : t1g;
final Term t2vl = t2gisvar ? get(t2gv) : t2g;
if (t1vl != null && t2vl != null) { // unifies the two values of the vars
return unifiesNoUndo(t1vl, t2vl);
} else if (t1vl != null) { // unifies var with value
return bind(t2gv, t1vl);
} else if (t2vl != null) {
return bind(t1gv, t2vl);
} else { // unify two vars
if (! t1gv.getNS().equals(t2gv.getNS()))
return false;
if (t1gv.negated() != t2gv.negated())
return false;
bind(t1gv, t2gv);
return true;
}
}
// both terms are not vars
// if any of the terms is not a literal (is a number or a
// string), they must be equal
// (for unification, lists are literals)
if (!t1g.isLiteral() && !t1g.isList() || !t2g.isLiteral() && !t2g.isList())
return t1g.equals(t2g);
// both terms are literal
Literal t1s = (Literal)t1g;
Literal t2s = (Literal)t2g;
// different arities
final int ts = t1s.getArity();
if (ts != t2s.getArity())
return false;
// if both are literal, they must have the same negated
if (t1s.negated() != t2s.negated())
return false;
// different functor
if (!t1s.getFunctor().equals(t2s.getFunctor()))
return false;
// different name space
if (!unifiesNamespace(t1s, t2s))
return false;
// unify inner terms
// do not use iterator! (see ListTermImpl class)
for (int i = 0; i < ts; i++)
if (!unifiesNoUndo(t1s.getTerm(i), t2s.getTerm(i)))
return false;
// the first's annots must be subset of the second's annots
if ( ! t1s.hasSubsetAnnot(t2s, this))
return false;
return true;
}