本文整理汇总了Java中jason.asSyntax.Literal.parseLiteral方法的典型用法代码示例。如果您正苦于以下问题:Java Literal.parseLiteral方法的具体用法?Java Literal.parseLiteral怎么用?Java Literal.parseLiteral使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类jason.asSyntax.Literal
的用法示例。
在下文中一共展示了Literal.parseLiteral方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFindAll
import jason.asSyntax.Literal; //导入方法依赖的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);
}
示例2: testMakeVarAnnon1
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void testMakeVarAnnon1() {
Literal l1 = Literal.parseLiteral("likes(jane,X,peter)");
Literal l2 = Literal.parseLiteral("likes(X,Y,Y)");
Literal l3 = Literal.parseLiteral("likes(X,Y,X)");
Literal l4 = Literal.parseLiteral("likes(Z,Y,Y)");
Unifier u = new Unifier();
assertFalse(u.unifies(l1, l2));
u.clear();
assertFalse(u.unifies(l1, l3));
u.clear();
assertTrue(u.unifies(l1, l4));
l2.makeVarsAnnon();
u.clear();
assertTrue(u.unifies(l1, l2));
l3.makeVarsAnnon();
u.clear();
assertFalse(u.unifies(l1, l3));
l4.makeVarsAnnon();
u.clear();
assertTrue(u.unifies(l1, l4));
}
示例3: 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));
}
}
}
示例4: testLogCons2
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void testLogCons2() {
Agent ag = new Agent();
ag.initAg();
Rule r = new Rule(Literal.parseLiteral("r([],a(X),b(X,4))"), Literal.parseLiteral("true"));
ag.getBB().add(r);
Iterator<Unifier> iun = Literal.parseLiteral("r([],a(20),X)").logicalConsequence(ag, new Unifier());
//assertEquals(iun.next().get("X").toString(),"b(20,4)");
assertTrue(iun.hasNext());
Literal result = Literal.parseLiteral("r([],a(20),X)");
Unifier u = iun.next();
assertTrue(u.get("X").isStructure());
assertEquals( ((Structure)u.get("X")).getArity(), 2);
assertEquals( ((Structure)u.get("X")).getFunctor(), "b");
assertEquals(result.capply(u), Literal.parseLiteral("r([],a(20),b(20,4))"));
iun = Literal.parseLiteral("r([],a(20),b(X,Y))").logicalConsequence(ag, new Unifier());
u = iun.next();
assertEquals(u.get("X"), ASSyntax.createNumber(20));
assertEquals(u.get("Y"), ASSyntax.createNumber(4));
}
示例5: testLogConsRec
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void testLogConsRec() {
Agent ag = new Agent();
ag.initAg();
// add
// min([],M,M).
// min([C|T],V,M) :- C < V & min(T,C,M).
// min([_|T],V,M) :- min(T,V,M).
//ag.getBB().add(Literal.parseLiteral("min([],M,M)"));
ag.getBB().add(new Rule(Literal.parseLiteral("min([],M,M)"), Literal.LTrue));
ag.getBB().add(new Rule(Literal.parseLiteral("min([op(C)|T], op(V), M)"),
LogExpr.parseExpr("C < V & min(T,op(C),M)")));
ag.getBB().add(new Rule(Literal.parseLiteral("min([op(C)|T], op(V), M)"),
LogExpr.parseExpr("C >= V & min(T,op(V),M)")));
Iterator<Unifier> iun = Literal.parseLiteral("min([],op(20),op(M))").logicalConsequence(ag, new Unifier());
assertTrue(iun.hasNext());
Unifier u = iun.next();
assertEquals(u.get("M").toString(),"20");
Literal cons = Literal.parseLiteral("min([op(5),op(3),op(8),op(1),op(40)],op(1000),op(M))");
Iterator<Literal> il = ag.getBB().getCandidateBeliefs(cons, null);
assertEquals(3,iteratorSize(il));
iun = cons.logicalConsequence(ag, new Unifier());
u = iun.next();
assertEquals((int)Double.parseDouble(u.get("M").toString()),1);
}
示例6: 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;
}
示例7: testAnnotsUnify3
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void testAnnotsUnify3() {
Literal l1 = Literal.parseLiteral("s(tuesday)");
Unifier u = new Unifier();
u.unifies(l1, Literal.parseLiteral("s(Day)"));
assertEquals(u.get("Day").toString(),"tuesday");
Literal l2 = Literal.parseLiteral("bel[monday]");
Literal l3 = Literal.parseLiteral("bel[Day]");
assertFalse(u.unifies(l3, l2));
assertEquals(u.get("Day").toString(),"tuesday");
}
示例8: testAnnotsUnify4
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void testAnnotsUnify4() {
Literal l1 = Literal.parseLiteral("s[A]");
Literal l2 = Literal.parseLiteral("s[3]");
Unifier u = new Unifier();
assertTrue(u.unifies(l1, l2));
assertEquals(u.get("A").toString(),"3");
}
示例9: testAnnotsUnify5
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void testAnnotsUnify5() {
Literal l1 = Literal.parseLiteral("s[source(self)]");
Literal l2 = Literal.parseLiteral("s");
Unifier u = new Unifier();
assertFalse(u.unifies(l1, l2));
assertTrue(u.unifies(l2, l1));
}
示例10: testHasVar
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void testHasVar() {
Rule r = new Rule(Literal.parseLiteral("a(X,Y)"), LogExpr.parseExpr("b(X) & c(Y,W) & d(Y,W,R)"));
Map<VarTerm, Integer> c = new HashMap<VarTerm, Integer>();
r.countVars(c);
assertEquals(3,c.get(new VarTerm("Y")).intValue());
assertEquals(1, r.getSingletonVars().size());
assertEquals("[R]", r.getSingletonVars().toString());
assertTrue(r.hasVar(new VarTerm("X"), null));
assertTrue(r.hasVar(new VarTerm("W"), null));
assertFalse(r.hasVar(new VarTerm("III"), null));
}
示例11: testMakeVarAnnon3
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void testMakeVarAnnon3() {
Literal l1 = Literal.parseLiteral("calc(AgY,X)[vl(X),source(AgY),bla(Y),X]");
l1.makeVarsAnnon();
Map<VarTerm, Integer> v = new HashMap<VarTerm, Integer>();
l1.countVars(v);
assertEquals(3, v.size());
assertEquals("vl("+l1.getTerm(1)+")",l1.getAnnots("vl").get(0).toString());
l1 = Literal.parseLiteral("calc(a)[a,b|T]");
assertFalse(l1.isGround());
l1.makeVarsAnnon();
assertFalse(l1.isGround());
assertTrue(l1.toString().contains("_"));
assertFalse("calc(a)[a,b|T]".equals(l1.toString()));
}
示例12: testMakeVarAnnon4
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void testMakeVarAnnon4() {
Literal l = Literal.parseLiteral("p(X)");
Unifier u = new Unifier();
u.unifies(new UnnamedVar(4), new VarTerm("X"));
u.unifies(new VarTerm("X"), new UnnamedVar(2));
u.unifies(new UnnamedVar(2), new VarTerm("Y"));
u.unifies(new UnnamedVar(10), new VarTerm("Y"));
u.unifies(new VarTerm("X"), new VarTerm("Z"));
/*
Iterator<VarTerm> i = u.binds(new VarTerm("X"));
while (i.hasNext()) {
System.out.println(i.next());
}
*/
l.makeVarsAnnon(u);
// ensure that X derefs to _10
assertTrue(u.deref(new VarTerm("X")).equals(new UnnamedVar(10)));
// ensure that unifying a value with X will bind a value for all aliases as well.
Term val = new StringTermImpl("value");
u.unifies(new VarTerm("X"), val);
assertTrue(u.get(new VarTerm("X")).equals(val));
assertTrue(u.get(new VarTerm("Y")).equals(val));
assertTrue(u.get(new VarTerm("Z")).equals(val));
assertTrue(u.get(new UnnamedVar(4)).equals(val));
assertTrue(u.get(new UnnamedVar(2)).equals(val));
assertTrue(u.get(new UnnamedVar(10)).equals(val));
}
示例13: testMakeVarAnnon5
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void testMakeVarAnnon5() {
Literal l = Literal.parseLiteral("p(X,Y)[s(Y)]");
Unifier u = new Unifier();
u.unifies(new VarTerm("X"), new VarTerm("Y"));
l.makeVarsAnnon(u);
assertEquals(l.getTerm(0), l.getTerm(1));
assertEquals("[s("+l.getTerm(0)+")]", l.getAnnots().toString());
}
示例14: testLiteralBuilder
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void testLiteralBuilder() throws JasonException {
Literal l = Literal.parseLiteral("~p(t1,t2)[a1,a2]");
assertEquals(l.getAsListOfTerms().size(), 4);
ListTerm lt1 = ListTermImpl.parseList("[~p,[t1,t2],[a1,a2]]");
assertTrue(l.equals(Literal.newFromListOfTerms(lt1)));
ListTerm lt2 = ListTermImpl.parseList("[p,[t1,t2],[a1,a2]]");
assertFalse(l.equals(Literal.newFromListOfTerms(lt2)));
ListTerm lt3 = ListTermImpl.parseList("[~p,[t1,t2],[a1,a2,a3]]");
assertFalse(l.equals(Literal.newFromListOfTerms(lt3)));
Unifier u = new Unifier();
assertFalse(u.unifies(lt1, lt2));
assertTrue( new RelExpr(l, RelExpr.RelationalOp.literalBuilder, lt1).logicalConsequence(null, u).hasNext());
assertFalse(new RelExpr(l, RelExpr.RelationalOp.literalBuilder, lt2).logicalConsequence(null, u).hasNext());
assertFalse(new RelExpr(l, RelExpr.RelationalOp.literalBuilder, lt3).logicalConsequence(null, u).hasNext());
VarTerm v = new VarTerm("X");
u.clear();
assertTrue(new RelExpr(v, RelExpr.RelationalOp.literalBuilder, lt1).logicalConsequence(null, u).hasNext());
assertEquals(u.get("X").toString(), l.toString());
assertEquals(u.get("X"), l);
assertEquals(l, u.get("X"));
u.clear();
assertTrue(new RelExpr(l, RelExpr.RelationalOp.literalBuilder, v).logicalConsequence(null, u).hasNext());
ListTerm lt4 = ListTermImpl.parseList("[default,~p,[t1,t2],[a1,a2]]");
System.out.println(u);
assertEquals(u.get("X").toString(), lt4.toString());
assertEquals(u.get("X"), lt4);
assertEquals(lt4, u.get("X"));
l = Literal.parseLiteral("p(t1,t2)");
assertEquals(l.getAsListOfTerms().size(), 4);
assertEquals(((ListTerm)l.getAsListOfTerms().get(2)).size(), 2);
assertEquals(((ListTerm)l.getAsListOfTerms().get(3)).size(), 0);
}
示例15: testGetSources
import jason.asSyntax.Literal; //导入方法依赖的package包/类
public void testGetSources() {
Literal p1 = Literal.parseLiteral("p1");
assertEquals(0, p1.getSources().size());
assertEquals(1, Literal.parseLiteral("p2[source(a)]").getSources().size());
Literal p2 = Literal.parseLiteral("p2[a1,source(ag1),a2,source(ag2),source(ag3)]");
assertEquals(3, p2.getSources().size());
assertEquals("[ag1,ag2,ag3]",p2.getSources().toString());
}