本文整理汇总了Java中jason.asSyntax.Literal.copy方法的典型用法代码示例。如果您正苦于以下问题:Java Literal.copy方法的具体用法?Java Literal.copy怎么用?Java Literal.copy使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jason.asSyntax.Literal
的用法示例。
在下文中一共展示了Literal.copy方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: execute
import jason.asSyntax.Literal; //导入方法依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
try {
Literal pattern = (Literal)args[0];
ListTerm result = new ListTermImpl();
synchronized (ts.getAg().getBB().getLock()) {
Iterator<Literal> i = ts.getAg().getBB().getCandidateBeliefs(pattern, un);
while (i.hasNext()) {
Literal l = i.next();
if (l.isRule()) {
if (un.clone().unifies(pattern, l)) {
l = l.copy();
l.delSources();
((Rule)l).setAsTerm(true);
result.add(l);
}
}
}
}
return un.unifies(args[1],result);
} catch (Exception e) {
ts.getLogger().warning("Error in internal action 'get_rules'! "+e);
}
return false;
}
示例2: process
import jason.asSyntax.Literal; //导入方法依赖的package包/类
@Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Agent newAg = new Agent();
newAg.initAg();
Literal goal = Literal.parseLiteral(directive.getTerm(0).toString());
// add +!g : g <- true.
newAg.getPL().add(ASSyntax.parsePlan("+!"+goal+" : " +goal+"."));
// add ?g in the end of all inner plans
for (Plan p: innerContent.getPL()) {
// only for +!g plans
if (p.getTrigger().isAchvGoal()) {
Literal planGoal = p.getTrigger().getLiteral();
if (new Unifier().unifies(planGoal, goal)) { // if the plan goal unifier the pattern goal
PlanBody b = new PlanBodyImpl(BodyType.test, planGoal.copy()); //goal.copy());
p.getBody().add(b);
}
}
newAg.getPL().add(p);
}
// add +g : true <- .succeed_goal(g).
newAg.getPL().add(ASSyntax.parsePlan("+"+goal+" <- .succeed_goal("+goal+")."));
return newAg;
} catch (Exception e) {
logger.log(Level.SEVERE,"Directive error.", e);
}
return null;
}
示例3: process
import jason.asSyntax.Literal; //导入方法依赖的package包/类
@Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Literal goal = Literal.parseLiteral(directive.getTerm(0).toString());
Pred subDir;
if (directive.getArity() > 1) {
subDir = Pred.parsePred(directive.getTerm(1).toString());
} else {
subDir = Pred.parsePred("bc("+goal+")");
}
Directive sd = DirectiveProcessor.getDirective(subDir.getFunctor());
// apply sub directive
Agent newAg = sd.process(subDir, outerContent, innerContent);
if (newAg != null) {
// add bel g
Literal ig = goal.copy();
ig.addAnnot(BeliefBase.TPercept);
newAg.addInitialBel(goal);
// 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;
}
示例4: add
import jason.asSyntax.Literal; //导入方法依赖的package包/类
protected boolean add(Literal l, boolean addInEnd) {
if (!l.canBeAddedInBB()) {
logger.log(Level.SEVERE, "Error: '"+l+"' can not be added in the belief base.");
return false;
}
Literal bl = contains(l);
if (bl != null && !bl.isRule()) {
// add only annots
if (bl.importAnnots(l)) {
// check if it needs to be added in the percepts list
// (note that l contains only the annots imported)
if (l.hasAnnot(TPercept)) {
percepts.add(bl);
}
return true;
}
} else {
// new bel
l = l.copy(); // we need to clone l for the consequent event to not have a ref to this bel (which may change before the event is processed); see bug from Viviana Marcardi
BelEntry entry = provideBelEntry(l);
entry.add(l, addInEnd);
// add it in the percepts list
if (l.hasAnnot(TPercept)) {
percepts.add(l);
}
size++;
return true;
}
return false;
}
示例5: process
import jason.asSyntax.Literal; //导入方法依赖的package包/类
@Override
public Agent process(Pred directive, Agent outerContent, Agent innerContent) {
try {
Agent newAg = new Agent();
newAg.initAg();
Literal goal = Literal.parseLiteral(directive.getTerm(0).toString());
// add +!g : g <- true.
newAg.getPL().add(ASSyntax.parsePlan("+!"+goal+" : " +goal+"."));
// change all inner plans
int i = 0;
for (Plan p: innerContent.getPL()) {
if (p.getTrigger().isAchvGoal()) {
Literal planGoal = p.getTrigger().getLiteral();
if (new Unifier().unifies(planGoal, goal)) { // if the plan goal unifier the pattern goal
i++;
// create p__f(i,g)
Literal pi = ASSyntax.createLiteral("p__f", ASSyntax.createNumber(i), goal.copy());
// change context to "not p__f(i,g) & c"
LogicalFormula context = p.getContext();
if (context == null) {
p.setContext(new LogExpr(LogicalOp.not, pi));
} else {
p.setContext(new LogExpr(new LogExpr(LogicalOp.not, pi), LogicalOp.and, context));
}
// change body
// add +p__f(i,g)
PlanBody b1 = new PlanBodyImpl(BodyType.addBel, pi);
p.getBody().add(0, b1);
// add ?g
PlanBody b2 = new PlanBodyImpl(BodyType.test, planGoal.copy()); //goal.copy());
p.getBody().add(b2);
}
}
newAg.getPL().add(p);
}
// add -!g : true <- !!g.
newAg.getPL().add(ASSyntax.parsePlan("-!"+goal+" <- !!"+goal+"."));
// add +g : true <- .abolish(p__f(_,g)); .succeed_goal(g).
newAg.getPL().add(ASSyntax.parsePlan("+"+goal+" <- .abolish(p__f(_,"+goal+")); .succeed_goal("+goal+")."));
// add -g <- .abolish(p__f(_,g)).
newAg.getPL().add(ASSyntax.parsePlan("-"+goal+" <- .abolish(p__f(_,"+goal+"))."));
return newAg;
} catch (Exception e) {
logger.log(Level.SEVERE,"Directive EBDG error.", e);
}
return null;
}