本文整理汇总了Java中jason.asSyntax.Literal类的典型用法代码示例。如果您正苦于以下问题:Java Literal类的具体用法?Java Literal怎么用?Java Literal使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Literal类属于jason.asSyntax包,在下文中一共展示了Literal类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: perceive
import jason.asSyntax.Literal; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public List<Literal> perceive() {
if (!isRunning()) return null;
if (getEnvironmentAg() == null) return null;
@SuppressWarnings("rawtypes")
List percepts = null;
try {
ACLMessage askMsg = new ACLMessage(ACLMessage.QUERY_REF);
askMsg.addReceiver(environmentAID);
askMsg.setOntology(JadeEnvironment.perceptionOntology);
askMsg.setContent("getPercepts");
ACLMessage r = jadeAg.ask(askMsg);
if (r != null && r.getContent().startsWith("[")) {
percepts = ListTermImpl.parseList(r.getContent());
}
} catch (Exception e) {
logger.log(Level.SEVERE, "Error in perceive.", e);
}
return percepts;
}
示例2: addAllPositionsToPool
import jason.asSyntax.Literal; //导入依赖的package包/类
private void addAllPositionsToPool() {
view.setIgnoreRepaint(true);
for (int x = 0; x < W_GRID; x++) {
for (int y = 0; y < H_GRID; y++) {
if (!isOccupied(x, y)) {
model.possiblePosition.add(new Position(x, y, UP));
addPercept(SCOUT, Literal.parseLiteral("pos(" + x + "," + y + "," + UP + ")"));
model.possiblePosition.add(new Position(x, y, DOWN));
addPercept(SCOUT, Literal.parseLiteral("pos(" + x + "," + y + "," + DOWN + ")"));
model.possiblePosition.add(new Position(x, y, LEFT));
addPercept(SCOUT, Literal.parseLiteral("pos(" + x + "," + y + "," + LEFT + ")"));
model.possiblePosition.add(new Position(x, y, RIGHT));
addPercept(SCOUT, Literal.parseLiteral("pos(" + x + "," + y + "," + RIGHT + ")"));
}
}
}
view.setIgnoreRepaint(false);
view.update();
}
示例3: getColorFromSimulation
import jason.asSyntax.Literal; //导入依赖的package包/类
public void getColorFromSimulation() {
String color;
if (containsPercept(DETERMINED_LOC))
realPos = model.getPosition();
if (realPos.getLoc().equals(realVictims[0])) {
color = RED;
} else if (realPos.getLoc().equals(realVictims[1])) {
color = BLUE;
} else if (realPos.getLoc().equals(realVictims[2])) {
color = GREEN;
} else {
color = WHITE;
}
delay();
System.out.println("Simulation: The color is " + color);
addPercept(SCOUT, Literal.parseLiteral("color(" + color + ")"));
}
示例4: testMakeVarsAnnon6
import jason.asSyntax.Literal; //导入依赖的package包/类
public void testMakeVarsAnnon6() {
// if we make a literal anonymous multiple times, the instances should not
// be equal but should eb unifiable.
Literal literal = Literal.parseLiteral("literal(Variable, _)");
List<Literal> literals = new ArrayList<Literal>();
literals.add(literal);
// create a list of anonymized l1s
for (int i = 0; i < 5; i++) {
literals.add((literal.copy()).makeVarsAnnon());
}
// ensure that all the anonymizations of Variable are different
// ensure that all the anonymizations of _ are different
// ensure that all pairs are unifiable
for (Literal l1 : literals) {
for (Literal l2 : literals) {
if (l1 == l2) {
continue;
}
assertFalse(l1.getTerm(0).equals(l2.getTerm(0)));
assertFalse(l1.getTerm(1).equals(l2.getTerm(1)));
assertTrue(new Unifier().unifies(l1, l2));
}
}
}
示例5: consultPercepts
import jason.asSyntax.Literal; //导入依赖的package包/类
/**
* Returns a copy of the perception for an agent.
*
* It is the same list returned by getPercepts, but
* doesn't consider the last call of the method.
*/
public List<Literal> consultPercepts(String agName) {
int size = percepts.size();
List<Literal> agl = agPercepts.get(agName);
if (agl != null) {
size += agl.size();
}
List<Literal> p = new ArrayList<Literal>(size);
if (! percepts.isEmpty()) { // has global perception?
synchronized (percepts) {
// make a local copy of the environment percepts
// Note: a deep copy will be done by BB.add
p.addAll(percepts);
}
}
if (agl != null) { // add agent personal perception
synchronized (agl) {
p.addAll(agl);
}
}
return p;
}
示例6: removePerceptsByUnif
import jason.asSyntax.Literal; //导入依赖的package包/类
/** Removes all percepts from the common perception list that unifies with <i>per</i>.
*
* Example: removePerceptsByUnif(Literal.parseLiteral("position(_)")) will remove
* all percepts that unifies "position(_)".
*
* @return the number of removed percepts.
*/
public int removePerceptsByUnif(Literal per) {
int c = 0;
if (! percepts.isEmpty()) { // has global perception?
synchronized (percepts) {
Iterator<Literal> i = percepts.iterator();
while (i.hasNext()) {
Literal l = i.next();
if (new Unifier().unifies(l,per)) {
i.remove();
c++;
}
}
}
if (c>0) uptodateAgs.clear();
}
return c;
}
示例7: abolish
import jason.asSyntax.Literal; //导入依赖的package包/类
@Override
public boolean abolish(Atom namespace, PredicateIndicator pi) {
BelEntry entry = nameSpaces.get(namespace).remove(pi);
if (entry != null) {
size -= entry.size();
// remove also in percepts list!
Iterator<Literal> i = percepts.iterator();
while (i.hasNext()) {
Literal l = i.next();
if (l.getPredicateIndicator().equals(pi))
i.remove();
}
return true;
} else {
return false;
}
//return belsMap.remove(pi) != null;
}
示例8: testObTerm
import jason.asSyntax.Literal; //导入依赖的package包/类
public void testObTerm() {
ObjectTerm term = new ObjectTermImpl("test");
assertTrue(term.equals(term));
assertTrue(new Unifier().unifies(new ObjectTermImpl("test"), new ObjectTermImpl("test")));
String string = "test";
assertTrue(new Unifier().unifies(new ObjectTermImpl(string), new ObjectTermImpl(string)));
BeliefBase base = new DefaultBeliefBase();
base.add(ASSyntax.createLiteral("test", new ObjectTermImpl("test")));
Iterator<Literal> iterator = base.getCandidateBeliefs(ASSyntax.createLiteral("test", new ObjectTermImpl("test")), new Unifier());
assertTrue(iterator != null && iterator.hasNext());
Literal result = iterator.next();
assertTrue(result.getFunctor().equals("test"));
assertTrue(result.getTerm(0).getClass().equals(ObjectTermImpl.class));
assertTrue(result.getTerm(0).equals(new ObjectTermImpl("test")));
assertFalse(iterator.hasNext());
}
示例9: 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;
}
示例10: testCyclicTerm3
import jason.asSyntax.Literal; //导入依赖的package包/类
public void testCyclicTerm3() throws ParseException {
Unifier u = new Unifier();
assertTrue(u.unifies(new VarTerm("Merge"), parseTerm("choice([Off,Fork])")));
assertTrue(u.unifies(new VarTerm("Off"), parseTerm("seq(tell(b,c,offer),seq(tell(c,b,counter),Merge))")));
assertTrue(u.unifies(new VarTerm("Fork"), parseTerm("fork(seq(tell(b,s,final),end),seq(tell(b,c,result),end))")));
assertTrue(u.unifies(new VarTerm("Glob"), parseTerm("seq(tell(s,b,item),Merge)")));
//assertTrue(u.unifies(new VarTerm("X"), parseTerm("f(Y)")));
//assertTrue(u.unifies(new VarTerm("Y"), parseTerm("g(X)")));
//System.out.println(u);
VarTerm m = new VarTerm("Glob");
Literal tm = (Literal)m.capply(u);
assertTrue(tm.getTerm(1).isCyclicTerm());
}
示例11: testPercept2
import jason.asSyntax.Literal; //导入依赖的package包/类
public void testPercept2() {
BeliefBase bb = new DefaultBeliefBase();
assertTrue(bb.add(Literal.parseLiteral("p1[source(percept),source(ag1)]")));
assertTrue(bb.add(Literal.parseLiteral("p2[source(percept),a1]")));
assertEquals(iteratorSize(bb.getPercepts()),2);
Iterator<Literal> i = bb.getPercepts();
Literal l = i.next();
while (!l.getFunctor().equals("p1")) l = i.next();
i.remove();
assertEquals("p1[source(ag1)]",l.toString());
assertEquals(1,iteratorSize(bb.getPercepts()));
assertEquals(2,bb.size());
i = bb.getPercepts();
l = i.next(); // get the p2
i.remove();
assertEquals("p2[a1]",l.toString());
assertEquals(0,iteratorSize(bb.getPercepts()));
assertEquals(1,bb.size());
}
示例12: fixAgInIAandFunctions
import jason.asSyntax.Literal; //导入依赖的package包/类
private void fixAgInIAandFunctions(Agent a, Literal l) throws Exception {
// if l is internal action/function
if (l instanceof InternalActionLiteral) {
((InternalActionLiteral)l).setIA(null); // reset the IA in the literal, the IA there will be updated next getIA call
}
if (l instanceof ArithFunctionTerm) {
((ArithFunctionTerm)l).setAgent(a);
}
if (l instanceof Rule) {
LogicalFormula f = ((Rule)l).getBody();
if (f instanceof Literal) {
fixAgInIAandFunctions(a, (Literal)f);
}
}
for (int i=0; i<l.getArity(); i++) {
if (l.getTerm(i) instanceof Literal)
fixAgInIAandFunctions(a, (Literal)l.getTerm(i));
}
}
示例13: testAtomParsing
import jason.asSyntax.Literal; //导入依赖的package包/类
public void testAtomParsing() throws ParseException {
Literal l = parseLiteral("b");
assertTrue(l instanceof Literal);
assertTrue(l.isAtom());
// if is atom, can be cast to Atom
@SuppressWarnings("unused")
Atom x = (Atom)l;
l = parseLiteral("b(10,a,c(10,x))[ant1,source(c)]");
assertTrue(l.getTerm(1) instanceof Atom);
assertFalse(l.getTerm(2).isAtom());
assertTrue(l.getAnnots().get(0) instanceof Atom);
l = parseLiteral("b(a.r)"); // internal actions should not be atoms
assertFalse(l.getTerm(0).isAtom());
}
示例14: testCompare
import jason.asSyntax.Literal; //导入依赖的package包/类
public void testCompare() throws ParseException {
Literal p1 = ASSyntax.parseLiteral("ns1::a");
Literal p2 = ASSyntax.parseLiteral("ns2::b");
Literal p3 = ASSyntax.parseLiteral("ns2::a");
//assertNotSame(p1.getPredicateIndicator().hashCode(), p2.getPredicateIndicator().hashCode() );
//assertNotSame(p1.getPredicateIndicator().hashCode(), p3.getPredicateIndicator().hashCode() );
assertNotSame(p1.hashCode(), p3.hashCode() );
assertEquals(p1.compareTo(p2), -1);
assertEquals(p1.compareTo(null), -1);
assertEquals(p2.compareTo(p1), 1);
assertEquals(p1.compareTo(p1), 0);
p1 = ASSyntax.parseLiteral("ns1::a");
p2 = ASSyntax.parseLiteral("ns1::b");
assertEquals(p1.compareTo(p2), -1);
assertEquals(p1.compareTo(null), -1);
assertEquals(p2.compareTo(p1), 1);
assertEquals(p1.compareTo(p1), 0);
}
示例15: 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);
}
}
}