@stll/anonymize 1.5.0 → 2.0.0-alpha.1
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/ATTRIBUTION.md +70 -0
- package/README.md +86 -48
- package/dist/address-boundaries.mjs +2 -0
- package/dist/address-jurisdiction-prefixes.mjs +16 -0
- package/dist/address-jurisdiction-prefixes.mjs.map +1 -0
- package/dist/address-stop-keywords.mjs +12 -1
- package/dist/address-unit-abbreviations.mjs +15 -0
- package/dist/address-unit-abbreviations.mjs.map +1 -0
- package/dist/clause-noun-heads.mjs +5 -1
- package/dist/coreference-org-determiners.mjs +19 -0
- package/dist/coreference-org-determiners.mjs.map +1 -0
- package/dist/defined-term-heads.mjs +15 -0
- package/dist/defined-term-heads.mjs.map +1 -0
- package/dist/false-positive-shapes.mjs +36 -0
- package/dist/false-positive-shapes.mjs.map +1 -0
- package/dist/index.d.mts +3 -1201
- package/dist/index.mjs +3 -16267
- package/dist/index.mjs.map +1 -1
- package/dist/legal-role-heads.cs.mjs +6 -0
- package/dist/native-node.d.mts +124 -0
- package/dist/native-node.mjs +3 -0
- package/dist/native-node2.d.mts +3 -0
- package/dist/native-node2.mjs +13353 -0
- package/dist/native-node2.mjs.map +1 -0
- package/dist/native.d.mts +1158 -0
- package/dist/native.mjs +230 -0
- package/dist/native.mjs.map +1 -0
- package/dist/native2.d.mts +2 -0
- package/dist/organization-unit-heads.mjs +20 -0
- package/dist/organization-unit-heads.mjs.map +1 -0
- package/dist/person-stopwords.mjs +205 -199
- package/dist/signing-clauses.mjs +33 -9
- package/index.cjs +3 -0
- package/native-pipeline.cs.stlanonpkg +0 -0
- package/native-pipeline.de.stlanonpkg +0 -0
- package/native-pipeline.en.stlanonpkg +0 -0
- package/native-pipeline.stlanonpkg +0 -0
- package/package.json +40 -6
- package/scripts/build-native-pipeline-package.mjs +225 -0
- package/dist/address-prepositions.mjs +0 -182
- package/dist/address-prepositions.mjs.map +0 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { mkdirSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
import { pathToFileURL } from "node:url";
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
DEFAULT_NATIVE_PIPELINE_CONFIG,
|
|
8
|
+
prepareNativePipelinePackage,
|
|
9
|
+
} from "../dist/index.mjs";
|
|
10
|
+
import { loadNativeAnonymizeBinding } from "../dist/native-node.mjs";
|
|
11
|
+
|
|
12
|
+
const args = parseArgs(process.argv.slice(2));
|
|
13
|
+
const outputPath = resolve(args.out ?? "native-pipeline.stlanonpkg");
|
|
14
|
+
const compressed = args.compressed === true;
|
|
15
|
+
const { config, gazetteerEntries } = await loadPackageInput(args);
|
|
16
|
+
const binding = loadNativeAnonymizeBinding();
|
|
17
|
+
const packageBytes = await prepareNativePipelinePackage({
|
|
18
|
+
binding,
|
|
19
|
+
config,
|
|
20
|
+
gazetteerEntries,
|
|
21
|
+
compressed,
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
mkdirSync(dirname(outputPath), { recursive: true });
|
|
25
|
+
writeFileSync(outputPath, packageBytes);
|
|
26
|
+
|
|
27
|
+
console.log(
|
|
28
|
+
JSON.stringify({
|
|
29
|
+
event: "native-pipeline-package",
|
|
30
|
+
outputPath,
|
|
31
|
+
bytes: packageBytes.byteLength,
|
|
32
|
+
compressed,
|
|
33
|
+
nativeVersion: binding.nativePackageVersion(),
|
|
34
|
+
}),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
function parseArgs(values) {
|
|
38
|
+
const result = {};
|
|
39
|
+
for (let index = 0; index < values.length; index += 1) {
|
|
40
|
+
const value = values[index];
|
|
41
|
+
switch (value) {
|
|
42
|
+
case "--config": {
|
|
43
|
+
result.config = requiredValue(values, index, value);
|
|
44
|
+
index += 1;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
case "--export": {
|
|
48
|
+
result.exportName = requiredValue(values, index, value);
|
|
49
|
+
index += 1;
|
|
50
|
+
break;
|
|
51
|
+
}
|
|
52
|
+
case "--out": {
|
|
53
|
+
result.out = requiredValue(values, index, value);
|
|
54
|
+
index += 1;
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
case "--raw": {
|
|
58
|
+
result.raw = true;
|
|
59
|
+
break;
|
|
60
|
+
}
|
|
61
|
+
case "--compressed": {
|
|
62
|
+
result.compressed = true;
|
|
63
|
+
break;
|
|
64
|
+
}
|
|
65
|
+
case "--default-dictionaries": {
|
|
66
|
+
result.defaultDictionaries = true;
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
case "--language": {
|
|
70
|
+
result.language = requiredValue(values, index, value);
|
|
71
|
+
index += 1;
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
case "--languages": {
|
|
75
|
+
result.languages = requiredValue(values, index, value);
|
|
76
|
+
index += 1;
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
case "--help": {
|
|
80
|
+
printHelp();
|
|
81
|
+
process.exit(0);
|
|
82
|
+
}
|
|
83
|
+
default:
|
|
84
|
+
throw new Error(`Unknown option: ${value}`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
if (result.raw && result.compressed) {
|
|
88
|
+
throw new Error("Use either --raw or --compressed, not both");
|
|
89
|
+
}
|
|
90
|
+
return result;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function requiredValue(values, index, option) {
|
|
94
|
+
const value = values[index + 1];
|
|
95
|
+
if (value === undefined || value.startsWith("--")) {
|
|
96
|
+
throw new Error(`${option} requires a value`);
|
|
97
|
+
}
|
|
98
|
+
return value;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function loadPackageInput(options) {
|
|
102
|
+
const input = await loadBasePackageInput(options);
|
|
103
|
+
const withDictionaries =
|
|
104
|
+
!options.defaultDictionaries || input.config.dictionaries !== undefined
|
|
105
|
+
? input
|
|
106
|
+
: {
|
|
107
|
+
...input,
|
|
108
|
+
config: {
|
|
109
|
+
...input.config,
|
|
110
|
+
dictionaries: await loadDefaultDictionaries(),
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
...withDictionaries,
|
|
115
|
+
config: applyCliLanguageScope(withDictionaries.config, options),
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
async function loadBasePackageInput(options) {
|
|
120
|
+
if (!options.config) {
|
|
121
|
+
return { config: defaultNativePipelineConfig(), gazetteerEntries: [] };
|
|
122
|
+
}
|
|
123
|
+
const moduleUrl = pathToFileURL(resolve(options.config)).href;
|
|
124
|
+
// eslint-disable-next-line stll/no-dynamic-import-specifier
|
|
125
|
+
const loaded = await import(moduleUrl);
|
|
126
|
+
const exportName = options.exportName ?? "default";
|
|
127
|
+
const candidate =
|
|
128
|
+
exportName === "default" ? loaded.default : loaded[exportName];
|
|
129
|
+
if (candidate === undefined) {
|
|
130
|
+
throw new Error(`Config module does not export ${exportName}`);
|
|
131
|
+
}
|
|
132
|
+
const value =
|
|
133
|
+
typeof candidate === "function" ? await candidate() : await candidate;
|
|
134
|
+
if (!value || typeof value !== "object") {
|
|
135
|
+
throw new TypeError("Native package config export must be an object");
|
|
136
|
+
}
|
|
137
|
+
if ("config" in value) {
|
|
138
|
+
return {
|
|
139
|
+
config: value.config,
|
|
140
|
+
gazetteerEntries: value.gazetteerEntries ?? [],
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
return { config: value, gazetteerEntries: [] };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function defaultNativePipelineConfig() {
|
|
147
|
+
return {
|
|
148
|
+
...DEFAULT_NATIVE_PIPELINE_CONFIG,
|
|
149
|
+
labels: [...DEFAULT_NATIVE_PIPELINE_CONFIG.labels],
|
|
150
|
+
workspaceId: "native-pipeline-package",
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function applyCliLanguageScope(pipelineConfig, options) {
|
|
155
|
+
if (options.language !== undefined && options.languages !== undefined) {
|
|
156
|
+
throw new Error("Use either --language or --languages, not both");
|
|
157
|
+
}
|
|
158
|
+
if (options.language !== undefined) {
|
|
159
|
+
const language = normalizeLanguageOption(options.language, "--language");
|
|
160
|
+
return { ...pipelineConfig, language, languages: undefined };
|
|
161
|
+
}
|
|
162
|
+
if (options.languages === undefined) {
|
|
163
|
+
return pipelineConfig;
|
|
164
|
+
}
|
|
165
|
+
const languages = normalizeLanguageList(options.languages);
|
|
166
|
+
return { ...pipelineConfig, language: undefined, languages };
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
function normalizeLanguageOption(value, option) {
|
|
170
|
+
const language = value.trim().toLowerCase();
|
|
171
|
+
if (language.length === 0) {
|
|
172
|
+
throw new Error(`${option} requires a non-empty language code`);
|
|
173
|
+
}
|
|
174
|
+
return language;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function normalizeLanguageList(value) {
|
|
178
|
+
const languages = value
|
|
179
|
+
.split(",")
|
|
180
|
+
.map((entry) => normalizeLanguageOption(entry, "--languages"))
|
|
181
|
+
.filter((entry, index, entries) => entries.indexOf(entry) === index);
|
|
182
|
+
if (languages.length === 0) {
|
|
183
|
+
throw new Error("--languages requires at least one language code");
|
|
184
|
+
}
|
|
185
|
+
return languages;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
async function loadDefaultDictionaries() {
|
|
189
|
+
let loaded;
|
|
190
|
+
try {
|
|
191
|
+
loaded = await import("@stll/anonymize-data/dictionaries");
|
|
192
|
+
} catch (error) {
|
|
193
|
+
throw new Error(
|
|
194
|
+
`--default-dictionaries requires @stll/anonymize-data: ${formatError(error)}`,
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
if (typeof loaded.loadDictionaryBundle !== "function") {
|
|
198
|
+
throw new TypeError(
|
|
199
|
+
"@stll/anonymize-data/dictionaries does not export loadDictionaryBundle",
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
return loaded.loadDictionaryBundle();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
function formatError(error) {
|
|
206
|
+
if (error instanceof Error) {
|
|
207
|
+
return error.message;
|
|
208
|
+
}
|
|
209
|
+
return String(error);
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
function printHelp() {
|
|
213
|
+
console.log(`Usage: build-native-pipeline-package [options]
|
|
214
|
+
|
|
215
|
+
Options:
|
|
216
|
+
--out <path> Output package path. Defaults to native-pipeline.stlanonpkg.
|
|
217
|
+
--config <path> ESM module exporting a PipelineConfig or { config, gazetteerEntries }.
|
|
218
|
+
--export <name> Export name to read from the config module. Defaults to default.
|
|
219
|
+
--language <code> Build a package scoped to one content language.
|
|
220
|
+
--languages <codes> Build a package scoped to comma-separated content languages.
|
|
221
|
+
--default-dictionaries Load @stll/anonymize-data into configs that do not provide dictionaries.
|
|
222
|
+
--compressed Write an LZ4-compressed package.
|
|
223
|
+
--raw Write an uncompressed package. This is the default.
|
|
224
|
+
`);
|
|
225
|
+
}
|
|
@@ -1,182 +0,0 @@
|
|
|
1
|
-
//#region src/data/address-prepositions.json
|
|
2
|
-
var _comment = "Prepositions used in street/address names by language. Used by backward scan to continue through lowercase words, and by temporal guard to skip date-like patterns.";
|
|
3
|
-
var address = {
|
|
4
|
-
"cs": [
|
|
5
|
-
"nad",
|
|
6
|
-
"pod",
|
|
7
|
-
"u",
|
|
8
|
-
"na",
|
|
9
|
-
"v",
|
|
10
|
-
"ve",
|
|
11
|
-
"ke",
|
|
12
|
-
"za",
|
|
13
|
-
"při",
|
|
14
|
-
"do",
|
|
15
|
-
"od",
|
|
16
|
-
"mezi"
|
|
17
|
-
],
|
|
18
|
-
"sk": [
|
|
19
|
-
"nad",
|
|
20
|
-
"pod",
|
|
21
|
-
"pri",
|
|
22
|
-
"na",
|
|
23
|
-
"vo",
|
|
24
|
-
"ke",
|
|
25
|
-
"za",
|
|
26
|
-
"do",
|
|
27
|
-
"od",
|
|
28
|
-
"medzi"
|
|
29
|
-
],
|
|
30
|
-
"de": [
|
|
31
|
-
"am",
|
|
32
|
-
"an",
|
|
33
|
-
"im",
|
|
34
|
-
"bei",
|
|
35
|
-
"zum",
|
|
36
|
-
"zur",
|
|
37
|
-
"auf",
|
|
38
|
-
"in",
|
|
39
|
-
"vor"
|
|
40
|
-
],
|
|
41
|
-
"en": [
|
|
42
|
-
"upon",
|
|
43
|
-
"on",
|
|
44
|
-
"in",
|
|
45
|
-
"by",
|
|
46
|
-
"at",
|
|
47
|
-
"near"
|
|
48
|
-
],
|
|
49
|
-
"fr": [
|
|
50
|
-
"sur",
|
|
51
|
-
"sous",
|
|
52
|
-
"de",
|
|
53
|
-
"du",
|
|
54
|
-
"des",
|
|
55
|
-
"aux",
|
|
56
|
-
"en"
|
|
57
|
-
],
|
|
58
|
-
"pl": [
|
|
59
|
-
"nad",
|
|
60
|
-
"pod",
|
|
61
|
-
"przy",
|
|
62
|
-
"na",
|
|
63
|
-
"za",
|
|
64
|
-
"do",
|
|
65
|
-
"od",
|
|
66
|
-
"między"
|
|
67
|
-
],
|
|
68
|
-
"it": [
|
|
69
|
-
"di",
|
|
70
|
-
"del",
|
|
71
|
-
"della",
|
|
72
|
-
"sul",
|
|
73
|
-
"al"
|
|
74
|
-
],
|
|
75
|
-
"es": [
|
|
76
|
-
"de",
|
|
77
|
-
"del",
|
|
78
|
-
"en",
|
|
79
|
-
"sobre"
|
|
80
|
-
],
|
|
81
|
-
"hu": [
|
|
82
|
-
"melletti",
|
|
83
|
-
"alatti",
|
|
84
|
-
"feletti"
|
|
85
|
-
],
|
|
86
|
-
"ro": [
|
|
87
|
-
"de",
|
|
88
|
-
"din",
|
|
89
|
-
"pe",
|
|
90
|
-
"la"
|
|
91
|
-
],
|
|
92
|
-
"sv": [
|
|
93
|
-
"vid",
|
|
94
|
-
"på",
|
|
95
|
-
"i"
|
|
96
|
-
]
|
|
97
|
-
};
|
|
98
|
-
var temporal = {
|
|
99
|
-
"_comment": "Prepositions that indicate temporal context (dates), not addresses. Used as negative guard.",
|
|
100
|
-
"cs": [
|
|
101
|
-
"od",
|
|
102
|
-
"do",
|
|
103
|
-
"ke",
|
|
104
|
-
"na",
|
|
105
|
-
"dne",
|
|
106
|
-
"ze",
|
|
107
|
-
"ve",
|
|
108
|
-
"za",
|
|
109
|
-
"při",
|
|
110
|
-
"mezi"
|
|
111
|
-
],
|
|
112
|
-
"sk": [
|
|
113
|
-
"od",
|
|
114
|
-
"do",
|
|
115
|
-
"dňa",
|
|
116
|
-
"na",
|
|
117
|
-
"vo",
|
|
118
|
-
"za"
|
|
119
|
-
],
|
|
120
|
-
"de": [
|
|
121
|
-
"ab",
|
|
122
|
-
"bis",
|
|
123
|
-
"am",
|
|
124
|
-
"vom",
|
|
125
|
-
"seit"
|
|
126
|
-
],
|
|
127
|
-
"en": [
|
|
128
|
-
"from",
|
|
129
|
-
"to",
|
|
130
|
-
"on",
|
|
131
|
-
"at",
|
|
132
|
-
"since",
|
|
133
|
-
"until",
|
|
134
|
-
"by"
|
|
135
|
-
],
|
|
136
|
-
"fr": [
|
|
137
|
-
"du",
|
|
138
|
-
"au",
|
|
139
|
-
"dès",
|
|
140
|
-
"depuis",
|
|
141
|
-
"le"
|
|
142
|
-
],
|
|
143
|
-
"pl": [
|
|
144
|
-
"od",
|
|
145
|
-
"do",
|
|
146
|
-
"dnia",
|
|
147
|
-
"na",
|
|
148
|
-
"za"
|
|
149
|
-
],
|
|
150
|
-
"it": [
|
|
151
|
-
"dal",
|
|
152
|
-
"al",
|
|
153
|
-
"fino",
|
|
154
|
-
"da"
|
|
155
|
-
],
|
|
156
|
-
"es": [
|
|
157
|
-
"del",
|
|
158
|
-
"al",
|
|
159
|
-
"desde",
|
|
160
|
-
"hasta"
|
|
161
|
-
],
|
|
162
|
-
"hu": ["tól", "ig"],
|
|
163
|
-
"ro": [
|
|
164
|
-
"de",
|
|
165
|
-
"din",
|
|
166
|
-
"până"
|
|
167
|
-
],
|
|
168
|
-
"sv": [
|
|
169
|
-
"från",
|
|
170
|
-
"till",
|
|
171
|
-
"den"
|
|
172
|
-
]
|
|
173
|
-
};
|
|
174
|
-
var address_prepositions_default = {
|
|
175
|
-
_comment,
|
|
176
|
-
address,
|
|
177
|
-
temporal
|
|
178
|
-
};
|
|
179
|
-
//#endregion
|
|
180
|
-
export { _comment, address, address_prepositions_default as default, temporal };
|
|
181
|
-
|
|
182
|
-
//# sourceMappingURL=address-prepositions.mjs.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"address-prepositions.mjs","names":[],"sources":["../src/data/address-prepositions.json"],"sourcesContent":[""],"mappings":""}
|