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

Python unification.var函数代码示例

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

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



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

示例1: test_reify_object

def test_reify_object():
    obj = reify_object(Foo(1, var(3)), {var(3): 4})
    assert obj.a == 1
    assert obj.b == 4

    f = Foo(1, 2)
    assert reify_object(f, {}) is f
开发者ID:vitormazzi,项目名称:unification,代码行数:7,代码来源:test_more.py


示例2: test_unify_slice

def test_unify_slice():
    x = var('x')
    y = var('y')

    assert unify(slice(1), slice(1), {}) == {}
    assert unify(slice(1, 2, 3), x, {}) == {x: slice(1, 2, 3)}
    assert unify(slice(1, 2, None), slice(x, y), {}) == {x: 1, y: 2}
开发者ID:vitormazzi,项目名称:unification,代码行数:7,代码来源:test_more.py


示例3: test_reify_object_attrs

def test_reify_object_attrs():
    x, y = var('x'), var('y')
    f, g = Foo(1, 2), Foo(x, y)
    s = {x: 1, y: 2}
    assert reify_object_attrs(g, s, ['a', 'b']) == f
    assert reify_object_attrs(g, s, ['a']) ==  Foo(1, y)
    assert reify_object_attrs(g, s, ['b']) ==  Foo(x, 2)
    assert reify_object_attrs(g, s, []) is g
开发者ID:logpy,项目名称:unification,代码行数:8,代码来源:test_more.py


示例4: test_goaleval

def test_goaleval():
    x, y = var('x'), var('y')
    g = eq(x, 2)
    assert goaleval(g) == g
    assert callable(goaleval((eq, x, 2)))
    with raises(EarlyGoalError):
        goaleval((membero, x, y))
    assert callable(goaleval((lallgreedy, (eq, x, 2))))
开发者ID:logpy,项目名称:logpy,代码行数:8,代码来源:test_core.py


示例5: test_reify

def test_reify():
    x, y, z = var(), var(), var()
    s = {x: 1, y: 2, z: (x, y)}
    assert reify(x, s) == 1
    assert reify(10, s) == 10
    assert reify((1, y), s) == (1, 2)
    assert reify((1, (x, (y, 2))), s) == (1, (1, (2, 2)))
    assert reify(z, s) == (1, 2)
开发者ID:vitormazzi,项目名称:unification,代码行数:8,代码来源:test_core.py


示例6: test_lall

def test_lall(lall_impl):
    x, y = var('x'), var('y')
    assert results(lall_impl((eq, x, 2))) == ({x: 2}, )
    assert results(lall_impl((eq, x, 2), (eq, x, 3))) == ()
    assert results(lall_impl()) == ({}, )

    assert run(0, x, lall_impl((eq, y, (1, 2)), (membero, x, y)))
    assert run(0, x, lall_impl()) == (x, )
    with pytest.raises(EarlyGoalError):
        run(0, x, lall_impl(membero(x, y)))
开发者ID:logpy,项目名称:logpy,代码行数:10,代码来源:test_core.py


示例7: test_unify_isinstance_list

def test_unify_isinstance_list():
    class Foo2(Foo): pass
    x = var('x')
    y = var('y')
    f, g = Foo2(1, 2), Foo2(x, y)

    _unify.add((Foo, Foo, dict), unify_object)
    _reify.add((Foo, dict), reify_object)

    assert unify(f, g, {})
    assert reify(g, {x: 1, y: 2}) == f
开发者ID:logpy,项目名称:unification,代码行数:11,代码来源:test_more.py


示例8: test_unify_tuple

def test_unify_tuple():
    # Tests that adding facts can be unified with unpacked versions of those
    # facts.
    valido = Relation()
    fact(valido, (0, 1))
    fact(valido, (1, 0))
    fact(valido, (1, 1))
    x = var()
    y = var()
    assert set(run(0, x, valido((x, y)))) == set([0, 1])
    assert set(run(0, (x, y), valido((x, y)))) == set([(0, 1), (1, 0), (1, 1)])
    assert run(0, x, valido((x, x))) == (1, )
开发者ID:logpy,项目名称:logpy,代码行数:12,代码来源:test_facts.py


示例9: itero

def itero(l):
    """A relation asserting that a term is an iterable type.

    This is a generic version of the standard `listo` that accounts for
    different iterable types supported by `cons` in Python.

    See `nullo`
    """
    c, d = var(), var()
    return (conde,
            [(nullo, l), success],
            [(conso, c, d, l),
             (itero, d)])
开发者ID:logpy,项目名称:logpy,代码行数:13,代码来源:goals.py


示例10: test_expr

def test_expr():
    add = 'add'
    mul = 'mul'
    fact(commutative, add)
    fact(associative, add)
    fact(commutative, mul)
    fact(associative, mul)

    x, y = var('x'), var('y')

    pattern = (mul, (add, 1, x), y)  # (1 + x) * y
    expr = (mul, 2, (add, 3, 1))  # 2 * (3 + 1)
    assert run(0, (x, y), eq_assoccomm(pattern, expr)) == ((3, 2), )
开发者ID:logpy,项目名称:logpy,代码行数:13,代码来源:test_assoccomm.py


示例11: test_nullo_itero

