示例#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):
     """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 = 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]
 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]
示例#5
0
    def test_prefer_diff_types_diff_levels(self):
        """Generally assume that the same depth only contains one type of
        marker"""
        self.add_assignment(markers.lower, 'h', 0)
        self.add_assignment(markers.ints, '1', 1)
        self.add_assignment(markers.roman, 'i', 2)
        self.add_assignment(markers.upper, 'A', 3)
        solution1 = self.solution

        self.setUp()

        self.add_assignment(markers.lower, 'h', 0)
        self.add_assignment(markers.ints, '1', 1)
        self.add_assignment(markers.roman, 'i', 0)
        self.add_assignment(markers.upper, 'A', 1)
        solution2 = self.solution

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