Skip to content

Yuan1z0825/nature-skills / skills/nature-paper-to-patent

nature-paper-to-patent

Flagged

Turn research papers or inventor materials into evidence-grounded Chinese invention patent drafts and technical disclosures. Use for 技术交底书、专利撰写、现有技术对比 and Chinese DOCX patent packages; not general manuscript writing.

FileKindSize
README.mdmarkdown2.9 KB
README_EN.mdmarkdown3.3 KB
SKILL.mdskill md4.5 KB
agents/openai.yamlconfig248 B
evals/evals.jsonconfig1.5 KB
manifest.yamlconfig3.1 KB
references/cn-patent-drafting-guide.mdmarkdown8.0 KB
references/corpus-derived-patterns.mdmarkdown3.5 KB
references/corpus-pair-audit.mdmarkdown2.9 KB
references/disclosure/correction_handler.mdmarkdown2.8 KB
references/disclosure/disclosure_builder.mdmarkdown12.1 KB
references/disclosure/disclosure_preview.mdmarkdown917 B
references/disclosure/disclosure_self_check.mdmarkdown5.9 KB
references/disclosure/intake.mdmarkdown943 B
references/disclosure/iteration_context.mdmarkdown4.3 KB
references/disclosure/merger.mdmarkdown3.4 KB
references/disclosure/patent-disclosure-skill-MIT-LICENSE.txtmarkdown1.0 KB
references/disclosure/patent_points_analyzer.mdmarkdown951 B
references/disclosure/prior_art_search.mdmarkdown10.4 KB
references/disclosure/project_scan.mdmarkdown3.6 KB
references/disclosure/template_reference.mdmarkdown9.2 KB
references/disclosure/tooling.mdmarkdown16.2 KB
references/draft-schema.mdmarkdown9.0 KB
references/patent-figure-guide.mdmarkdown2.9 KB
requirements.txtmanifest121 B
scripts/audit_claims.pyscript6.4 KB
scripts/build_patent_package.pyscript6.5 KB
scripts/disclosure/cnipa_epub_crawler.pyscript10.7 KB
scripts/disclosure/cnipa_epub_parse.pyscript8.8 KB
scripts/disclosure/cnipa_epub_search.pyscript5.9 KB
scripts/disclosure/docx_to_md.pyscript3.7 KB
scripts/disclosure/iteration_dialog_log.pyscript3.2 KB
scripts/disclosure/math_render.pyscript12.7 KB
scripts/disclosure/md_to_docx.pyscript32.2 KB
scripts/disclosure/mermaid_render.pyscript15.2 KB
scripts/disclosure/package-lock.jsonmanifest84.4 KB
scripts/disclosure/package.jsonmanifest279 B
scripts/disclosure/pptx_to_md.pyscript4.9 KB
scripts/disclosure/requirements-cnipa.txtmarkdown172 B
scripts/extract_pdf_text.pyscript2.3 KB
scripts/init_patent_project.pyscript3.1 KB
scripts/math_to_omml.pyscript4.8 KB
scripts/render_flowchart_svg.pyscript14.3 KB
scripts/render_patent_docx.pyscript10.3 KB
scripts/validate_patent_draft.pyscript14.6 KB
static/core/output-contract.mdmarkdown2.0 KB
static/core/principles.mdmarkdown1016 B
static/core/workflow.mdmarkdown3.8 KB
static/fragments/invention/algorithm-software.mdmarkdown366 B
static/fragments/invention/apparatus-system.mdmarkdown288 B
static/fragments/invention/mixed.mdmarkdown255 B
static/fragments/invention/process-material.mdmarkdown278 B
static/fragments/source/mixed-project.mdmarkdown369 B
static/fragments/source/pasted-text.mdmarkdown316 B
static/fragments/source/pdf-text.mdmarkdown290 B
static/fragments/source/scanned-pdf.mdmarkdown272 B
static/fragments/task/claim-set.mdmarkdown249 B
static/fragments/task/disclosure-analysis.mdmarkdown236 B
static/fragments/task/disclosure-iteration.mdmarkdown1005 B
static/fragments/task/full-draft.mdmarkdown247 B
static/fragments/task/paper-patent-audit.mdmarkdown280 B
static/fragments/task/technical-disclosure.mdmarkdown1.5 KB
tests/test_audit_claims.pyscript1.6 KB
tests/test_inline_math_paren.pyscript1.7 KB
tests/test_math_to_omml_superscript.pyscript2.2 KB
tests/test_md_to_docx_source_overwrite.pyscript1.4 KB
tests/test_mermaid_render.pyscript2.3 KB
tests/test_validation.pyscript6.0 KB
tests/test_validation_figure_node_ids.pyscript614 B

