Yuan1z0825/nature-skills / skills/nature-paper-to-patent
nature-paper-to-patent
FlaggedTurn 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.
scripts/audit_claims.py
View on GitHub#!/usr/bin/env python3
"""Run deterministic structural checks on Chinese patent claims."""
import argparse
import json
import re
from dataclasses import dataclass
from pathlib import Path
CLAIM_START = re.compile(r"(?m)^\s*(\d+)\s*[.、.]\s*")
REFERENCE = re.compile(
r"权利要求\s*(\d+)(?:\s*[-—~~至]\s*(\d+))?"
r"|权利要求\s*(\d+)\s*(?:或|、)\s*(\d+)"
)
TERM_INTRO = re.compile(r"(?:所述|该)([\u4e00-\u9fffA-Za-z][\u4e00-\u9fffA-Za-z0-9_-]{1,20})")
PLACEHOLDER = re.compile(r"\[(?:TO CONFIRM|待确认)[^\]]*\]", re.IGNORECASE)
@dataclass
class Finding:
level: str
claim: int | None
code: str
message: str
def split_claims(text: str) -> list[tuple[int, str]]:
matches = list(CLAIM_START.finditer(text))
claims = []
for index, match in enumerate(matches):
end = matches[index + 1].start() if index + 1 < len(matches) else len(text)
claims.append((int(match.group(1)), text[match.end() : end].strip()))
return claims
def references(body: str) -> list[int]:
result = []
for match in REFERENCE.finditer(body):
if match.group(1):
start = int(match.group(1))
finish = int(match.group(2) or start)
result.extend(range(start, finish + 1))
else:
result.extend((int(match.group(3)), int(match.group(4))))
return sorted(set(result))
def normalize(text: str) -> str:
return re.sub(r"\s+", "", text)
def term_is_introduced(term: str, basis: str, claim: str) -> bool:
"""Whether the term (or a 2+ character prefix of it) has an antecedent.
TERM_INTRO captures up to 20 characters after 所述/该 with no word boundary,
so the captured string is often a noun plus the verb phrase that follows it.
An antecedent is the prefix occurring in an earlier claim, or in this claim
without a 所述/该 in front of it.
"""
for end in range(2, len(term) + 1):
prefix = term[:end]
if prefix in basis or re.search(rf"(?<!所述)(?<!该){re.escape(prefix)}", claim):
return True
return False
def audit(text: str) -> list[Finding]:
claims = split_claims(text)
findings = []
if not claims:
return [Finding("ERROR", None, "NO_CLAIMS", "未识别到以“1.”形式起始的权利要求。")]
numbers = [number for number, _ in claims]
expected = list(range(1, len(claims) + 1))
if numbers != expected:
findings.append(
Finding("ERROR", None, "NUMBER_SEQUENCE", f"编号应连续为{expected},实际为{numbers}。")
)
previous_text = ""
claim_map = {}
for number, body in claims:
compact = normalize(body)
claim_map[number] = compact
refs = references(body)
if not body:
findings.append(Finding("ERROR", number, "EMPTY", "权利要求正文为空。"))
continue
if PLACEHOLDER.search(body):
findings.append(
Finding("ERROR", number, "PLACEHOLDER", "正式权利要求中仍含待确认标记。")
)
if number == 1 and refs:
findings.append(
Finding("ERROR", number, "INDEPENDENT_REFERENCE", "权利要求1不应引用其他权利要求。")
)
if number > 1 and not refs:
findings.append(
Finding("WARNING", number, "NO_REFERENCE", "未检测到从属引用;确认其是否为独立权利要求。")
)
for ref in refs:
if ref >= number:
findings.append(
Finding("ERROR", number, "FORWARD_REFERENCE", f"引用了非在先权利要求{ref}。")
)
if ref not in claim_map:
findings.append(
Finding("ERROR", number, "MISSING_REFERENCE", f"引用的权利要求{ref}不存在。")
)
if "其特征在于" not in compact:
findings.append(
Finding("WARNING", number, "TRANSITION", "未检测到“其特征在于”过渡语。")
)
if len(compact) < 25:
findings.append(
Finding("WARNING", number, "TOO_SHORT", "权利要求较短,确认是否完整限定技术方案。")
)
if re.search(r"(效果更好|性能优异|显著提高|大大提高|最佳|最优)", compact):
findings.append(
Finding("WARNING", number, "RESULT_LANGUAGE", "含结果或宣传性措辞,确认是否改为技术限定。")
)
searchable_basis = previous_text + "".join(
claim_map.get(ref, "") for ref in refs
)
# "根据权利要求1所述的装置" captures "的装置"; drop the 的 so the generic head noun is skipped.
terms = {found[1:] if found.startswith("的") else found for found in TERM_INTRO.findall(body)}
for term in sorted(terms):
if len(term) < 2 or term in {"方法", "装置", "设备", "系统", "步骤", "程序"}:
continue
if not term_is_introduced(term, searchable_basis, compact):
findings.append(
Finding(
"WARNING",
number,
"ANTECEDENT_BASIS",
f"术语“{term}”可能缺少清晰的前置基础。",
)
)
previous_text += compact
return findings
def main() -> int:
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("claims", type=Path, help="UTF-8 claims text file")
parser.add_argument("--json", action="store_true", help="Output findings as JSON")
args = parser.parse_args()
text = args.claims.read_text(encoding="utf-8")
findings = audit(text)
if args.json:
print(json.dumps([finding.__dict__ for finding in findings], ensure_ascii=False, indent=2))
elif not findings:
print("PASS: 未发现结构性问题。")
else:
for finding in findings:
location = f"权利要求{finding.claim}" if finding.claim else "整体"
print(f"{finding.level}\t{location}\t{finding.code}\t{finding.message}")
errors = sum(finding.level == "ERROR" for finding in findings)
warnings = sum(finding.level == "WARNING" for finding in findings)
print(f"\n汇总: {errors} 个错误, {warnings} 个警告")
return 1 if any(finding.level == "ERROR" for finding in findings) else 0
if __name__ == "__main__":
raise SystemExit(main())
Related skills
| Skill | Stars | Updated | Works with | Status | Install |
|---|---|---|---|---|---|
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |
| 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: 198k | Updated | Claude CodeCodex | Verified | Install |