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


Java Term.capply方法代码示例

本文整理汇总了Java中jason.asSyntax.Term.capply方法的典型用法代码示例。如果您正苦于以下问题:Java Term.capply方法的具体用法?Java Term.capply怎么用?Java Term.capply使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在jason.asSyntax.Term的用法示例。


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

示例1: joinRenamedVarsIntoIntentionUnifier

import jason.asSyntax.Term; //导入方法依赖的package包/类
private void joinRenamedVarsIntoIntentionUnifier(IntendedMeans im, Unifier values) {
    if (im.renamedVars != null) {
        for (VarTerm ov: im.renamedVars.function.keySet()) {
            //System.out.println("looking for a value for "+ov+" in "+im.renamedVars+" and "+topIM.unif);
            UnnamedVar vt = (UnnamedVar)im.renamedVars.function.get(ov);
            //System.out.println("   via "+vt);
            im.unif.unifiesNoUndo(ov, vt); // introduces the renaming in the current unif
            // if vt has got a value from the top (a "return" value), include this value in the current unif
            Term vl = values.function.get(vt);
            //System.out.println(ov+"="+vt+"="+vl);
            if (vl != null) { // vt has value in top
                //System.out.println("   and found "+vl);
                vl = vl.capply(values);
                if (vl.isLiteral())
                    ((Literal)vl).makeVarsAnnon();
                im.unif.bind(vt, vl);
            }
        }
    }
    
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:22,代码来源:TransitionSystem.java

示例2: testApplyAnnots

import jason.asSyntax.Term; //导入方法依赖的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

示例3: testUnify2

import jason.asSyntax.Term; //导入方法依赖的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

示例4: testPlanTermWithVarBody

import jason.asSyntax.Term; //导入方法依赖的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

示例5: testVarTermAsNumber

import jason.asSyntax.Term; //导入方法依赖的package包/类
public void testVarTermAsNumber() throws Exception {
    Term k = new VarTerm("K");
    Unifier u = new Unifier();
    NumberTermImpl n = new NumberTermImpl(10);
    assertTrue(n.isNumeric());
    assertFalse(n.isVar());
    assertTrue(u.unifies(k, n));
    k = k.capply(u);
    // System.out.println(k+" u="+u);
    assertTrue(k.isNumeric());
    assertFalse(k.isLiteral());

    ArithExpr exp = new ArithExpr((NumberTerm)k, ArithmeticOp.plus, new NumberTermImpl(20));
    assertTrue(exp.solve() == 30d);
    NumberTerm nt = ArithExpr.parseExpr("5 div 2");
    assertTrue(nt.solve() == 2d);
    nt = ArithExpr.parseExpr("5 mod 2");
    assertTrue(nt.solve() == 1d);
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:20,代码来源:VarTermTest.java

示例6: testSimple1

import jason.asSyntax.Term; //导入方法依赖的package包/类
public void testSimple1() {
    Term um = new NumberTermImpl(1);
    Term dois = new NumberTermImpl(2);
    Term exp = ArithExpr.parse("X+1");
    Unifier u = new Unifier();
    u.unifies(new VarTerm("X"), new NumberTermImpl(1));
    // X+1 not unifies with 1
    exp = exp.capply(u);
    assertFalse(u.unifies(exp, um));
    // X+1 unifies with 2
    assertTrue(u.unifies(exp, dois));
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:13,代码来源:VarTermTest.java

示例7: execute

import jason.asSyntax.Term; //导入方法依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
    checkArguments(args);
    
    StringBuffer sb = new StringBuffer();
    for (Term term : args) {
        if (!term.isString()) {
            continue;
        }
        StringTerm st = (StringTerm) term;
        Matcher matcher = regex.matcher(st.getString());

        while (matcher.find()) {
            /*
             * System.out.println("I found the text \""+matcher.group()+ "\"
             * starting at index "+matcher.start()+ " and ending at index
             * "+matcher.end());
             */
            String sVar = matcher.group();
            sVar = sVar.substring(2, sVar.length() - 1);
            try {
                Term t = ASSyntax.parseTerm(sVar);
                //We use t.apply to evaluate any logical or arithmetic expression in Jason
                t = t.capply(un);
                matcher.appendReplacement(sb, t.toString());
            } catch (ParseException pe) {
                // TODO: handle exception
                // TODO: Decide whether or not we should ignore the exception and print the call instead
                // Right now, if I get a parse error from ASSyntax, I just print the original escaped
                // sequence, so a user can see that his/her expression was problematic
                matcher.appendReplacement(sb, "#{"+sVar+"}");
            }
            
        }
        matcher.appendTail(sb);
    }

    if (args[args.length - 1].isVar()) {
        StringTerm stRes = new StringTermImpl(sb.toString());
        return un.unifies(stRes, args[args.length - 1]);
    } else {
        ts.getLogger().info(sb.toString());
        return true;
    }
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:46,代码来源:puts.java

示例8: unifyTerms

import jason.asSyntax.Term; //导入方法依赖的package包/类
protected boolean unifyTerms(Term t1g, Term t2g) {
    // if args are expressions, apply them and use their values
    if (t1g.isArithExpr())
        t1g = t1g.capply(this);
    if (t2g.isArithExpr())
        t2g = t2g.capply(this);

    final boolean t1gisvar = t1g.isVar();
    final boolean t2gisvar = t2g.isVar();

    // one of the args is a var
    if (t1gisvar || t2gisvar) { 
        final VarTerm t1gv = t1gisvar ? (VarTerm)t1g : null;
        final VarTerm t2gv = t2gisvar ? (VarTerm)t2g : null;

        // get their values
        final Term t1vl = t1gisvar ? get(t1gv) : t1g;
        final Term t2vl = t2gisvar ? get(t2gv) : t2g;

        if (t1vl != null && t2vl != null) { // unifies the two values of the vars                
            return unifiesNoUndo(t1vl, t2vl);
        } else if (t1vl != null) { // unifies var with value
            return bind(t2gv, t1vl);
        } else if (t2vl != null) {
            return bind(t1gv, t2vl);
        } else {                 // unify two vars
            if (! t1gv.getNS().equals(t2gv.getNS())) 
                return false;
            
            if (t1gv.negated() != t2gv.negated())
                return false;

            bind(t1gv, t2gv);
            return true;
        }
    }        
    
    // both terms are not vars
    
    // if any of the terms is not a literal (is a number or a
    // string), they must be equal
    // (for unification, lists are literals)
    if (!t1g.isLiteral() && !t1g.isList() || !t2g.isLiteral() && !t2g.isList())
        return t1g.equals(t2g);

    // both terms are literal

    Literal t1s = (Literal)t1g;
    Literal t2s = (Literal)t2g;

    // different arities
    final int ts = t1s.getArity();
    if (ts != t2s.getArity())
        return false;
    
    // if both are literal, they must have the same negated
    if (t1s.negated() != t2s.negated())
        return false;
        
    // different functor
    if (!t1s.getFunctor().equals(t2s.getFunctor()))  
        return false;
    
    // different name space
    if (!unifiesNamespace(t1s, t2s))
        return false;

    // unify inner terms
    // do not use iterator! (see ListTermImpl class)
    for (int i = 0; i < ts; i++)
        if (!unifiesNoUndo(t1s.getTerm(i), t2s.getTerm(i)))
            return false;

    // the first's annots must be subset of the second's annots
    if ( ! t1s.hasSubsetAnnot(t2s, this))
        return false;
    
    return true;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:80,代码来源:Unifier.java

示例9: testCompare

import jason.asSyntax.Term; //导入方法依赖的package包/类
public void testCompare() throws ParseException {
    // order is: numbers, strings, lists, literals (by arity, functor, terms, annots), variables
    // variables must be the last, subsetannots requires that
    
    Pred p1 = Pred.parsePred("a");
    Pred p2 = Pred.parsePred("b");
    
    assertEquals(p1.compareTo(p2), -1);
    assertEquals(p1.compareTo(null), -1);
    assertEquals(p2.compareTo(p1), 1);
    assertEquals(p1.compareTo(p1), 0);
    
    p1 = Pred.parsePred("a(3)[3]");
    p2 = Pred.parsePred("a(3)[10]");
    Pred p3 = Pred.parsePred("a(3)[10]");        
    assertEquals(1, p2.compareTo(p1));
    assertEquals(-1, p1.compareTo(p2));
    assertEquals(0, p2.compareTo(p3));
    
    Term p4 = parseTerm("a");
    assertTrue(p1.compareTo(p4) > 0);
    assertTrue(p4.compareTo(p1) < 0);

    Literal l1 = Literal.parseLiteral("~a(3)");
    Literal l2 = Literal.parseLiteral("a(3)");
    Literal l3 = Literal.parseLiteral("a(10)[5]");
    assertTrue(l1.compareTo(l2) == 1);
    assertTrue(l1.compareTo(l3) == 1);
    assertTrue(l2.compareTo(l3) == -1);

    assertTrue(l2.compareTo(new Atom("g")) > 0);
    assertTrue(new Atom("g").compareTo(l2) < 0);
    assertTrue(new Atom("g").compareTo(new Atom("g")) == 0);

    ListTerm lt1 = ListTermImpl.parseList("[3,10]");
    ListTerm lt2 = ListTermImpl.parseList("[3,4]");
    ListTerm lt3 = ListTermImpl.parseList("[1,1,1]");
    assertTrue(lt1.compareTo(lt2) > 0);
    assertTrue(lt1.compareTo(lt3) < 0);
    assertTrue(lt1.compareTo(p1) < 0);
    
    ListTerm l = ListTermImpl.parseList("[C,b(4),A,4,b(1,1),\"x\",[],[c],[a],[b,c],[a,b],~a(3),a(e,f),b,a(3),b(3),a(10)[30],a(10)[5],a,a(d,e)]");
    Collections.sort(l);
    assertEquals("[4,\"x\",[],[a],[c],[a,b],[b,c],a,b,a(3),a(10)[5],a(10)[30],b(3),b(4),a(d,e),a(e,f),b(1,1),~a(3),A,C]", l.toString());
    
    l = ListTermImpl.parseList("[b,[1,1,1],c,10,g,casa,f(10),5,[3,10],f(4),[3,4]]");
    Collections.sort(l);
    assertEquals("[5,10,[3,4],[3,10],[1,1,1],b,c,casa,g,f(4),f(10)]",l.toString());
    
    Term t1 = ASSyntax.createNumber(10);
    Term t2 = ASSyntax.createNumber(10);
    assertEquals(0, t1.compareTo(t2));
    Term v1 = new VarTerm("X1");
    Unifier u = new Unifier();
    u.unifies(v1, t1);
    v1 = v1.capply(u);
    assertEquals(0, v1.compareTo(t2));
    assertEquals(0, t2.compareTo(v1));
    
    assertTrue(new StringTermImpl("string").compareTo(new NumberTermImpl(1)) > 0);
    assertTrue(new NumberTermImpl(1).compareTo(new StringTermImpl("string")) < 0);
    assertTrue(new StringTermImpl("string").compareTo(new ListTermImpl()) < 0);
    assertTrue(new ListTermImpl().compareTo(new StringTermImpl("string")) > 0);
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:65,代码来源:TermTest.java


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