scripts/render_patent_docx.py

View on GitHub
#!/usr/bin/env python3
"""Render a structured Chinese patent draft JSON file as DOCX."""

import argparse
import json
from pathlib import Path

from docx import Document
from docx.enum.section import WD_SECTION
from docx.enum.text import WD_ALIGN_PARAGRAPH
from docx.oxml import OxmlElement
from docx.oxml.ns import qn
from docx.shared import Cm, Pt

from math_to_omml import latex_to_omml


def set_run_font(run, name: str, size: float, bold: bool = False) -> None:
    run.font.name = name
    run.font.size = Pt(size)
    run.bold = bold
    run._element.rPr.rFonts.set(qn("w:eastAsia"), name)


def add_heading(document: Document, text: str, level: int = 1) -> None:
    paragraph = document.add_paragraph()
    paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER if level == 1 else WD_ALIGN_PARAGRAPH.LEFT
    run = paragraph.add_run(text)
    set_run_font(run, "宋体", 16 if level == 1 else 14, bold=True)


def add_body(document: Document, text: str, indent: bool = True) -> None:
    paragraph = document.add_paragraph()
    paragraph.paragraph_format.line_spacing = 1.5
    if indent:
        paragraph.paragraph_format.first_line_indent = Cm(0.74)
    run = paragraph.add_run(str(text))
    set_run_font(run, "宋体", 12)


def add_equation(document: Document, equation: dict) -> None:
    paragraph = document.add_paragraph()
    paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
    paragraph.paragraph_format.space_before = Pt(6)
    paragraph.paragraph_format.space_after = Pt(6)
    latex = equation.get("latex")
    if not latex:
        raise ValueError(
            f"Equation {equation.get('number')} has no latex source for native Office Math"
        )
    paragraph._p.append(latex_to_omml(latex))
    number_run = paragraph.add_run(f"    ({equation.get('number', '')})")
    set_run_font(number_run, "Cambria Math", 12)
    description = equation.get("description")
    if description:
        add_body(document, description)


def add_page_number(section) -> None:
    paragraph = section.footer.paragraphs[0]
    paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
    run = paragraph.add_run()
    begin = OxmlElement("w:fldChar")
    begin.set(qn("w:fldCharType"), "begin")
    instruction = OxmlElement("w:instrText")
    instruction.set(qn("xml:space"), "preserve")
    instruction.text = " PAGE "
    end = OxmlElement("w:fldChar")
    end.set(qn("w:fldCharType"), "end")
    run._r.extend((begin, instruction, end))


def configure(document: Document) -> None:
    section = document.sections[0]
    section.top_margin = Cm(2.54)
    section.bottom_margin = Cm(2.54)
    section.left_margin = Cm(3.17)
    section.right_margin = Cm(3.17)
    add_page_number(section)


def add_claims(document: Document, claims: list[dict]) -> None:
    add_heading(document, "权利要求书")
    for claim in claims:
        add_body(document, f"{claim['number']}. {claim['text']}", indent=False)


