Commit bc141bca authored by Miguel Angel Reina Ortega's avatar Miguel Angel Reina Ortega
Browse files

Fix for abbreviations

parent ee3ecc69
Loading
Loading
Loading
Loading
Loading
+10 −4
Changes for generateBaseline/postprocessing.py: 10 added lines, 4 removed lines.
Original line number Diff line number Diff line
@@ -821,7 +821,7 @@ def _is_in_abbreviations_clause(para, ns):
            continue
        if (_paragraph_style_val(previous, ns) or '').startswith('Heading'):  # Heading1, Heading2 or Heading3
            heading_text = _normalize_ws(_paragraph_text(previous))
            return bool(re.search(r'\b(?:abbreviations|symbols)\b', heading_text, flags=re.IGNORECASE))
            return bool(re.search(r'\b(?:abbreviations|symbols|terms)\b', heading_text, flags=re.IGNORECASE))
        previous = previous.getprevious()
    return False

@@ -2704,7 +2704,6 @@ def update_abbreviations(docx_input, docx_output):
        
        # Process each verbatim run separately
        new_paragraphs = []
        option2_definition = False
        for verbatim_run in verbatim_runs:
            # Extract text from this specific verbatim run
            full_text_in_verbatim_run = ""
@@ -2720,10 +2719,17 @@ def update_abbreviations(docx_input, docx_output):
            # Check if text contains multiple spaces (2 or more) separating two parts
            # Pattern: abbreviation followed by 2+ spaces followed by definition
            match = re.match(r'^(.+?)\s{2,}(.+)$', full_text_in_verbatim_run.strip())
            option2_definition = False
            if not match:
                # Option 2: abbreviation (in a verbatim run) followed by definition (in the remaining runs of the paragraph) separated by one or more spaces
                # Take all remaining runs of the paragraph as they are, except the verbatim run
                remaining_runs = [run for run in para.xpath('./w:r', namespaces=ns) if run != verbatim_run]
                # Take all remaining runs of the paragraph as they are, except the verbatim run up to the hard break
                remaining_runs = []
                sibling = verbatim_run.getnext()
                while sibling is not None:
                    if sibling.tag == f"{{{ns['w']}}}r" and sibling.xpath('./w:br', namespaces=ns) and _run_text(sibling).strip() == '':
                        break
                    remaining_runs.append(sibling)
                    sibling = sibling.getnext()
                while remaining_runs and _run_text(remaining_runs[0]).isspace():
                    remaining_runs.pop(0)
                abbreviation = full_text_in_verbatim_run.strip()