# -*- coding: utf-8 -*- import io,re,hashlib,collections P="0_사건종류_추가/사건종류_말소등기대위에의한소유권이전등기말소청구/청구취지작성규칙_말소등기대위에의한소유권이전등기말소청구_v2.md" raw=io.open(P,"rb").read() s=raw.decode("utf-8") lines=s.split("\n") print("UTF-8 decode: OK") print("lines(개행수 기준) =",len(lines)-1 if s.endswith("\n") else len(lines)) print("bytes =",len(raw)) print("sha256 =",hashlib.sha256(raw).hexdigest()) print("미치환 토큰 =",len(re.findall(r"\{\{|<사건키>|\[사건종류\]",s))) print("## 절 수 =",sum(1 for l in lines if l.startswith("## "))) secs=[l for l in lines if re.match(r"^## \d+\.",l)] print("번호 절 =",len(secs),[re.match(r"^## (\d+)",l).group(1) for l in secs]) print("코드펜스 =",sum(1 for l in lines if l.startswith("```"))) print("후행 공백 행 =",sum(1 for l in lines if re.search(r"[ \t]+$",l))) IDPAT=r"\b(?:Q|RULE|LEAF|FORM|CHECK|STOP|SRC)-[A-Za-z0-9]+" refs=collections.Counter(re.findall(IDPAT,s)) defs=set() for l in lines: m=re.match(r"^[-*|#`>\s]*\**\s*("+IDPAT.strip(r"\b")+r")",l) if m: defs.add(m.group(1)) # 표 머리글 제외 hdr={"LEAF-ID","FORM-ID","CHECK-ID","STOP-ID","RULE-ID","Q-ID","SRC-ID"} orph=[k for k,v in refs.items() if v==1 and k not in hdr] print("고아 ID(1회 등장) =",len(orph),sorted(orph)) und=sorted(k for k in refs if k not in defs and k not in hdr) print("정의 없는 참조 =",len(und),und) rng=[ (i+1,l) for i,l in enumerate(lines) if re.search(r"(CHECK|FORM|LEAF|STOP|RULE|Q)-[0-9A-Za-z]+ ?(~|내지|부터) ?(CHECK|FORM|LEAF|STOP|RULE|Q)?-?[0-9]|(CHECK|FORM|LEAF|STOP|RULE|Q)-[A-Z]?[0-9]* ?계열",l)] print("범위·계열 축약 =",len(rng),[r[0] for r in rng]) # 계열별 결번 ser=collections.defaultdict(set) for k in refs: m=re.match(r"^(Q|RULE|LEAF|FORM|CHECK|STOP-[HCR]|SRC-[LPE])-?([0-9]+)$",k) or re.match(r"^(Q|RULE|LEAF|FORM|CHECK)-([0-9]+)$",k) if m: ser[m.group(1)].add(int(m.group(2))) for k in sorted(ser): v=sorted(ser[k]); gaps=[x for x in range(v[0],v[-1]+1) if x not in ser[k]] print("계열",k,"범위",v[0],"-",v[-1],"결번",gaps) # 대괄호 토큰 사전 대조 brs=collections.Counter(re.findall(r"\[[^\[\]\n]{1,30}\]",s)) sec11=s[s.index("## 11."):s.index("## 12.")] dic=set(re.findall(r"\[[^\[\]\n]{1,30}\]",sec11)) sec7=s[s.index("## 7."):s.index("## 8.")] dic|=set(re.findall(r"\[[^\[\]\n]{1,30}\]",sec7)) out=sorted(k for k in brs if k not in dic) print("§7·§11 사전 밖 대괄호 토큰 =",len(out),out) # §10.2 / §11 변수 정합 sec10=s[s.index("### 10.1"):s.index("## 11.")] forms={} for m in re.finditer(r"### (FORM-\d+) — .*?\n(.*?)(?=\n### |\Z)",sec11,re.S): fid=m.group(1); blk=m.group(2) dec=re.search(r"^변수: (.*)$",blk,re.M) decl=set(re.findall(r"\[[^\[\]\n]+\]",dec.group(1))) if dec else set() fence=re.findall(r"```\n(.*?)```",blk,re.S) used=set(re.findall(r"\[[^\[\]\n]+\]","".join(fence))) forms[fid]=(decl,used) if decl!=used: print(" !! %s 선언%s vs 주문%s"%(fid,sorted(decl-used),sorted(used-decl))) print("§11 내부 선언 vs 주문 불일치 검사 완료") for line in sec10.split("\n"): m=re.match(r"^\| (FORM-\d+) \|",line) if m and m.group(1) in forms: cells=[c.strip() for c in line.strip("|").split("|")] req=set(re.findall(r"\[[^\[\]\n]+\]",cells[2])) if req!=forms[m.group(1)][1]: print(" !! §10.2 %s 표%s vs 주문%s"%(m.group(1),sorted(req-forms[m.group(1)][1]),sorted(forms[m.group(1)][1]-req))) print("§10.2 대조 완료") skel={"LEAF-01":"FORM-01","LEAF-02":"FORM-02","LEAF-03":"FORM-03","LEAF-04":"FORM-04","LEAF-05":"FORM-05","LEAF-06":"FORM-06"} for line in sec10.split("\n"): m=re.match(r"^\| (LEAF-0\d) \|",line) if m: cells=[c.strip() for c in line.strip("|").split("|")] req=set(re.findall(r"\[[^\[\]\n]+\]",cells[5])) must=set(re.findall(r"FORM-\d+",cells[3]))|{skel[m.group(1)]} need=set() for f in must: if f in forms: need|=forms[f][1] if not need<=req: print(" !! §10.1 %s 누락%s"%(m.group(1),sorted(need-req))) if not req<=need: print(" .. §10.1 %s 여분%s"%(m.group(1),sorted(req-need))) print("§10.1 대조 완료")