当前位置: 首页>>代码示例>>Java>>正文


Java ParseException类代码示例

本文整理汇总了Java中jason.asSyntax.parser.ParseException的典型用法代码示例。如果您正苦于以下问题:Java ParseException类的具体用法?Java ParseException怎么用?Java ParseException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ParseException类属于jason.asSyntax.parser包,在下文中一共展示了ParseException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: tryToGetTrigger

import jason.asSyntax.parser.ParseException; //导入依赖的package包/类
/** try to convert the term t into a trigger, in case t is a trigger term, a string that can be parsed to a trigger, a var with value trigger, .... */
public static Trigger tryToGetTrigger(Term t) throws ParseException {
    if (t instanceof Trigger) {
        return (Trigger)t;
    }
    if (t.isPlanBody()) {
        PlanBody p = (PlanBody)t;
        if (p.getPlanSize() == 1) {
            TEOperator op = null;
            if (p.getBodyType() == BodyType.addBel) 
                op = TEOperator.add;
            else if (p.getBodyType() == BodyType.delBel)
                op = TEOperator.del;
            if (op != null) {
                Literal l = (Literal)p.getBodyTerm().clone();
                l.delAnnot(BeliefBase.TSelf); // remove the eventual auto added annotation of source
                return new Trigger(op, TEType.belief, l);
                
            }
        }
    }
    if (t.isString()) {
        return ASSyntax.parseTrigger(((StringTerm)t).getString());
    }
    return null;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:27,代码来源:Trigger.java

示例2: makeVarsAnnon

import jason.asSyntax.parser.ParseException; //导入依赖的package包/类
public void makeVarsAnnon(Literal l, Unifier un) {
    try {
        for (int i=0; i<l.getArity(); i++) {
            Term t = l.getTerm(i);
            if (t.isString()) {
                StringTerm st = (StringTerm)t;
                Matcher matcher = regex.matcher(st.getString());
                StringBuffer sb = new StringBuffer();

                while (matcher.find()) {
                    String sVar = matcher.group();
                    sVar = sVar.substring(2, sVar.length() - 1);
                    Term v = ASSyntax.parseTerm(sVar);
                    if (v.isVar()) {
                        VarTerm to = ((Structure)l).varToReplace(v, un);
                        matcher.appendReplacement(sb, "#{"+to.toString()+"}");
                    }
                }
                matcher.appendTail(sb);
                l.setTerm(i, new StringTermImpl(sb.toString()));
            }
        }
    } catch (ParseException pe) {
        pe.printStackTrace();
    }
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:27,代码来源:puts.java

示例3: parseMsg

import jason.asSyntax.parser.ParseException; //导入依赖的package包/类
/**
 * Creates a new message object based on a string that 
 * follows the format of the toString of Message class.
 * 
 * @author Rogier
 * @param msg the string message
 * @return the parsed Message
 */
public static Message parseMsg(String msg) throws ParseException {
    int one, two;
    Message newmsg = new Message();
    if (msg.startsWith("<")) {
        one = msg.indexOf(",");
        int arrowIndex = msg.indexOf("->");
        if ((arrowIndex > 0) && (one > arrowIndex)) { // If there is an arrow before the first comma
            newmsg.msgId = msg.substring(1, arrowIndex);
            newmsg.inReplyTo = msg.substring(arrowIndex + 2, one);
        } else { // If not (either there is no arrow, or there is one behind the first comma)
            newmsg.msgId = msg.substring(1, one);
        }
        two = msg.indexOf(",", one + 1);
        newmsg.sender = msg.substring(one + 1, two);
        one = msg.indexOf(",", two + 1);
        newmsg.ilForce = msg.substring(two + 1, one);
        two = msg.indexOf(",", one + 1);
        newmsg.receiver = msg.substring(one + 1, two);
        one = msg.indexOf(">", two + 1);
        String content = msg.substring(two + 1, one);
        newmsg.propCont = ASSyntax.parseTerm(content);
    }
    return newmsg;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:33,代码来源:Message.java

示例4: testApplyAnnots

import jason.asSyntax.parser.ParseException; //导入依赖的package包/类
public void testApplyAnnots() throws ParseException {
    Term t1 = parseTerm("p[a,X,c,d]");
    Unifier u = new Unifier();
    u.unifies(new VarTerm("X"), new Atom("z"));
    t1 = t1.capply(u);
    assertEquals("p[a,c,d,z]",t1.toString());
    
    t1 = parseTerm("p[X,b,c,d]");
    t1 = t1.capply(u);
    assertEquals("p[b,c,d,z]",t1.toString());

    t1 = parseTerm("p[a,b,c,X]");
    assertFalse(t1.isGround());
    t1 = t1.capply(u);
    assertTrue(t1.isGround());
    assertEquals("p[a,b,c,z]",t1.toString());
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:18,代码来源:TermTest.java

示例5: testHasVar

import jason.asSyntax.parser.ParseException; //导入依赖的package包/类
public void testHasVar() throws ParseException {
    Literal l = parseLiteral("a(Test,X,Y,b(g([V1,X,V2,V1]),c))[b,source(Y),B,kk(_),oo(oo(OO))]");
    assertTrue(l.hasVar(new VarTerm("X"), null));
    assertTrue(l.hasVar(new VarTerm("V2"), null));
    assertTrue(l.hasVar(new VarTerm("OO"), null));
    assertFalse(l.hasVar(new VarTerm("O"), null));
    
    Unifier u = new Unifier();
    u.unifies(parseTerm("X"), parseTerm("f(Y)"));        
    u.unifies(parseTerm("Y"), parseTerm("g(X)"));
    u.unifies(parseTerm("T"), parseTerm("X"));
    VarTerm t = new VarTerm("T");
    assertFalse(t.hasVar(new VarTerm("X"), null));
    assertTrue(t.hasVar(new VarTerm("X"), u));
    assertFalse(t.hasVar(new VarTerm("Y"), null));
    assertTrue(t.hasVar(new VarTerm("Y"), u));
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:18,代码来源:TermTest.java

示例6: testAtomParsing

import jason.asSyntax.parser.ParseException; //导入依赖的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());
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:18,代码来源:TermTest.java

示例7: testCyclicTerm3

import jason.asSyntax.parser.ParseException; //导入依赖的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());
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:17,代码来源:TermTest.java

示例8: testUnify2

import jason.asSyntax.parser.ParseException; //导入依赖的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));
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:17,代码来源:ExprTermTest.java

示例9: testCompare

import jason.asSyntax.parser.ParseException; //导入依赖的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);
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:23,代码来源:NSTest.java

示例10: testRelevant

import jason.asSyntax.parser.ParseException; //导入依赖的package包/类
public void testRelevant() throws JasonException, ParseException {
    PlanLibrary pl = new PlanLibrary();
    pl.add(Plan.parse("+p(0) <- .print(a)."));
    pl.add(Plan.parse("+p(X) : X > 0 <- .print(a)."));
    
    pl.add(Plan.parse("+!p(0) <- .print(a)."));
    pl.add(Plan.parse("+!p(X) : X > 0 <- .print(a)."));

    pl.add(Plan.parse("+!X <- .print(a)."));
    
    List<Plan> pls = pl.getCandidatePlans(ASSyntax.parseTrigger("+p(3)"));
    assertEquals(2, pls.size());

    pls = pl.getCandidatePlans(ASSyntax.parseTrigger("+!p(3)"));
    assertEquals(3, pls.size());    

    pls = pl.getCandidatePlans(ASSyntax.parseTrigger("+!bla"));
    assertEquals(1, pls.size());    

    pls = pl.getCandidatePlans(ASSyntax.parseTrigger("+bla"));
    assertNull(pls);    
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:23,代码来源:PlanTest.java

示例11: testPlanTermWithVarBody

import jason.asSyntax.parser.ParseException; //导入依赖的package包/类
public void testPlanTermWithVarBody() throws ParseException {
    Term pt = ASSyntax.parseTerm("{ +!g : c <- B }");
    assertEquals("{ +!g : c <- B }", pt.toString());
    assertTrue(pt instanceof Plan);
    
    Unifier u = new Unifier();
    u.unifies(new VarTerm("B"), ASSyntax.parseTerm("{ .print(a); .print(b); .print(c) }"));
    pt = pt.capply(u);
    assertEquals("{ +!g : c <- .print(a); .print(b); .print(c) }", pt.toString());
    pt = ASSyntax.parseTerm("{ +!g : c <- B; a1; B }");
    pt = pt.capply(u);
    assertEquals("{ +!g : c <- .print(a); .print(b); .print(c); a1; .print(a); .print(b); .print(c) }", pt.toString());
    
    pt = ASSyntax.parseTerm("{ +!g : c <- .print(0); B; B; .print(d); C }");
    u.unifies(new VarTerm("C"), ASSyntax.parseTerm("{ a1 }"));
    pt = pt.capply(u);
    assertEquals(9, ((Plan)pt).getBody().getPlanSize());
    assertEquals("{ +!g : c <- .print(0); .print(a); .print(b); .print(c); .print(a); .print(b); .print(c); .print(d); a1 }", pt.toString());
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:20,代码来源:PlanTest.java

示例12: testSimple2

import jason.asSyntax.parser.ParseException; //导入依赖的package包/类
public void testSimple2() throws ParseException {
    VarTerm v = new VarTerm("X");
    assertFalse(v.isAtom());
    assertTrue(v.isVar());
    Term t;

    as2jTokenManager tokens = new as2jTokenManager(new SimpleCharStream(new StringReader("Event")));
    Token tk = tokens.getNextToken();
    assertEquals(tk.kind, jason.asSyntax.parser.as2jConstants.VAR);
    
    t = ASSyntax.parseVar("Ea");
    assertFalse(t.isAtom());
    assertTrue(t.isVar());
    
    t = ASSyntax.parseTerm("Event");
    assertFalse(t.isAtom());
    assertTrue(t.isVar());
    
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:20,代码来源:VarTermTest.java

示例13: testFindAll

import jason.asSyntax.parser.ParseException; //导入依赖的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);
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:27,代码来源:StdLibTest.java

示例14: init

import jason.asSyntax.parser.ParseException; //导入依赖的package包/类
@Override
public void init(String[] args) {
    // associate agents to users
    try {
        for (int i=1; i<args.length; i++) {
            Term t = ASSyntax.parseTerm(args[i]);
            if (t.isStructure()) {
                Structure arg = (Structure)t;
                if (arg.getFunctor().equals("agent_entity")) {
                    addPercept(arg.getTerm(0).toString(), Literal.parseLiteral("myNameInContest("+arg.getTerm(2).toString()+")"));
                    agToMassimContest.put(arg.getTerm(0).toString(), arg.getTerm(2).toString());
                }
            }
        }
        
        super.init(args);
        
        //startCartago();
    } catch (ParseException e) {
        e.printStackTrace();
    }
}
 
开发者ID:jason-lang,项目名称:apps,代码行数:23,代码来源:CustomEISEnv.java

示例15: init

import jason.asSyntax.parser.ParseException; //导入依赖的package包/类
@Override
public void init(String[] args) {
    // associate agents to users
    try {
        for (int i=1; i<args.length; i++) {
            Term t = ASSyntax.parseTerm(args[i]);
            if (t.isStructure()) {
                Structure arg = (Structure)t;
                if (arg.getFunctor().equals("agent_entity")) {
                    addPercept(arg.getTerm(0).toString(), Literal.parseLiteral("myNameInContest("+arg.getTerm(2).toString()+")"));
                    agToMassimContest.put(arg.getTerm(0).toString(), arg.getTerm(2).toString());
                }
            }
        }
        
        super.init(args);
        
        //startCartago();
    } catch (ParseException e) {
        e.printStackTrace();
    }
    startCartago(args);
}
 
开发者ID:jason-lang,项目名称:apps,代码行数:24,代码来源:CustomEISEnv.java


注:本文中的jason.asSyntax.parser.ParseException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。