Пример #1
0
def test_inconsistent_assumptions():
    kb = FactKB(FactRules(['npos -> ~pos', 'pos -> ~npos']))
    with pytest.raises(InconsistentAssumptions) as err:
        kb.deduce_all_facts({'pos': T, 'npos': T})
    assert str(err.value) in [
        '{\n\tnpos: False,\n\tpos: True}, npos=True',
        '{\n\tnpos: True,\n\tpos: False}, pos=True'
    ]
Пример #2
0
def test_FactRules_deduce_base():
    # deduction that starts from base

    f = FactRules(['real  == neg | zero | pos',
                   'neg   -> real & ~zero & ~pos',
                   'pos   -> real & ~zero & ~neg'])
    base = FactKB(f)

    base.deduce_all_facts({'real': T, 'neg': F})
    assert base == {'real': T, 'neg': F}

    base.deduce_all_facts({'zero': F})
    assert base == {'real': T, 'neg': F, 'zero': F, 'pos': T}
Пример #3
0
def test_FactRules_deduce_base():
    # deduction that starts from base

    f = FactRules(['real  == neg | zero | pos',
                   'neg   -> real & ~zero & ~pos',
                   'pos   -> real & ~zero & ~neg'])
    base = FactKB(f)

    base.deduce_all_facts({'real': T, 'neg': F})
    assert base == {'real': T, 'neg': F}

    base.deduce_all_facts({'zero': F})
    assert base == {'real': T, 'neg': F, 'zero': F, 'pos': T}
Пример #4
0
 def D(facts):
     kb = FactKB(f)
     kb.deduce_all_facts(facts)
     return kb
Пример #5
0
def test_inconsistent_assumptions():
    kb = FactKB(FactRules(['npos -> ~pos', 'pos -> ~npos']))
    with pytest.raises(InconsistentAssumptions) as err:
        kb.deduce_all_facts({'pos': T, 'npos': T})
    assert str(err.value) in ['{\n\tnpos: False,\n\tpos: True}, npos=True',
                              '{\n\tnpos: True,\n\tpos: False}, pos=True']
Пример #6
0
 def D(facts):
     kb = FactKB(f)
     kb.deduce_all_facts(facts)
     return kb