Extract comments from Word (.docx) documents and format them into standardized review opinions. The script handles data extraction (comment text, anchor text, page numbers) and outputs structured JSON. The agent then performs semantic polishing to produce professional, publication-ready review opinions.
Core capabilities:
extract_comments.py): Handles all data extraction locally. Unpacks the .docx file (using Python's built-in zipfile), parses XML to extract comments and anchor text, retrieves page numbers via Word COM. Outputs JSON. No external dependencies beyond pywin32.bash
python extract_comments.py <docx_file_path>
The script takes a single argument — the path to the .docx file. It handles unpacking internally.
Output is a JSON array, each element containing:
index: Comment sequence numberpage: Page numbercomment_text: Original comment textanchor_text: The document text that the comment is attached toAfter receiving the JSON data, the agent processes each comment:
Extract a concise, precise content description from the anchor text for the "regarding XX" part of the output.
Requirements:
Examples:
Core principle: Understand intent, rewrite professionally, never mechanically concatenate.
Rules:
1. Understand the commenter's true intent
2. Combine with anchor text context
3. Neither expand nor reduce
4. Professional language standards
5. Prohibited error patterns
Original commentAnchor text contextCorrect polishingThe reason for the price decline wasn't mentionedSensor gross margin decline, unit price declinePlease supplement the specific reasons for the average unit price declineThe wording here isn't very clear, it's actually more about product mix or specific products, specific customers having a bigger impactOxygen sensor revenue fluctuationPlease clarify the core factors driving the fluctuation: product mix, specific product characteristics, and specific customer dynamicsAdd numbering to subheadings, same belowOxygen sensor downstream domestic substitutionPlease add numbering; apply the same numbering format to all subsequent subheadingsThe performance improvement compared to externally sourced chip modules needs to be mentioned hereMEMS pressure sensor costPlease supplement the specific performance improvements of the self-developed chip module compared to externally sourced modulesAfter reading, the comparison doesn't convey much information. Are there more in-depth capacity parameter comparisons?Capacity parameter comparison tableThe current comparison lacks depth. Please supplement with a more detailed cross-comparison of core capacity parametersTypo?Text contains character errorPlease verify and correct the typo at this locationBe more precise, make it clear this is projectedGross margin related statementPlease ensure precise wording, explicitly stating the "projected" nature to avoid ambiguity
Each comment formatted as:
text
[number]. Page [X]: Regarding [description], [polished suggestion]
Overall structure:
text
[comment 1]
[comment 2]
...
Total: XX review opinions
================================================================================
[Page number note]
Page numbers correspond to physical pages in the document and may differ from
displayed page numbers (e.g., if the document has cover pages or table of contents
that are not numbered). If adjustment is needed, provide the offset between
physical and displayed page numbers for batch correction.
================================================================================
Output requirement: Only output the polished comment list + page number note. No additional summaries, category descriptions, or polishing explanations.
pip install pywin32