コード例 #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]
コード例 #2
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]
コード例 #3
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]
コード例 #4
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_shallow_depths(self):
        """Generate two solutions which vary only in depth. Verify that we
        prefer the more shallow"""
        self.add_assignment(markers.markerless, markers.MARKERLESS, 0)
        self.add_assignment(markers.ints, '1', 1)
        self.add_assignment(markers.markerless, markers.MARKERLESS, 0)
        solution1 = self.solution

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

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