Exemple #1
0
    def test_initial_markers(self):
        """Should not find any collapsed markers and should find all of the
        markers at the beginning of the text"""
        text = '(k)(2)(iii) abc (j)'
        result = [m for m in reg_text.initial_markers(text)]
        self.assertEqual(['k', '2', 'iii'], result)

        text = '(i)(A) The minimum period payment'
        result = [m for m in reg_text.initial_markers(text)]
        self.assertEqual(['i', 'A'], result)
    def test_initial_markers(self):
        """Should not find any collapsed markers and should find all of the
        markers at the beginning of the text"""
        text = '(k)(2)(iii) abc (j)'
        result = [m for m in reg_text.initial_markers(text)]
        self.assertEqual(['k', '2', 'iii'], result)

        text = '(i)(A) The minimum period payment'
        result = [m for m in reg_text.initial_markers(text)]
        self.assertEqual(['i', 'A'], result)
def overwrite_marker(origin, new_label):
    """ The node passed in has a label, but we're going to give it a
    new one (new_label). This is necessary during node moves.  """

    if origin.node_type == Node.REGTEXT:
        marker_list = reg_text.initial_markers(origin.text)
        if len(marker_list) > 0:
            marker = '(%s)' % marker_list[0]
            new_marker = '(%s)' % new_label
            origin.text = origin.text.replace(marker, new_marker, 1)
    elif origin.node_type == Node.INTERP:
        marker = interpretations.get_first_interp_marker(origin.text)
        marker = marker + '.'
        new_marker = new_label + '.'
        origin.text = origin.text.replace(marker, new_marker, 1)

    return origin
def overwrite_marker(origin, new_label):
    """ The node passed in has a label, but we're going to give it a
    new one (new_label). This is necessary during node moves.  """

    if origin.node_type == Node.REGTEXT:
        marker_list = reg_text.initial_markers(origin.text)
        if len(marker_list) > 0:
            marker = '(%s)' % marker_list[0]
            new_marker = '(%s)' % new_label
            origin.text = origin.text.replace(marker, new_marker, 1)
    elif origin.node_type == Node.INTERP:
        marker = interpretations.get_first_interp_marker(origin.text)
        marker = marker + '.'
        new_marker = new_label + '.'
        origin.text = origin.text.replace(marker, new_marker, 1)

    return origin
Exemple #5
0
 def get_subsections_for_paragraph(self, paragraph, next_paragraph):
     subsections = []
     if next_paragraph:
         next_markers = initial_markers(next_paragraph)
         if len(next_markers) > 0:
             next_marker = next_markers[0]
         else:
             next_marker = "MARKERLESS"
     else:
         next_marker = None
     markers = get_markers(paragraph, next_marker)
     if not markers:
         subsections.append(('MARKERLESS', paragraph))
     else:
         marker_regex = ".*" + "(\( ?%s ?\).*)"*len(markers) % tuple(markers)
         match = re.match(marker_regex, paragraph, re.S)
         subsections.extend(zip(markers, match.groups()))
     return subsections
 def get_subsections_for_paragraph(self, paragraph, next_paragraph):
     subsections = []
     if next_paragraph:
         next_markers = initial_markers(next_paragraph)
         if len(next_markers) > 0:
             next_marker = next_markers[0]
         else:
             next_marker = "MARKERLESS"
     else:
         next_marker = None
     markers = get_markers(paragraph, next_marker)
     if not markers:
         subsections.append(('MARKERLESS', paragraph))
     else:
         tail = paragraph
         for marker in markers:
             head, tail = self.split_text_by_marker(marker, tail)
             subsections.append((marker, tail))
     return subsections