def add_specification(document: Document, data: dict, figure_dir: Path | None = None) -> None:
    add_heading(document, "说明书")
    add_heading(document, data.get("title", "[TO CONFIRM: title]"), level=2)
    spec = data.get("specification", {})
    sections = [
        ("技术领域", spec.get("technical_field", [])),
        ("背景技术", spec.get("background", [])),
    ]
    invention = spec.get("invention_content", {})
    sections.extend(
        [
            ("发明内容", invention.get("problem", []) + invention.get("solution", [])),
            ("有益效果", invention.get("beneficial_effects", [])),
            ("附图说明", spec.get("figure_descriptions", [])),
        ]
    )
    for heading, paragraphs in sections:
        add_heading(document, heading, level=2)
        for paragraph in paragraphs:
            add_body(document, paragraph)

    equations = spec.get("equations", [])
    if equations:
        add_heading(document, "公式及符号说明", level=2)
        for equation in equations:
            add_equation(document, equation)

    if figure_dir:
        figures = data.get("figures", [])
        if figures:
            add_heading(document, "说明书附图", level=2)
        for figure in figures:
            image = figure_dir / f"figure-{figure['number']}.png"
            if not image.exists():
                continue
            paragraph = document.add_paragraph()
            paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
            run = paragraph.add_run()
            run.add_picture(str(image), width=Cm(14))
            caption = document.add_paragraph()
            caption.alignment = WD_ALIGN_PARAGRAPH.CENTER
            caption_run = caption.add_run(f"图{figure['number']} {figure.get('title', '')}")
            set_run_font(caption_run, "宋体", 11)

    add_heading(document, "具体实施方式", level=2)
    for embodiment in spec.get("embodiments", []):
        add_heading(document, embodiment.get("heading", "实施例"), level=2)
        for paragraph in embodiment.get("paragraphs", []):
            add_body(document, paragraph)


def add_figure(
    document: Document,
    figure: dict,
    figure_dir: Path | None,
    heading: str | None = None,
) -> bool:
    if not figure_dir:
        return False
    image = figure_dir / f"figure-{figure['number']}.png"
    if not image.exists():
        return False
    if heading:
        add_heading(document, heading, level=2)
    paragraph = document.add_paragraph()
    paragraph.alignment = WD_ALIGN_PARAGRAPH.CENTER
    run = paragraph.add_run()
    run.add_picture(str(image), width=Cm(14))
    caption = document.add_paragraph()
    caption.alignment = WD_ALIGN_PARAGRAPH.CENTER
    caption_run = caption.add_run(f"图{figure['number']} {figure.get('title', '')}")
    set_run_font(caption_run, "宋体", 11)
    return True


def abstract_figure(data: dict) -> dict | None:
    number = data.get("abstract_figure_number")
    return next(
        (figure for figure in data.get("figures", []) if figure.get("number") == number),
        None,
    )


def add_abstract(
    document: Document,
    data: dict,
    figure_dir: Path | None = None,
    include_figure: bool = True,
) -> None:
    add_heading(document, "说明书摘要")
    add_heading(document, data.get("title", "[TO CONFIRM: title]"), level=2)
    add_body(document, data.get("abstract", ""), indent=False)
    figure = abstract_figure(data)
    if include_figure and figure:
        add_figure(document, figure, figure_dir, heading="摘要附图")


def add_abstract_figure(
    document: Document,
    data: dict,
    figure_dir: Path | None,
) -> None:
    add_heading(document, "摘要附图")
    figure = abstract_figure(data)
    if figure:
        add_figure(document, figure, figure_dir)


def add_review_appendix(document: Document, data: dict) -> None:
    document.add_section(WD_SECTION.NEW_PAGE)
    add_heading(document, "起草审查附录")
    metadata = data.get("metadata", {})
    for key, value in metadata.items():
        add_body(document, f"{key}: {value}", indent=False)

    add_heading(document, "前提假设", level=2)
    for item in data.get("assumptions", []):
        add_body(document, f"- {item}", indent=False)

    concept = data.get("invention_concept", {})
    add_heading(document, "发明构思", level=2)
    for key in ("technical_problem", "technical_means", "technical_effect"):
        if concept.get(key):
            add_body(document, f"{key}: {concept[key]}", indent=False)

    ledger = data.get("evidence_ledger", [])
    if ledger:
        add_heading(document, "证据台账", level=2)
        table = document.add_table(rows=1, cols=6)
        table.style = "Table Grid"
        headers = ("ID", "技术特征", "来源位置", "技术作用", "效果", "支持状态")
        for cell, header in zip(table.rows[0].cells, headers):
            cell.text = header
        keys = ("id", "feature", "source_location", "technical_role", "effect", "support_status")
        for item in ledger:
            cells = table.add_row().cells
            for cell, key in zip(cells, keys):
                cell.text = str(item.get(key, ""))

    audit = data.get("audit", {})
    for heading, key in (
        ("支持性检查", "support_findings"),
        ("一致性检查", "consistency_findings"),
        ("发明人待确认问题", None),
    ):
        add_heading(document, heading, level=2)
        items = data.get("inventor_questions", []) if key is None else audit.get(key, [])
        for item in items:
            add_body(document, f"- {item}", indent=False)


