本文整理汇总了Java中jason.asSyntax.Literal.isRule方法的典型用法代码示例。如果您正苦于以下问题:Java Literal.isRule方法的具体用法?Java Literal.isRule怎么用?Java Literal.isRule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jason.asSyntax.Literal
的用法示例。
在下文中一共展示了Literal.isRule方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: findBel
import jason.asSyntax.Literal; //导入方法依赖的package包/类
/**
* Find a literal in BB using unification to test.
*
* Returns the belief as it is in BB, e.g. findBel(a(_),...)
* may returns a(10)[source(ag)].
*
* The unifier <i>un</i> is updated by the method.
*/
public Literal findBel(Literal bel, Unifier un) {
synchronized (bb.getLock()) {
Iterator<Literal> relB = bb.getCandidateBeliefs(bel, un);
if (relB != null) {
while (relB.hasNext()) {
Literal b = relB.next();
// recall that order is important because of annotations!
if (!b.isRule() && un.unifies(bel, b)) {
return b;
}
}
}
return null;
}
}
示例3: abolish
import jason.asSyntax.Literal; //导入方法依赖的package包/类
/** Removes all occurrences of <i>bel</i> in BB.
If <i>un</i> is null, an empty Unifier is used.
*/
public void abolish(Literal bel, Unifier un) throws RevisionFailedException {
List<Literal> toDel = new ArrayList<Literal>();
if (un == null) un = new Unifier();
synchronized (bb.getLock()) {
Iterator<Literal> il = getBB().getCandidateBeliefs(bel, un);
if (il != null) {
while (il.hasNext()) {
Literal inBB = il.next();
if (!inBB.isRule()) {
// need to clone unifier since it is changed in previous iteration
if (un.clone().unifiesNoUndo(bel, inBB)) {
toDel.add(inBB);
}
}
}
}
for (Literal l: toDel) {
delBel(l);
}
}
}
示例4: stop
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void stop() {
try {
logger.fine("writting to file " + file);
PrintWriter out = new PrintWriter(new FileWriter(file));
out.println("// BB stored by TextPersistentBB\n");
for (Literal b: this) {
if (! b.isRule()) {
out.println(b.toString()+".");
}
}
out.close();
} catch (Exception e) {
logger.log(Level.SEVERE, "Error writing BB in file " + file, e);
}
nextBB.stop();
}
示例5: 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;
}
示例6: add
import jason.asSyntax.Literal; //导入方法依赖的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);
}