File size: 855 Bytes
7ac8503
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
"""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:])