"""Find people's names in a text. pip install onnxruntime tokenizers numpy python example.py python example.py letter.txt """ import sys from pathlib import Path HERE = Path(__file__).resolve().parent sys.path.insert(0, str(HERE / 'code')) import runtime SAMPLE = """Dear Ms Okonjo, Sam Hill has checked the figures with the Planning team. AR to circulate the draft before the committee meets. Yours sincerely Priya Raman Information Governance Officer """ detector = runtime.Detector(HERE) text = Path(sys.argv[1]).read_text() if len(sys.argv) > 1 else SAMPLE found = detector.findings(text) for f in found: print(f"{f['start']:>6}-{f['end']:<6} {f['score']:.2f} {text[f['start']:f['end']]}") masked, last = [], 0 for f in found: masked += [text[last:f['start']], '[NAME]'] last = f['end'] print() print(''.join(masked) + text[last:])