def test_nullo_itero():
    assert isvar(run(0, y, nullo([]))[0])
    assert isvar(run(0, y, nullo(None))[0])
    assert run(0, y, nullo(y))[0] is None
    assert run(0, y, (conso, var(), y, [1]), nullo(y))[0] == []
    assert run(0, y, (conso, var(), y, (1,)), nullo(y))[0] == ()

    assert run(1, y, conso(1, x, y), itero(y))[0] == [1]
    assert run(1, y, conso(1, x, y), conso(2, z, x), itero(y))[0] == [1, 2]

    # Make sure that the remaining results end in logic variables
    res_2 = run(2, y, conso(1, x, y), conso(2, z, x), itero(y))[1]
    assert res_2[:2] == [1, 2]
    assert isvar(res_2[-1])
开发者ID:logpy,项目名称:logpy,代码行数:14,代码来源:test_goals.py


示例12: test_unify_variable_with_itself_should_not_unify

def test_unify_variable_with_itself_should_not_unify():
    # Regression test for https://github.com/logpy/logpy/issues/33
    valido = Relation()
    fact(valido, "a", "b")
    fact(valido, "b", "a")
    x = var()
    assert run(0, x, valido(x, x)) == ()
开发者ID:logpy,项目名称:logpy,代码行数:7,代码来源:test_facts.py


示例13: test_unify_variable_with_itself_should_unify

def test_unify_variable_with_itself_should_unify():
    valido = Relation()
    fact(valido, 0, 1)
    fact(valido, 1, 0)
    fact(valido, 1, 1)
    x = var()
    assert run(0, x, valido(x, x)) == (1, )
开发者ID:logpy,项目名称:logpy,代码行数:7,代码来源:test_facts.py


示例14: test_eq_assoccomm

def test_eq_assoccomm():
    x, y = var(), var()
    eqac = eq_assoccomm
    ac = 'commassoc_op'
    fact(commutative, ac)
    fact(associative, ac)
    assert results(eqac(1, 1))
    assert results(eqac((1, ), (1, )))
    assert results(eqac(x, (1, )))
    assert results(eqac((1, ), x))
    assert results(eqac((ac, (ac, 1, x), y), (ac, 2, (ac, 3, 1))))
    assert results((eqac, 1, 1))
    assert results(eqac((a, (a, 1, 2), 3), (a, 1, 2, 3)))
    assert results(eqac((ac, (ac, 1, 2), 3), (ac, 1, 2, 3)))
    assert results(eqac((ac, 3, (ac, 1, 2)), (ac, 1, 2, 3)))
    assert not results(eqac((ac, 1, 1), ('other_op', 1, 1)))
    assert run(0, x, eqac((ac, 3, (ac, 1, 2)), (ac, 1, x, 3))) == (2, )
开发者ID:logpy,项目名称:logpy,代码行数:17,代码来源:test_assoccomm.py


示例15: tailo

def tailo(tail, coll):
    """ tail is the tail of coll

    See also:
        heado
        conso
    """
    return (eq, cons(var(), tail), coll)
开发者ID:logpy,项目名称:logpy,代码行数:8,代码来源:goals.py


示例16: test_buildo

def test_buildo():
    x = var('x')
    assert results(
        buildo('add', (1, 2, 3), x), {}) == ({x: ('add', 1, 2, 3)}, )
    assert results(
        buildo(x, (1, 2, 3), ('add', 1, 2, 3)), {}) == ({x: 'add'}, )
    assert results(
        buildo('add', x, ('add', 1, 2, 3)), {}) == ({x: (1, 2, 3)}, )
开发者ID:logpy,项目名称:logpy,代码行数:8,代码来源:test_assoccomm.py


示例17: test_buildo_object

def test_buildo_object():
    x = var('x')
    assert results(buildo(Add, (1, 2, 3), x), {}) == \
        ({x: add(1, 2, 3)}, )
    assert results(buildo(x, (1, 2, 3), add(1, 2, 3)), {}) == \
        ({x: Add}, )
    assert results(buildo(Add, x, add(1, 2, 3)), {}) == \
        ({x: (1, 2, 3)}, )
开发者ID:logpy,项目名称:logpy,代码行数:8,代码来源:test_assoccomm.py


示例18: heado

def heado(head, coll):
    """ head is the head of coll

    See also:
        tailo
        conso
    """
    return (eq, cons(head, var()), coll)
开发者ID:logpy,项目名称:logpy,代码行数:8,代码来源:goals.py


示例19: test_condeseq

def test_condeseq():
    x = var('x')
    assert set(run(0, x, condeseq(([eq(x, 2)], [eq(x, 3)])))) == {2, 3}
    assert set(run(0, x, condeseq([[eq(x, 2), eq(x, 3)]]))) == set()

    goals = ([eq(x, i)] for i in count())  # infinite number of goals
    assert run(1, x, condeseq(goals)) == (0, )
    assert run(1, x, condeseq(goals)) == (1, )
开发者ID:logpy,项目名称:logpy,代码行数:8,代码来源:test_core.py


示例20: test_unifiable_with_term

def test_unifiable_with_term():
    add = Op('add')
    t = MyTerm(add, (1, 2))
    assert arguments(t) == (1, 2)
    assert operator(t) == add
    assert term(operator(t), arguments(t)) == t

    x = var('x')
    assert unify(MyTerm(add, (1, x)), MyTerm(add, (1, 2)), {}) == {x: 2}
开发者ID:logpy,项目名称:logpy,代码行数:9,代码来源:test_term.py



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
Python unihandecode.Unihandecoder类代码示例发布时间:2022-05-27
下一篇:
Python unidecode.unidecode函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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