@prosopo/datasets-fs 0.1.18 → 0.1.19
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/dist/cli.d.ts +2 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +49 -0
- package/dist/cli.js.map +1 -0
- package/dist/flatten/args.d.ts +16 -0
- package/dist/flatten/args.d.ts.map +1 -0
- package/dist/flatten/args.js +8 -0
- package/dist/flatten/args.js.map +1 -0
- package/dist/flatten/cli.d.ts +18 -0
- package/dist/flatten/cli.d.ts.map +1 -0
- package/dist/flatten/cli.js +30 -0
- package/dist/flatten/cli.js.map +1 -0
- package/dist/flatten/flatten.d.ts +5 -0
- package/dist/flatten/flatten.d.ts.map +1 -0
- package/dist/flatten/flatten.js +65 -0
- package/dist/flatten/flatten.js.map +1 -0
- package/dist/flatten/index.d.ts +4 -0
- package/dist/flatten/index.d.ts.map +1 -0
- package/dist/flatten/index.js +4 -0
- package/dist/flatten/index.js.map +1 -0
- package/dist/generate/args.d.ts +37 -0
- package/dist/generate/args.d.ts.map +1 -0
- package/dist/generate/args.js +15 -0
- package/dist/generate/args.js.map +1 -0
- package/dist/generate/cli.d.ts +32 -0
- package/dist/generate/cli.d.ts.map +1 -0
- package/dist/generate/cli.js +62 -0
- package/dist/generate/cli.js.map +1 -0
- package/dist/generate/distinct/args.d.ts +49 -0
- package/dist/generate/distinct/args.d.ts.map +1 -0
- package/dist/generate/distinct/args.js +10 -0
- package/dist/generate/distinct/args.js.map +1 -0
- package/dist/generate/distinct/cli.d.ts +20 -0
- package/dist/generate/distinct/cli.d.ts.map +1 -0
- package/dist/generate/distinct/cli.js +31 -0
- package/dist/generate/distinct/cli.js.map +1 -0
- package/dist/generate/distinct/dummy.d.ts +2 -0
- package/dist/generate/distinct/dummy.d.ts.map +1 -0
- package/dist/generate/distinct/dummy.js +29 -0
- package/dist/generate/distinct/dummy.js.map +1 -0
- package/dist/generate/distinct/generate.d.ts +5 -0
- package/dist/generate/distinct/generate.d.ts.map +1 -0
- package/dist/generate/distinct/generate.js +186 -0
- package/dist/generate/distinct/generate.js.map +1 -0
- package/dist/generate/distinct/index.d.ts +4 -0
- package/dist/generate/distinct/index.d.ts.map +1 -0
- package/dist/generate/distinct/index.js +4 -0
- package/dist/generate/distinct/index.js.map +1 -0
- package/dist/generate/index.d.ts +5 -0
- package/dist/generate/index.d.ts.map +1 -0
- package/dist/generate/index.js +5 -0
- package/dist/generate/index.js.map +1 -0
- package/dist/generate/union/args.d.ts +52 -0
- package/dist/generate/union/args.d.ts.map +1 -0
- package/dist/generate/union/args.js +11 -0
- package/dist/generate/union/args.js.map +1 -0
- package/dist/generate/union/cli.d.ts +22 -0
- package/dist/generate/union/cli.d.ts.map +1 -0
- package/dist/generate/union/cli.js +35 -0
- package/dist/generate/union/cli.js.map +1 -0
- package/dist/generate/union/generate.d.ts +5 -0
- package/dist/generate/union/generate.d.ts.map +1 -0
- package/dist/generate/union/generate.js +168 -0
- package/dist/generate/union/generate.js.map +1 -0
- package/dist/generate/union/index.d.ts +4 -0
- package/dist/generate/union/index.d.ts.map +1 -0
- package/dist/generate/union/index.js +4 -0
- package/dist/generate/union/index.js.map +1 -0
- package/dist/generate/util.d.ts +6 -0
- package/dist/generate/util.d.ts.map +1 -0
- package/dist/generate/util.js +20 -0
- package/dist/generate/util.js.map +1 -0
- package/dist/get/args.d.ts +10 -0
- package/dist/get/args.d.ts.map +1 -0
- package/dist/get/args.js +6 -0
- package/dist/get/args.js.map +1 -0
- package/dist/get/cli.d.ts +14 -0
- package/dist/get/cli.d.ts.map +1 -0
- package/dist/get/cli.js +19 -0
- package/dist/get/cli.js.map +1 -0
- package/dist/get/get.d.ts +5 -0
- package/dist/get/get.d.ts.map +1 -0
- package/dist/get/get.js +60 -0
- package/dist/get/get.js.map +1 -0
- package/dist/get/index.d.ts +4 -0
- package/dist/get/index.d.ts.map +1 -0
- package/dist/get/index.js +4 -0
- package/dist/get/index.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +15 -0
- package/dist/index.js.map +1 -0
- package/dist/labels/args.d.ts +10 -0
- package/dist/labels/args.d.ts.map +1 -0
- package/dist/labels/args.js +6 -0
- package/dist/labels/args.js.map +1 -0
- package/dist/labels/cli.d.ts +14 -0
- package/dist/labels/cli.d.ts.map +1 -0
- package/dist/labels/cli.js +19 -0
- package/dist/labels/cli.js.map +1 -0
- package/dist/labels/index.d.ts +4 -0
- package/dist/labels/index.d.ts.map +1 -0
- package/dist/labels/index.js +4 -0
- package/dist/labels/index.js.map +1 -0
- package/dist/labels/labels.d.ts +5 -0
- package/dist/labels/labels.d.ts.map +1 -0
- package/dist/labels/labels.js +22 -0
- package/dist/labels/labels.js.map +1 -0
- package/dist/relocate/args.d.ts +16 -0
- package/dist/relocate/args.d.ts.map +1 -0
- package/dist/relocate/args.js +8 -0
- package/dist/relocate/args.js.map +1 -0
- package/dist/relocate/cli.d.ts +18 -0
- package/dist/relocate/cli.d.ts.map +1 -0
- package/dist/relocate/cli.js +29 -0
- package/dist/relocate/cli.js.map +1 -0
- package/dist/relocate/relocate.d.ts +5 -0
- package/dist/relocate/relocate.d.ts.map +1 -0
- package/dist/relocate/relocate.js +40 -0
- package/dist/relocate/relocate.js.map +1 -0
- package/dist/scale/args.d.ts +22 -0
- package/dist/scale/args.d.ts.map +1 -0
- package/dist/scale/args.js +10 -0
- package/dist/scale/args.js.map +1 -0
- package/dist/scale/cli.d.ts +22 -0
- package/dist/scale/cli.d.ts.map +1 -0
- package/dist/scale/cli.js +38 -0
- package/dist/scale/cli.js.map +1 -0
- package/dist/scale/index.d.ts +4 -0
- package/dist/scale/index.d.ts.map +1 -0
- package/dist/scale/index.js +4 -0
- package/dist/scale/index.js.map +1 -0
- package/dist/scale/scale.d.ts +5 -0
- package/dist/scale/scale.d.ts.map +1 -0
- package/dist/scale/scale.js +67 -0
- package/dist/scale/scale.js.map +1 -0
- package/package.json +4 -4
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
import { CaptchaTypes, CaptchasContainerSchema, DataSchema, LabelledDataSchema, LabelsContainerSchema, } from '@prosopo/types';
|
|
2
|
+
import { ProsopoEnvError, getLoggerDefault } from '@prosopo/common';
|
|
3
|
+
import { at, get, lodash, setSeedGlobal } from '@prosopo/util';
|
|
4
|
+
import { blake2AsHex } from '@polkadot/util-crypto';
|
|
5
|
+
import { checkDuplicates } from '../util.js';
|
|
6
|
+
import bcrypt from 'bcrypt';
|
|
7
|
+
import cliProgress from 'cli-progress';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
export default async (args, logger) => {
|
|
10
|
+
logger = logger || getLoggerDefault();
|
|
11
|
+
logger.debug(args, 'generating...');
|
|
12
|
+
const outFile = args.out;
|
|
13
|
+
const overwrite = args.overwrite || false;
|
|
14
|
+
if (!overwrite && fs.existsSync(outFile)) {
|
|
15
|
+
throw new ProsopoEnvError(new Error(`output file already exists: ${outFile}`), 'FS.FILE_ALREADY_EXISTS');
|
|
16
|
+
}
|
|
17
|
+
const labelledMapFile = args.labelled;
|
|
18
|
+
if (labelledMapFile && !fs.existsSync(labelledMapFile)) {
|
|
19
|
+
throw new ProsopoEnvError(new Error(`labelled map file does not exist: ${labelledMapFile}`), 'FS.FILE_NOT_FOUND');
|
|
20
|
+
}
|
|
21
|
+
const unlabelledMapFile = args.unlabelled;
|
|
22
|
+
if (unlabelledMapFile && !fs.existsSync(unlabelledMapFile)) {
|
|
23
|
+
throw new ProsopoEnvError(new Error(`unlabelled map file does not exist: ${unlabelledMapFile}`), 'FS.FILE_NOT_FOUND');
|
|
24
|
+
}
|
|
25
|
+
const labelsFile = args.labels;
|
|
26
|
+
const seed = args.seed || 0;
|
|
27
|
+
const size = args.size || 9;
|
|
28
|
+
const minCorrect = args.minCorrect || 1;
|
|
29
|
+
const maxCorrect = args.maxCorrect || size - 1;
|
|
30
|
+
const solved = args.solved || 0;
|
|
31
|
+
const unsolved = args.unsolved || 0;
|
|
32
|
+
const saltRounds = 10;
|
|
33
|
+
const allowDuplicatesLabelled = args.allowDuplicatesLabelled || args.allowDuplicates || false;
|
|
34
|
+
const allowDuplicatesUnlabelled = args.allowDuplicatesUnlabelled || args.allowDuplicates || false;
|
|
35
|
+
// set the seed
|
|
36
|
+
setSeedGlobal(seed);
|
|
37
|
+
// get lodash (with seeded rng)
|
|
38
|
+
const _ = lodash();
|
|
39
|
+
// load the map to get the labelled and unlabelled data
|
|
40
|
+
const labelled = labelledMapFile
|
|
41
|
+
? LabelledDataSchema.parse(JSON.parse(fs.readFileSync(labelledMapFile, 'utf8'))).items
|
|
42
|
+
: [];
|
|
43
|
+
const unlabelled = unlabelledMapFile
|
|
44
|
+
? DataSchema.parse(JSON.parse(fs.readFileSync(unlabelledMapFile, 'utf8'))).items
|
|
45
|
+
: [];
|
|
46
|
+
// check for duplicates
|
|
47
|
+
checkDuplicates(labelled, unlabelled, {
|
|
48
|
+
allowDuplicatesLabelled,
|
|
49
|
+
allowDuplicatesUnlabelled,
|
|
50
|
+
});
|
|
51
|
+
// split the labelled data by label
|
|
52
|
+
const labelToImages = {};
|
|
53
|
+
for (const entry of labelled) {
|
|
54
|
+
const arr = labelToImages[entry.label] || [];
|
|
55
|
+
arr.push(entry);
|
|
56
|
+
labelToImages[entry.label] = arr;
|
|
57
|
+
}
|
|
58
|
+
const targets = Object.keys(labelToImages);
|
|
59
|
+
// load the labels from file
|
|
60
|
+
// these are the labels that unlabelled data will be assigned to
|
|
61
|
+
// note that these can be different to the labels in the map file as the labelled data is independent of the unlabelled data in terms of labels
|
|
62
|
+
const labels = [];
|
|
63
|
+
if (labelsFile && fs.existsSync(labelsFile)) {
|
|
64
|
+
labels.push(...[...LabelsContainerSchema.parse(JSON.parse(fs.readFileSync(labelsFile, 'utf8'))).labels]);
|
|
65
|
+
}
|
|
66
|
+
else {
|
|
67
|
+
// else default to the labels in the labelled data
|
|
68
|
+
labels.push(...[...targets]);
|
|
69
|
+
}
|
|
70
|
+
// generate n solved captchas
|
|
71
|
+
const solvedCaptchas = [];
|
|
72
|
+
// create a new progress bar instance and use shades_classic theme
|
|
73
|
+
const barSolved = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
|
74
|
+
logger.info(`Generating ${solved} solved captchas...`);
|
|
75
|
+
barSolved.start(solved, 0);
|
|
76
|
+
for (let i = 0; i < solved; i++) {
|
|
77
|
+
// update the current value in your application..
|
|
78
|
+
barSolved.update(i + 1);
|
|
79
|
+
if (targets.length <= 1) {
|
|
80
|
+
throw new ProsopoEnvError(new Error(`not enough different labels in labelled data: ${labelledMapFile}`), 'DATASET.NOT_ENOUGH_LABELS');
|
|
81
|
+
}
|
|
82
|
+
// uniformly sample targets
|
|
83
|
+
const target = at(targets, i % targets.length);
|
|
84
|
+
const notTargets = targets.filter((t) => t !== target);
|
|
85
|
+
// how many correct items should be in the captcha?
|
|
86
|
+
const nCorrect = _.random(minCorrect, maxCorrect);
|
|
87
|
+
// how many incorrect items should be in the captcha?
|
|
88
|
+
const nIncorrect = size - nCorrect;
|
|
89
|
+
const targetItems = get(labelToImages, target);
|
|
90
|
+
const notTargetItems = notTargets.map((notTarget) => get(labelToImages, notTarget)).flat();
|
|
91
|
+
if (targetItems.length < nCorrect) {
|
|
92
|
+
throw new ProsopoEnvError(new Error(`not enough images for target (${target})`), 'DATASET.NOT_ENOUGH_IMAGES');
|
|
93
|
+
}
|
|
94
|
+
if (notTargetItems.length < nIncorrect) {
|
|
95
|
+
throw new ProsopoEnvError(new Error(`not enough non-matching images for target (${target})`), 'DATASET.NOT_ENOUGH_IMAGES');
|
|
96
|
+
}
|
|
97
|
+
// get the correct items
|
|
98
|
+
const correctItems = _.sampleSize(targetItems, nCorrect);
|
|
99
|
+
// get the incorrect items
|
|
100
|
+
const incorrectItems = _.sampleSize(notTargetItems, nIncorrect);
|
|
101
|
+
let items = [...correctItems, ...incorrectItems];
|
|
102
|
+
let indices = [...Array(items.length).keys()];
|
|
103
|
+
indices = _.shuffle(indices);
|
|
104
|
+
items = indices.map((i) => at(items, i));
|
|
105
|
+
items = items.map((item) => {
|
|
106
|
+
return {
|
|
107
|
+
data: item.data,
|
|
108
|
+
hash: item.hash,
|
|
109
|
+
type: item.type,
|
|
110
|
+
};
|
|
111
|
+
});
|
|
112
|
+
// the first n indices are the correct items
|
|
113
|
+
const solution = indices
|
|
114
|
+
.map((index, i) => {
|
|
115
|
+
return {
|
|
116
|
+
pre: index,
|
|
117
|
+
post: i, // the index of the item in the shuffled array
|
|
118
|
+
};
|
|
119
|
+
})
|
|
120
|
+
.filter((item) => item.pre < correctItems.length) // keep all items that were in the first n slots of the original item array - these were the correct items
|
|
121
|
+
.map((item) => {
|
|
122
|
+
return item.post; // return the index in the shuffled array
|
|
123
|
+
});
|
|
124
|
+
const salt = blake2AsHex(bcrypt.genSaltSync(saltRounds));
|
|
125
|
+
// create the captcha
|
|
126
|
+
const captcha = {
|
|
127
|
+
salt,
|
|
128
|
+
target,
|
|
129
|
+
items,
|
|
130
|
+
solution,
|
|
131
|
+
};
|
|
132
|
+
solvedCaptchas.push(captcha);
|
|
133
|
+
}
|
|
134
|
+
barSolved.stop();
|
|
135
|
+
logger.info(`Generating ${unsolved} unsolved captchas...`);
|
|
136
|
+
// create a new progress bar instance and use shades_classic theme
|
|
137
|
+
const barUnsolved = new cliProgress.SingleBar({}, cliProgress.Presets.shades_classic);
|
|
138
|
+
barUnsolved.start(unsolved, 0);
|
|
139
|
+
// generate n unsolved captchas
|
|
140
|
+
const unsolvedCaptchas = [];
|
|
141
|
+
for (let i = 0; i < unsolved; i++) {
|
|
142
|
+
barUnsolved.update(i + 1);
|
|
143
|
+
if (unlabelled.length <= size) {
|
|
144
|
+
throw new ProsopoEnvError(new Error(`unlabelled map file does not contain enough data: ${unlabelledMapFile}`), 'DATASET.NOT_ENOUGH_IMAGES');
|
|
145
|
+
}
|
|
146
|
+
// pick a random label to be the target
|
|
147
|
+
// note that these are potentially different to the labelled data labels
|
|
148
|
+
if (labels.length <= 0) {
|
|
149
|
+
throw new ProsopoEnvError(new Error(`no labels found for unlabelled data: ${labelsFile}`), 'DATASET.NOT_ENOUGH_LABELS');
|
|
150
|
+
}
|
|
151
|
+
const index = _.random(0, labels.length - 1);
|
|
152
|
+
const target = at(labels, index);
|
|
153
|
+
// randomly pick images from the unlabelled data
|
|
154
|
+
const itemSet = _.sampleSize(unlabelled, size);
|
|
155
|
+
// shuffle the items
|
|
156
|
+
let items = [...itemSet];
|
|
157
|
+
let indices = [...Array(items.length).keys()];
|
|
158
|
+
indices = _.shuffle(indices);
|
|
159
|
+
items = indices.map((i) => at(items, i));
|
|
160
|
+
items = items.map((item) => {
|
|
161
|
+
return {
|
|
162
|
+
data: item.data,
|
|
163
|
+
hash: item.hash,
|
|
164
|
+
type: item.type,
|
|
165
|
+
};
|
|
166
|
+
});
|
|
167
|
+
const salt = blake2AsHex(bcrypt.genSaltSync(saltRounds));
|
|
168
|
+
// create the captcha
|
|
169
|
+
const captcha = {
|
|
170
|
+
salt,
|
|
171
|
+
target,
|
|
172
|
+
items,
|
|
173
|
+
};
|
|
174
|
+
unsolvedCaptchas.push(captcha);
|
|
175
|
+
}
|
|
176
|
+
barUnsolved.stop();
|
|
177
|
+
// write to file
|
|
178
|
+
const output = {
|
|
179
|
+
captchas: [...solvedCaptchas, ...unsolvedCaptchas],
|
|
180
|
+
format: CaptchaTypes.SelectAll,
|
|
181
|
+
};
|
|
182
|
+
// verify the output
|
|
183
|
+
CaptchasContainerSchema.parse(output);
|
|
184
|
+
fs.writeFileSync(outFile, JSON.stringify(output, null, 4));
|
|
185
|
+
};
|
|
186
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/generate/distinct/generate.ts"],"names":[],"mappings":"AACA,OAAO,EACH,YAAY,EAGZ,uBAAuB,EACvB,UAAU,EAEV,kBAAkB,EAElB,qBAAqB,GAExB,MAAM,gBAAgB,CAA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
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/generate/distinct/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/generate/distinct/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/generate/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/generate/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,QAAQ,MAAM,qBAAqB,CAAA;AAC/C,OAAO,KAAK,KAAK,MAAM,kBAAkB,CAAA;AACzC,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
export declare const argsSchema: z.ZodObject<{
|
|
3
|
+
out: z.ZodString;
|
|
4
|
+
overwrite: z.ZodOptional<z.ZodBoolean>;
|
|
5
|
+
labels: z.ZodOptional<z.ZodString>;
|
|
6
|
+
labelled: z.ZodOptional<z.ZodString>;
|
|
7
|
+
unlabelled: z.ZodOptional<z.ZodString>;
|
|
8
|
+
seed: z.ZodOptional<z.ZodNumber>;
|
|
9
|
+
size: z.ZodOptional<z.ZodNumber>;
|
|
10
|
+
allowDuplicates: z.ZodOptional<z.ZodBoolean>;
|
|
11
|
+
allowDuplicatesLabelled: z.ZodOptional<z.ZodBoolean>;
|
|
12
|
+
allowDuplicatesUnlabelled: z.ZodOptional<z.ZodBoolean>;
|
|
13
|
+
minCorrect: z.ZodOptional<z.ZodNumber>;
|
|
14
|
+
minIncorrect: z.ZodOptional<z.ZodNumber>;
|
|
15
|
+
minLabelled: z.ZodOptional<z.ZodNumber>;
|
|
16
|
+
maxLabelled: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
count: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
}, "strip", z.ZodTypeAny, {
|
|
19
|
+
out: string;
|
|
20
|
+
overwrite?: boolean | undefined;
|
|
21
|
+
labels?: string | undefined;
|
|
22
|
+
labelled?: string | undefined;
|
|
23
|
+
unlabelled?: string | undefined;
|
|
24
|
+
seed?: number | undefined;
|
|
25
|
+
size?: number | undefined;
|
|
26
|
+
allowDuplicates?: boolean | undefined;
|
|
27
|
+
allowDuplicatesLabelled?: boolean | undefined;
|
|
28
|
+
allowDuplicatesUnlabelled?: boolean | undefined;
|
|
29
|
+
minCorrect?: number | undefined;
|
|
30
|
+
minIncorrect?: number | undefined;
|
|
31
|
+
minLabelled?: number | undefined;
|
|
32
|
+
maxLabelled?: number | undefined;
|
|
33
|
+
count?: number | undefined;
|
|
34
|
+
}, {
|
|
35
|
+
out: string;
|
|
36
|
+
overwrite?: boolean | undefined;
|
|
37
|
+
labels?: string | undefined;
|
|
38
|
+
labelled?: string | undefined;
|
|
39
|
+
unlabelled?: string | undefined;
|
|
40
|
+
seed?: number | undefined;
|
|
41
|
+
size?: number | undefined;
|
|
42
|
+
allowDuplicates?: boolean | undefined;
|
|
43
|
+
allowDuplicatesLabelled?: boolean | undefined;
|
|
44
|
+
allowDuplicatesUnlabelled?: boolean | undefined;
|
|
45
|
+
minCorrect?: number | undefined;
|
|
46
|
+
minIncorrect?: number | undefined;
|
|
47
|
+
minLabelled?: number | undefined;
|
|
48
|
+
maxLabelled?: number | undefined;
|
|
49
|
+
count?: number | undefined;
|
|
50
|
+
}>;
|
|
51
|
+
export type Args = z.infer<typeof argsSchema>;
|
|
52
|
+
//# sourceMappingURL=args.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.d.ts","sourceRoot":"","sources":["../../../src/generate/union/args.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,eAAO,MAAM,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAMrB,CAAA;AAEF,MAAM,MAAM,IAAI,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,UAAU,CAAC,CAAA"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { argsSchema as parentSchema } from '../args.js';
|
|
2
|
+
// Args for generating a dataset
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
export const argsSchema = parentSchema.extend({
|
|
5
|
+
minCorrect: z.number().optional(),
|
|
6
|
+
minIncorrect: z.number().optional(),
|
|
7
|
+
minLabelled: z.number().optional(),
|
|
8
|
+
maxLabelled: z.number().optional(),
|
|
9
|
+
count: z.number().optional(),
|
|
10
|
+
});
|
|
11
|
+
//# sourceMappingURL=args.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"args.js","sourceRoot":"","sources":["../../../src/generate/union/args.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,IAAI,YAAY,EAAE,MAAM,YAAY,CAAA;AACvD,gCAAgC;AAEhC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC,MAAM,CAAC;IAC1C,UAAU,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACjC,YAAY,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IACnC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;IAClC,KAAK,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,QAAQ,EAAE;CAC/B,CAAC,CAAA"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ArgumentsCamelCase, Argv } from 'yargs';
|
|
2
|
+
import { Logger } from '@prosopo/common';
|
|
3
|
+
declare const _default: (cmdArgs?: {
|
|
4
|
+
logger?: Logger;
|
|
5
|
+
}) => {
|
|
6
|
+
command: string;
|
|
7
|
+
describe: string;
|
|
8
|
+
builder: (yargs: Argv) => Argv<{
|
|
9
|
+
count: number | undefined;
|
|
10
|
+
} & {
|
|
11
|
+
"min-correct": number | undefined;
|
|
12
|
+
} & {
|
|
13
|
+
"min-incorrect": number | undefined;
|
|
14
|
+
} & {
|
|
15
|
+
"min-labelled": number | undefined;
|
|
16
|
+
} & {
|
|
17
|
+
"max-labelled": number | undefined;
|
|
18
|
+
}>;
|
|
19
|
+
handler: (argv: ArgumentsCamelCase) => Promise<void>;
|
|
20
|
+
};
|
|
21
|
+
export default _default;
|
|
22
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../../src/generate/union/cli.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,OAAO,CAAA;AAChD,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAA;mCAId;IAAE,MAAM,CAAC,EAAE,MAAM,CAAA;CAAE;;;qBAKpB,IAAI;;;;;;;;;;;oBAuBC,kBAAkB;;AA5BhD,wBAgCC"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { argsSchema } from './args.js';
|
|
2
|
+
import generate from './generate.js';
|
|
3
|
+
export default (cmdArgs) => {
|
|
4
|
+
return {
|
|
5
|
+
command: 'union',
|
|
6
|
+
describe: 'Generate distinct captchas producing captcha challenges comprising one or more rounds, mixing labelled and unlabelled data into a single round',
|
|
7
|
+
builder: (yargs) => {
|
|
8
|
+
return yargs
|
|
9
|
+
.option('count', {
|
|
10
|
+
type: 'number',
|
|
11
|
+
description: 'Number of captchas to generate',
|
|
12
|
+
})
|
|
13
|
+
.option('min-correct', {
|
|
14
|
+
type: 'number',
|
|
15
|
+
description: 'Minimum number of target images in each captcha',
|
|
16
|
+
})
|
|
17
|
+
.option('min-incorrect', {
|
|
18
|
+
type: 'number',
|
|
19
|
+
description: 'Minimum number of incorrect images in each captcha',
|
|
20
|
+
})
|
|
21
|
+
.option('min-labelled', {
|
|
22
|
+
type: 'number',
|
|
23
|
+
description: 'Minimum number of labelled images in each captcha',
|
|
24
|
+
})
|
|
25
|
+
.option('max-labelled', {
|
|
26
|
+
type: 'number',
|
|
27
|
+
description: 'Maximum number of labelled images in each captcha',
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
handler: async (argv) => {
|
|
31
|
+
await generate(argsSchema.parse(argv), cmdArgs?.logger);
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
//# sourceMappingURL=cli.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../../../src/generate/union/cli.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AACtC,OAAO,QAAQ,MAAM,eAAe,CAAA;AAEpC,eAAe,CAAC,OAA6B,EAAE,EAAE;IAC7C,OAAO;QACH,OAAO,EAAE,OAAO;QAChB,QAAQ,EACJ,gJAAgJ;QACpJ,OAAO,EAAE,CAAC,KAAW,EAAE,EAAE;YACrB,OAAO,KAAK;iBACP,MAAM,CAAC,OAAO,EAAE;gBACb,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,gCAAgC;aAChD,CAAC;iBACD,MAAM,CAAC,aAAa,EAAE;gBACnB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,iDAAiD;aACjE,CAAC;iBACD,MAAM,CAAC,eAAe,EAAE;gBACrB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,oDAAoD;aACpE,CAAC;iBACD,MAAM,CAAC,cAAc,EAAE;gBACpB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,mDAAmD;aACnE,CAAC;iBACD,MAAM,CAAC,cAAc,EAAE;gBACpB,IAAI,EAAE,QAAQ;gBACd,WAAW,EAAE,mDAAmD;aACnE,CAAC,CAAA;QACV,CAAC;QACD,OAAO,EAAE,KAAK,EAAE,IAAwB,EAAE,EAAE;YACxC,MAAM,QAAQ,CAAC,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;QAC3D,CAAC;KACJ,CAAA;AACL,CAAC,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.d.ts","sourceRoot":"","sources":["../../../src/generate/union/generate.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAahC,OAAO,EAAE,MAAM,EAAqC,MAAM,iBAAiB,CAAA;+BAO/C,IAAI,WAAW,MAAM;AAAjD,wBA8LC"}
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
import { CaptchaTypes, CaptchasContainerSchema, DataSchema, LabelledDataSchema, LabelsContainerSchema, } from '@prosopo/types';
|
|
2
|
+
import { ProsopoEnvError, getLoggerDefault } from '@prosopo/common';
|
|
3
|
+
import { at, get, lodash, setSeedGlobal } from '@prosopo/util';
|
|
4
|
+
import { blake2AsHex } from '@polkadot/util-crypto';
|
|
5
|
+
import { checkDuplicates } from '../util.js';
|
|
6
|
+
import bcrypt from 'bcrypt';
|
|
7
|
+
import fs from 'fs';
|
|
8
|
+
export default async (args, logger) => {
|
|
9
|
+
logger = logger || getLoggerDefault();
|
|
10
|
+
logger.debug(args, 'generating...');
|
|
11
|
+
const outFile = args.out;
|
|
12
|
+
const overwrite = args.overwrite || false;
|
|
13
|
+
if (!overwrite && fs.existsSync(outFile)) {
|
|
14
|
+
throw new ProsopoEnvError(new Error(`Output file already exists: ${outFile}`), 'FS.FILE_ALREADY_EXISTS');
|
|
15
|
+
}
|
|
16
|
+
const labelledMapFile = args.labelled;
|
|
17
|
+
if (labelledMapFile && !fs.existsSync(labelledMapFile)) {
|
|
18
|
+
throw new ProsopoEnvError(new Error(`Labelled map file does not exist: ${labelledMapFile}`), 'FS.FILE_NOT_FOUND');
|
|
19
|
+
}
|
|
20
|
+
const unlabelledMapFile = args.unlabelled;
|
|
21
|
+
if (unlabelledMapFile && !fs.existsSync(unlabelledMapFile)) {
|
|
22
|
+
throw new ProsopoEnvError(new Error(`Unlabelled map file does not exist: ${unlabelledMapFile}`), 'FS.FILE_NOT_FOUND');
|
|
23
|
+
}
|
|
24
|
+
const labelsFile = args.labels;
|
|
25
|
+
const seed = args.seed || 0;
|
|
26
|
+
const size = args.size || 9;
|
|
27
|
+
const minCorrect = args.minCorrect || 1;
|
|
28
|
+
const saltRounds = 10;
|
|
29
|
+
const allowDuplicatesLabelled = args.allowDuplicatesLabelled || args.allowDuplicates || false;
|
|
30
|
+
const allowDuplicatesUnlabelled = args.allowDuplicatesUnlabelled || args.allowDuplicates || false;
|
|
31
|
+
const minIncorrect = Math.max(args.minIncorrect || 1, 1); // at least 1 incorrect image
|
|
32
|
+
const minLabelled = minCorrect + minIncorrect; // min incorrect + correct
|
|
33
|
+
const maxLabelled = Math.min(args.maxLabelled || size, size); // at least 1 labelled image
|
|
34
|
+
const count = args.count || 0;
|
|
35
|
+
// set the seed
|
|
36
|
+
setSeedGlobal(seed);
|
|
37
|
+
// get lodash (with seeded rng)
|
|
38
|
+
const _ = lodash();
|
|
39
|
+
// the captcha contains n images. Each of these images are either labelled, being correct or incorrect against the target, or unlabelled. To construct one of these captchas, we need to decide how many of the images should be labelled vs unlabelled, and then how many of the labelled images should be correct vs incorrect
|
|
40
|
+
// in the traditional captcha, two rounds are produced, one with labelled images and the other with unlabelled images. This gives 18 images overall, 9 labels produced.
|
|
41
|
+
// the parameters for generation can regulate how many labels are collected vs how much of a test the captcha posses. E.g. 18 images could have 16 unlabelled and 2 labelled, or 2 unlabelled and 16 labelled. The former is a better test of the user being human, but the latter is a better for maximising label collection.
|
|
42
|
+
// if we focus on a single captcha round of 9 images, we must have at least 1 labelled correct image in the captcha for it to work, otherwise it's just a labelling phase, which normally isn't a problem but if we're treating these as tests for humanity too then we need some kind of test in there. (e.g. we abolish the labelled then unlabelled pattern of the challenge rounds in favour of mixing labelled and unlabelled data, but we then run a small chance of serving two completely unlabelled rounds if we don't set the min number of labelled images to 1 per captcha round)
|
|
43
|
+
// load the map to get the labelled and unlabelled data
|
|
44
|
+
const labelled = labelledMapFile
|
|
45
|
+
? LabelledDataSchema.parse(JSON.parse(fs.readFileSync(labelledMapFile, 'utf8'))).items
|
|
46
|
+
: [];
|
|
47
|
+
const unlabelled = unlabelledMapFile
|
|
48
|
+
? DataSchema.parse(JSON.parse(fs.readFileSync(unlabelledMapFile, 'utf8'))).items
|
|
49
|
+
: [];
|
|
50
|
+
// check for duplicates
|
|
51
|
+
checkDuplicates(labelled, unlabelled, {
|
|
52
|
+
allowDuplicatesLabelled,
|
|
53
|
+
allowDuplicatesUnlabelled,
|
|
54
|
+
});
|
|
55
|
+
// split the labelled data by label
|
|
56
|
+
const labelToImages = {};
|
|
57
|
+
for (const entry of labelled) {
|
|
58
|
+
const arr = labelToImages[entry.label] || [];
|
|
59
|
+
arr.push(entry);
|
|
60
|
+
labelToImages[entry.label] = arr;
|
|
61
|
+
}
|
|
62
|
+
const targets = Object.keys(labelToImages);
|
|
63
|
+
// load the labels from file
|
|
64
|
+
// these are the labels that unlabelled data will be assigned to
|
|
65
|
+
// note that these can be differen to the labels in the map file as the labelled data is independent of the unlabelled data in terms of labels
|
|
66
|
+
const labels = [];
|
|
67
|
+
if (labelsFile && fs.existsSync(labelsFile)) {
|
|
68
|
+
labels.push(...[...LabelsContainerSchema.parse(JSON.parse(fs.readFileSync(labelsFile, 'utf8'))).labels]);
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
// else use the labels from the labelled data
|
|
72
|
+
labels.push(...[...targets]);
|
|
73
|
+
}
|
|
74
|
+
// generate n captchas
|
|
75
|
+
const captchas = [];
|
|
76
|
+
for (let i = 0; i < count; i++) {
|
|
77
|
+
logger.info(`generating captcha ${i + 1} of ${count}`);
|
|
78
|
+
if (targets.length <= 1) {
|
|
79
|
+
throw new ProsopoEnvError(new Error(`not enough different labels in labelled data: ${labelledMapFile}`), 'DATASET.NOT_ENOUGH_LABELS');
|
|
80
|
+
}
|
|
81
|
+
// uniformly sample targets
|
|
82
|
+
const target = at(targets, i % targets.length);
|
|
83
|
+
const notTargets = targets.filter((t) => t !== target);
|
|
84
|
+
// how many labelled images should be in the captcha?
|
|
85
|
+
const nLabelled = _.random(minLabelled, maxLabelled);
|
|
86
|
+
// how many correct labelled images should be in the captcha?
|
|
87
|
+
const maxCorrect = nLabelled - minCorrect;
|
|
88
|
+
const nCorrect = _.random(minCorrect, maxCorrect);
|
|
89
|
+
const nIncorrect = nLabelled - nCorrect;
|
|
90
|
+
const nUnlabelled = size - nLabelled;
|
|
91
|
+
const targetItems = get(labelToImages, target);
|
|
92
|
+
const notTargetItems = notTargets.map((notTarget) => get(labelToImages, notTarget)).flat();
|
|
93
|
+
if (nUnlabelled > unlabelled.length) {
|
|
94
|
+
throw new ProsopoEnvError(new Error(`not enough unlabelled data`), 'DATASET.NOT_ENOUGH_IMAGES');
|
|
95
|
+
}
|
|
96
|
+
if (nCorrect > targetItems.length) {
|
|
97
|
+
throw new ProsopoEnvError(new Error(`not enough images for target (${target})`), 'DATASET.NOT_ENOUGH_IMAGES');
|
|
98
|
+
}
|
|
99
|
+
if (nIncorrect > notTargetItems.length) {
|
|
100
|
+
throw new ProsopoEnvError(new Error(`not enough non-matching images for target (${target})`), 'DATASET.NOT_ENOUGH_IMAGES');
|
|
101
|
+
}
|
|
102
|
+
// get the correct items
|
|
103
|
+
const correctItems = _.sampleSize(targetItems, nCorrect);
|
|
104
|
+
// get the incorrect items
|
|
105
|
+
const incorrectItems = _.sampleSize(notTargetItems, nIncorrect);
|
|
106
|
+
// get the unlabelled items
|
|
107
|
+
const unlabelledItems = new Set();
|
|
108
|
+
while (unlabelledItems.size < size - nLabelled) {
|
|
109
|
+
// get a random image from the unlabelled data
|
|
110
|
+
const image = at(unlabelled, _.random(0, unlabelled.length - 1));
|
|
111
|
+
unlabelledItems.add(image);
|
|
112
|
+
}
|
|
113
|
+
let items = [...correctItems, ...incorrectItems, ...unlabelledItems];
|
|
114
|
+
let indices = [...Array(items.length).keys()];
|
|
115
|
+
indices = _.shuffle(indices);
|
|
116
|
+
items = indices.map((i) => at(items, i));
|
|
117
|
+
items = items.map((item) => {
|
|
118
|
+
return {
|
|
119
|
+
data: item.data,
|
|
120
|
+
hash: item.hash,
|
|
121
|
+
type: item.type,
|
|
122
|
+
};
|
|
123
|
+
});
|
|
124
|
+
// the first n indices are the correct items
|
|
125
|
+
const solution = indices
|
|
126
|
+
.map((index, i) => {
|
|
127
|
+
return {
|
|
128
|
+
pre: index,
|
|
129
|
+
post: i, // the index of the item in the shuffled array
|
|
130
|
+
};
|
|
131
|
+
})
|
|
132
|
+
.filter((item) => item.pre < correctItems.length) // keep all items that were in the first n slots of the original item array - these were the correct items
|
|
133
|
+
.map((item) => {
|
|
134
|
+
return item.post; // return the index in the shuffled array
|
|
135
|
+
});
|
|
136
|
+
// the unlabelled indices were after the correct and incorrect
|
|
137
|
+
const unlabelledIndices = indices
|
|
138
|
+
.map((index, i) => {
|
|
139
|
+
return {
|
|
140
|
+
pre: index,
|
|
141
|
+
post: i, // the index of the item in the shuffled array
|
|
142
|
+
};
|
|
143
|
+
})
|
|
144
|
+
.filter((item) => item.pre >= correctItems.length + incorrectItems.length) // keep all items that were in the first n slots of the original item array - these were the correct items
|
|
145
|
+
.map((item) => {
|
|
146
|
+
return item.post; // return the index in the shuffled array
|
|
147
|
+
});
|
|
148
|
+
const salt = blake2AsHex(bcrypt.genSaltSync(saltRounds));
|
|
149
|
+
// create the captcha
|
|
150
|
+
const captcha = {
|
|
151
|
+
salt,
|
|
152
|
+
target,
|
|
153
|
+
items,
|
|
154
|
+
solution,
|
|
155
|
+
unlabelled: unlabelledIndices,
|
|
156
|
+
};
|
|
157
|
+
captchas.push(captcha);
|
|
158
|
+
}
|
|
159
|
+
// write to file
|
|
160
|
+
const output = {
|
|
161
|
+
captchas,
|
|
162
|
+
format: CaptchaTypes.SelectAll,
|
|
163
|
+
};
|
|
164
|
+
// verify the output
|
|
165
|
+
CaptchasContainerSchema.parse(output);
|
|
166
|
+
fs.writeFileSync(outFile, JSON.stringify(output, null, 4));
|
|
167
|
+
};
|
|
168
|
+
//# sourceMappingURL=generate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"generate.js","sourceRoot":"","sources":["../../../src/generate/union/generate.ts"],"names":[],"mappings":"AACA,OAAO,EACH,YAAY,EAGZ,uBAAuB,EACvB,UAAU,EAEV,kBAAkB,EAElB,qBAAqB,GAExB,MAAM,gBAAgB,CAAA;AACvB,OAAO,EAAU,eAAe,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAC3E,OAAO,EAAE,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,eAAe,CAAA;AAC9D,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnD,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAC5C,OAAO,MAAM,MAAM,QAAQ,CAAA;AAC3B,OAAO,EAAE,MAAM,IAAI,CAAA;AAEnB,eAAe,KAAK,EAAE,IAAU,EAAE,MAAe,EAAE,EAAE;IACjD,MAAM,GAAG,MAAM,IAAI,gBAAgB,EAAE,CAAA;IAErC,MAAM,CAAC,KAAK,CAAC,IAAI,EAAE,eAAe,CA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,WAAW,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/generate/union/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAA;AAC7B,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { Item, LabelledItem } from '@prosopo/types';
|
|
2
|
+
export declare const checkDuplicates: (labelled: LabelledItem[], unlabelled: Item[], options: {
|
|
3
|
+
allowDuplicatesLabelled?: boolean;
|
|
4
|
+
allowDuplicatesUnlabelled?: boolean;
|
|
5
|
+
}) => void;
|
|
6
|
+
//# sourceMappingURL=util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.d.ts","sourceRoot":"","sources":["../../src/generate/util.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAEnD,eAAO,MAAM,eAAe,aACd,YAAY,EAAE,cACZ,IAAI,EAAE,WACT;IACL,uBAAuB,CAAC,EAAE,OAAO,CAAA;IACjC,yBAAyB,CAAC,EAAE,OAAO,CAAA;CACtC,SAmBJ,CAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export const checkDuplicates = (labelled, unlabelled, options) => {
|
|
2
|
+
// check for duplicates
|
|
3
|
+
const all = new Set();
|
|
4
|
+
if (!options.allowDuplicatesLabelled) {
|
|
5
|
+
for (const entry of labelled) {
|
|
6
|
+
if (all.has(entry.data)) {
|
|
7
|
+
throw new Error(`Duplicate data entry in labelled data: ${JSON.stringify(entry)}`);
|
|
8
|
+
}
|
|
9
|
+
all.add(entry.data);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
if (!options.allowDuplicatesUnlabelled) {
|
|
13
|
+
for (const entry of unlabelled) {
|
|
14
|
+
if (all.has(entry.data)) {
|
|
15
|
+
throw new Error(`Duplicate data entry in unlabelled data: ${JSON.stringify(entry)}`);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../../src/generate/util.ts"],"names":[],"mappings":"AAEA,MAAM,CAAC,MAAM,eAAe,GAAG,CAC3B,QAAwB,EACxB,UAAkB,EAClB,OAGC,EACH,EAAE;IACA,uBAAuB;IACvB,MAAM,GAAG,GAAG,IAAI,GAAG,EAAU,CAAA;IAC7B,IAAI,CAAC,OAAO,CAAC,uBAAuB,EAAE;QAClC,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE;YAC1B,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;gBACrB,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;aACrF;YACD,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;SACtB;KACJ;IACD,IAAI,CAAC,OAAO,CAAC,yBAAyB,EAAE;QACpC,KAAK,MAAM,KAAK,IAAI,UAAU,EAAE;YAC5B,IAAI,GAAG,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,EAAE;gBACrB,MAAM,IAAI,KAAK,CAAC,4CAA4C,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAA;aACvF;SACJ;KACJ;AACL,CAAC,CAAA"}
|