@waswrongassembled/pii-shield 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +29 -0
- package/LICENSE +22 -0
- package/README.md +276 -2
- package/dist/ai-sdk/index.d.ts +19 -0
- package/dist/ai-sdk/index.js +30 -0
- package/dist/ai-sdk/middleware.d.ts +63 -0
- package/dist/ai-sdk/middleware.js +388 -0
- package/dist/bin.d.ts +2 -0
- package/dist/bin.js +9 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +124 -0
- package/dist/detector.d.ts +28 -0
- package/dist/detector.js +3 -0
- package/dist/detectors/at-svnr.d.ts +14 -0
- package/dist/detectors/at-svnr.js +31 -0
- package/dist/detectors/authority-context.d.ts +22 -0
- package/dist/detectors/authority-context.js +278 -0
- package/dist/detectors/birth-date.d.ts +10 -0
- package/dist/detectors/birth-date.js +21 -0
- package/dist/detectors/email.d.ts +15 -0
- package/dist/detectors/email.js +29 -0
- package/dist/detectors/file-number.d.ts +16 -0
- package/dist/detectors/file-number.js +20 -0
- package/dist/detectors/iban.d.ts +10 -0
- package/dist/detectors/iban.js +41 -0
- package/dist/detectors/license-plate.d.ts +9 -0
- package/dist/detectors/license-plate.js +13 -0
- package/dist/detectors/phone.d.ts +13 -0
- package/dist/detectors/phone.js +38 -0
- package/dist/detectors/postal-address.d.ts +14 -0
- package/dist/detectors/postal-address.js +19 -0
- package/dist/detectors/salutation-person.d.ts +18 -0
- package/dist/detectors/salutation-person.js +37 -0
- package/dist/detectors/tax-number.d.ts +14 -0
- package/dist/detectors/tax-number.js +33 -0
- package/dist/entity-extractor.d.ts +47 -0
- package/dist/entity-extractor.js +245 -0
- package/dist/entity-type.d.ts +24 -0
- package/dist/entity-type.js +26 -0
- package/dist/entity.d.ts +28 -0
- package/dist/entity.js +11 -0
- package/dist/errors.d.ts +48 -0
- package/dist/errors.js +49 -0
- package/dist/index.d.ts +42 -0
- package/dist/index.js +40 -0
- package/dist/internal/pcre.d.ts +55 -0
- package/dist/internal/pcre.js +102 -0
- package/dist/internal/php-json.d.ts +15 -0
- package/dist/internal/php-json.js +48 -0
- package/dist/internal/placeholder-stream.d.ts +24 -0
- package/dist/internal/placeholder-stream.js +118 -0
- package/dist/internal/text-spans.d.ts +8 -0
- package/dist/internal/text-spans.js +15 -0
- package/dist/learning/char-set.d.ts +29 -0
- package/dist/learning/char-set.js +158 -0
- package/dist/learning/custom-entity-detector.d.ts +26 -0
- package/dist/learning/custom-entity-detector.js +70 -0
- package/dist/learning/custom-entity-type.d.ts +49 -0
- package/dist/learning/custom-entity-type.js +150 -0
- package/dist/learning/entity-learner.d.ts +50 -0
- package/dist/learning/entity-learner.js +87 -0
- package/dist/learning/json-file-store.d.ts +36 -0
- package/dist/learning/json-file-store.js +132 -0
- package/dist/learning/learned-pattern.d.ts +48 -0
- package/dist/learning/learned-pattern.js +640 -0
- package/dist/learning/pattern-grammar.d.ts +12 -0
- package/dist/learning/pattern-grammar.js +148 -0
- package/dist/learning/pattern-learner.d.ts +10 -0
- package/dist/learning/pattern-learner.js +116 -0
- package/dist/learning/store.d.ts +51 -0
- package/dist/learning/store.js +84 -0
- package/dist/masking/partial-mask.d.ts +23 -0
- package/dist/masking/partial-mask.js +43 -0
- package/dist/masking/strategy.d.ts +10 -0
- package/dist/masking/strategy.js +1 -0
- package/dist/masking/type-label-mask.d.ts +17 -0
- package/dist/masking/type-label-mask.js +28 -0
- package/dist/mcp/index.d.ts +33 -0
- package/dist/mcp/index.js +146 -0
- package/dist/mcp/tools.d.ts +63 -0
- package/dist/mcp/tools.js +183 -0
- package/dist/model/chunks.d.ts +13 -0
- package/dist/model/chunks.js +74 -0
- package/dist/model/model-detector.d.ts +110 -0
- package/dist/model/model-detector.js +420 -0
- package/dist/model/prompt.d.ts +16 -0
- package/dist/model/prompt.js +192 -0
- package/dist/pii-masker.d.ts +27 -0
- package/dist/pii-masker.js +56 -0
- package/dist/pii-shield.d.ts +40 -0
- package/dist/pii-shield.js +142 -0
- package/dist/placeholder.d.ts +48 -0
- package/dist/placeholder.js +138 -0
- package/dist/redaction.d.ts +76 -0
- package/dist/redaction.js +52 -0
- package/dist/server/config.d.ts +23 -0
- package/dist/server/config.js +187 -0
- package/dist/server/http-server.d.ts +63 -0
- package/dist/server/http-server.js +241 -0
- package/dist/server/index.d.ts +9 -0
- package/dist/server/index.js +9 -0
- package/dist/server/model-providers.d.ts +31 -0
- package/dist/server/model-providers.js +158 -0
- package/dist/service/json-body.d.ts +14 -0
- package/dist/service/json-body.js +35 -0
- package/dist/service/local-peer.d.ts +16 -0
- package/dist/service/local-peer.js +83 -0
- package/dist/service/service-api.d.ts +75 -0
- package/dist/service/service-api.js +305 -0
- package/dist/validators/at-svnr.d.ts +8 -0
- package/dist/validators/at-svnr.js +21 -0
- package/dist/validators/de-tax-id.d.ts +8 -0
- package/dist/validators/de-tax-id.js +35 -0
- package/dist/validators/iban.d.ts +5 -0
- package/dist/validators/iban.js +24 -0
- package/dist/vault/encrypted-vault.d.ts +37 -0
- package/dist/vault/encrypted-vault.js +152 -0
- package/dist/vault/in-memory-vault.d.ts +17 -0
- package/dist/vault/in-memory-vault.js +39 -0
- package/dist/vault/memory-vault-storage.d.ts +16 -0
- package/dist/vault/memory-vault-storage.js +37 -0
- package/dist/vault/vault.d.ts +38 -0
- package/dist/vault/vault.js +16 -0
- package/dist/vault-redis/index.d.ts +28 -0
- package/dist/vault-redis/index.js +33 -0
- package/docs/openapi.yaml +422 -0
- package/package.json +122 -4
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { asciiDigits, LINE_START, SPACE, WORD, WORD_END, WORD_START } from '../internal/pcre.js';
|
|
2
|
+
/**
|
|
3
|
+
* Heuristic: is a contact detail (e-mail, phone) the sender authority's own contact?
|
|
4
|
+
*
|
|
5
|
+
* Authority contact data is needed for the action steps ("where do I send my objection?")
|
|
6
|
+
* and is not the recipient's personal data, so it is kept by default. A sentence counts as
|
|
7
|
+
* authority context if it speaks in first person plural ("erreichen Sie uns") or refers
|
|
8
|
+
* to an authority or to filing something ("einzubringen"). The sentence, not the whole line:
|
|
9
|
+
* OCR and copied text put whole paragraphs on one line, and "Sie haben Einspruch erhoben.
|
|
10
|
+
* Ihre Nummer ist ..." must not keep the recipient's number.
|
|
11
|
+
*
|
|
12
|
+
* Never authority context: a sentence about the recipient's contact ("Ihre Telefonnummer") and mobile
|
|
13
|
+
* numbers (authorities publish landlines; see isMobileNumber()). First person singular is no signal:
|
|
14
|
+
* case workers write "stehe ich Ihnen unter ... zur Verfügung".
|
|
15
|
+
*
|
|
16
|
+
* Window sizes and the letterhead limit count UTF-8 bytes, as in PHP, so the same text gives the same result.
|
|
17
|
+
*
|
|
18
|
+
* @internal
|
|
19
|
+
*/
|
|
20
|
+
const KEYWORDS = new RegExp(`${WORD_START}(?:uns|wir|unser${WORD}*|einzubringen|Einspruch|Beschwerde|Bezirkshauptmannschaft|Finanzamt${WORD}*|Magistrat${WORD}*|Behörde${WORD}*|Gericht${WORD}*|Amt)${WORD_END}`, 'iu');
|
|
21
|
+
/** The recipient's own contact: "Ihre Telefonnummer", "Ihrer Rufnummer", "Ihre E-Mail-Adresse" (not "Ihrer E-Mail vom ..."). */
|
|
22
|
+
const PERSONAL = new RegExp(`${WORD_START}Ihre[mnrs]?${SPACE}+(?:(?:Telefon|Handy|Mobil|Ruf|Rückruf|Mobilfunk)${WORD}*|(?:E-Mail|Mail)-?Adresse${WORD}*|Kontaktdaten)${WORD_END}`, 'u');
|
|
23
|
+
/**
|
|
24
|
+
* Mobile numbers. AT: the common mobile blocks only (0662, 065xx, 07xxx are landlines). DE and CH only with
|
|
25
|
+
* the country code: national "015x" or "07xx" are Austrian landlines too.
|
|
26
|
+
*/
|
|
27
|
+
const MOBILE = /^(?:(?:\+|00)43|0)(?:650|660|664|676|677|678|680|681|688|699)|^(?:\+|00)49(?:15|16|17)|^(?:\+|00)41(?:7[5-9])/;
|
|
28
|
+
/** Names of authorities: a letterhead needs one ("uns" or "wir" are not enough there). */
|
|
29
|
+
const AUTHORITY_NAMES = new RegExp(`${WORD_START}(?:Bezirkshauptmannschaft|Finanzamt|Magistrat|Magistratsabteilung|Behörde|Gericht|Bezirksgericht|Landesgericht|Amtsgericht|Amt|Gemeindeamt|Gemeinde|Stadtgemeinde|Marktgemeinde|Landesregierung|Ministerium|Polizei|Polizeiinspektion|Landespolizeidirektion|Stadtverwaltung)${WORD_END}`, 'iu');
|
|
30
|
+
/** Short forms authorities put before their name in a domain ("bh-musterstadt.gv.at"). */
|
|
31
|
+
const SECOND_LEVEL_DOMAINS = ['gv', 'co', 'or', 'ac', 'gov'];
|
|
32
|
+
const DOMAIN_PREFIXES = [
|
|
33
|
+
'bh',
|
|
34
|
+
'fa',
|
|
35
|
+
'ma',
|
|
36
|
+
'mag',
|
|
37
|
+
'gem',
|
|
38
|
+
'stadt',
|
|
39
|
+
'markt',
|
|
40
|
+
'land',
|
|
41
|
+
'lpd',
|
|
42
|
+
'bg',
|
|
43
|
+
'lg',
|
|
44
|
+
];
|
|
45
|
+
/** The authority's name must be on one of the first lines of the letterhead. */
|
|
46
|
+
const AUTHORITY_NAME_LINES = 2;
|
|
47
|
+
const LETTERHEAD_LINES = 6;
|
|
48
|
+
const LETTERHEAD_BYTES = 2_000;
|
|
49
|
+
const SENTENCE_WINDOW = 400;
|
|
50
|
+
/** Abbreviations whose dot does not end a sentence ("Abt. Verkehr, Tel. 05572 ..."). */
|
|
51
|
+
const ABBREVIATIONS = [
|
|
52
|
+
'Abs',
|
|
53
|
+
'Abt',
|
|
54
|
+
'Art',
|
|
55
|
+
'bzw',
|
|
56
|
+
'ca',
|
|
57
|
+
'Dr',
|
|
58
|
+
'DI',
|
|
59
|
+
'Fa',
|
|
60
|
+
'Fr',
|
|
61
|
+
'gem',
|
|
62
|
+
'GZ',
|
|
63
|
+
'Hr',
|
|
64
|
+
'inkl',
|
|
65
|
+
'Ing',
|
|
66
|
+
'lit',
|
|
67
|
+
'lt',
|
|
68
|
+
'Mag',
|
|
69
|
+
'Nr',
|
|
70
|
+
'Prof',
|
|
71
|
+
'Str',
|
|
72
|
+
'Tel',
|
|
73
|
+
'usw',
|
|
74
|
+
'vgl',
|
|
75
|
+
'z.B',
|
|
76
|
+
'Zl',
|
|
77
|
+
];
|
|
78
|
+
const NO_SENTENCE_END = [...ABBREVIATIONS.map((a) => a.replaceAll('.', String.raw `\.`)), String.raw `\p{Lu}`]
|
|
79
|
+
.map((a) => WORD_START + a)
|
|
80
|
+
.join('|');
|
|
81
|
+
const SENTENCE_END = new RegExp(String.raw `(?<!${NO_SENTENCE_END})[.!?]${SPACE}+(?=\p{Lu})`, 'gu');
|
|
82
|
+
const utf8 = new TextEncoder();
|
|
83
|
+
const strictUtf8 = new TextDecoder('utf-8', { fatal: true });
|
|
84
|
+
/**
|
|
85
|
+
* Whether the contact at `offset` (UTF-16 index) is in a sentence that speaks for the authority.
|
|
86
|
+
*/
|
|
87
|
+
export function isAuthorityContact(text, offset) {
|
|
88
|
+
const sentence = sentenceAround(text, offset);
|
|
89
|
+
return KEYWORDS.test(sentence) && !PERSONAL.test(sentence);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Whether a phone number is a mobile number (AT, DE, CH). Mobile numbers are treated as personal even
|
|
93
|
+
* next to authority keywords: "Ihren Einspruch haben wir unter 0664 ... notiert".
|
|
94
|
+
*/
|
|
95
|
+
export function isMobileNumber(phone) {
|
|
96
|
+
const digits = asciiDigits(phone)
|
|
97
|
+
.replace(/[^0-9+]/g, '')
|
|
98
|
+
// "+43 0664 ..." / "+43 (0)664 ...": the trunk zero after the country code is not part of the number
|
|
99
|
+
.replace(/^((?:\+|00)[0-9]{2})0/, '$1');
|
|
100
|
+
return MOBILE.test(digits);
|
|
101
|
+
}
|
|
102
|
+
/** Whether `offset` (UTF-16 index) lies in the letterhead of an authority (see letterhead()). */
|
|
103
|
+
export function isInLetterhead(text, offset) {
|
|
104
|
+
const head = letterhead(text);
|
|
105
|
+
return head !== null && offset < head.length;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Whether an e-mail address belongs to the authority in the letterhead: the domain's name (the label
|
|
109
|
+
* before the top-level domain, e.g. "musterhausen" in "parken@musterhausen.example") equals a word of the
|
|
110
|
+
* line that names the authority, optionally after a known short form ("bh-musterstadt"). A similar
|
|
111
|
+
* domain ("musterhausen-fitness") does not count: when in doubt, the address is redacted.
|
|
112
|
+
*
|
|
113
|
+
* `authority` is the authority line of the text (authorityLine()), passed in so it is computed once per text.
|
|
114
|
+
*/
|
|
115
|
+
export function isAuthorityEmail(text, email, authority = authorityLine(text)) {
|
|
116
|
+
const at = email.lastIndexOf('@');
|
|
117
|
+
if (authority === null || at === -1) {
|
|
118
|
+
return false;
|
|
119
|
+
}
|
|
120
|
+
// PHP's strtolower() only maps A-Z.
|
|
121
|
+
const labels = email
|
|
122
|
+
.slice(at + 1)
|
|
123
|
+
.replace(/[A-Z]/g, (c) => c.toLowerCase())
|
|
124
|
+
.split('.');
|
|
125
|
+
if (labels.length < 2) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
const words = authority
|
|
129
|
+
.toLowerCase()
|
|
130
|
+
.split(/[^\p{L}]+/u)
|
|
131
|
+
.filter((w) => w !== '' && [...w].length >= 5);
|
|
132
|
+
// "bh-musterstadt.gv.at": the name is the label before a second-level domain like "gv" or "co"
|
|
133
|
+
let nameIndex = labels.length - 2;
|
|
134
|
+
if (nameIndex > 0 && SECOND_LEVEL_DOMAINS.includes(labels[nameIndex] ?? '')) {
|
|
135
|
+
nameIndex--;
|
|
136
|
+
}
|
|
137
|
+
const parts = (labels[nameIndex] ?? '').split('-');
|
|
138
|
+
const name = parts.pop() ?? '';
|
|
139
|
+
return words.includes(name) && parts.every((p) => DOMAIN_PREFIXES.includes(p));
|
|
140
|
+
}
|
|
141
|
+
/** The line of the letterhead that names the authority, or null. */
|
|
142
|
+
export function authorityLine(text) {
|
|
143
|
+
const head = letterheadBytes(text);
|
|
144
|
+
return head === null ? null : authorityLineOf(head);
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* The sentence around an offset, within its line. A sentence ends at ".", "!" or "?" followed by
|
|
148
|
+
* whitespace and an upper-case letter, unless the dot ends a known abbreviation or an initial.
|
|
149
|
+
*
|
|
150
|
+
* Only SENTENCE_WINDOW bytes on each side are looked at: OCR text can be one long line with many
|
|
151
|
+
* contacts, and scanning the whole line per contact would be quadratic.
|
|
152
|
+
*/
|
|
153
|
+
function sentenceAround(text, offset) {
|
|
154
|
+
// Start and end on whole characters, at least SENTENCE_WINDOW UTF-8 bytes away (or at the text's ends).
|
|
155
|
+
let from = offset;
|
|
156
|
+
for (let bytes = 0; from > 0 && bytes < SENTENCE_WINDOW;) {
|
|
157
|
+
const step = isLowSurrogateAt(text, from - 1) && isHighSurrogateAt(text, from - 2) ? 2 : 1;
|
|
158
|
+
bytes += utf8Length(text, from - step);
|
|
159
|
+
from -= step;
|
|
160
|
+
}
|
|
161
|
+
let to = offset;
|
|
162
|
+
for (let bytes = 0; to < text.length && bytes < SENTENCE_WINDOW;) {
|
|
163
|
+
const step = isHighSurrogateAt(text, to) && isLowSurrogateAt(text, to + 1) ? 2 : 1;
|
|
164
|
+
bytes += utf8Length(text, to);
|
|
165
|
+
to += step;
|
|
166
|
+
}
|
|
167
|
+
let window = text.slice(from, to);
|
|
168
|
+
let relative = offset - from;
|
|
169
|
+
const lineStart = window.slice(0, relative).lastIndexOf('\n');
|
|
170
|
+
if (lineStart !== -1) {
|
|
171
|
+
window = window.slice(lineStart + 1);
|
|
172
|
+
relative -= lineStart + 1;
|
|
173
|
+
}
|
|
174
|
+
const lineEnd = window.indexOf('\n', relative);
|
|
175
|
+
if (lineEnd !== -1) {
|
|
176
|
+
window = window.slice(0, lineEnd);
|
|
177
|
+
}
|
|
178
|
+
// preg_split() into sentences; the last one starting at or before the offset.
|
|
179
|
+
let start = 0;
|
|
180
|
+
let end = window.length;
|
|
181
|
+
for (const match of window.matchAll(SENTENCE_END)) {
|
|
182
|
+
const next = match.index + match[0].length;
|
|
183
|
+
if (next > relative) {
|
|
184
|
+
end = match.index;
|
|
185
|
+
break;
|
|
186
|
+
}
|
|
187
|
+
start = next;
|
|
188
|
+
}
|
|
189
|
+
return window.slice(start, end);
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* The letterhead: the first block of the text, ending at a blank line or at the recipient's salutation
|
|
193
|
+
* within the first LETTERHEAD_LINES lines, and only when it names an authority. Otherwise null: without
|
|
194
|
+
* a clear letterhead everything is treated as personal data.
|
|
195
|
+
*/
|
|
196
|
+
function letterhead(text) {
|
|
197
|
+
const bytes = letterheadBytes(text);
|
|
198
|
+
return bytes === null ? null : strictUtf8.decode(bytes);
|
|
199
|
+
}
|
|
200
|
+
const BLOCK_BOUNDARY = new RegExp(String.raw `(?=(\r\n|[\n\v\f\r\x85\u{2028}\u{2029}]))\1[ \t]*(?=(\r\n|[\n\v\f\r\x85\u{2028}\u{2029}]))\2|${LINE_START}(?:Herrn?|Frau|An)${WORD_END}`, 'u');
|
|
201
|
+
/** The letterhead as UTF-8 bytes; PHP finds it with byte offsets, and the exact cut decides the result. */
|
|
202
|
+
function letterheadBytes(text) {
|
|
203
|
+
// Only the start of the text is searched: this runs for every e-mail found and must not scan the text.
|
|
204
|
+
// LETTERHEAD_BYTES UTF-16 units encode to at least as many bytes; one more keeps a surrogate pair whole.
|
|
205
|
+
const head = utf8.encode(text.slice(0, LETTERHEAD_BYTES + 1)).subarray(0, LETTERHEAD_BYTES);
|
|
206
|
+
// PHP matches the lines without /u, on bytes: "\R" there also ends a line at the byte 0x85, which
|
|
207
|
+
// occurs inside UTF-8 characters like "Å" (C3 85). Latin-1 maps each byte to one UTF-16 unit.
|
|
208
|
+
const latin1 = bytesToLatin1(head);
|
|
209
|
+
const lines = new RegExp(String.raw `^(?:[^\r\n]*(?=(\r\n|[\n\v\f\r\x85]))\1){${String(LETTERHEAD_LINES)}}`).exec(latin1);
|
|
210
|
+
const limit = lines === null ? head.length : lines[0].length;
|
|
211
|
+
// A blank line right after the last allowed line still ends the block.
|
|
212
|
+
const block = head.subarray(0, limit + 2);
|
|
213
|
+
let blockText;
|
|
214
|
+
try {
|
|
215
|
+
blockText = strictUtf8.decode(block);
|
|
216
|
+
}
|
|
217
|
+
catch {
|
|
218
|
+
return null; // the cut split a character: PHP's /u regex fails on the invalid UTF-8
|
|
219
|
+
}
|
|
220
|
+
const boundary = BLOCK_BOUNDARY.exec(blockText);
|
|
221
|
+
if (boundary === null) {
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
const end = utf8.encode(blockText.slice(0, boundary.index)).length;
|
|
225
|
+
if (end > limit) {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
const result = block.subarray(0, end);
|
|
229
|
+
return authorityLineOf(result) === null ? null : result;
|
|
230
|
+
}
|
|
231
|
+
function authorityLineOf(letterheadBytes) {
|
|
232
|
+
// PHP splits without /u, on bytes (see letterheadBytes()); a piece that is no valid UTF-8 never matches.
|
|
233
|
+
for (const piece of bytesToLatin1(letterheadBytes)
|
|
234
|
+
.split(/\r\n|[\n\v\f\r\x85]/)
|
|
235
|
+
.slice(0, AUTHORITY_NAME_LINES)) {
|
|
236
|
+
let line;
|
|
237
|
+
try {
|
|
238
|
+
line = strictUtf8.decode(Uint8Array.from(piece, (c) => c.charCodeAt(0)));
|
|
239
|
+
}
|
|
240
|
+
catch {
|
|
241
|
+
continue;
|
|
242
|
+
}
|
|
243
|
+
if (AUTHORITY_NAMES.test(line)) {
|
|
244
|
+
return line;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
return null;
|
|
248
|
+
}
|
|
249
|
+
/** One UTF-16 unit per byte (ISO-8859-1), so byte-mode PCRE patterns can be run as JavaScript regexes. */
|
|
250
|
+
function bytesToLatin1(bytes) {
|
|
251
|
+
let result = '';
|
|
252
|
+
for (const byte of bytes) {
|
|
253
|
+
result += String.fromCharCode(byte);
|
|
254
|
+
}
|
|
255
|
+
return result;
|
|
256
|
+
}
|
|
257
|
+
function isHighSurrogateAt(text, i) {
|
|
258
|
+
const unit = text.charCodeAt(i);
|
|
259
|
+
return unit >= 0xd800 && unit <= 0xdbff;
|
|
260
|
+
}
|
|
261
|
+
function isLowSurrogateAt(text, i) {
|
|
262
|
+
const unit = text.charCodeAt(i);
|
|
263
|
+
return unit >= 0xdc00 && unit <= 0xdfff;
|
|
264
|
+
}
|
|
265
|
+
/** UTF-8 length of the character starting at `i` (a lone surrogate encodes as U+FFFD, 3 bytes). */
|
|
266
|
+
function utf8Length(text, i) {
|
|
267
|
+
const unit = text.charCodeAt(i);
|
|
268
|
+
if (unit < 0x80) {
|
|
269
|
+
return 1;
|
|
270
|
+
}
|
|
271
|
+
if (unit < 0x800) {
|
|
272
|
+
return 2;
|
|
273
|
+
}
|
|
274
|
+
if (isHighSurrogateAt(text, i) && isLowSurrogateAt(text, i + 1)) {
|
|
275
|
+
return 4;
|
|
276
|
+
}
|
|
277
|
+
return 3;
|
|
278
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Detector } from '../detector.js';
|
|
2
|
+
import { type Entity } from '../entity.js';
|
|
3
|
+
/**
|
|
4
|
+
* Dates are only personal data when they are birth dates. All other dates
|
|
5
|
+
* (deadlines, letter dates) must survive, so this detector requires a birth keyword.
|
|
6
|
+
*/
|
|
7
|
+
export declare class BirthDateDetector implements Detector {
|
|
8
|
+
readonly name = "birth_date";
|
|
9
|
+
detect(text: string): Entity[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { createEntity } from '../entity.js';
|
|
2
|
+
import { EntityType } from '../entity-type.js';
|
|
3
|
+
import { checkdate, DIGIT, matchAll, phpIntval, SPACE, WORD_START } from '../internal/pcre.js';
|
|
4
|
+
const D = DIGIT;
|
|
5
|
+
const S = SPACE;
|
|
6
|
+
const PATTERN = new RegExp(String.raw `(?:${WORD_START}geb\.(?:${S}*am)?|${WORD_START}geboren(?:${S}+am)?|${WORD_START}Geburtsdatum:?)${S}*(?<date>${D}{1,2}\.${S}?${D}{1,2}\.${S}?${D}{4})(?!${D})`, 'dgiu');
|
|
7
|
+
/**
|
|
8
|
+
* Dates are only personal data when they are birth dates. All other dates
|
|
9
|
+
* (deadlines, letter dates) must survive, so this detector requires a birth keyword.
|
|
10
|
+
*/
|
|
11
|
+
export class BirthDateDetector {
|
|
12
|
+
name = 'birth_date';
|
|
13
|
+
detect(text) {
|
|
14
|
+
return matchAll(PATTERN, text, 'date')
|
|
15
|
+
.filter(({ value }) => {
|
|
16
|
+
const [day = 0, month = 0, year = 0] = value.replaceAll(' ', '').split('.').map(phpIntval);
|
|
17
|
+
return checkdate(month, day, year);
|
|
18
|
+
})
|
|
19
|
+
.map(({ value, offset }) => createEntity({ type: EntityType.BirthDate, value, offset, confidence: 0.95, detector: 'birth_date' }));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Detector } from '../detector.js';
|
|
2
|
+
import { type Entity } from '../entity.js';
|
|
3
|
+
export interface ContactDetectorOptions {
|
|
4
|
+
/**
|
|
5
|
+
* Keep the sender authority's own contact details (default true): they are needed for the action steps
|
|
6
|
+
* and are not the recipient's personal data. See the heuristic in authority-context.ts.
|
|
7
|
+
*/
|
|
8
|
+
keepAuthorityContacts?: boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare class EmailDetector implements Detector {
|
|
11
|
+
#private;
|
|
12
|
+
readonly name = "email";
|
|
13
|
+
constructor(options?: ContactDetectorOptions);
|
|
14
|
+
detect(text: string): Entity[];
|
|
15
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { createEntity } from '../entity.js';
|
|
2
|
+
import { EntityType } from '../entity-type.js';
|
|
3
|
+
import { matchAll, WORD_CHARS, WORD_END } from '../internal/pcre.js';
|
|
4
|
+
import { authorityLine, isAuthorityContact, isAuthorityEmail } from './authority-context.js';
|
|
5
|
+
const PATTERN = new RegExp(String.raw `(?<![${WORD_CHARS}.%+\-])[A-Za-z0-9._%+\-]+@[A-Za-z0-9\-]+(?:\.[A-Za-z0-9\-]+)*\.[A-Za-z]{2,}${WORD_END}`, 'gu');
|
|
6
|
+
export class EmailDetector {
|
|
7
|
+
name = 'email';
|
|
8
|
+
#keepAuthorityContacts;
|
|
9
|
+
constructor(options = {}) {
|
|
10
|
+
this.#keepAuthorityContacts = options.keepAuthorityContacts ?? true;
|
|
11
|
+
}
|
|
12
|
+
detect(text) {
|
|
13
|
+
const entities = [];
|
|
14
|
+
let authority;
|
|
15
|
+
for (const { value, offset } of matchAll(PATTERN, text)) {
|
|
16
|
+
if (this.#keepAuthorityContacts) {
|
|
17
|
+
if (isAuthorityContact(text, offset)) {
|
|
18
|
+
continue;
|
|
19
|
+
}
|
|
20
|
+
authority ??= authorityLine(text);
|
|
21
|
+
if (isAuthorityEmail(text, value, authority)) {
|
|
22
|
+
continue;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
entities.push(createEntity({ type: EntityType.Email, value, offset, confidence: 1, detector: 'email' }));
|
|
26
|
+
}
|
|
27
|
+
return entities;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Detector } from '../detector.js';
|
|
2
|
+
import { type Entity } from '../entity.js';
|
|
3
|
+
/**
|
|
4
|
+
* Words that introduce a file or customer number (regex source); also used to check a model's findings.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
export declare const FILE_NUMBER_KEYWORDS: string;
|
|
9
|
+
/**
|
|
10
|
+
* Case and customer references (Aktenzahl, Geschäftszahl, Kundennummer, ...).
|
|
11
|
+
* Only matches after a keyword; the reference must contain a digit.
|
|
12
|
+
*/
|
|
13
|
+
export declare class FileNumberDetector implements Detector {
|
|
14
|
+
readonly name = "file_number";
|
|
15
|
+
detect(text: string): Entity[];
|
|
16
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createEntity } from '../entity.js';
|
|
2
|
+
import { EntityType } from '../entity-type.js';
|
|
3
|
+
import { DIGIT, matchAll, WORD_CHARS, WORD_START } from '../internal/pcre.js';
|
|
4
|
+
/**
|
|
5
|
+
* Words that introduce a file or customer number (regex source); also used to check a model's findings.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
export const FILE_NUMBER_KEYWORDS = String.raw `(?:Zahl|GZ|Gz\.|Geschäftszahl|Aktenzahl|Aktenzeichen|Az\.|Kundennummer|Kunden-Nr\.?|Vertragsnummer|Versicherungsnummer|Verwendungszweck)`;
|
|
10
|
+
const PATTERN = new RegExp(String.raw `${WORD_START}${FILE_NUMBER_KEYWORDS}[ \t]*:?[ \t]*(?<ref>(?=[A-Z0-9.\/\-]*${DIGIT})[A-Z0-9][A-Z0-9.\/\-]{2,}[A-Z0-9])(?![${WORD_CHARS}\/\-])`, 'dgu');
|
|
11
|
+
/**
|
|
12
|
+
* Case and customer references (Aktenzahl, Geschäftszahl, Kundennummer, ...).
|
|
13
|
+
* Only matches after a keyword; the reference must contain a digit.
|
|
14
|
+
*/
|
|
15
|
+
export class FileNumberDetector {
|
|
16
|
+
name = 'file_number';
|
|
17
|
+
detect(text) {
|
|
18
|
+
return matchAll(PATTERN, text, 'ref').map(({ value, offset }) => createEntity({ type: EntityType.FileNumber, value, offset, confidence: 0.9, detector: 'file_number' }));
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { Detector, Validator } from '../detector.js';
|
|
2
|
+
import { type Entity } from '../entity.js';
|
|
3
|
+
export declare class IbanDetector implements Detector {
|
|
4
|
+
#private;
|
|
5
|
+
readonly name = "iban";
|
|
6
|
+
constructor(options?: {
|
|
7
|
+
validator?: Validator;
|
|
8
|
+
});
|
|
9
|
+
detect(text: string): Entity[];
|
|
10
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { createEntity } from '../entity.js';
|
|
2
|
+
import { EntityType } from '../entity-type.js';
|
|
3
|
+
import { DIGIT, matchAll, WORD_END, WORD_START } from '../internal/pcre.js';
|
|
4
|
+
import { isValidIban } from '../validators/iban.js';
|
|
5
|
+
const GAP = String.raw `(?: |[ \t]*\n[ \t]*)?`;
|
|
6
|
+
const PATTERN = new RegExp(`${WORD_START}[A-Z]{2}${DIGIT}{2}(?:${GAP}[A-Z0-9]{4}){2,7}(?:${GAP}[A-Z0-9]{1,3})?${WORD_END}`, 'gu');
|
|
7
|
+
/** PHP matches this without /u: ASCII whitespace. */
|
|
8
|
+
const LAST_GROUP = /^([^]*[^\t\n\v\f\r ])[\t\n\v\f\r ]+[^\t\n\v\f\r ]+$/;
|
|
9
|
+
export class IbanDetector {
|
|
10
|
+
name = 'iban';
|
|
11
|
+
#validator;
|
|
12
|
+
constructor(options = {}) {
|
|
13
|
+
this.#validator = options.validator ?? isValidIban;
|
|
14
|
+
}
|
|
15
|
+
detect(text) {
|
|
16
|
+
const entities = [];
|
|
17
|
+
for (const { value: candidate, offset } of matchAll(PATTERN, text)) {
|
|
18
|
+
const value = this.#longestValidPrefix(candidate);
|
|
19
|
+
if (value !== null) {
|
|
20
|
+
entities.push(createEntity({ type: EntityType.Iban, value, offset, confidence: 1, detector: 'iban' }));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return entities;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* The greedy pattern may swallow a following uppercase token ("... 3201 BIC"), also from the next line.
|
|
27
|
+
* Drop trailing whitespace-separated groups until the checksum matches.
|
|
28
|
+
*/
|
|
29
|
+
#longestValidPrefix(candidate) {
|
|
30
|
+
for (;;) {
|
|
31
|
+
if (this.#validator(candidate)) {
|
|
32
|
+
return candidate;
|
|
33
|
+
}
|
|
34
|
+
const shorter = LAST_GROUP.exec(candidate)?.[1];
|
|
35
|
+
if (shorter === undefined) {
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
candidate = shorter;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { Detector } from '../detector.js';
|
|
2
|
+
import { type Entity } from '../entity.js';
|
|
3
|
+
/**
|
|
4
|
+
* AT and DE license plates, only after the keyword "Kennzeichen".
|
|
5
|
+
*/
|
|
6
|
+
export declare class LicensePlateDetector implements Detector {
|
|
7
|
+
readonly name = "license_plate";
|
|
8
|
+
detect(text: string): Entity[];
|
|
9
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { createEntity } from '../entity.js';
|
|
2
|
+
import { EntityType } from '../entity-type.js';
|
|
3
|
+
import { DIGIT, matchAll, WORD_CHARS, WORD_START } from '../internal/pcre.js';
|
|
4
|
+
const PATTERN = new RegExp(String.raw `${WORD_START}Kennzeichen[ \t]*:?[ \t]+(?<plate>[A-ZÄÖÜ]{1,3}[\- ](?:[A-Z]{1,2} )?${DIGIT}{1,6}[A-Z]{0,3})(?![${WORD_CHARS}\-])`, 'dgu');
|
|
5
|
+
/**
|
|
6
|
+
* AT and DE license plates, only after the keyword "Kennzeichen".
|
|
7
|
+
*/
|
|
8
|
+
export class LicensePlateDetector {
|
|
9
|
+
name = 'license_plate';
|
|
10
|
+
detect(text) {
|
|
11
|
+
return matchAll(PATTERN, text, 'plate').map(({ value, offset }) => createEntity({ type: EntityType.LicensePlate, value, offset, confidence: 0.9, detector: 'license_plate' }));
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Detector } from '../detector.js';
|
|
2
|
+
import { type Entity } from '../entity.js';
|
|
3
|
+
import type { ContactDetectorOptions } from './email.js';
|
|
4
|
+
/**
|
|
5
|
+
* International (+43 ..., 0049 ...) and national (0664/...) phone numbers.
|
|
6
|
+
* Requires at least 7 digits; dates and times do not match because "." and ":" are not separators.
|
|
7
|
+
*/
|
|
8
|
+
export declare class PhoneDetector implements Detector {
|
|
9
|
+
#private;
|
|
10
|
+
readonly name = "phone";
|
|
11
|
+
constructor(options?: ContactDetectorOptions);
|
|
12
|
+
detect(text: string): Entity[];
|
|
13
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { createEntity } from '../entity.js';
|
|
2
|
+
import { EntityType } from '../entity-type.js';
|
|
3
|
+
import { asciiDigits, DIGIT, matchAll, WORD_CHARS } from '../internal/pcre.js';
|
|
4
|
+
import { isAuthorityContact, isMobileNumber } from './authority-context.js';
|
|
5
|
+
const D = DIGIT;
|
|
6
|
+
/*
|
|
7
|
+
* PHP's pattern as of clarifile PR #95: each digit group must run to the end of its digit run ((?!\d)).
|
|
8
|
+
* The older form "(?:[ /-]?\d{2,}){1,5}" split a long digit run into groups in O(n^4) ways before the final
|
|
9
|
+
* lookahead failed (PHP threw "Backtrack limit exhausted"; JavaScript has no limit and hangs). A match can
|
|
10
|
+
* only end where a digit run ends, so the lookahead never changes which text matches.
|
|
11
|
+
*/
|
|
12
|
+
const PATTERN = new RegExp(String.raw `(?<![${WORD_CHARS}+\/])(?:(?:\+|00)${D}{1,3}|0${D}{1,4})(?:[ \/\-]?${D}{2,}(?!${D})){1,5}(?![${WORD_CHARS}\/])`, 'gu');
|
|
13
|
+
const MIN_DIGITS = 7;
|
|
14
|
+
/**
|
|
15
|
+
* International (+43 ..., 0049 ...) and national (0664/...) phone numbers.
|
|
16
|
+
* Requires at least 7 digits; dates and times do not match because "." and ":" are not separators.
|
|
17
|
+
*/
|
|
18
|
+
export class PhoneDetector {
|
|
19
|
+
name = 'phone';
|
|
20
|
+
#keepAuthorityContacts;
|
|
21
|
+
constructor(options = {}) {
|
|
22
|
+
this.#keepAuthorityContacts = options.keepAuthorityContacts ?? true;
|
|
23
|
+
}
|
|
24
|
+
detect(text) {
|
|
25
|
+
const entities = [];
|
|
26
|
+
for (const { value, offset } of matchAll(PATTERN, text)) {
|
|
27
|
+
// PHP counts ASCII digits only here (no /u), so it drops numbers in other digits (docs/DEVIATIONS.md).
|
|
28
|
+
if (asciiDigits(value).replace(/[^0-9]/g, '').length < MIN_DIGITS) {
|
|
29
|
+
continue;
|
|
30
|
+
}
|
|
31
|
+
if (this.#keepAuthorityContacts && !isMobileNumber(value) && isAuthorityContact(text, offset)) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
entities.push(createEntity({ type: EntityType.Phone, value, offset, confidence: 0.8, detector: 'phone' }));
|
|
35
|
+
}
|
|
36
|
+
return entities;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Detector } from '../detector.js';
|
|
2
|
+
import { type Entity } from '../entity.js';
|
|
3
|
+
/**
|
|
4
|
+
* Two-line postal address as found in the recipient block:
|
|
5
|
+
* "Street 12[/3]" followed by "AT 4-digit or DE 5-digit postcode + city", with up to two blank
|
|
6
|
+
* lines in between (OCR output).
|
|
7
|
+
*
|
|
8
|
+
* Single-line addresses ("Hauptplatz 1, 6999 Musterstadt") are typically the sender's
|
|
9
|
+
* letterhead and are kept. Street names without house number are left to NER.
|
|
10
|
+
*/
|
|
11
|
+
export declare class PostalAddressDetector implements Detector {
|
|
12
|
+
readonly name = "postal_address";
|
|
13
|
+
detect(text: string): Entity[];
|
|
14
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { createEntity } from '../entity.js';
|
|
2
|
+
import { EntityType } from '../entity-type.js';
|
|
3
|
+
import { DIGIT, LINE_END, LINE_START, matchAll } from '../internal/pcre.js';
|
|
4
|
+
const D = DIGIT;
|
|
5
|
+
const PATTERN = new RegExp(String.raw `${LINE_START}(?<address>\p{Lu}[\p{L}.' \-]*?[ \t]${D}{1,4}[a-zA-Z]?(?:\/${D}{1,4}[a-zA-Z]?)*[ \t]*\n(?:[ \t]*\n){0,2}(?:(?:A|D|CH)-)?(?:[1-9]${D}{3}|${D}{5})[ \t]+\p{Lu}[\p{L}.' \-]*\p{L})[ \t]*${LINE_END}`, 'dgu');
|
|
6
|
+
/**
|
|
7
|
+
* Two-line postal address as found in the recipient block:
|
|
8
|
+
* "Street 12[/3]" followed by "AT 4-digit or DE 5-digit postcode + city", with up to two blank
|
|
9
|
+
* lines in between (OCR output).
|
|
10
|
+
*
|
|
11
|
+
* Single-line addresses ("Hauptplatz 1, 6999 Musterstadt") are typically the sender's
|
|
12
|
+
* letterhead and are kept. Street names without house number are left to NER.
|
|
13
|
+
*/
|
|
14
|
+
export class PostalAddressDetector {
|
|
15
|
+
name = 'postal_address';
|
|
16
|
+
detect(text) {
|
|
17
|
+
return matchAll(PATTERN, text, 'address').map(({ value, offset }) => createEntity({ type: EntityType.Address, value, offset, confidence: 0.8, detector: 'postal_address' }));
|
|
18
|
+
}
|
|
19
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Detector } from '../detector.js';
|
|
2
|
+
import { type Entity } from '../entity.js';
|
|
3
|
+
/**
|
|
4
|
+
* Offline fallback for person names: names following "Herr", "Herrn" or "Frau".
|
|
5
|
+
*
|
|
6
|
+
* - Address block: salutation alone on a line, name on the next non-empty line ("Frau\nMaria Musterfrau").
|
|
7
|
+
* Tolerates OCR output: up to two blank lines in between and a split first word ("J ohann").
|
|
8
|
+
* - Inline: "Sehr geehrter Herr Beispielmann", up to two capitalised words. A following German
|
|
9
|
+
* noun ("Herr Muster Bescheid") is indistinguishable from a surname without NER; over-redaction
|
|
10
|
+
* is preferred to leaking half a name.
|
|
11
|
+
*
|
|
12
|
+
* Academic titles are skipped and not part of the value. Names without salutation
|
|
13
|
+
* (e.g. the signing official) are left to the NER detector.
|
|
14
|
+
*/
|
|
15
|
+
export declare class SalutationPersonDetector implements Detector {
|
|
16
|
+
readonly name = "salutation_person";
|
|
17
|
+
detect(text: string): Entity[];
|
|
18
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createEntity } from '../entity.js';
|
|
2
|
+
import { EntityType } from '../entity-type.js';
|
|
3
|
+
import { LINE_END, LINE_START, matchAll, WORD_START } from '../internal/pcre.js';
|
|
4
|
+
const TITLES = String.raw `(?:(?:Dr|Mag|DI|Dipl\.-Ing|Ing|Prof|MMag|Mag\.\(FH\))\.?[ \t]+)*`;
|
|
5
|
+
const WORD = String.raw `\p{Lu}[\p{L}'\-]+`;
|
|
6
|
+
/** Like WORD, but also an initial split off by OCR: "J ohann". */
|
|
7
|
+
const OCR_WORD = String.raw `\p{Lu}(?:[ \t](?=\p{Ll}))?[\p{L}'\-]+`;
|
|
8
|
+
const BLOCK = new RegExp(String.raw `${LINE_START}(?:Herrn?|Frau)[ \t]*\n(?:[ \t]*\n){0,2}${TITLES}(?<name>${OCR_WORD}(?:[ \t]+${WORD})+)[ \t]*${LINE_END}`, 'dgu');
|
|
9
|
+
const INLINE = new RegExp(String.raw `${WORD_START}(?:Herrn?|Frau)[ \t]+${TITLES}(?<name>${WORD}(?:[ \t]+${WORD})?)`, 'dgu');
|
|
10
|
+
/**
|
|
11
|
+
* Offline fallback for person names: names following "Herr", "Herrn" or "Frau".
|
|
12
|
+
*
|
|
13
|
+
* - Address block: salutation alone on a line, name on the next non-empty line ("Frau\nMaria Musterfrau").
|
|
14
|
+
* Tolerates OCR output: up to two blank lines in between and a split first word ("J ohann").
|
|
15
|
+
* - Inline: "Sehr geehrter Herr Beispielmann", up to two capitalised words. A following German
|
|
16
|
+
* noun ("Herr Muster Bescheid") is indistinguishable from a surname without NER; over-redaction
|
|
17
|
+
* is preferred to leaking half a name.
|
|
18
|
+
*
|
|
19
|
+
* Academic titles are skipped and not part of the value. Names without salutation
|
|
20
|
+
* (e.g. the signing official) are left to the NER detector.
|
|
21
|
+
*/
|
|
22
|
+
export class SalutationPersonDetector {
|
|
23
|
+
name = 'salutation_person';
|
|
24
|
+
detect(text) {
|
|
25
|
+
// The address block is a strong signal; inline matches may include a following noun.
|
|
26
|
+
const entities = [];
|
|
27
|
+
for (const [pattern, confidence, detector] of [
|
|
28
|
+
[BLOCK, 0.8, 'salutation_block'],
|
|
29
|
+
[INLINE, 0.6, 'salutation_inline'],
|
|
30
|
+
]) {
|
|
31
|
+
for (const { value, offset } of matchAll(pattern, text, 'name')) {
|
|
32
|
+
entities.push(createEntity({ type: EntityType.Person, value, offset, confidence, detector }));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return entities.sort((a, b) => a.offset - b.offset);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Detector, Validator } from '../detector.js';
|
|
2
|
+
import { type Entity } from '../entity.js';
|
|
3
|
+
/**
|
|
4
|
+
* AT Steuernummer (e.g. "46 123/4567"), DE Steuernummer (e.g. "181/815/08155")
|
|
5
|
+
* and DE Steuer-ID (11 digits, checksum-validated).
|
|
6
|
+
*/
|
|
7
|
+
export declare class TaxNumberDetector implements Detector {
|
|
8
|
+
#private;
|
|
9
|
+
readonly name = "tax_number";
|
|
10
|
+
constructor(options?: {
|
|
11
|
+
taxIdValidator?: Validator;
|
|
12
|
+
});
|
|
13
|
+
detect(text: string): Entity[];
|
|
14
|
+
}
|