本文整理汇总了Java中jason.asSemantics.Unifier.get方法的典型用法代码示例。如果您正苦于以下问题:Java Unifier.get方法的具体用法?Java Unifier.get怎么用?Java Unifier.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jason.asSemantics.Unifier
的用法示例。
在下文中一共展示了Unifier.get方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: hasVar
import jason.asSemantics.Unifier; //导入方法依赖的package包/类
@Override
public boolean hasVar(VarTerm t, Unifier u) {
if (equals(t))
return true;
if (u != null) { // if the var has a value in the unifier, search in that value
Term vl = u.get(this);
if (vl != null) {
try {
u.remove(this); // remove this var from the unifier to avoid going to search inside it again
return vl.hasVar(t, u);
} finally {
u.bind(this, vl);
}
}
}
return false;
}
示例2: testFindAll
import jason.asSemantics.Unifier; //导入方法依赖的package包/类
public void testFindAll() throws RevisionFailedException, ParseException {
Agent ag = new Agent();
ag.initAg();
Literal l1 = Literal.parseLiteral("a(10,x)");
assertFalse(l1.hasSource());
ag.addBel(l1);
ag.addBel(Literal.parseLiteral("a(20,y)"));
ag.addBel(Literal.parseLiteral("a(30,x)"));
assertEquals(ag.getBB().size(),3);
Unifier u = new Unifier();
Term X = ASSyntax.parseTerm("f(X)");
Literal c = Literal.parseLiteral("a(X,x)");
c.addAnnot(BeliefBase.TSelf);
VarTerm L = new VarTerm("L");
// System.out.println(ag.getPS().getAllRelevant(Trigger.parseTrigger(ste.getFunctor())));
try {
assertTrue((Boolean)new jason.stdlib.findall().execute(ag.getTS(), u, new Term[] { X, c, L }));
} catch (Exception e) {
e.printStackTrace();
}
ListTerm lt = (ListTerm) u.get("L");
//System.out.println("found=" + lt);
assertEquals(lt.size(), 2);
}
示例3: testUnifClone
import jason.asSemantics.Unifier; //导入方法依赖的package包/类
public void testUnifClone() {
VarTerm x1 = new VarTerm("X");
VarTerm x2 = new VarTerm("X");
assertEquals(x1,x2);
Unifier u1 = new Unifier();
u1.unifies(x1, new VarTerm("Y"));
u1.unifies(x2, new VarTerm("Z"));
Unifier u2 = (Unifier)u1.clone();
Object o1 = u1.get("X");
Object o2 = u2.get("X");
assertEquals(o1,o2);
assertEquals(u1,u2);
}
示例4: capply
import jason.asSemantics.Unifier; //导入方法依赖的package包/类
@Override
public Term capply(Unifier u) {
if (u != null) {
Term vl = u.get(this);
if (vl != null) {
if (!vl.isCyclicTerm() && vl.hasVar(this, u)) {
//logger.warning("The value of a variable contains itself, variable "+super.getFunctor()+" "+super.getSrcInfo()+", value="+vl+", unifier="+u);
u.remove(this); // remove this var to avoid loops in the apply below
Term tempVl = vl.capply(u);
u.bind(this, vl);
CyclicTerm ct = new CyclicTerm((Literal)tempVl, this);
Unifier renamedVars = new Unifier(); // remove "this" from the value to avoid loops in apply
ct.makeVarsAnnon(renamedVars);
renamedVars.remove(this);
u.compose(renamedVars);
vl = ct;
}
vl = vl.capply(u); // should clone here, since there is no cloning in unify
if (vl.isLiteral()) {
if (getNS() != Literal.DefaultNS) {
// TODO: change capply to has the new namespace as parameter and them remove this code
// use var ns for the value ns
vl = ((Literal)vl).cloneNS( (Atom)getNS().capply(u) ); // this var ns could be a var, so capply
}
if (negated()) {
((Literal)vl).setNegated(Literal.LNeg);
}
}
// decide whether to use var annots in apply
// X = p[a]
// !X[b]
// what's the event:
// +!p[a]
// or
// +!p[a,b]
// Answer: use annots of var, useful for meta-programming like
// P[step(N)]
if (vl.isLiteral() && this.hasAnnot()) { // if this var has annots, add them in the value's annots (Experimental)
vl = ((Literal)vl).forceFullLiteralImpl().addAnnots((ListTerm)this.getAnnots().capply(u));
}
return vl;
}
}
return clone();
}
示例5: hasSubsetAnnot
import jason.asSemantics.Unifier; //导入方法依赖的package包/类
@Override
public boolean hasSubsetAnnot(Literal p, Unifier u) {
if (annots == null)
return true;
if (!p.hasAnnot())
return false;
Term thisTail = null;
// since p's annots will be changed, clone the list (but not the terms)
ListTerm pAnnots = p.getAnnots().cloneLTShallow();
VarTerm pTail = pAnnots.getTail();
Term pAnnot = null;
ListTerm pAnnotsTail = null;
Iterator<Term> i2 = pAnnots.iterator();
boolean i2Reset = false;
Iterator<ListTerm> i1 = annots.listTermIterator(); // use this iterator to get the tail of the list
while (i1.hasNext()) {
ListTerm lt = i1.next();
Term annot = lt.getTerm();
if (annot == null)
break;
if (lt.isTail())
thisTail = lt.getTail();
if (annot.isVar() && !i2Reset) { // when we arrive to the vars in the annots of this, we need to start searching from the begin again
i2Reset = true;
i2 = pAnnots.iterator();
pAnnot = null;
}
// search annot in p's annots
boolean ok = false;
while (true) {
if (pAnnot != null && u.unifiesNoUndo(annot, pAnnot)) {
ok = true;
i2.remove();
pAnnot = i2.next();
break;
} else if (pAnnot != null && pAnnot.compareTo(annot) > 0) {
break; // quite the loop, the current p annot is greater than this annot, so annot is not in p's annots
} else if (i2.hasNext()) {
pAnnot = i2.next();
} else {
break;
}
}
// if p has a tail, add annot in p's tail
if (!ok && pTail != null) {
if (pAnnotsTail == null) {
pAnnotsTail = (ListTerm)u.get(pTail);
if (pAnnotsTail == null) {
pAnnotsTail = new ListTermImpl();
u.unifies(pTail, pAnnotsTail);
pAnnotsTail = (ListTerm)u.get(pTail);
}
}
pAnnotsTail.add(annot.clone());
ok = true;
}
if (!ok)
return false;
}
// if this Pred has a Tail, unify it with p remaining annots
if (thisTail != null)
u.unifies(thisTail, pAnnots);
return true;
}
示例6: testGetRelevantPlansAndAddPlan
import jason.asSemantics.Unifier; //导入方法依赖的package包/类
public void testGetRelevantPlansAndAddPlan() throws Exception {
Agent ag = new Agent();
ag.initAg();
Plan pa = ASSyntax.parsePlan("@t1 +a : g(10) <- .print(\"ok 10\").");
ag.getPL().add(pa, null, false);
assertTrue(pa != null);
assertEquals("@t1[source(self)] +a : g(10) <- .print(\"ok 10\").", pa.toASString());
ag.getPL().add(ASSyntax.parsePlan("@t2 +a : g(20) <- .print(\"ok 20\")."), new Structure("nosource"), false);
((Plan) ag.getPL().getPlans().get(1)).getLabel().addSource(new Structure("ag1"));
ag.getPL().add(ASSyntax.parsePlan("@t3 +b : true <- true."), null, false);
//System.out.println(ag.getPL());
TransitionSystem ts = new TransitionSystem(ag, null, null, null);
Unifier u = new Unifier();
StringTerm ste = new StringTermImpl("+a");
VarTerm X = new VarTerm("X");
//System.out.println(ag.getPL().getAllRelevant(Trigger.parseTrigger(ste.getFunctor()).getPredicateIndicator()));
new relevant_plans().execute(ts, u, new Term[] { ste, X });
assertTrue(ag.getPL().getPlans().get(0).equals(pa));
ListTerm plans = (ListTerm) u.get("X");
//System.out.println("plans="+plans);
assertEquals(plans.size(), 2);
assertEquals(ag.getPL().getPlans().size(), 3);
// remove plan t1 from PS
new remove_plan().execute(ts, new Unifier(), new Term[] { new Pred("t1") });
// ag.getPS().remove(0);
assertEquals(ag.getPL().getPlans().size(), 2);
// add plans returned from getRelevantPlans
// using IA addPlan
Iterator<Term> i = plans.iterator();
while (i.hasNext()) {
Term t = i.next();
new add_plan().execute(ts, new Unifier(), new Term[] { t, new Structure("fromGR") });
}
// add again plans returned from getRelevantPlans
// using IA addPlan receiving a list of plans
new add_plan().execute(ts, new Unifier(), new Term[] { plans, new Structure("fromLT") });
// the plan t2 (first plan now) must have 4 sources
assertEquals(ag.getPL().get("t2").getLabel().getSources().size(), 4);
// the plan t1 (third plan now) must have 2 sources
assertEquals(ag.getPL().get("t1").getLabel().getSources().size(), 2);
// remove plan t2,t3 (source = nosource) from PS
ListTerm llt = ListTermImpl.parseList("[t2,t3]");
assertTrue((Boolean)new remove_plan().execute(ts, new Unifier(), new Term[] { (Term) llt, new Pred("nosource") }));
assertEquals(ag.getPL().getPlans().size(), 3);
// remove plan t2,t3 (source = self) from PS
llt = ListTermImpl.parseList("[t2,t3]");
assertTrue((Boolean)new remove_plan().execute(ts, new Unifier(), new Term[] { (Term) llt }));
assertEquals(ag.getPL().getPlans().size(), 2);
// the plan t2 (first plan now) must have 3 sources
assertEquals(ag.getPL().get("t2").getLabel().getSources().size(), 3);
}