本文整理汇总了Java中jason.asSyntax.Term类的典型用法代码示例。如果您正苦于以下问题:Java Term类的具体用法?Java Term怎么用?Java Term使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Term类属于jason.asSyntax包,在下文中一共展示了Term类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: process
import jason.asSyntax.Term; //导入依赖的package包/类
@Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Term goal = directive.getTerm(0);
Pred subDir;
if (directive.getArity() > 1) {
subDir = Pred.parsePred(directive.getTerm(1).toString());
} else {
subDir = Pred.parsePred("bdg("+goal+")");
}
Directive sd = DirectiveProcessor.getDirective(subDir.getFunctor());
// apply sub directive
Agent newAg = sd.process((Pred)subDir, outerContent, innerContent);
if (newAg != null) {
// add +!g : true <- !!g.
newAg.getPL().add(ASSyntax.parsePlan("+!"+goal+" <- !!"+goal+"."));
return newAg;
}
} catch (Exception e) {
logger.log(Level.SEVERE,"Directive error.", e);
}
return null;
}
示例2: process
import jason.asSyntax.Term; //导入依赖的package包/类
@Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Term goal = directive.getTerm(0);
Term motivation = directive.getTerm(1);
Pred subDir = Pred.parsePred("bc("+goal+")");
//logger.fine("parameters="+goal+","+motivation+","+subDir);
Directive sd = DirectiveProcessor.getDirective(subDir.getFunctor());
// apply sub directive
Agent newAg = sd.process(subDir, outerContent, innerContent);
if (newAg != null) {
// add -m : true <- .succeed_goal(g).
newAg.getPL().add(ASSyntax.parsePlan("-"+motivation+" <- .succeed_goal("+goal+")."));
return newAg;
}
} catch (Exception e) {
logger.log(Level.SEVERE,"Directive error.", e);
}
return null;
}
示例3: process
import jason.asSyntax.Term; //导入依赖的package包/类
@Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Term goal = directive.getTerm(0);
Term fail = directive.getTerm(1);
Pred subDir = Pred.parsePred("bc("+goal+")");
//logger.fine("parameters="+goal+","+fail+","+subDir);
Directive sd = DirectiveProcessor.getDirective(subDir.getFunctor());
// apply sub directive
Agent newAg = sd.process(subDir, outerContent, innerContent);
if (newAg != null) {
// add +f : true <- .fail_goal(g).
newAg.getPL().add(ASSyntax.parsePlan("+"+fail+" <- .fail_goal("+goal+")."));
return newAg;
}
} catch (Exception e) {
logger.log(Level.SEVERE,"Directive error.", e);
}
return null;
}
示例4: act
import jason.asSyntax.Term; //导入依赖的package包/类
@Override
public void act(ActionExec action) { //, List<ActionExec> feedback) {
if (!isRunning()) return;
if (getEnvironmentAg() == null) return;
try {
Term acTerm = action.getActionTerm();
logger.fine("doing: " + acTerm);
String rw = "id"+jadeAg.incReplyWithId();
ACLMessage m = new ACLMessage(ACLMessage.REQUEST);
m.addReceiver(environmentAID);
m.setOntology(JadeEnvironment.actionOntology);
m.setContent(acTerm.toString());
m.setReplyWith(rw);
myPA.put(rw, action);
jadeAg.send(m);
} catch (Exception e) {
logger.log(Level.SEVERE, "Error sending action " + action, e);
}
}
示例5: execute
import jason.asSyntax.Term; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
checkArguments(args);
Term source = BeliefBase.ASelf;
if (args.length > 1)
source = args[1];
boolean before = false;
if (args.length > 2)
before = args[2].toString().equals("begin");
if (args[0].isList()) { // arg[0] is a list of strings
for (Term t: (ListTerm) args[0]) {
ts.getAg().getPL().add( transform2plan(t), source, before);
}
} else { // args[0] is a plan
ts.getAg().getPL().add( transform2plan(args[0]), source, before);
}
if (ts.getAg().getPL().hasMetaEventPlans())
ts.addGoalListener(new GoalListenerForMetaEvents(ts));
return true;
}
示例6: execute
import jason.asSyntax.Term; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception{
try {
boolean result = false;
int iagx = (int)((NumberTerm)terms[0]).solve();//Atual
int iagy = (int)((NumberTerm)terms[1]).solve();//Atual
String dir = terms[2].toString();
if(dir.equals("up")) {
result = (un.unifies(terms[3], new Atom(String.valueOf(iagx))) && un.unifies(terms[4], new Atom(String.valueOf(1))));
}else if(dir.equals("down")) {
result = (un.unifies(terms[3], new Atom(String.valueOf(iagx))) && un.unifies(terms[4], new Atom(String.valueOf(48))));
}else if(dir.equals("left")) {
result = (un.unifies(terms[3], new Atom(String.valueOf(1))) && un.unifies(terms[4], new Atom(String.valueOf(iagy))));
}else if(dir.equals("right")) {
result = (un.unifies(terms[3], new Atom(String.valueOf(48))) && un.unifies(terms[4], new Atom(String.valueOf(iagy))));
}
return result;
}catch(Throwable e) {
e.printStackTrace();
return false;
}
}
示例7: testVarTermAsNumber
import jason.asSyntax.Term; //导入依赖的package包/类
public void testVarTermAsNumber() throws Exception {
Term k = new VarTerm("K");
Unifier u = new Unifier();
NumberTermImpl n = new NumberTermImpl(10);
assertTrue(n.isNumeric());
assertFalse(n.isVar());
assertTrue(u.unifies(k, n));
k = k.capply(u);
// System.out.println(k+" u="+u);
assertTrue(k.isNumeric());
assertFalse(k.isLiteral());
ArithExpr exp = new ArithExpr((NumberTerm)k, ArithmeticOp.plus, new NumberTermImpl(20));
assertTrue(exp.solve() == 30d);
NumberTerm nt = ArithExpr.parseExpr("5 div 2");
assertTrue(nt.solve() == 2d);
nt = ArithExpr.parseExpr("5 mod 2");
assertTrue(nt.solve() == 1d);
}
示例8: execute
import jason.asSyntax.Term; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
checkArguments(args);
// try to get the intention from the "body"
Intention i = ts.getC().getSelectedIntention();
if (i == null) {
// try to get the intention from the event
Event evt = ts.getC().getSelectedEvent();
if (evt != null)
i = evt.getIntention();
}
if (i != null)
return un.unifies(i.getAsTerm(), args[0]);
else
return false;
}
示例9: testUnnamedVar2
import jason.asSyntax.Term; //导入依赖的package包/类
public void testUnnamedVar2() {
Structure t1 = Structure.parse("a(Y)");
assertFalse(t1.isGround());
Structure t1c = (Structure)t1.clone();
assertFalse(t1c.isGround());
t1c.makeVarsAnnon();
assertFalse(t1c.isGround());
Term t1cc = (Term)t1c.clone();
assertFalse(t1cc.isGround());
Unifier u = new Unifier();
VarTerm v = new VarTerm("X");
assertTrue(v.isVar());
u.unifies(v, t1cc);
assertTrue(v.isVar());
assertFalse(v.isGround());
Term tv = v.capply(u);
assertFalse(tv.isVar());
assertFalse(tv.isGround());
}
示例10: joinRenamedVarsIntoIntentionUnifier
import jason.asSyntax.Term; //导入依赖的package包/类
private void joinRenamedVarsIntoIntentionUnifier(IntendedMeans im, Unifier values) {
if (im.renamedVars != null) {
for (VarTerm ov: im.renamedVars.function.keySet()) {
//System.out.println("looking for a value for "+ov+" in "+im.renamedVars+" and "+topIM.unif);
UnnamedVar vt = (UnnamedVar)im.renamedVars.function.get(ov);
//System.out.println(" via "+vt);
im.unif.unifiesNoUndo(ov, vt); // introduces the renaming in the current unif
// if vt has got a value from the top (a "return" value), include this value in the current unif
Term vl = values.function.get(vt);
//System.out.println(ov+"="+vt+"="+vl);
if (vl != null) { // vt has value in top
//System.out.println(" and found "+vl);
vl = vl.capply(values);
if (vl.isLiteral())
((Literal)vl).makeVarsAnnon();
im.unif.bind(vt, vl);
}
}
}
}
示例11: testUnify2
import jason.asSyntax.Term; //导入依赖的package包/类
public void testUnify2() throws ParseException {
Unifier u = new Unifier();
u.unifies(new VarTerm("X"), new NumberTermImpl(3));
Term e1 = ASSyntax.parseTerm("X-1");
e1 = e1.capply(u);
assertTrue(u.unifies(new NumberTermImpl(2), e1));
assertTrue(u.unifies(e1, new NumberTermImpl(2)));
assertTrue(u.unifies(new NumberTermImpl(2), e1.clone()));
u.unifies(new VarTerm("Y"), new NumberTermImpl(1));
Term e2 = ASSyntax.parseTerm("Y+1");
e2 = e2.capply(u);
assertFalse(e1.isLiteral());
assertFalse(e2.isLiteral());
assertTrue(u.unifies(e2, e1));
}
示例12: execute
import jason.asSyntax.Term; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
checkArguments(args);
Circumstance C = ts.getC();
Trigger teGoal = new Trigger(TEOperator.add, TEType.achieve, (Literal)args[0]);
// search in PA
for (ActionExec a: C.getPendingActions().values())
if (a.getIntention().hasTrigger(teGoal, un))
return un.unifies(args[1], aAct);
// search in PI
Map<String, Intention> pi = C.getPendingIntentions();
for (String reason: pi.keySet())
if (pi.get(reason).hasTrigger(teGoal, un))
return un.unifies(args[1], new StringTermImpl(reason));
return false;
}
示例13: process
import jason.asSyntax.Term; //导入依赖的package包/类
@Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Trigger trigger = ASSyntax.parseTrigger(((StringTerm)directive.getTerm(0)).getString());
LogicalFormula context = LogExpr.parseExpr(((StringTerm)directive.getTerm(1)).getString());
Term goal = directive.getTerm(2);
Agent newAg = new Agent();
newAg.initAg();
// add t : not f__l(_) & c <- !f__g(g).
newAg.getPL().add(ASSyntax.parsePlan(trigger+" : not f__l(_) & " +context +" <- !f__g("+goal+")."));
// add t : f__l(_) & c <- +f__l(g).
newAg.getPL().add(ASSyntax.parsePlan(trigger+" : f__l(_) & (" +context +") <- +f__l("+goal+")."));
// add +!fg(g) : true <- +fl(g); !g; -fl(g)
newAg.getPL().add(ASSyntax.parsePlan("+!f__g("+goal+") <- +f__l("+goal+"); !"+goal+"; -f__l("+goal+")."));
// add -!fg(g) : true <- -fl(g)
newAg.getPL().add(ASSyntax.parsePlan("-!f__g("+goal+") <- -f__l("+goal+")."));
// add -fl(_) : fg(g) <- !fg(g)
newAg.getPL().add(ASSyntax.parsePlan("-f__l("+goal+") : f__l("+goal+") <- !f__g("+goal+")."));
return newAg;
} catch (Exception e) {
logger.log(Level.SEVERE,"Directive DG error.", e);
}
return null;
}
示例14: resumeSyncAskIntention
import jason.asSyntax.Term; //导入依赖的package包/类
private void resumeSyncAskIntention(String msgId, Term answerVar, Term answerValue) throws JasonException {
Intention i = getC().removePendingIntention(msgId);
i.peek().removeCurrentStep(); // removes the .send in the plan body
if (i.peek().getUnif().unifies(answerVar, answerValue)) {
getC().resumeIntention(i);
} else {
generateGoalDeletion(i, JasonException.createBasicErrorAnnots("ask_failed", "reply of an ask message ('"+answerValue+"') does not unify with fourth argument of .send ('"+answerVar+"')"));
}
}
示例15: testString
import jason.asSyntax.Term; //导入依赖的package包/类
private Structure testString(Term t) {
if (t.isStructure())
return (Structure)t;
if (t.isString())
return Structure.parse(((StringTerm)t).getString());
return null;
}