本文整理汇总了Java中jason.asSyntax.Term.isVar方法的典型用法代码示例。如果您正苦于以下问题:Java Term.isVar方法的具体用法?Java Term.isVar怎么用?Java Term.isVar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jason.asSyntax.Term
的用法示例。
在下文中一共展示了Term.isVar方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeVarsAnnon
import jason.asSyntax.Term; //导入方法依赖的package包/类
public void makeVarsAnnon(Literal l, Unifier un) {
try {
for (int i=0; i<l.getArity(); i++) {
Term t = l.getTerm(i);
if (t.isString()) {
StringTerm st = (StringTerm)t;
Matcher matcher = regex.matcher(st.getString());
StringBuffer sb = new StringBuffer();
while (matcher.find()) {
String sVar = matcher.group();
sVar = sVar.substring(2, sVar.length() - 1);
Term v = ASSyntax.parseTerm(sVar);
if (v.isVar()) {
VarTerm to = ((Structure)l).varToReplace(v, un);
matcher.appendReplacement(sb, "#{"+to.toString()+"}");
}
}
matcher.appendTail(sb);
l.setTerm(i, new StringTermImpl(sb.toString()));
}
}
} catch (ParseException pe) {
pe.printStackTrace();
}
}
示例2: argsToString
import jason.asSyntax.Term; //导入方法依赖的package包/类
protected String argsToString(Term[] args) {
StringBuilder sout = new StringBuilder();
//try {
// if (ts.getSettings().logLevel() != Level.WARNING && args.length > 0) {
// sout = new StringBuilder();
// }
//} catch (Exception e) {}
for (int i = 0; i < args.length; i++) {
if (args[i].isString()) {
StringTerm st = (StringTerm)args[i];
sout.append(st.getString());
} else {
Term t = args[i];
if (! t.isVar()) {
sout.append(t);
} else {
sout.append(t+"<no-value>");
}
}
}
return sout.toString();
}
示例3: get
import jason.asSyntax.Term; //导入方法依赖的package包/类
/**
* gets the value for a Var, if it is unified with another var, gets this
* other's value
*/
public Term get(VarTerm vtp) {
Term vl = function.get(vtp);
if (vl != null && vl.isVar()) { // optimised deref
return get((VarTerm)vl);
}
/* vars in unifier are not negated anymore! (works like namespace)
if (vl == null) { // try negated value of the var
//System.out.println("for "+vtp+" try "+new VarTerm(vtp.negated(), vtp.getFunctor())+" in "+this);
vl = function.get( new VarTerm(vtp.negated(), vtp.getFunctor()) );
//System.out.println(" and found "+vl);
if (vl != null && vl.isVar()) {
vl = get((VarTerm)vl);
}
if (vl != null && vl.isLiteral()) {
vl = vl.clone();
((Literal)vl).setNegated(((Literal)vl).negated());
}
}
*/
return vl;
}
示例4: compose
import jason.asSyntax.Term; //导入方法依赖的package包/类
/** add all unifications from u */
public void compose(Unifier u) {
for (VarTerm k: u.function.keySet()) {
Term current = get(k);
Term kValue = u.function.get(k);
if (current != null && (current.isVar() || kValue.isVar())) { // current unifier has the new var
unifies(kValue, current);
} else {
function.put( (VarTerm)k.clone(), kValue.clone());
}
}
}
示例5: 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;
}
示例6: add
import jason.asSyntax.Term; //导入方法依赖的package包/类
@Override
public boolean add(Literal bel) {
Structure kb = indexedBels.get(bel.getFunctor());
if (kb != null && kb.getArity() == bel.getArity()) { // is a constrained bel?
// find the bel in BB and eventually remove it
u.clear();
Literal linbb = null;
boolean remove = false;
Iterator<Literal> relevant = getCandidateBeliefs(bel, null);
if (relevant != null) {
final int kbArity = kb.getArity();
while (relevant.hasNext() && !remove) {
linbb = relevant.next();
if (!linbb.isRule()) {
// check equality of all terms that are "key"
// if some key is different, no problem
// otherwise, remove the current bel
boolean equals = true;
for (int i = 0; i<kbArity; i++) {
Term kbt = kb.getTerm(i);
if (!kbt.isVar()) { // is key?
if (!u.unifies(bel.getTerm(i), linbb.getTerm(i))) {
equals = false;
break;
}
}
}
if (equals) {
remove = true;
}
}
}
}
if (remove) {
remove(linbb);
}
}
return super.add(bel);
}