def validate(data: dict) -> None:
    required = ("title", "claims", "specification", "abstract")
    missing = [key for key in required if key not in data]
    if missing:
        raise ValueError(f"Missing required keys: {', '.join(missing)}")
    numbers = [claim.get("number") for claim in data["claims"]]
    if numbers != list(range(1, len(numbers) + 1)):
        raise ValueError(f"Claim numbers must be consecutive integers starting at 1: {numbers}")


def main() -> int:
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("draft", type=Path, help="UTF-8 JSON draft")
    parser.add_argument("--output", type=Path, required=True, help="Output DOCX path")
    parser.add_argument(
        "--part",
        choices=("all", "claims", "specification", "abstract", "abstract-figure"),
        default="all",
        help="Document part to render",
    )
    parser.add_argument(
        "--figure-dir",
        type=Path,
        help="Directory containing figure-N.png images for the specification",
    )
    args = parser.parse_args()

    data = json.loads(args.draft.read_text(encoding="utf-8"))
    validate(data)
    document = Document()
    configure(document)
    if args.part == "claims":
        add_claims(document, data["claims"])
    elif args.part == "specification":
        add_specification(document, data, args.figure_dir)
    elif args.part == "abstract":
        add_abstract(document, data, args.figure_dir)
    elif args.part == "abstract-figure":
        add_abstract_figure(document, data, args.figure_dir)
    else:
        add_claims(document, data["claims"])
        document.add_page_break()
        add_specification(document, data, args.figure_dir)
        document.add_page_break()
        add_abstract(document, data, args.figure_dir)
        add_review_appendix(document, data)
    args.output.parent.mkdir(parents=True, exist_ok=True)
    document.save(args.output)
    print(args.output)
    return 0


if __name__ == "__main__":
    raise SystemExit(main())
canvas-designanthropics/skillsCreate beautiful visual art in .png and .pdf documents using design philosophy. You should use this skill when the user asks to create a poster, piece of art, design, or other static piece. Create original visual designs, never copying existing artists' work to avoid copyright violations.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
docxanthropics/skillsUse this skill whenever the user wants to create, read, edit, or manipulate Word documents (.docx files) or Word templates (.dotx files). Triggers include: any mention of 'Word doc', 'word document', '.docx', '.dotx', or requests to produce professional documents with formatting like tables of contents, headings, page numbers, or letterheads. Also use when extracting or reorganizing content from .docx or .dotx files, inserting or replacing images in documents, performing find-and-replace in Word files, working with tracked changes or comments, or converting content into a polished Word document. If the user asks for a 'report', 'memo', 'letter', 'template', or similar deliverable as a Word or .docx file, use this skill. Do NOT use for PDFs, spreadsheets, Google Docs, or general coding tasks unrelated to document generation.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pdfanthropics/skillsUse this skill whenever the user wants to do anything with PDF files. This includes reading or extracting text/tables from PDFs, combining or merging multiple PDFs into one, splitting PDFs apart, rotating pages, adding watermarks, creating new PDFs, filling PDF forms, encrypting/decrypting PDFs, extracting images, and OCR on scanned PDFs to make them searchable. If the user mentions a .pdf file or asks to produce one, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
pptxanthropics/skillsUse this skill any time a .pptx or .potx file is involved in any way — as input, output, or both. This includes: creating slide decks, pitch decks, or presentations; reading, parsing, or extracting text from any .pptx or .potx file (even if the extracted content will be used elsewhere, like in an email or summary); editing, modifying, or updating existing presentations; combining or splitting slide files; working with templates (.potx), layouts, speaker notes, or comments. Trigger whenever the user mentions "deck," "slides," "presentation," or references a .pptx or .potx filename, regardless of what they plan to do with the content afterward. If a .pptx or .potx file needs to be opened, created, or touched, use this skill.Stars: 198kUpdated Claude CodeCodexVerifiedInstall