def test_depth_type_inverses_t2d(self):
        """Two markers of the same type should have the same depth"""
        self.assert_depth_match_extra(
            ['1', STARS_TAG, 'b', STARS_TAG, 'C', STARS_TAG, 'd'],
            [optional_rules.limit_sequence_gap()], [0, 1, 1, 2, 2, 3, 3],
            [0, 1, 1, 2, 2, 1, 1])

        self.assert_depth_match_extra(
            ['1', STARS_TAG, 'b', STARS_TAG, 'C', STARS_TAG, 'd'], [
                optional_rules.limit_sequence_gap(),
                optional_rules.depth_type_inverses
            ], [0, 1, 1, 2, 2, 1, 1])
    def test_depth_type_inverses_d2t(self):
        """Two markers of the same depth should have the same type"""
        self.assert_depth_match_extra(
            ['1', STARS_TAG, 'c', '2', INLINE_STARS, 'i', STARS_TAG, 'iii'],
            [optional_rules.limit_sequence_gap()], [0, 1, 1, 0, 1, 1, 1, 1],
            [0, 1, 1, 0, 1, 1, 2, 2])

        self.assert_depth_match_extra(
            ['1', STARS_TAG, 'c', '2', INLINE_STARS, 'i', STARS_TAG, 'iii'], [
                optional_rules.limit_sequence_gap(),
                optional_rules.depth_type_inverses
            ], [0, 1, 1, 0, 1, 1, 2, 2])
    def test_limit_sequence_gap(self):
        """The limit_sequence_gap rule should limit our ability to derive
        depths with gaps between adjacent paragraphs. It should be
        configurable to allow any value"""
        self.assert_depth_match(['a', '1', 'i'], [0, 1, 2], [0, 1, 0])

        self.assert_depth_match_extra(['a', '1', 'i'],
                                      [optional_rules.limit_sequence_gap()],
                                      [0, 1, 2])

        self.assert_depth_match_extra(['a', '1', 'i'],
                                      [optional_rules.limit_sequence_gap(10)],
                                      [0, 1, 2], [0, 1, 0])
    def test_depth_type_inverses_d2t(self):
        """Two markers of the same depth should have the same type"""
        self.assert_depth_match_extra(
            ['1', STARS_TAG, 'c', '2', INLINE_STARS, 'i', STARS_TAG, 'iii'],
            [optional_rules.limit_sequence_gap()],
            [0, 1, 1, 0, 1, 1, 1, 1],
            [0, 1, 1, 0, 1, 1, 2, 2])

        self.assert_depth_match_extra(
            ['1', STARS_TAG, 'c', '2', INLINE_STARS, 'i', STARS_TAG, 'iii'],
            [optional_rules.limit_sequence_gap(),
             optional_rules.depth_type_inverses],
            [0, 1, 1, 0, 1, 1, 2, 2])
    def test_depth_type_inverses_t2d(self):
        """Two markers of the same type should have the same depth"""
        self.assert_depth_match_extra(
            ['1', STARS_TAG, 'b', STARS_TAG, 'C', STARS_TAG, 'd'],
            [optional_rules.limit_sequence_gap()],
            [0, 1, 1, 2, 2, 3, 3],
            [0, 1, 1, 2, 2, 1, 1])

        self.assert_depth_match_extra(
            ['1', STARS_TAG, 'b', STARS_TAG, 'C', STARS_TAG, 'd'],
            [optional_rules.limit_sequence_gap(),
             optional_rules.depth_type_inverses],
            [0, 1, 1, 2, 2, 1, 1])
예제 #6
0
    def test_simple_stars(self):
        self.assert_depth_match(['A', '1', STARS_TAG, 'd'],
                                [0, 1, 2, 2])

        self.assert_depth_match_extra(['A', '1', 'a', STARS_TAG, 'd'],
                                      [optional_rules.limit_sequence_gap()],
                                      [0, 1, 2, 2, 2])
    def test_limit_sequence_gap(self):
        """The limit_sequence_gap rule should limit our ability to derive
        depths with gaps between adjacent paragraphs. It should be
        configurable to allow any value"""
        self.assert_depth_match(['a', '1', 'i'],
                                [0, 1, 2],
                                [0, 1, 0])

        self.assert_depth_match_extra(['a', '1', 'i'],
                                      [optional_rules.limit_sequence_gap()],
                                      [0, 1, 2])

        self.assert_depth_match_extra(['a', '1', 'i'],
                                      [optional_rules.limit_sequence_gap(10)],
                                      [0, 1, 2],
                                      [0, 1, 0])
