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

Java Unifier类代码示例

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

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



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

示例1: testLogCons2

import jason.asSemantics.Unifier; //导入依赖的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));

}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:24,代码来源:RuleTest.java


示例2: testMakeVarAnnon1

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


示例3: execute

import jason.asSemantics.Unifier; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
    checkArguments(args);

    if (args[0].isNumeric() && args[1].isString()) {
        return un.unifies(args[2], deleteFromString((int)((NumberTerm)args[0]).solve(),(StringTerm)args[1]));
    } 
    if (args[0].isNumeric() && args[1].isList()) {
        return un.unifies(args[2], deleteFromList((int)((NumberTerm)args[0]).solve(),(ListTerm)args[1]));
    }
    if (args[0].isString() && args[1].isString()) {
        return un.unifies(args[2], deleteFromString((StringTerm)args[0],(StringTerm)args[1]));
    }
    if (args[0].isString()) { // consider arg[1] as string
        return un.unifies(args[2], deleteFromString((StringTerm)args[0], new StringTermImpl(args[1].toString())));
    }
    
    
    // first element as term
    if (args[1].isList()) {
        return un.unifies(args[2], deleteFromList(args[0],(ListTerm)args[1], un.clone()));
    }
    throw new JasonException("Incorrect use of the internal action '.delete' (see documentation).");
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:25,代码来源:delete.java


示例4: testVarTermAsNumber

import jason.asSemantics.Unifier; //导入依赖的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


示例5: testUnify2

import jason.asSemantics.Unifier; //导入依赖的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


示例6: makeVarsAnnon

import jason.asSemantics.Unifier; //导入依赖的package包/类
@Override
public Literal makeVarsAnnon(Unifier un) {
    if (annots != null) {
        ListTerm lt = annots;
        while (!lt.isEmpty()) {
            Term ta = lt.getTerm();
            if (ta.isVar())
                lt.setTerm(varToReplace(ta, un));
            else if (ta instanceof Structure)
                ((Structure)ta).makeVarsAnnon(un);
            if (lt.isTail() && lt.getNext().isVar()) {
                lt.setNext(varToReplace(lt.getNext(), un));
                break;
            }
            lt = lt.getNext();
        }
    }
    return super.makeVarsAnnon(un);
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:20,代码来源:Pred.java


示例7: execute

import jason.asSemantics.Unifier; //导入依赖的package包/类
@Override public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
    checkArguments(args);
    
    Agent ag = ts.getAg();
    Pred inc = new Pred(ns, "include");
    inc.addTerms(args);
    
    Agent result = ((Include)DirectiveProcessor.getDirective("include")).process(
            inc, 
            ag, 
            null);
    
    ag.importComponents(result);
    ag.addInitialBelsInBB();
    ag.addInitialGoalsInTS();
    return true;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:18,代码来源:include.java


示例8: testLogConsWithAnnotsBacktracking

import jason.asSemantics.Unifier; //导入依赖的package包/类
public void testLogConsWithAnnotsBacktracking() {
    Agent ag = new Agent();
    ag.initAg();

    ag.getBB().add(Literal.parseLiteral("p(10)[source(ag1),source(ag2),b,40,2]"));
    ag.getBB().add(Literal.parseLiteral("p(10)[source(ag3),source(ag2),b,40,2]"));
    ag.getBB().add(Literal.parseLiteral("p(20)[source(ag4),source(ag2),b,u,k]"));
    ag.getBB().add(Literal.parseLiteral("p(30)[source(ag5),source(ag2),40,u,k]"));

    Iterator<Unifier> iun = Literal.parseLiteral("p(Y)[source(X),b]").logicalConsequence(ag, new Unifier());
    int c = 0;
    while (iun.hasNext()) {
        iun.next();
        c++;
    }
    assertEquals(5, c);
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:18,代码来源:BeliefBaseTest.java


示例9: execute

import jason.asSemantics.Unifier; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
    checkArguments(args);

    ListTerm list = (ListTerm)args[0];
    if (list.isEmpty()) {
        return false;               
    }

    Iterator<Term> i = list.iterator();
    Term min = i.next();
    while (i.hasNext()) {
        Term t = i.next();
        if (compare(min,t)) {
            min = t;
        }
    }
    return un.unifies(args[1], min.clone());
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:20,代码来源:min.java


示例10: removePerceptsByUnif

import jason.asSemantics.Unifier; //导入依赖的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;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:25,代码来源:Environment.java


示例11: execute

import jason.asSemantics.Unifier; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] terms) throws Exception{
	try {
		boolean result = false;
		int iagx = (int)((NumberTerm)terms[0]).solve();//Atual
        int iagy = (int)((NumberTerm)terms[1]).solve();//Atual
        String dir = terms[2].toString();
        if(dir.equals("up")) {
        	result = (un.unifies(terms[3], new Atom(String.valueOf(iagx))) && un.unifies(terms[4], new Atom(String.valueOf(1))));  	
        }else if(dir.equals("down")) {
        	result = (un.unifies(terms[3], new Atom(String.valueOf(iagx))) && un.unifies(terms[4], new Atom(String.valueOf(48))));
        }else if(dir.equals("left")) {
        	result = (un.unifies(terms[3], new Atom(String.valueOf(1))) && un.unifies(terms[4], new Atom(String.valueOf(iagy))));
        }else if(dir.equals("right")) {
        	result = (un.unifies(terms[3], new Atom(String.valueOf(48))) && un.unifies(terms[4], new Atom(String.valueOf(iagy))));
        }
        return result;
        
	}catch(Throwable e) {
		e.printStackTrace();
		return false;
	}
}
 
