def test__is_subargument_of__min_min(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 = Structure(set(), Literal.parse('bird(tina)'), d1)
        d2 = Derivation([
            Rule.parse('flies(tina) -< bird(tina).'),
            Rule.parse('bird(tina) <- chicken(tina).'),
            Rule.parse('chicken(tina).'),
        ], i)
        s2 = Structure({Rule.parse('flies(tina) -< bird(tina).')},
                       Literal.parse('flies(tina)'), d2)
        expected = True
        result = s1.is_subargument_of(s1)

        assert_that(result).is_equal_to(expected)
Ejemplo n.º 2
0
    def test__disagreement__2(self):
        literal1 = Literal.parse('a')
        literal2 = Literal.parse('c')
        program = Program.parse('~h <- b. h <- a.')
        result = disagree(literal1, literal2, program.rules)

        assert_that(result).is_false()
    def test__get_structure__flies_tina_2__not_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('flies(tina) -< chicken(tina), scared(tina).'),
            Rule.parse('chicken(tina).'),
            Rule.parse('scared(tina).'),
        ], i)
        expected = Structure(
            {Rule.parse('flies(tina) -< chicken(tina), scared(tina).')},
            Literal.parse('flies(tina)'), d)
        result = d.get_structure()

        assert_that(result).is_equal_to(expected)
        assert_that(result.is_strict()).is_false()
Ejemplo n.º 4
0
    def test__get_derivations__3(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('b <- c.'),
                Rule.parse('c <- f, g.'),
                Rule.parse('f.'),
                Rule.parse('g.')
            ], i),
            Derivation([
                Rule.parse('b <- d, e.'),
                Rule.parse('d <- h.'),
                Rule.parse('h.'),
                Rule.parse('e.')
            ], i),
        }
        result = i.get_derivations(Literal.parse('b'))

        assert_that(result).is_equal_to(expected)
Ejemplo n.º 5
0
    def test__get_derivations__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), scared(tina).'),
                Rule.parse('chicken(tina).'),
                Rule.parse('scared(tina).')
            ], i),
            Derivation([
                Rule.parse('flies(tina) -< bird(tina).'),
                Rule.parse('bird(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)
Ejemplo n.º 6
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)
Ejemplo n.º 7
0
    def test__disagreement__0(self):
        literal1 = Literal.parse('a')
        literal2 = Literal.parse('~a')
        result = disagree(literal1, literal2, {})

        assert_that(result).is_true()