"""Controlled local extraction demonstration, NOT an AI citation experiment.""" import datetime import hashlib import json import pathlib import platform import re import sys from html.parser import HTMLParser ROOT=pathlib.Path(__file__).parent SENTENCES=[ '이 안내문은 신청 전에 준비할 자료 세 가지를 설명합니다.', '신청자는 연락처, 요청 범위, 희망 일정을 제출합니다.' ] EXPECTED=' '.join(SENTENCES) FRAGMENTS=['이 안내문은 신청 전에','준비할 자료 세 가지를 설명합니다.','신청자는 연락처, 요청 범위,','희망 일정을 제출합니다.'] FIXTURES={ 'complete-paragraphs':'\n'.join('
'+s+'
' for s in SENTENCES), 'complete-sentences-br':''+'
'.join(SENTENCES)+'
'+'
'.join(FRAGMENTS)+'
'+s+'
' for s in FRAGMENTS), } class Extractor(HTMLParser): def __init__(self, boundary_aware): super().__init__(convert_charrefs=True) self.boundary_aware=boundary_aware self.parts=[] def handle_data(self,data): self.parts.append(data) def handle_starttag(self,tag,attrs): if self.boundary_aware and tag=='br': self.parts.append('\n') def handle_endtag(self,tag): if self.boundary_aware and tag=='p': self.parts.append('\n') def output(self): return ''.join(self.parts) def normalize(text):return re.sub(r'\s+',' ',text).strip() def glyphs(text):return re.sub(r'\s+','',text) def main(): rows=[] for fixture_id,markup in FIXTURES.items(): for extractor_id,aware in [('data-concat',False),('boundary-aware',True)]: parser=Extractor(aware);parser.feed(markup);parser.close() output=parser.output();normalized=normalize(output) rows.append({'fixtureId':fixture_id,'extractorId':extractor_id,'htmlSha256':hashlib.sha256(markup.encode()).hexdigest(),'extractedText':output,'normalizedText':normalized,'normalizedEqualsExpected':normalized==EXPECTED,'nonWhitespaceCharactersPreserved':glyphs(output)==glyphs(EXPECTED),'exactSentenceMatches':sum(s in normalized for s in SENTENCES)}) result={'status':'observed-local-extraction-only','executedAt':datetime.datetime.now(datetime.timezone.utc).isoformat(),'pythonVersion':sys.version,'platform':platform.platform(),'scriptSha256':hashlib.sha256(pathlib.Path(__file__).read_bytes()).hexdigest(),'fixtureCount':len(FIXTURES),'extractorCount':2,'observationCount':len(rows),'expectedNormalizedText':EXPECTED,'rows':rows,'scope':'No network requests, no AI calls, no actual CMS sample, no crawling/indexing/citation measurement. Exact string matching is not semantic understanding.','checks':{'sameNonWhitespaceCharactersAllConditions':all(r['nonWhitespaceCharactersPreserved'] for r in rows),'boundaryAwareMatchesAllFixtures':all(r['normalizedEqualsExpected'] for r in rows if r['extractorId']=='boundary-aware')}} for name,data in [('parsing-fixtures.json',{'status':'synthetic-neutral-fixtures','sentences':SENTENCES,'fixtures':FIXTURES}),('parsing-observed-results.json',result)]: (ROOT/name).write_text(json.dumps(data,ensure_ascii=False,indent=2)+'\n',encoding='utf-8') assert all(result['checks'].values()) print(json.dumps({'observations':len(rows),'checks':result['checks']},ensure_ascii=True)) if __name__=='__main__':main()