开发者ID:MTeixeira24,项目名称:Jasovacs_fire,代码行数:24,代码来源:get_sign_point.java


示例12: testObTerm

import jason.asSemantics.Unifier; //导入依赖的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());

}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:22,代码来源:TermTest.java


示例13: makeVarsAnnon

import jason.asSemantics.Unifier; //导入依赖的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


示例14: execute

import jason.asSemantics.Unifier; //导入依赖的package包/类
@Override
public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
    checkArguments(args);
    
    // try to get the intention from the "body"
    Intention i = ts.getC().getSelectedIntention();

    if (i == null) {
        // try to get the intention from the event
        Event evt = ts.getC().getSelectedEvent();
        if (evt != null)
            i = evt.getIntention();
    }
    if (i != null)
        return un.unifies(i.getAsTerm(), args[0]);
    else
        return false;            
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:19,代码来源:current_intention.java


示例15: dropGoal

import jason.asSemantics.Unifier; //导入依赖的package包/类
@Override
public boolean dropGoal(Trigger te, Unifier un) {
    boolean r = super.dropGoal(te, un);
    if (r && size() < forkPoint) {
        //System.out.println("drop "+te+" i.size = "+size()+" fork point "+forkPoint+" to f "+fd+"\n"+this);
        if (fd.toFinish > 0) { // the first intentions of the fork being dropped, keep it and ignore the rest
            fd.toFinish = 0;
            //System.out.println("put it back");
            return true;
        } else {
            clearIM();
            //System.out.println("ignore intention");
            return false;
        }
    } 
    return r;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:18,代码来源:fork.java


示例16: testMakeVarAnnon4

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


示例17: isRelevant

import jason.asSemantics.Unifier; //导入依赖的package包/类
/** returns an unifier if this plan is relevant for the event <i>te</i>, 
    returns null otherwise.
*/
public Unifier isRelevant(Trigger te) {
    // annots in plan's TE must be a subset of the ones in the event!
    // (see definition of Unifier.unifies for 2 Preds)
    Unifier u = new Unifier();
    if (u.unifiesNoUndo(tevent, te))
        return u;
    else
        return null;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:13,代码来源:Plan.java


示例18: testCount

import jason.asSemantics.Unifier; //导入依赖的package包/类
public void testCount() throws Exception {
    Agent ag = new Agent();
    ag.initAg();

    assertTrue(ag.getFunction(".count",1) != null);
    ag.getBB().add(Literal.parseLiteral("b(10)"));
    ag.getBB().add(Literal.parseLiteral("a(x)"));
    ag.getBB().add(Literal.parseLiteral("b(20)"));
    assertEquals(3, ag.getBB().size());
    
    ArithFunctionTerm nb = (ArithFunctionTerm)ArithExpr.parseExpr(ag,".count(b(_))");
    NumberTerm tnb = (NumberTerm)nb.capply(new Unifier());
    assertEquals(2.0,tnb.solve());
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:15,代码来源:ExprTermTest.java


示例19: useDerefVars

import jason.asSemantics.Unifier; //导入依赖的package包/类
private void useDerefVars(Term p, Unifier un) {
    if (p instanceof Literal) {
        Literal l = (Literal)p;
        for (int i=0; i<l.getArity(); i++) {
            Term t = l.getTerm(i);
            if (t.isVar()) {
                l.setTerm(i, un.deref( (VarTerm)t));
            } else {
                useDerefVars(t, un);                    
            }
        }
    }
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:14,代码来源:Literal.java


示例20: execute

import jason.asSemantics.Unifier; //导入依赖的package包/类
@Override public Object execute(TransitionSystem ts, Unifier un, Term[] args) throws Exception {
    Trigger te = null;
    if (args.length == 1 && args[0] instanceof Trigger)
        te = Trigger.tryToGetTrigger(args[0]);
    
    for (Plan p: ts.getAg().getPL()) {
        if (!p.getLabel().toString().startsWith("kqml")) { // do not list kqml plans
            if (te == null || new Unifier().unifies(p.getTrigger(), te)) {
                ts.getLogger().info(p.toString());
            }
        }
    }
    return true;
}
 
开发者ID:nickrfer,项目名称:code-sentinel,代码行数:15,代码来源:list_plans.java



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Java Comment类代码示例发布时间:2022-05-22
下一篇:
Java TimeoutEvent类代码示例发布时间: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