Exemplo n.º 1
0
def test_logic_example_2():
    """
    Source: Mail by Nico
    """
    decisionSupportSystem = DecisionSupportSystem(
        initial_information=[
            # parse('p')
        ],
        rules=[
            Rule(
                parse('p'),
                parse('q')
            ),
            Rule(
                parse('q'),
                parse('r')
            ),
            Rule(
                parse('r'),
                parse('¬q')
            )
        ],
        question=parse('q')
    )
    decisionSupportSystem.run()
Exemplo n.º 2
0
def test_law_example():
    """
    Tomas Cremers (2016), Appendix C.1
    """
    decisionSupportSystem = DecisionSupportSystem(
        initial_information=[

        ],
        rules=[
            Rule(
                parse('Employed'),
                parse('CanMakeRequestForChange')
            ),
            Rule(
                parse('Employed & LessThanTenEmployees'),
                parse('¬CanMakeRequestForChange')
            ),
            Rule(
                parse('Employed & ReachedOldAgeInsurance'),
                parse('¬CanMakeRequestForChange')
            ),
            Rule(
                parse('Employed & MilitaryOfficial'),
                parse('¬CanMakeRequestForChange')
            )
        ],
        question=parse('¬CanMakeRequestForChange')
    )
    decisionSupportSystem.run()
Exemplo n.º 3
0
def test_presentation():
    """

    """
    decisionSupportSystem = DecisionSupportSystem(
        initial_information=[

        ],
        rules=[
            Rule(
                parse('justifiable_defense'),
                parse('¬conviction')
            ),
            Rule(
                parse('threaten & attacked'),
                parse('justifiable_defense')
            ),
            Rule(
                parse('kill_person '),
                parse('conviction')
            ),
        ],
        question=parse('conviction')
    )
    decisionSupportSystem.run()
Exemplo n.º 4
0
def test_cremers():
    config = Configuration(Rule, toProposition)
    a, b = config.parse_json("./sample_rule_sets/cremers_example.json")
    rules = set(a)
    initial = set(b)
    decisionSupportSystem = DecisionSupportSystem(
        initial_information=[],
        rules=rules,
        question=parse('LEGAL_RequestedChangeWorkingHours')
    )
    decisionSupportSystem.run()
Exemplo n.º 5
0
def test_BNA():
    config = Configuration(Rule, toProposition)
    a, b = config.parse_json(
        "./src/sample_rule_sets/british_national_act.json")
    #rules = set(a)
    #initial = set(b)
    rules = set()
    initial = set()
    for i in a:
        rules.add(i)
    for j in b:
        initial.add(j)
    decisionSupportSystem = DecisionSupportSystem(
        initial_information=[],
        rules=rules,
        question=parse('BritishCitizen')
    )
    decisionSupportSystem.run()
Exemplo n.º 6
0
def test_defeasible_rules():
    decisionSupportSystem = DecisionSupportSystem(
        question=parse('¬f'),
        initial_information=[],
        rules=[
            Rule(
                parse('(a or b)'),
                parse('c')
            ),
            Rule(
                parse('c and x'),
                parse('f')
            ),
            Rule(
                parse('x or c'),
                parse('¬f')
            )
        ]
    )
    decisionSupportSystem.run()
    preference = [
        (2, 1)
    ]
Exemplo n.º 7
0
 def do_POST(self):
     length = int(self.headers['Content-Length'])
     body = self.rfile.read(length).decode('utf-8')
     self.send_response(200)
     self.send_header('Content-type', 'text/html')
     self.end_headers()
     input = json.loads(body)
     t = Tableau(
         question=parse(input['question']),
         initial_information={
             parse(p)
             for p in input['initial_information']
         },
         rules={Rule(parse(a), parse(b))
                for (a, b) in input['rules']})
     flag, result = t.evaluate()
     if flag == 'known':
         pro, contra = result
         output = json.dumps({
             'flag':
             'known',
             'result': [[str(p) for p in pro], [str(p) for p in contra]]
         })
     if flag == 'unknown':
         question = DecisionSupportSystem(
             question=parse(input['question']),
             initial_information={
                 parse(p)
                 for p in input['initial_information']
             },
             rules={Rule(parse(a), parse(b))
                    for (a, b) in input['rules']
                    }).get_promising_tests(result)
         output = json.dumps({'flag': 'unknown', 'result': list(question)})
     print(output.encode('utf-8'))
     self.wfile.write(output.encode('utf-8'))
Exemplo n.º 8
0
def test_example_three():
    decisionSupportSystem = DecisionSupportSystem(
        question=parse('c'),
        initial_information=[parse('((a and b) or c) -> c')]
    )
    decisionSupportSystem.run()
Exemplo n.º 9
0
def test_example_two():
    decisionSupportSystem = DecisionSupportSystem(
        question=parse('e'),
        initial_information=[parse('((a and b) or (c and d)) -> e')]
    )
    decisionSupportSystem.run()
Exemplo n.º 10
0
def test_example_one():
    decisionSupportSystem = DecisionSupportSystem(
        question=parse('d'),
        initial_information=[parse('((a or b) and c) -> d')])
    decisionSupportSystem.run()