Esempio n. 1
0
 def select_depth(self, depths):
     """Override ParagraphProcessor to add different weights"""
     depths = heuristics.prefer_diff_types_diff_levels(depths, 0.2)
     depths = heuristics.prefer_multiple_children(depths, 0.4)
     depths = heuristics.prefer_shallow_depths(depths, 0.8)
     depths = heuristics.prefer_no_markerless_sandwich(depths, 0.2)
     depths = sorted(depths, key=lambda d: d.weight, reverse=True)
     return depths[0]
 def select_depth(self, depths):
     """Override ParagraphProcessor to add different weights"""
     depths = heuristics.prefer_diff_types_diff_levels(depths, 0.2)
     depths = heuristics.prefer_multiple_children(depths, 0.4)
     depths = heuristics.prefer_shallow_depths(depths, 0.8)
     depths = heuristics.prefer_no_markerless_sandwich(depths, 0.2)
     depths = sorted(depths, key=lambda d: d.weight, reverse=True)
     return depths[0]
Esempio n. 3
0
    def test_prefer_no_markerless_sandwich(self):
        """Generate two solutions, one in which a markerless sandwich
        is used to skip depth, and another where it is not used to
        skip depth."""

        self.add_assignment(markers.ints, '1', 0)
        self.add_assignment(markers.markerless, markers.MARKERLESS, 1)
        self.add_assignment(markers.roman, 'i', 1)
        solution1 = self.solution

        self.setUp()
        self.add_assignment(markers.ints, '1', 0)
        self.add_assignment(markers.markerless, markers.MARKERLESS, 1)
        self.add_assignment(markers.roman, 'i', 2)
        solution2 = self.solution

        solutions = [Solution(solution1), Solution(solution2)]
        solutions = heuristics.prefer_no_markerless_sandwich(solutions, 0.5)
        self.assertEqual(solutions[0].weight, 1.0)
        self.assertTrue(solutions[1].weight < solutions[0].weight)

        self.setUp()
        self.add_assignment(markers.markerless, markers.MARKERLESS, 0)
        self.add_assignment(markers.markerless, markers.MARKERLESS, 0)
        self.add_assignment(markers.lower, 'a', 1)
        self.add_assignment(markers.lower, 'b', 1)
        self.add_assignment(markers.markerless, markers.MARKERLESS, 0)
        self.add_assignment(markers.lower, 'a', 1)
        self.add_assignment(markers.lower, 'b', 1)
        solution1 = self.solution

        self.setUp()
        self.add_assignment(markers.markerless, markers.MARKERLESS, 0)
        self.add_assignment(markers.markerless, markers.MARKERLESS, 0)
        self.add_assignment(markers.lower, 'a', 1)
        self.add_assignment(markers.lower, 'b', 1)
        self.add_assignment(markers.markerless, markers.MARKERLESS, 2)
        self.add_assignment(markers.lower, 'a', 3)
        self.add_assignment(markers.lower, 'b', 3)
        solution2 = self.solution

        solutions = [Solution(solution1), Solution(solution2)]
        solutions = heuristics.prefer_no_markerless_sandwich(solutions, 0.5)
        self.assertEqual(solutions[0].weight, 1.0)
        self.assertTrue(solutions[1].weight < solutions[0].weight)
 def select_depth(self, depths):
     """There might be multiple solutions to our depth processing problem.
     Use heuristics to select one."""
     depths = heuristics.prefer_diff_types_diff_levels(depths, 0.8)
     depths = heuristics.prefer_multiple_children(depths, 0.4)
     depths = heuristics.prefer_shallow_depths(depths, 0.2)
     depths = heuristics.prefer_no_markerless_sandwich(depths, 0.2)
     depths = sorted(depths, key=lambda d: d.weight, reverse=True)
     return depths[0]
 def select_depth(self, depths):
     """There might be multiple solutions to our depth processing problem.
     Use heuristics to select one."""
     depths = heuristics.prefer_diff_types_diff_levels(depths, 0.8)
     depths = heuristics.prefer_multiple_children(depths, 0.4)
     depths = heuristics.prefer_shallow_depths(depths, 0.2)
     depths = heuristics.prefer_no_markerless_sandwich(depths, 0.2)
     depths = sorted(depths, key=lambda d: d.weight, reverse=True)
     return depths[0]