paperlint 18.2.1 → 18.3.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/.github/dependabot.yml +17 -0
- package/.github/workflows/ci.yml +30 -5
- package/CLAUDE.md +2 -1
- package/dist/domain/register.d.ts +1 -1
- package/dist/domain/register.d.ts.map +1 -1
- package/dist/domain/sentences.d.ts +3 -11
- package/dist/domain/sentences.d.ts.map +1 -1
- package/dist/domain/sentences.js +53 -8
- package/dist/domain/sentences.js.map +1 -1
- package/dist/eslint-rules/CLAUDE.md.spec.js +2 -2
- package/dist/eslint-rules/CLAUDE.md.spec.js.map +1 -1
- package/dist/folder-venue-rule.js +1 -1
- package/dist/readability.d.ts +12 -9
- package/dist/readability.d.ts.map +1 -1
- package/dist/readability.js +3 -3
- package/dist/readability.js.map +1 -1
- package/docs/design/paper-sources.md +1 -1
- package/docs/e2e.md +2 -2
- package/docs/optional-rules.md +2 -2
- package/docs/rules/pdf/body-size.md +1 -1
- package/docs/rules/tex/heading-case.md +2 -2
- package/docs/rules/tex/max-paragraph-numbers.md +13 -7
- package/docs/rules/tex/max-paragraph-words.md +17 -28
- package/docs/rules/tex/max-sentence-words.md +3 -2
- package/docs/rules/tex/negated-sentences.md +2 -2
- package/docs/rules/tex/register.md +1 -1
- package/docs/rules/tex/term-before-definition.md +1 -1
- package/docs/rules.md +3 -3
- package/docs/venues.md +1 -1
- package/docs/website.md +61 -5
- package/eslint-rules/CLAUDE.md +3 -3
- package/eslint-rules/CLAUDE.md.spec.ts +2 -2
- package/eslint.config.mjs +15 -4
- package/fixtures/real-papers.test.ts +24 -19
- package/package.json +4 -5
- package/presets/acm-sigconf.jsonc +1 -1
- package/presets/aidc-2026.jsonc +4 -4
- package/presets/aidc-2026.md +1 -1
- package/presets/ase-2026.md +1 -1
- package/presets/ieee-conference.jsonc +1 -1
- package/presets/msr-2027.jsonc +1 -1
- package/presets/neurips-style.jsonc +2 -2
- package/presets/neurips-style.md +1 -1
- package/presets/sp-2027.md +1 -1
- package/presets/venue-profile.schema.json +1 -1
- package/scripts/check.ts +9 -1
- package/scripts/coverage-config.test.ts +2 -0
- package/scripts/grow-real-papers/archive.test.ts +294 -0
- package/scripts/grow-real-papers/archive.ts +287 -0
- package/scripts/grow-real-papers/collect.test.ts +329 -0
- package/scripts/grow-real-papers/collect.ts +316 -0
- package/scripts/grow-real-papers/http.test.ts +95 -0
- package/scripts/grow-real-papers/http.ts +76 -0
- package/scripts/grow-real-papers/main.test.ts +295 -0
- package/scripts/grow-real-papers/main.ts +221 -0
- package/scripts/grow-real-papers/paper.test.ts +305 -0
- package/scripts/grow-real-papers/paper.ts +241 -0
- package/scripts/grow-real-papers/rules.test.ts +222 -0
- package/scripts/grow-real-papers/rules.ts +250 -0
- package/scripts/grow-real-papers/sources.test.ts +275 -0
- package/scripts/grow-real-papers/sources.ts +239 -0
- package/scripts/grow-real-papers/testkit.ts +79 -0
- package/src/domain/register.ts +1 -1
- package/src/domain/sentences.test.ts +128 -0
- package/src/domain/sentences.ts +60 -11
- package/src/folder-venue-rule.test.ts +1 -1
- package/src/folder-venue-rule.ts +1 -1
- package/src/readability.test.ts +82 -41
- package/src/readability.ts +12 -9
- package/src/register-bands.test.ts +4 -4
- package/src/rule-cases.test.ts +6 -6
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The walk over a fake world: which candidates are judged, in what order, why each is rejected,
|
|
3
|
+
* when an edition is full, and that quotas and caps count the whole manifest, earlier batches too.
|
|
4
|
+
*/
|
|
5
|
+
import { describe, expect, test } from "vitest";
|
|
6
|
+
import {
|
|
7
|
+
collect,
|
|
8
|
+
targets,
|
|
9
|
+
type Counted,
|
|
10
|
+
type ProbeLine,
|
|
11
|
+
type Queries,
|
|
12
|
+
type Walk,
|
|
13
|
+
} from "./collect.ts";
|
|
14
|
+
import type { KeptPaper } from "./paper.ts";
|
|
15
|
+
import type { Slot } from "./rules.ts";
|
|
16
|
+
import { fakeGet, mainTex, tarGz, type Route } from "./testkit.ts";
|
|
17
|
+
|
|
18
|
+
const BY = "http://creativecommons.org/licenses/by/4.0/";
|
|
19
|
+
const slot: Slot = {
|
|
20
|
+
field: "nlp",
|
|
21
|
+
series: "ACL",
|
|
22
|
+
year: 2025,
|
|
23
|
+
cap: 1,
|
|
24
|
+
queries: ['co:"ACL 2025"'],
|
|
25
|
+
max_results: 50,
|
|
26
|
+
venue: "acl",
|
|
27
|
+
classSpec: "acl",
|
|
28
|
+
};
|
|
29
|
+
const queries = (over: Partial<Queries> = {}): Queries => ({
|
|
30
|
+
hardCap: 5,
|
|
31
|
+
maxPages: 1,
|
|
32
|
+
quotas: { nlp: 9 },
|
|
33
|
+
slots: [slot],
|
|
34
|
+
...over,
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
const entry = (id: string, comment: string) =>
|
|
38
|
+
`<entry><id>http://arxiv.org/abs/${id}</id><updated>2025-05-01</updated><title>T</title><arxiv:comment>${comment}</arxiv:comment></entry>`;
|
|
39
|
+
const feed = (es: readonly (readonly [string, string])[]) =>
|
|
40
|
+
`<feed>${es.map(([id, c]) => entry(id, c)).join("")}</feed>`;
|
|
41
|
+
const ACCEPTED = "Accepted at ACL 2025";
|
|
42
|
+
const camera = tarGz([
|
|
43
|
+
{
|
|
44
|
+
name: "main.tex",
|
|
45
|
+
body: mainTex("Hi.", "\\documentclass{article}\\usepackage{acl}"),
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
48
|
+
|
|
49
|
+
/** A world where each id has a licence and an e-print, and the search lists `listed` in order. */
|
|
50
|
+
function world(
|
|
51
|
+
listed: readonly (readonly [string, string])[],
|
|
52
|
+
papers: Readonly<Record<string, Readonly<{ licence?: Route; src?: Route }>>>,
|
|
53
|
+
) {
|
|
54
|
+
const routes: (readonly [string, Route])[] = [
|
|
55
|
+
["api/query", feed(listed)],
|
|
56
|
+
...Object.entries(papers).flatMap(([id, p]) => [
|
|
57
|
+
[`arXiv.org:${id}&`, p.licence ?? `<license>${BY}</license>`] as const,
|
|
58
|
+
[`src/${id}`, p.src ?? camera] as const,
|
|
59
|
+
]),
|
|
60
|
+
];
|
|
61
|
+
return fakeGet(routes);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
async function walk(over: Partial<Walk> & Pick<Walk, "get">) {
|
|
65
|
+
const lines: ProbeLine[] = [];
|
|
66
|
+
const kept: KeptPaper[] = [];
|
|
67
|
+
const ends = await collect({
|
|
68
|
+
queries: queries(),
|
|
69
|
+
only: null,
|
|
70
|
+
entries: [],
|
|
71
|
+
otherIds: new Set(),
|
|
72
|
+
logged: [],
|
|
73
|
+
shipped: new Set(),
|
|
74
|
+
outOfTime: () => false,
|
|
75
|
+
emit: (line, paper) => {
|
|
76
|
+
lines.push(line);
|
|
77
|
+
if (paper !== undefined) kept.push(paper);
|
|
78
|
+
},
|
|
79
|
+
...over,
|
|
80
|
+
});
|
|
81
|
+
return {
|
|
82
|
+
ends,
|
|
83
|
+
kept: kept.map((k) => k.id),
|
|
84
|
+
log: lines.map((l) => [l.rank, l.id, l.outcome, l.reason]),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
describe("rules 1 to 4 in the fixed order", () => {
|
|
89
|
+
test("each candidate's first failing rule is its reason; the first passing are kept", async () => {
|
|
90
|
+
const big = mainTex(
|
|
91
|
+
"x".repeat(300_001),
|
|
92
|
+
"\\documentclass{article}\\usepackage{acl}",
|
|
93
|
+
);
|
|
94
|
+
const { get } = world(
|
|
95
|
+
[
|
|
96
|
+
["p0", "Submitted to ACL 2025"],
|
|
97
|
+
["p1", ACCEPTED],
|
|
98
|
+
["p2", ACCEPTED],
|
|
99
|
+
["p3", ACCEPTED],
|
|
100
|
+
["p4", ACCEPTED],
|
|
101
|
+
["p5", ACCEPTED],
|
|
102
|
+
["p6", ACCEPTED],
|
|
103
|
+
["p7", ACCEPTED],
|
|
104
|
+
["p8", ACCEPTED],
|
|
105
|
+
["p9", ACCEPTED],
|
|
106
|
+
],
|
|
107
|
+
{
|
|
108
|
+
p1: { licence: { status: "503 after 4 attempts" } },
|
|
109
|
+
p2: { licence: "<record/>" },
|
|
110
|
+
p3: { src: { status: "403" } },
|
|
111
|
+
p4: { src: "%PDF" },
|
|
112
|
+
p5: { src: tarGz([{ name: "a.bib", body: "" }]) },
|
|
113
|
+
p6: {
|
|
114
|
+
src: tarGz([
|
|
115
|
+
{ name: "m.tex", body: mainTex("", "\\documentclass{revtex4}") },
|
|
116
|
+
]),
|
|
117
|
+
},
|
|
118
|
+
p7: { src: tarGz([{ name: "m.tex", body: big }]) },
|
|
119
|
+
p8: {},
|
|
120
|
+
p9: {},
|
|
121
|
+
},
|
|
122
|
+
);
|
|
123
|
+
const r = await walk({ get, queries: queries({ quotas: { nlp: 1 } }) });
|
|
124
|
+
// Guards: one reason per rule, in the order the rules run, and the walk stops when full.
|
|
125
|
+
expect(r.log).toEqual([
|
|
126
|
+
[1, "p0", "rejected", 'not accepted wording: comment says "Submitted"'],
|
|
127
|
+
[2, "p1", "rejected", "download failed: OAI 503 after 4 attempts"],
|
|
128
|
+
[3, "p2", "rejected", "licence arXiv default (none)"],
|
|
129
|
+
[4, "p3", "rejected", "download failed: src 403"],
|
|
130
|
+
[5, "p4", "rejected", "no source: not gzip (PDF-only submission)"],
|
|
131
|
+
[6, "p5", "rejected", "no main .tex found"],
|
|
132
|
+
[7, "p6", "rejected", "template: class revtex4, not article"],
|
|
133
|
+
[
|
|
134
|
+
8,
|
|
135
|
+
"p7",
|
|
136
|
+
"rejected",
|
|
137
|
+
`>300KB of text sources (${String(big.length)} bytes)`,
|
|
138
|
+
],
|
|
139
|
+
[9, "p8", "kept", "passes rules 1-4"],
|
|
140
|
+
]);
|
|
141
|
+
// Guards: how the edition's walk ended, and where.
|
|
142
|
+
expect(r.ends).toEqual([
|
|
143
|
+
{ slot: "nlp/ACL 2025", ended: "full", walkedTo: 9 },
|
|
144
|
+
]);
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
describe("quotas and caps are totals over the manifest", () => {
|
|
149
|
+
const earlier: readonly Counted[] = [
|
|
150
|
+
{ arxiv_id: "old1", field: "nlp", series: "ACL", year: 2024 },
|
|
151
|
+
{ arxiv_id: "old2", field: "nlp", series: "ACL", year: 2024 },
|
|
152
|
+
];
|
|
153
|
+
const three = () =>
|
|
154
|
+
world(
|
|
155
|
+
[
|
|
156
|
+
["n1", ACCEPTED],
|
|
157
|
+
["n2", ACCEPTED],
|
|
158
|
+
["n3", ACCEPTED],
|
|
159
|
+
],
|
|
160
|
+
{ n1: {}, n2: {}, n3: {} },
|
|
161
|
+
);
|
|
162
|
+
|
|
163
|
+
test("a quota already met adds nothing and asks nothing", async () => {
|
|
164
|
+
const { get, asked } = three();
|
|
165
|
+
const r = await walk({
|
|
166
|
+
get,
|
|
167
|
+
entries: earlier,
|
|
168
|
+
queries: queries({ quotas: { nlp: 2 } }),
|
|
169
|
+
});
|
|
170
|
+
// Guards: two earlier nlp papers fill a quota of 2; no request is made.
|
|
171
|
+
expect([r.kept, r.ends, asked]).toEqual([[], [], []]);
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
test("a raised quota adds only the difference", async () => {
|
|
175
|
+
const { get } = three();
|
|
176
|
+
const r = await walk({
|
|
177
|
+
get,
|
|
178
|
+
entries: earlier,
|
|
179
|
+
queries: queries({ quotas: { nlp: 3 } }),
|
|
180
|
+
});
|
|
181
|
+
// Guards: quota 3 with 2 earlier papers keeps exactly one.
|
|
182
|
+
expect(r.kept).toEqual(["n1"]);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
test("an edition holds at most its round's target, round-robin up to 5", async () => {
|
|
186
|
+
const { get } = three();
|
|
187
|
+
const fullEdition: readonly Counted[] = Array.from(
|
|
188
|
+
{ length: 5 },
|
|
189
|
+
(_, i) => ({
|
|
190
|
+
arxiv_id: `e${String(i)}`,
|
|
191
|
+
series: "ACL",
|
|
192
|
+
year: 2025,
|
|
193
|
+
}),
|
|
194
|
+
);
|
|
195
|
+
const r = await walk({ get, entries: fullEdition });
|
|
196
|
+
// Guards: five papers of ACL 2025 already, so the edition takes no more.
|
|
197
|
+
expect([r.kept, r.ends]).toEqual([[], []]);
|
|
198
|
+
// Guards: the rounds: cap 1 then 2…5 for one slot, a slot at 5 only in round 0.
|
|
199
|
+
expect(
|
|
200
|
+
targets([slot, { ...slot, series: "EMNLP", cap: 5 }], 5).map(
|
|
201
|
+
([s, t]) => `${s.series} ${String(t)}`,
|
|
202
|
+
),
|
|
203
|
+
).toEqual(["ACL 1", "EMNLP 5", "ACL 2", "ACL 3", "ACL 4", "ACL 5"]);
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
const logged = (
|
|
208
|
+
id: string,
|
|
209
|
+
reason: string,
|
|
210
|
+
outcome: "kept" | "rejected" = "rejected",
|
|
211
|
+
): ProbeLine => ({
|
|
212
|
+
id,
|
|
213
|
+
field: "nlp",
|
|
214
|
+
series: "ACL",
|
|
215
|
+
year: 2025,
|
|
216
|
+
rank: 1,
|
|
217
|
+
query: "q",
|
|
218
|
+
source: "arxiv-comment",
|
|
219
|
+
acceptance: "arxiv-comment",
|
|
220
|
+
outcome,
|
|
221
|
+
reason,
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
describe("a run resumes, skips and stops", () => {
|
|
225
|
+
test("a judged candidate is not judged again, a failed download is; a taken id is skipped", async () => {
|
|
226
|
+
const { get } = world(
|
|
227
|
+
[
|
|
228
|
+
["a1", ACCEPTED],
|
|
229
|
+
["a2v2", ACCEPTED],
|
|
230
|
+
["a3", ACCEPTED],
|
|
231
|
+
["a4", ACCEPTED],
|
|
232
|
+
["a5", ACCEPTED],
|
|
233
|
+
],
|
|
234
|
+
{ a1: {}, a2: {}, a3: {}, a4: {}, a5: {} },
|
|
235
|
+
);
|
|
236
|
+
const r = await walk({
|
|
237
|
+
get,
|
|
238
|
+
queries: queries({ quotas: { nlp: 2 }, hardCap: 1 }),
|
|
239
|
+
otherIds: new Set(["a2"]),
|
|
240
|
+
logged: [
|
|
241
|
+
logged("a1", "licence arXiv default (none)"),
|
|
242
|
+
logged("a3", "download failed: src 503"),
|
|
243
|
+
logged("a4", "passes rules 1-4", "kept"),
|
|
244
|
+
],
|
|
245
|
+
});
|
|
246
|
+
// Guards: a1 and a4 stand as judged; a2 is a preprint already; a3's failed download is retried.
|
|
247
|
+
expect([r.log, r.ends]).toEqual([
|
|
248
|
+
[
|
|
249
|
+
[2, "a2v2", "rejected", "already in the corpora"],
|
|
250
|
+
[3, "a3", "kept", "passes rules 1-4"],
|
|
251
|
+
],
|
|
252
|
+
[{ slot: "nlp/ACL 2025", ended: "full", walkedTo: 3 }],
|
|
253
|
+
]);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
test("the time box stops the whole run; an exhausted edition moves on", async () => {
|
|
257
|
+
const { get } = world([["t1", "no"]], {});
|
|
258
|
+
const two = queries({
|
|
259
|
+
slots: [slot, { ...slot, series: "EMNLP", venue: "emnlp" }],
|
|
260
|
+
});
|
|
261
|
+
const ticks = { n: 0 };
|
|
262
|
+
const r = await walk({ get, queries: two, outOfTime: () => ++ticks.n > 1 });
|
|
263
|
+
// Guards: the first edition ran out of candidates, the second hit the deadline; nothing after it.
|
|
264
|
+
expect(r.ends).toEqual([
|
|
265
|
+
{ slot: "nlp/ACL 2025", ended: "exhausted", walkedTo: 1 },
|
|
266
|
+
{ slot: "nlp/EMNLP 2025", ended: "time", walkedTo: 0 },
|
|
267
|
+
]);
|
|
268
|
+
});
|
|
269
|
+
|
|
270
|
+
test("a search error ends the edition; --only and a field without a quota", async () => {
|
|
271
|
+
const failing = fakeGet([["api/query", { status: "503" }]]);
|
|
272
|
+
const r = await walk({ get: failing.get });
|
|
273
|
+
// Guards: the error is the edition's end.
|
|
274
|
+
expect(r.ends).toEqual([
|
|
275
|
+
{
|
|
276
|
+
slot: "nlp/ACL 2025",
|
|
277
|
+
ended: "search error",
|
|
278
|
+
walkedTo: 0,
|
|
279
|
+
error: 'co:"ACL 2025" page 0: 503',
|
|
280
|
+
},
|
|
281
|
+
]);
|
|
282
|
+
const other = queries({ slots: [slot, { ...slot, field: "ml" }] });
|
|
283
|
+
// Guards: --only leaves the other field out, and a field with no quota (ml) walks nothing.
|
|
284
|
+
expect(
|
|
285
|
+
(await walk({ get: failing.get, queries: other, only: ["ml"] })).ends,
|
|
286
|
+
).toEqual([]);
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
describe("from a Semantic Scholar listing", () => {
|
|
291
|
+
test("the listing's venue is rule 1, and an id arXiv does not describe is rejected", async () => {
|
|
292
|
+
const s2Slot: Slot = {
|
|
293
|
+
...slot,
|
|
294
|
+
source: "semantic-scholar",
|
|
295
|
+
s2Venue: "ACL",
|
|
296
|
+
};
|
|
297
|
+
const listing = JSON.stringify({
|
|
298
|
+
data: [
|
|
299
|
+
{ venue: "ACL", externalIds: { ArXiv: "s1" } },
|
|
300
|
+
{ venue: "ACL Workshop", externalIds: { ArXiv: "s2" } },
|
|
301
|
+
{ venue: "ACL", externalIds: { ArXiv: "s3" } },
|
|
302
|
+
],
|
|
303
|
+
});
|
|
304
|
+
const { get } = fakeGet([
|
|
305
|
+
["semanticscholar", listing],
|
|
306
|
+
[
|
|
307
|
+
"id_list=",
|
|
308
|
+
feed([
|
|
309
|
+
["s2v1", ""],
|
|
310
|
+
["s3v1", ""],
|
|
311
|
+
]),
|
|
312
|
+
],
|
|
313
|
+
["arXiv.org:s3&", `<license>${BY}</license>`],
|
|
314
|
+
["src/s3v1", camera],
|
|
315
|
+
]);
|
|
316
|
+
const r = await walk({ get, queries: queries({ slots: [s2Slot] }) });
|
|
317
|
+
// Guards: each listed id's reason, and the kept one.
|
|
318
|
+
expect(r.log).toEqual([
|
|
319
|
+
[1, "s1", "rejected", "arXiv metadata missing for the listed id"],
|
|
320
|
+
[
|
|
321
|
+
2,
|
|
322
|
+
"s2v1",
|
|
323
|
+
"rejected",
|
|
324
|
+
'S2 venue string is not the main proceedings: "ACL Workshop"',
|
|
325
|
+
],
|
|
326
|
+
[3, "s3v1", "kept", "passes rules 1-4"],
|
|
327
|
+
]);
|
|
328
|
+
});
|
|
329
|
+
});
|
|
@@ -0,0 +1,316 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The walk: for each field, the venue editions of `queries.json` in round-robin rounds; in each
|
|
3
|
+
* edition the candidates in their fixed order; each candidate through rules 1 to 4, the first
|
|
4
|
+
* failing rule logged as its reason; the first passing ones kept. Nothing is picked by hand.
|
|
5
|
+
*
|
|
6
|
+
* Quotas, caps and the 5 per edition are TOTALS over every entry of `venue-manifest.json`, earlier
|
|
7
|
+
* batches included: a field's quota counts the entries with that `field`, an edition's cap the
|
|
8
|
+
* entries of that series and year. So growing the set is raising a quota in `queries.json` and
|
|
9
|
+
* rerunning; a quota already met adds nothing.
|
|
10
|
+
*/
|
|
11
|
+
import { stagingPlan, sha256, unpack } from "./archive.ts";
|
|
12
|
+
import { keptPaper, type Candidate, type KeptPaper } from "./paper.ts";
|
|
13
|
+
import {
|
|
14
|
+
judgeClass,
|
|
15
|
+
judgeComment,
|
|
16
|
+
judgeLicence,
|
|
17
|
+
judgeListedVenue,
|
|
18
|
+
judgeSize,
|
|
19
|
+
PER_EDITION,
|
|
20
|
+
preambleOf,
|
|
21
|
+
type Preamble,
|
|
22
|
+
SlotSchema,
|
|
23
|
+
type Slot,
|
|
24
|
+
} from "./rules.ts";
|
|
25
|
+
import {
|
|
26
|
+
arxivCandidates,
|
|
27
|
+
baseId,
|
|
28
|
+
eprint,
|
|
29
|
+
licenceUrl,
|
|
30
|
+
s2Candidates,
|
|
31
|
+
type Found,
|
|
32
|
+
type Get,
|
|
33
|
+
} from "./sources.ts";
|
|
34
|
+
import * as R from "remeda";
|
|
35
|
+
import { z } from "zod";
|
|
36
|
+
|
|
37
|
+
export const QueriesSchema = z.object({
|
|
38
|
+
hardCap: z.number(),
|
|
39
|
+
maxPages: z.number(),
|
|
40
|
+
quotas: z.record(z.string(), z.number()),
|
|
41
|
+
slots: z.array(SlotSchema),
|
|
42
|
+
});
|
|
43
|
+
export type Queries = Readonly<z.infer<typeof QueriesSchema>>;
|
|
44
|
+
|
|
45
|
+
/** The part of a manifest entry the counts read. */
|
|
46
|
+
export const CountedSchema = z.looseObject({
|
|
47
|
+
arxiv_id: z.string(),
|
|
48
|
+
field: z.string().optional(),
|
|
49
|
+
series: z.string().optional(),
|
|
50
|
+
year: z.number().optional(),
|
|
51
|
+
});
|
|
52
|
+
export type Counted = Readonly<z.infer<typeof CountedSchema>>;
|
|
53
|
+
|
|
54
|
+
/** One line of `probe-log.jsonl`: every candidate that reached a rule, kept or with its reason. */
|
|
55
|
+
export const ProbeLineSchema = z.looseObject({
|
|
56
|
+
id: z.string(),
|
|
57
|
+
field: z.string(),
|
|
58
|
+
series: z.string(),
|
|
59
|
+
year: z.number(),
|
|
60
|
+
rank: z.number(),
|
|
61
|
+
query: z.string(),
|
|
62
|
+
source: z.enum(["arxiv-comment", "semantic-scholar"]),
|
|
63
|
+
acceptance: z.enum(["arxiv-comment", "s2-venue-listing"]),
|
|
64
|
+
outcome: z.enum(["kept", "rejected"]),
|
|
65
|
+
reason: z.string(),
|
|
66
|
+
});
|
|
67
|
+
export type ProbeLine = Readonly<z.infer<typeof ProbeLineSchema>>;
|
|
68
|
+
|
|
69
|
+
/** How a venue edition's walk ended. */
|
|
70
|
+
export type SlotEnd = Readonly<{
|
|
71
|
+
slot: string;
|
|
72
|
+
ended: "full" | "exhausted" | "time" | "search error";
|
|
73
|
+
walkedTo: number;
|
|
74
|
+
error?: string;
|
|
75
|
+
}>;
|
|
76
|
+
|
|
77
|
+
/** What the walk is given: the world through `get`, and everything already decided. */
|
|
78
|
+
export type Walk = Readonly<{
|
|
79
|
+
queries: Queries;
|
|
80
|
+
/** Only these fields; all when null. */
|
|
81
|
+
only: readonly string[] | null;
|
|
82
|
+
/** Every entry of the venue manifest (the counts) — with the preprints', the ids to skip. */
|
|
83
|
+
entries: readonly Counted[];
|
|
84
|
+
otherIds: ReadonlySet<string>;
|
|
85
|
+
/** Earlier log lines: a candidate already judged for this edition is not judged again. */
|
|
86
|
+
logged: readonly ProbeLine[];
|
|
87
|
+
shipped: ReadonlySet<string>;
|
|
88
|
+
get: Get;
|
|
89
|
+
outOfTime: () => boolean;
|
|
90
|
+
/** Called on each new log line, with the paper when it is kept, as soon as it is decided. */
|
|
91
|
+
emit: (line: ProbeLine, paper?: KeptPaper) => void | Promise<void>;
|
|
92
|
+
}>;
|
|
93
|
+
|
|
94
|
+
const edition = (
|
|
95
|
+
s: Readonly<{ series?: string | undefined; year?: number | undefined }>,
|
|
96
|
+
): string => `${String(s.series)} ${String(s.year)}`;
|
|
97
|
+
export const slotKey = (s: Slot): string =>
|
|
98
|
+
`${s.field}/${s.series} ${String(s.year)}`;
|
|
99
|
+
|
|
100
|
+
/** The rounds of one field: each slot's target per round, `cap + round`, at most `hardCap` and 5. */
|
|
101
|
+
export const targets = (
|
|
102
|
+
slots: readonly Slot[],
|
|
103
|
+
hardCap: number,
|
|
104
|
+
): readonly (readonly [Slot, number])[] => {
|
|
105
|
+
const cap = Math.min(hardCap, PER_EDITION);
|
|
106
|
+
return Array.from({ length: cap + 1 }, (_, round) => round).flatMap((round) =>
|
|
107
|
+
slots
|
|
108
|
+
.map((s) => [s, Math.min(cap, s.cap + round)] as const)
|
|
109
|
+
.filter(
|
|
110
|
+
([s, t]) => round === 0 || t !== Math.min(cap, s.cap + round - 1),
|
|
111
|
+
),
|
|
112
|
+
);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
type Judged = Readonly<{ reason: string; detail?: object; paper?: KeptPaper }>;
|
|
116
|
+
type Sources = Readonly<{
|
|
117
|
+
licence: Extract<ReturnType<typeof judgeLicence>, { ok: true }>;
|
|
118
|
+
plan: Extract<ReturnType<typeof stagingPlan>, { ok: true }>;
|
|
119
|
+
sourceSha: string;
|
|
120
|
+
}>;
|
|
121
|
+
|
|
122
|
+
/** Rule 2 and the download: the licence, then the e-print and what it stages. */
|
|
123
|
+
async function fetchSources(
|
|
124
|
+
get: Get,
|
|
125
|
+
id: string,
|
|
126
|
+
): Promise<Sources | Readonly<{ reason: string }>> {
|
|
127
|
+
const oai = await licenceUrl(get, id);
|
|
128
|
+
if (!oai.ok) return { reason: `download failed: OAI ${oai.status}` };
|
|
129
|
+
const licence = judgeLicence(oai.url);
|
|
130
|
+
if (!licence.ok) return licence;
|
|
131
|
+
const src = await eprint(get, id);
|
|
132
|
+
if (!src.ok) return { reason: `download failed: src ${src.status}` };
|
|
133
|
+
const files = unpack(src.bytes);
|
|
134
|
+
if (!files.ok) return files;
|
|
135
|
+
const plan = stagingPlan(files.files);
|
|
136
|
+
return plan.ok ? { licence, plan, sourceSha: sha256(src.bytes) } : plan;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Rules 3 and 4 on what the e-print staged: the class and style, then the size. */
|
|
140
|
+
function judgeStaged(
|
|
141
|
+
slot: Slot,
|
|
142
|
+
plan: Sources["plan"],
|
|
143
|
+
):
|
|
144
|
+
| Readonly<{ preamble: Preamble; style?: string; styleOpts?: string }>
|
|
145
|
+
| Judged {
|
|
146
|
+
const preamble = preambleOf(plan.mainText);
|
|
147
|
+
const cls = judgeClass(slot.classSpec, preamble);
|
|
148
|
+
if (!cls.ok)
|
|
149
|
+
return {
|
|
150
|
+
reason: cls.reason,
|
|
151
|
+
detail: { cls: preamble.cls, clsOpts: preamble.clsOpts },
|
|
152
|
+
};
|
|
153
|
+
const size = judgeSize(plan.size);
|
|
154
|
+
if (!size.ok) return { reason: size.reason };
|
|
155
|
+
return { preamble, ...R.omit(cls, ["ok"]) };
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** Rules 2 to 4, and the staging, for a candidate that passed rule 1. */
|
|
159
|
+
async function judgeSources(
|
|
160
|
+
w: Walk,
|
|
161
|
+
c: Candidate,
|
|
162
|
+
slot: Slot,
|
|
163
|
+
track: string | null,
|
|
164
|
+
): Promise<Judged> {
|
|
165
|
+
const got = await fetchSources(w.get, c.id);
|
|
166
|
+
if ("reason" in got) return { reason: got.reason };
|
|
167
|
+
const staged = judgeStaged(slot, got.plan);
|
|
168
|
+
if ("reason" in staged) return staged;
|
|
169
|
+
return {
|
|
170
|
+
reason: "passes rules 1-4",
|
|
171
|
+
detail: { licence: got.licence.name, comment: c.comment.slice(0, 200) },
|
|
172
|
+
paper: keptPaper({ ...got, ...staged, c, slot, track, shipped: w.shipped }),
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
/** What a walk remembers across editions: the counted entries, the ids taken, the pairs judged. */
|
|
177
|
+
type State = Readonly<{
|
|
178
|
+
counted: Counted[];
|
|
179
|
+
ids: Set<string>;
|
|
180
|
+
judged: Set<string>;
|
|
181
|
+
}>;
|
|
182
|
+
|
|
183
|
+
const judgedKey = (id: string, s: Readonly<{ series: string; year: number }>) =>
|
|
184
|
+
`${id} ${s.series} ${String(s.year)}`;
|
|
185
|
+
|
|
186
|
+
/** A failed download is judged again on the next run; every other verdict stands. */
|
|
187
|
+
const stateOf = (w: Walk): State => ({
|
|
188
|
+
counted: [...w.entries],
|
|
189
|
+
ids: new Set([...w.otherIds, ...w.entries.map((e) => baseId(e.arxiv_id))]),
|
|
190
|
+
judged: new Set(
|
|
191
|
+
w.logged
|
|
192
|
+
.filter(
|
|
193
|
+
(l) => l.outcome === "kept" || !l.reason.startsWith("download failed"),
|
|
194
|
+
)
|
|
195
|
+
.map((l) => judgedKey(l.id, l)),
|
|
196
|
+
),
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
/** Rule 1, then the rest, for one candidate. */
|
|
200
|
+
async function judge(w: Walk, st: State, c: Candidate, slot: Slot) {
|
|
201
|
+
if (st.ids.has(baseId(c.id))) return { reason: "already in the corpora" };
|
|
202
|
+
if (c.s2 !== undefined && c.updated === "")
|
|
203
|
+
return { reason: "arXiv metadata missing for the listed id" };
|
|
204
|
+
const rule1 =
|
|
205
|
+
c.s2 === undefined ? judgeComment(c, slot) : judgeListedVenue(c.s2.venue);
|
|
206
|
+
if (rule1.ok) return judgeSources(w, c, slot, rule1.track);
|
|
207
|
+
return {
|
|
208
|
+
reason: rule1.reason,
|
|
209
|
+
detail: c.s2 === undefined ? { comment: c.comment.slice(0, 160) } : {},
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
const lineOf = (slot: Slot, c: Candidate, v: Judged): ProbeLine => {
|
|
214
|
+
const s2 = slot.source === "semantic-scholar";
|
|
215
|
+
return {
|
|
216
|
+
id: c.id,
|
|
217
|
+
field: slot.field,
|
|
218
|
+
series: slot.series,
|
|
219
|
+
year: slot.year,
|
|
220
|
+
rank: c.rank,
|
|
221
|
+
query: c.query,
|
|
222
|
+
source: s2 ? "semantic-scholar" : "arxiv-comment",
|
|
223
|
+
acceptance: s2 ? "s2-venue-listing" : "arxiv-comment",
|
|
224
|
+
outcome: v.paper === undefined ? "rejected" : "kept",
|
|
225
|
+
reason: v.reason,
|
|
226
|
+
...v.detail,
|
|
227
|
+
};
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
/** Judges one candidate not judged before for this edition, counts it when kept, emits its line. */
|
|
231
|
+
async function probe(
|
|
232
|
+
w: Walk,
|
|
233
|
+
st: State,
|
|
234
|
+
slot: Slot,
|
|
235
|
+
c: Candidate,
|
|
236
|
+
): Promise<void> {
|
|
237
|
+
const key = judgedKey(c.id, slot);
|
|
238
|
+
if (st.judged.has(key)) return;
|
|
239
|
+
st.judged.add(key);
|
|
240
|
+
const verdict: Judged = await judge(w, st, c, slot);
|
|
241
|
+
if (verdict.paper !== undefined) {
|
|
242
|
+
const { field, series, year } = slot;
|
|
243
|
+
st.counted.push({ arxiv_id: c.id, field, series, year });
|
|
244
|
+
st.ids.add(baseId(c.id));
|
|
245
|
+
}
|
|
246
|
+
await w.emit(lineOf(slot, c, verdict), verdict.paper);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
type Stop = Omit<SlotEnd, "slot" | "walkedTo">;
|
|
250
|
+
|
|
251
|
+
/** The candidate to judge next, or why the walk stops before it. */
|
|
252
|
+
const next = (
|
|
253
|
+
f: Found,
|
|
254
|
+
w: Walk,
|
|
255
|
+
full: () => boolean,
|
|
256
|
+
): Readonly<{ stop: Stop }> | Readonly<{ candidate: Candidate }> => {
|
|
257
|
+
if ("searchError" in f)
|
|
258
|
+
return { stop: { ended: "search error", error: f.searchError } };
|
|
259
|
+
if (w.outOfTime()) return { stop: { ended: "time" } };
|
|
260
|
+
return full() ? { stop: { ended: "full" } } : { candidate: f };
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
async function walkSlot(
|
|
264
|
+
w: Walk,
|
|
265
|
+
st: State,
|
|
266
|
+
slot: Slot,
|
|
267
|
+
full: () => boolean,
|
|
268
|
+
): Promise<Omit<SlotEnd, "slot">> {
|
|
269
|
+
const found =
|
|
270
|
+
slot.source === "semantic-scholar"
|
|
271
|
+
? s2Candidates(w.get, slot)
|
|
272
|
+
: arxivCandidates(w.get, slot, w.queries.maxPages);
|
|
273
|
+
let walkedTo = 0;
|
|
274
|
+
for await (const f of found) {
|
|
275
|
+
const n = next(f, w, full);
|
|
276
|
+
if ("stop" in n) return { ...n.stop, walkedTo };
|
|
277
|
+
walkedTo = n.candidate.rank;
|
|
278
|
+
await probe(w, st, slot, n.candidate);
|
|
279
|
+
}
|
|
280
|
+
return { ended: full() ? "full" : "exhausted", walkedTo };
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* Walks every field of `w.queries`, and returns how each edition's walk ended. An edition is full
|
|
285
|
+
* when the manifest holds its round's target for it, or its field's quota: both TOTALS.
|
|
286
|
+
*/
|
|
287
|
+
export async function collect(w: Walk): Promise<readonly SlotEnd[]> {
|
|
288
|
+
const st = stateOf(w);
|
|
289
|
+
const count = (keep: (e: Counted) => boolean) =>
|
|
290
|
+
st.counted.filter(keep).length;
|
|
291
|
+
const slots = w.queries.slots.filter(
|
|
292
|
+
(s) => w.only === null || w.only.includes(s.field),
|
|
293
|
+
);
|
|
294
|
+
const order = [...new Set(slots.map((s) => s.field))].flatMap((field) =>
|
|
295
|
+
targets(
|
|
296
|
+
slots.filter((s) => s.field === field),
|
|
297
|
+
w.queries.hardCap,
|
|
298
|
+
),
|
|
299
|
+
);
|
|
300
|
+
const ends: SlotEnd[] = [];
|
|
301
|
+
// An edition that ran out of candidates or failed its search is not walked again in a later round.
|
|
302
|
+
const done = new Set<string>();
|
|
303
|
+
for (const [slot, target] of order) {
|
|
304
|
+
if (done.has(slotKey(slot))) continue;
|
|
305
|
+
const full = () =>
|
|
306
|
+
count((e) => edition(e) === edition(slot)) >= target ||
|
|
307
|
+
count((e) => e.field === slot.field) >=
|
|
308
|
+
(w.queries.quotas[slot.field] ?? 0);
|
|
309
|
+
if (full()) continue;
|
|
310
|
+
const end = await walkSlot(w, st, slot, full);
|
|
311
|
+
ends.push({ slot: slotKey(slot), ...end });
|
|
312
|
+
if (end.ended === "time") break;
|
|
313
|
+
if (end.ended !== "full") done.add(slotKey(slot));
|
|
314
|
+
}
|
|
315
|
+
return ends;
|
|
316
|
+
}
|