• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ParseException类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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


示例17: 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:jason-lang,项目名称:jason,代码行数:27,代码来源:StdLibTest.java


示例18: testGroupToProlog

import jason.asSyntax.parser.ParseException; //导入依赖的package包/类
@Test
public void testGroupToProlog() {
    //Group g = oe.getOS().getSS().getRootGrSpec().findSubGroup("attack");
    // the order changes always, improve this test
    //assertEquals("group_specification(attack,[role(middle,5,5,[leader],[link(communication,player,inter_group),link(communication,coach,inter_group)]),role(leader,0,1,[middle],[link(communication,player,inter_group),link(authority,player,inter_group),link(communication,coach,inter_group)]),role(attacker,2,2,[],[link(communication,player,inter_group),link(communication,coach,inter_group)])],[],properties([]))", g.getAsProlog());

    //g = oe.getOS().getSS().getRootGrSpec();
    // the order changes always, improve this test
    //assertEquals("group_specification(team,[role(coach,1,2,[],[link(authority,player,inter_group)])],[attack(1,1),defense(1,1)],properties([]))", g.getAsProlog());
    OS os = OS.loadOSFromURI("examples/auction/auction-os.xml");
    System.out.println(os.getAsProlog());
    
    Literal ospl = null;
    try {
        ospl = ASSyntax.parseLiteral(os.getAsProlog());
    } catch (ParseException e) {
        e.printStackTrace();
    }
    assertNotNull(ospl);
}
 
开发者ID:moise-lang,项目名称:moise,代码行数:21,代码来源:ToPrologTest.java


示例19: 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:jason-lang,项目名称:jason,代码行数:27,代码来源:Trigger.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java CreateDiagramViewOperation类代码示例发布时间:2022-05-22
下一篇:
Java ProjectAndLibrariesScope类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap