import textstat, re t = open('pfl_body.txt').read() print("=== READABILITY: EDD PFL Claim Process (body copy) ===") print(f"Words: {textstat.lexicon_count(t)}") print(f"Sentences: {textstat.sentence_count(t)}") print(f"Avg words/sentence: {textstat.avg_sentence_length(t):.1f}") print(f"Flesch Reading Ease: {textstat.flesch_reading_ease(t):.1f} (higher=easier; 60-70 = plain)") print(f"Flesch-Kincaid Grade: {textstat.flesch_kincaid_grade(t):.1f}") print(f"Gunning Fog: {textstat.gunning_fog(t):.1f}") print(f"SMOG Index: {textstat.smog_index(t):.1f}") print(f"Coleman-Liau: {textstat.coleman_liau_index(t):.1f}") print(f"Consensus grade: {textstat.text_standard(t)}") # Form / document codes the user must track codes = sorted(set(re.findall(r'\b(?:DE|CS|SOC|AD)[\s-]?\d{3,4}[A-Z]{0,3}(?:/S)?\b', t))) print(f"\n=== JARGON LOAD ===") print(f"Distinct form codes on one page: {len(codes)}") print(" " + ", ".join(codes)) terms = ["base period","wage replacement","care recipient","qualifying event", "covered active duty","physician/practitioner","valid claim","certification", "eligibility","determination","CASDI","Statement of Claimant"] print("\nUndefined domain terms (count of uses):") for term in terms: n = len(re.findall(re.escape(term), t, re.I)) if n: print(f" {term:<28} {n}") # Sentences over 20 words (plain-language ceiling) sents = [s.strip() for s in re.split(r'(?<=[.!?])\s+', t) if s.strip()] long_s = [s for s in sents if len(s.split()) > 20] print(f"\nSentences over 20 words: {len(long_s)} of {len(sents)} ({100*len(long_s)/len(sents):.0f}%)") # Contrast check def lum(h): h=h.lstrip('#'); r,g,b=[int(h[i:i+2],16)/255 for i in (0,2,4)] f=lambda c: c/12.92 if c<=0.03928 else ((c+0.055)/1.055)**2.4 return 0.2126*f(r)+0.7152*f(g)+0.0722*f(b) def ratio(a,b): l1,l2=sorted([lum(a),lum(b)],reverse=True); return (l1+0.05)/(l2+0.05) print("\n=== COLOR CONTRAST (WCAG 2.1) ===") for fg,bg,label in [("#046B46","#FFFFFF","EDD green on white"), ("#FFFFFF","#046B46","white on EDD green"), ("#046B46","#F2F2F2","EDD green on light grey panel")]: r=ratio(fg,bg) print(f" {label:<32} {r:>5.2f}:1 AA-normal {'PASS' if r>=4.5 else 'FAIL'} | AA-large {'PASS' if r>=3 else 'FAIL'}")