예제 #8
0
 def additional_constraints(self):
     return [
         optional_rules.limit_sequence_gap(),
         optional_rules.limit_paragraph_types(mtypes.lower, mtypes.ints,
                                              mtypes.upper, mtypes.roman,
                                              mtypes.upper_roman)
     ]
예제 #9
0
 def test_alpha_roman_ambiguous(self):
     self.assert_depth_match_extra(
         ['i', 'ii', STARS_TAG, 'v', STARS_TAG, 'vii'],
         [optional_rules.limit_sequence_gap()],
         [0, 0, 1, 1, 2, 2],
         [0, 0, 1, 1, 0, 0],
         [0, 0, 0, 0, 0, 0])
예제 #10
0
 def additional_constraints(self):
     return [optional_rules.depth_type_inverses,
             optional_rules.star_new_level,
             optional_rules.limit_sequence_gap(3),
             optional_rules.limit_paragraph_types(
                 mtypes.lower, mtypes.upper, mtypes.ints, mtypes.roman,
                 mtypes.em_ints, mtypes.em_roman, mtypes.stars,
                 mtypes.markerless)]
예제 #11
0
 def test_start_star(self):
     self.assert_depth_match_extra(
         [STARS_TAG, 'c', '1', STARS_TAG, 'ii', 'iii', '2', 'i', 'ii',
          STARS_TAG, 'v', STARS_TAG, 'vii', 'A'],
         [optional_rules.limit_sequence_gap()],
         [0, 0, 1, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 3],
         [0, 0, 1, 2, 2, 2, 1, 2, 2, 3, 3, 2, 2, 3],
         [0, 0, 1, 2, 2, 2, 1, 2, 2, 3, 3, 4, 4, 5],
         [0, 0, 1, 2, 2, 2, 1, 2, 2, 0, 0, 1, 1, 2])
예제 #12
0
 def additional_constraints(self):
     return [
         optional_rules.depth_type_inverses, optional_rules.star_new_level,
         optional_rules.limit_sequence_gap(3),
         optional_rules.limit_paragraph_types(mtypes.lower, mtypes.upper,
                                              mtypes.ints, mtypes.roman,
                                              mtypes.em_ints,
                                              mtypes.em_roman, mtypes.stars,
                                              mtypes.markerless)
     ]
def outline_depths(markers):
    """
    Infer an outline's structure.
    Return a list of outline depths for a given list of space-separated
    markers.
    """

    # Input is space-separated.
    marker_list = markers.split(' ')
    all_solutions = derive_depths(marker_list,
                                  [optional_rules.limit_sequence_gap(1)])
    depths = {tuple(str(a.depth) for a in s) for s in all_solutions}.pop()

    # Expected output is space-separated.
    formatted_output = ' '.join(depths)

    click.echo(formatted_output)
예제 #14
0
def outline_depths(markers):
    """
    Infer an outline's structure.
    Return a list of outline depths for a given list of space-separated
    markers.
    """

    # Input is space-separated.
    marker_list = markers.split(' ')
    all_solutions = derive_depths(
        marker_list,
        [optional_rules.limit_sequence_gap(1)]
    )
    depths = {tuple(str(a.depth) for a in s) for s in all_solutions}.pop()

    # Expected output is space-separated.
    formatted_output = ' '.join(depths)

    click.echo(formatted_output)
예제 #15
0
 def additional_constraints(self):
     return [optional_rules.depth_type_inverses,
             optional_rules.limit_sequence_gap(3)
             ] + self.relaxed_constraints()
예제 #16
0
 def additional_constraints(self):
     return [
         optional_rules.depth_type_inverses,
         optional_rules.limit_sequence_gap(3),
         optional_rules.stars_occupy_space,
     ] + self.relaxed_constraints()
예제 #17
0
 def additional_constraints(self):
     return [optional_rules.limit_sequence_gap(),
             optional_rules.limit_paragraph_types(
                 mtypes.lower, mtypes.ints, mtypes.upper, mtypes.roman,
                 mtypes.upper_roman)]