Exemple #1
0
    def test__is_contradictory__defeasibly(self):
        p = Program.parse("""
            bird(X) <- chicken(X).
            bird(X) <- penguin(X).
            ~flies(X) <- penguin(X).
            chicken(tina).
            penguin(tweety).
            scared(tina).
            flies(X) -< bird(X).
            flies(X) -< chicken(X), scared(X).
            nests_in_trees(X) -< flies(X).
            ~flies(X) -< chicken(X).
        """)
        i = Interpreter(p)
        expected = True
        result = bool(i.is_contradictory(RuleType.DEFEASIBLE))

        assert_that(result).is_equal_to(expected)
Exemple #2
0
    def test__get_derivations__not_flies_tina__strictly(self):
        p = Program.parse("""
            bird(X) <- chicken(X).
            bird(X) <- penguin(X).
            ~flies(X) <- penguin(X).
            chicken(tina).
            penguin(tweety).
            scared(tina).
            flies(X) -< bird(X).
            flies(X) -< chicken(X), scared(X).
            nests_in_trees(X) -< flies(X).
            ~flies(X) -< chicken(X).
        """)
        i = Interpreter(p)
        expected = set()
        result = i.get_derivations(Literal.parse('~flies(tina)'),
                                   RuleType.STRICT)

        assert_that(result).is_equal_to(expected)
    def test__is_counter_argument_of__9(self):
        p = Program.parse("""
            bird(X) <- chicken(X).
            bird(X) <- penguin(X).
            ~flies(X) <- penguin(X).
            chicken(tina).
            penguin(tweety).
            scared(tina).
            flies(X) -< bird(X).
            flies(X) -< chicken(X), scared(X).
            nests_in_trees(X) -< flies(X).
            ~flies(X) -< chicken(X).
        """)
        i = Interpreter(p)
        d1 = Derivation([
            Rule.parse('bird(tina) <- chicken(tina).'),
            Rule.parse('chicken(tina).'),
        ], i)
        s1 = d1.get_structure()
        result = s1.is_counter_argument_of(s1, s1)

        assert_that(result).is_false()
Exemple #4
0
    def test__get_derivations__2(self):
        p = Program.parse("""
            a <- b, c. 
            b <- d, e. 
            b <- c. 
            c <- f, g. 
            d <- h. 
            e. 
            f. 
            g. 
            h.
        """)
        i = Interpreter(p)
        expected = {
            Derivation(
                [Rule.parse('c <- f, g.'),
                 Rule.parse('f.'),
                 Rule.parse('g.')], i)
        }
        result = i.get_derivations(Literal.parse('c'))

        assert_that(result).is_equal_to(expected)
    def test__get_structure__bird_tina__strict(self):
        p = Program.parse("""
                    bird(X) <- chicken(X).
                    bird(X) <- penguin(X).
                    ~flies(X) <- penguin(X).
                    chicken(tina).
                    penguin(tweety).
                    scared(tina).
                    flies(X) -< bird(X).
                    flies(X) -< chicken(X), scared(X).
                    nests_in_trees(X) -< flies(X).
                    ~flies(X) -< chicken(X).
                """)
        i = Interpreter(p)
        d = Derivation([
            Rule.parse('bird(tina) <- chicken(tina).'),
            Rule.parse('chicken(tina).')
        ], i)
        expected = Structure(set(), Literal.parse('bird(tina)'), d)
        result = d.get_structure()

        assert_that(result).is_equal_to(expected)
        assert_that(result.is_strict()).is_true()
Exemple #6
0
    def test__get_derivations__not_flies_tina__defeasibly(self):
        p = Program.parse("""
            bird(X) <- chicken(X).
            bird(X) <- penguin(X).
            ~flies(X) <- penguin(X).
            chicken(tina).
            penguin(tweety).
            scared(tina).
            flies(X) -< bird(X).
            flies(X) -< chicken(X), scared(X).
            nests_in_trees(X) -< flies(X).
            ~flies(X) -< chicken(X).
        """)
        i = Interpreter(p)
        expected = {
            Derivation([
                Rule.parse('~flies(tina) -< chicken(tina).'),
                Rule.parse('chicken(tina).')
            ], i)
        }
        result = i.get_derivations(Literal.parse('~flies(tina)'),
                                   RuleType.DEFEASIBLE)

        assert_that(result).is_equal_to(expected)