示例#1
0
def test_Depth_update_agenda_asertion_order_affects_agenda_order_1():
    from pyknow.strategies import Depth
    from pyknow.activation import Activation
    from pyknow.rule import Rule
    from pyknow.agenda import Agenda

    act1 = Activation(rule=Rule(), facts=(1, ))
    act2 = Activation(rule=Rule(), facts=(2, ))
    first = {act1, act2}

    act3 = Activation(rule=Rule(), facts=(3, ))
    act4 = Activation(rule=Rule(), facts=(4, ))
    second = {act3, act4}

    a = Agenda()

    st = Depth()

    st.update_agenda(a, first)
    st.update_agenda(a, second)

    left, right = set(list(a.activations)[:2]), set(list(a.activations)[2:])

    assert left == second
    assert right == first
示例#2
0
def test_Depth_update_agenda_different_salience():
    from random import shuffle

    from pyknow.strategies import Depth
    from pyknow.activation import Activation
    from pyknow.rule import Rule
    from pyknow.agenda import Agenda

    act1 = Activation(rule=Rule(salience=1), facts=(1, ))
    act2 = Activation(rule=Rule(salience=2), facts=(2, ))
    act3 = Activation(rule=Rule(salience=3), facts=(3, ))
    act4 = Activation(rule=Rule(salience=4), facts=(4, ))

    acts = [act1, act2, act3, act4]
    shuffle(acts)

    st = Depth()
    a = Agenda()

    for act in acts:
        st.update_agenda(a, [act])

    order = list(a.activations)
    assert (order.index(act4) < order.index(act3) < order.index(act2) <
            order.index(act1))
示例#3
0
def test_Depth_update_agenda_asertion_order_affects_agenda_order_1():
    from pyknow.strategies import Depth
    from pyknow.activation import Activation
    from pyknow.rule import Rule
    from pyknow.agenda import Agenda

    act1 = Activation(rule=Rule(), facts=(1, ))
    act2 = Activation(rule=Rule(), facts=(2, ))
    first = {act1, act2}

    act3 = Activation(rule=Rule(), facts=(3, ))
    act4 = Activation(rule=Rule(), facts=(4, ))
    second = {act3, act4}

    a = Agenda()

    st = Depth()

    st.update_agenda(a, first)
    st.update_agenda(a, second)

    left, right = set(list(a.activations)[:2]), set(list(a.activations)[2:])

    assert left == second
    assert right == first
示例#4
0
def test_Depth_update_agenda_different_salience():
    from random import shuffle

    from pyknow.strategies import Depth
    from pyknow.activation import Activation
    from pyknow.rule import Rule
    from pyknow.agenda import Agenda

    act1 = Activation(rule=Rule(salience=1), facts=(1, ))
    act2 = Activation(rule=Rule(salience=2), facts=(2, ))
    act3 = Activation(rule=Rule(salience=3), facts=(3, ))
    act4 = Activation(rule=Rule(salience=4), facts=(4, ))

    acts = [act1, act2, act3, act4]
    shuffle(acts)

    st = Depth()
    a = Agenda()

    for act in acts:
        st.update_agenda(a, [act])
    
    order = list(a.activations)
    assert (order.index(act4) < order.index(act3) <
            order.index(act2) < order.index(act1))
示例#5
0
def test_Depth_update_agenda_no_facts_returns_empty_agenda():
    from pyknow.strategies import Depth
    from pyknow.agenda import Agenda

    st = Depth()
    a = Agenda()

    st.update_agenda(a, set())

    assert not a.activations
示例#6
0
def test_Depth_update_agenda_no_facts_returns_empty_agenda():
    from pyknow.strategies import Depth
    from pyknow.agenda import Agenda

    st = Depth()
    a = Agenda()

    st.update_agenda(a, set())

    assert not a.activations
示例#7
0
def test_Depth_update_agenda_activations_to_agenda():
    from pyknow.strategies import Depth
    from pyknow.activation import Activation
    from pyknow.rule import Rule
    from pyknow.agenda import Agenda

    act1 = Activation(rule=Rule(), facts=(1, ))
    act2 = Activation(rule=Rule(), facts=(2, ))

    a = Agenda()

    st = Depth()
    st.update_agenda(a, {act1, act2})

    assert act1 in a.activations
    assert act2 in a.activations
示例#8
0
def test_Depth_update_agenda_activations_to_agenda():
    from pyknow.strategies import Depth
    from pyknow.activation import Activation
    from pyknow.rule import Rule
    from pyknow.agenda import Agenda

    act1 = Activation(rule=Rule(), facts=(1, ))
    act2 = Activation(rule=Rule(), facts=(2, ))

    a = Agenda()

    st = Depth()
    st.update_agenda(a, {act1, act2})

    assert act1 in a.activations
    assert act2 in a.activations