"""FAQrank structural audit v1. Python standard library only. Run: python check-faqrank.py DIRECTORY > report.json DIRECTORY contains general.rst, design.rst, LICENSE, sources.json. No semantic, ranking or external-link verdict is inferred. """ import pathlib,sys,re,json,hashlib,unicodedata def audit(root): provenance=json.loads((root/'sources.json').read_text(encoding='utf-8')) documents=[] for name in ('general.rst','design.rst'): raw=(root/name).read_bytes(); lines=raw.decode('utf-8').splitlines(); headings=[] for i,line in enumerate(lines): if i and re.fullmatch(r'([-~=])\1{2,}',line) and lines[i-1].strip() and not re.fullmatch(r'([-~=])\1{2,}',lines[i-1]): start=i-1 while start>0 and lines[start-1].strip() and not re.fullmatch(r'([-~=])\1{2,}',lines[start-1]):start-=1 title=' '.join(x.strip() for x in lines[start:i]);key=' '.join(unicodedata.normalize('NFC',title).split()).casefold() headings.append(dict(line=start+1,end=i+1,title=title,key=key,question=title.endswith('?'))) keys={};rows=[] for j,h in enumerate(headings): end=headings[j+1]['line']-1 if j+1');refs.append(dict(line=i+1,text=m.group(0),target=target,local_target_line=targets.get(target),resolves_in_document=True if target in targets else None)) documents.append(dict(file=name,sha256=hashlib.sha256(raw).hexdigest(),line_count=len(lines),headings=rows,references=refs,semantic_answer_quality=None,external_reference_validity=None,search_rank=None,popularity=None,citation_rate=None)) return dict(method='faqrank-structural-v1',provenance=provenance,script_sha256=hashlib.sha256(pathlib.Path(__file__).read_bytes()).hexdigest(),notice='Modified analysis by Across Inc. Original English excerpts retained. No upstream endorsement. Copyright (c) 2001 Python Software Foundation; All Rights Reserved. Complete upstream license follows.',license=(root/'LICENSE').read_text(encoding='utf-8'),documents=documents) if __name__=='__main__':print(json.dumps(audit(pathlib.Path(sys.argv[1])),ensure_ascii=False,indent=2))