Skip to content

Commit 43ed903

Browse files
authored
Merge pull request #1 from piglee05022/codex/refactor-to-use-modular-design
2 parents 8ae8c34 + 2fb7c26 commit 43ed903

File tree

5 files changed

+101
-0
lines changed

5 files changed

+101
-0
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,3 +53,19 @@ In addition to the packages specified in the table above, the following packages
5353
- `bazelisk` / `bazel`
5454

5555
See [Dockerfile](Dockerfile) for the full details of installed packages.
56+
57+
## Legal document generator module
58+
59+
This repository includes a simple example module located in `legal_module/` that demonstrates how to generate Traditional Chinese legal filings using the `python-docx` package. The module exposes a `create_filing` function that accepts case information and outputs a formatted Word document.
60+
61+
Example usage:
62+
63+
```bash
64+
python3 -m legal_module.example
65+
```
66+
67+
This requires the optional dependency **python-docx**. Install it with:
68+
69+
```bash
70+
pip install python-docx
71+
```

legal_module/__init__.py

Whitespace-only changes.

legal_module/example.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from .filing import create_filing
2+
3+
sample_case = {
4+
'case_number': '臺北地方法院114年度訴字第1234號',
5+
'parties': '原告:李灃祐 被告:新鑫公司',
6+
'court': '臺灣臺北地方法院',
7+
'claims': '請求確認本票債權不存在,並請求返還不當得利新台幣1,000,000元。',
8+
'facts': '原告與被告簽署車輛分期契約,惟車輛自始未交付,卻遭告提出票據裁定……',
9+
'laws': ['民法第184條', '票據法第17條', '最高法院111年度台上字第3208號判決'],
10+
'evidence': [
11+
{'id': '乙1', 'summary': 'LINE對話紀錄,顯示告知車輛尚未交付'},
12+
{'id': '乙2', 'summary': '川立公司匯款憑證,顯示資金流向'}
13+
]
14+
}
15+
16+
if __name__ == '__main__':
17+
create_filing(sample_case, '法律文書_起訴狀.docx')
18+
print('Document generated: 法律文書_起訴狀.docx')

legal_module/filing.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from typing import Dict
2+
3+
try:
4+
from docx import Document
5+
from docx.shared import Pt
6+
except ImportError: # pragma: no cover - docx may not be installed
7+
Document = None
8+
Pt = None
9+
10+
class LegalDocumentGenerator:
11+
"""Generate legal filings in Traditional Chinese."""
12+
13+
def __init__(self, case_info: Dict[str, any]):
14+
self.case_info = case_info
15+
if Document is None:
16+
raise RuntimeError(
17+
"python-docx is required to generate documents. Please install it via 'pip install python-docx'."
18+
)
19+
self.doc = Document()
20+
style = self.doc.styles['Normal']
21+
font = style.font
22+
font.name = '標楷體'
23+
font.size = Pt(16)
24+
25+
def build(self) -> None:
26+
self.doc.add_heading(self.case_info.get('title', '起訴狀'), level=1)
27+
self._add_basic_info()
28+
self._add_claims()
29+
self._add_facts()
30+
self._add_laws()
31+
self._add_evidence()
32+
33+
def save(self, filepath: str) -> None:
34+
self.doc.save(filepath)
35+
36+
# Internal helpers
37+
def _add_basic_info(self) -> None:
38+
self.doc.add_paragraph(f"案號:{self.case_info.get('case_number', '')}")
39+
self.doc.add_paragraph(f"當事人:{self.case_info.get('parties', '')}")
40+
self.doc.add_paragraph(f"法院:{self.case_info.get('court', '')}")
41+
42+
def _add_claims(self) -> None:
43+
self.doc.add_paragraph("壹、訴之聲明")
44+
self.doc.add_paragraph(self.case_info.get('claims', ''))
45+
46+
def _add_facts(self) -> None:
47+
self.doc.add_paragraph("貳、事實與理由")
48+
self.doc.add_paragraph(self.case_info.get('facts', ''))
49+
50+
def _add_laws(self) -> None:
51+
self.doc.add_paragraph("參、法律依據")
52+
for law in self.case_info.get('laws', []):
53+
self.doc.add_paragraph(f"• {law}")
54+
55+
def _add_evidence(self) -> None:
56+
self.doc.add_paragraph("肆、證據目錄")
57+
for ev in self.case_info.get('evidence', []):
58+
self.doc.add_paragraph(f"【{ev['id']}{ev['summary']}")
59+
60+
61+
def create_filing(case_info: Dict[str, any], output_path: str) -> None:
62+
"""Helper function to quickly generate a filing document."""
63+
generator = LegalDocumentGenerator(case_info)
64+
generator.build()
65+
generator.save(output_path)
66+

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
python-docx

0 commit comments

Comments
 (0)