コード例 #1
0
    def test_viterbi_should_work_well_with_terminal_productions(self):
        # Given:
        production = Production(self.detector, self.rule)
        production.probability = 0.5
        production2 = Production(self.detector, self.rule)
        production2.probability = 0.8

        # When:
        self.sut.add_production(production, None, viterbi_probability_approach)
        self.sut.add_production(production2, None, viterbi_probability_approach)

        # Then:
        assert_that(self.sut.is_empty(), is_(equal_to(False)))
        assert_that(self.sut.get_effectors(), only_contains(Symbol("A")))
        assert_that(self.sut.get_non_empty_productions(), only_contains(production))
        assert_that(self.sut.effector_probabilities[Symbol("A")], is_(equal_to(0.8)))
コード例 #2
0
    def test_baum_welch_should_work_well_with_non_terminal_productions(self):
        # Given:
        production = Production(self.detector, self.rule)
        production.probability = 0.5
        production2 = Production(self.detector, self.rule)
        production2.probability = 0.8

        # When:
        self.sut.add_production(production, (anything(), 0.4, anything(), 0.6), baum_welch_probability_approach)
        self.sut.add_production(production2, (anything(), 0.1, anything(), 0.5), baum_welch_probability_approach)

        # Then:
        assert_that(self.sut.is_empty(), is_(equal_to(False)))
        assert_that(self.sut.get_effectors(), only_contains(Symbol("A")))
        assert_that(self.sut.get_non_empty_productions(), only_contains(production))
        assert_that(self.sut.effector_probabilities[Symbol("A")], is_(equal_to(0.16)))