@proposit/proposit-core 5.0.0 → 5.2.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/README.md +3 -2
- package/dist/cli/builder-repl.js +1 -1
- package/dist/cli/builder-repl.js.map +1 -1
- package/dist/extensions/citations/ieee/citation-claim.d.ts +117 -56
- package/dist/extensions/citations/ieee/citation-claim.d.ts.map +1 -1
- package/dist/extensions/citations/ieee/formatting.d.ts +1 -1
- package/dist/extensions/citations/ieee/formatting.d.ts.map +1 -1
- package/dist/extensions/citations/ieee/formatting.js.map +1 -1
- package/dist/extensions/citations/ieee/origin-document.d.ts +117 -56
- package/dist/extensions/citations/ieee/origin-document.d.ts.map +1 -1
- package/dist/extensions/citations/ieee/references.d.ts +364 -169
- package/dist/extensions/citations/ieee/references.d.ts.map +1 -1
- package/dist/extensions/citations/ieee/references.js +42 -4
- package/dist/extensions/citations/ieee/references.js.map +1 -1
- package/dist/extensions/citations/ieee/relaxed.d.ts +351 -168
- package/dist/extensions/citations/ieee/relaxed.d.ts.map +1 -1
- package/dist/extensions/citations/ieee/segment-builder.d.ts.map +1 -1
- package/dist/extensions/citations/ieee/segment-builder.js +11 -7
- package/dist/extensions/citations/ieee/segment-builder.js.map +1 -1
- package/dist/extensions/citations/ieee/segment-templates.d.ts +2 -0
- package/dist/extensions/citations/ieee/segment-templates.d.ts.map +1 -1
- package/dist/extensions/citations/ieee/segment-templates.js +121 -11
- package/dist/extensions/citations/ieee/segment-templates.js.map +1 -1
- package/dist/extensions/openai/openai-retrieval.d.ts.map +1 -1
- package/dist/extensions/openai/openai-retrieval.js +4 -2
- package/dist/extensions/openai/openai-retrieval.js.map +1 -1
- package/dist/extensions/openai/openai-tools.d.ts +8 -1
- package/dist/extensions/openai/openai-tools.d.ts.map +1 -1
- package/dist/extensions/openai/openai-tools.js +10 -0
- package/dist/extensions/openai/openai-tools.js.map +1 -1
- package/dist/extensions/openai/provider.d.ts.map +1 -1
- package/dist/extensions/openai/provider.js +5 -3
- package/dist/extensions/openai/provider.js.map +1 -1
- package/dist/extensions/openai/types.d.ts +2 -1
- package/dist/extensions/openai/types.d.ts.map +1 -1
- package/dist/extensions/openai/types.js.map +1 -1
- package/dist/extensions/pipelines/base/finalize-response-v2.d.ts +9 -6
- package/dist/extensions/pipelines/base/finalize-response-v2.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/finalize-response-v2.js +101 -20
- package/dist/extensions/pipelines/base/finalize-response-v2.js.map +1 -1
- package/dist/extensions/pipelines/base/index.d.ts +1 -1
- package/dist/extensions/pipelines/base/index.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/index.js.map +1 -1
- package/dist/extensions/pipelines/base/source-anchors.d.ts +33 -2
- package/dist/extensions/pipelines/base/source-anchors.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/source-anchors.js +191 -13
- package/dist/extensions/pipelines/base/source-anchors.js.map +1 -1
- package/dist/extensions/pipelines/base/stages/axiom-indicator-detection.d.ts +1 -1
- package/dist/extensions/pipelines/base/stages/axiom-indicator-detection.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/stages/axiom-indicator-detection.js +1 -1
- package/dist/extensions/pipelines/base/stages/axiom-indicator-detection.js.map +1 -1
- package/dist/extensions/pipelines/base/stages/citation-source-detection.d.ts +1 -1
- package/dist/extensions/pipelines/base/stages/citation-source-detection.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/stages/citation-source-detection.js +1 -1
- package/dist/extensions/pipelines/base/stages/citation-source-detection.js.map +1 -1
- package/dist/extensions/pipelines/base/stages/claim-canonicalization.d.ts +3 -2
- package/dist/extensions/pipelines/base/stages/claim-canonicalization.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/stages/claim-canonicalization.js +2 -2
- package/dist/extensions/pipelines/base/stages/claim-canonicalization.js.map +1 -1
- package/dist/extensions/pipelines/base/stages/claim-mention-extraction.d.ts +1 -1
- package/dist/extensions/pipelines/base/stages/claim-mention-extraction.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/stages/claim-mention-extraction.js +1 -1
- package/dist/extensions/pipelines/base/stages/claim-mention-extraction.js.map +1 -1
- package/dist/extensions/pipelines/base/stages/claim-type-classification.d.ts +1 -1
- package/dist/extensions/pipelines/base/stages/claim-type-classification.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/stages/claim-type-classification.js +1 -1
- package/dist/extensions/pipelines/base/stages/claim-type-classification.js.map +1 -1
- package/dist/extensions/pipelines/base/stages/conclusion-selection.d.ts +26 -3
- package/dist/extensions/pipelines/base/stages/conclusion-selection.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/stages/conclusion-selection.js +40 -2
- package/dist/extensions/pipelines/base/stages/conclusion-selection.js.map +1 -1
- package/dist/extensions/pipelines/base/stages/index.d.ts +1 -1
- package/dist/extensions/pipelines/base/stages/index.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/stages/index.js +1 -1
- package/dist/extensions/pipelines/base/stages/index.js.map +1 -1
- package/dist/extensions/pipelines/base/stages/relation-extraction.d.ts +4 -3
- package/dist/extensions/pipelines/base/stages/relation-extraction.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/stages/relation-extraction.js +6 -4
- package/dist/extensions/pipelines/base/stages/relation-extraction.js.map +1 -1
- package/dist/extensions/pipelines/base/stages/segmentation.d.ts +1 -1
- package/dist/extensions/pipelines/base/stages/segmentation.d.ts.map +1 -1
- package/dist/extensions/pipelines/base/stages/segmentation.js +1 -1
- package/dist/extensions/pipelines/base/stages/segmentation.js.map +1 -1
- package/dist/extensions/pipelines/base/types.d.ts +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/extract-stage.d.ts +61 -10
- package/dist/extensions/pipelines/ingestion/scribe/extract-stage.d.ts.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/extract-stage.js +203 -14
- package/dist/extensions/pipelines/ingestion/scribe/extract-stage.js.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/schemas.d.ts +15 -2
- package/dist/extensions/pipelines/ingestion/scribe/schemas.d.ts.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/schemas.js +14 -2
- package/dist/extensions/pipelines/ingestion/scribe/schemas.js.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/scribe.js +2 -2
- package/dist/extensions/pipelines/ingestion/scribe/scribe.js.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/source-attachment.d.ts +29 -0
- package/dist/extensions/pipelines/ingestion/scribe/source-attachment.d.ts.map +1 -0
- package/dist/extensions/pipelines/ingestion/scribe/source-attachment.js +200 -0
- package/dist/extensions/pipelines/ingestion/scribe/source-attachment.js.map +1 -0
- package/dist/extensions/pipelines/ingestion/scribe/structure-stage.d.ts +5 -3
- package/dist/extensions/pipelines/ingestion/scribe/structure-stage.d.ts.map +1 -1
- package/dist/extensions/pipelines/ingestion/scribe/structure-stage.js +42 -14
- package/dist/extensions/pipelines/ingestion/scribe/structure-stage.js.map +1 -1
- package/dist/lib/core/parser/formula-gen.js +309 -46
- package/dist/lib/llm/types.d.ts +8 -2
- package/dist/lib/llm/types.d.ts.map +1 -1
- package/dist/lib/llm/types.js.map +1 -1
- package/dist/lib/pipelines/debug-log.js +1 -1
- package/dist/lib/pipelines/debug-log.js.map +1 -1
- package/dist/lib/pipelines/index.d.ts +1 -1
- package/dist/lib/pipelines/index.d.ts.map +1 -1
- package/dist/lib/pipelines/index.js.map +1 -1
- package/dist/lib/pipelines/llm-stage-helpers.d.ts +22 -1
- package/dist/lib/pipelines/llm-stage-helpers.d.ts.map +1 -1
- package/dist/lib/pipelines/llm-stage-helpers.js +21 -9
- package/dist/lib/pipelines/llm-stage-helpers.js.map +1 -1
- package/dist/lib/pipelines/single-stage.d.ts +9 -1
- package/dist/lib/pipelines/single-stage.d.ts.map +1 -1
- package/dist/lib/pipelines/single-stage.js +14 -3
- package/dist/lib/pipelines/single-stage.js.map +1 -1
- package/dist/lib/pipelines/stage-helpers.d.ts +1 -1
- package/dist/lib/pipelines/stage-helpers.d.ts.map +1 -1
- package/dist/lib/pipelines/stage-helpers.js.map +1 -1
- package/dist/lib/schemata/shared.d.ts.map +1 -1
- package/dist/lib/schemata/shared.js +8 -6
- package/dist/lib/schemata/shared.js.map +1 -1
- package/package.json +1 -1
|
@@ -13,7 +13,7 @@ import { llmStage } from "../../../../lib/pipelines/stage-helpers.js";
|
|
|
13
13
|
import { deterministicStage } from "../../../../lib/pipelines/stage-helpers.js";
|
|
14
14
|
import { STAGE_IDS, buildResponseSchema, ClaimMentionExtractionOutputSchema, ClaimTypeClassificationOutputSchema, } from "../../base/stages/index.js";
|
|
15
15
|
import { buildExtractOutputSchema, } from "./schemas.js";
|
|
16
|
-
export const EXTRACT_MODEL = "gpt-
|
|
16
|
+
export const EXTRACT_MODEL = "gpt-6-sol";
|
|
17
17
|
/** Internal default knobs for scribe's `extract` stage. */
|
|
18
18
|
export const EXTRACT_STAGE_DEFAULTS = {
|
|
19
19
|
model: EXTRACT_MODEL,
|
|
@@ -22,6 +22,10 @@ export const EXTRACT_SYSTEM_PROMPT = `You read a raw argument and emit its canon
|
|
|
22
22
|
|
|
23
23
|
For each distinct proposition the author makes, emit one canonical claim. Two phrasings of the same proposition merge into a single claim.
|
|
24
24
|
|
|
25
|
+
Every explicit link or URL the author offers as evidence becomes its own citation claim — one per distinct link, even when several links sit in one sentence or a link backs a claim you also emit as a normal claim.
|
|
26
|
+
|
|
27
|
+
Lines that begin with "> " quote someone else, usually the person the author is replying to. They are not the author's claims: never emit a claim from them, and use them only to understand what the author is responding to.
|
|
28
|
+
|
|
25
29
|
Also emit \`mentions\` — where in the input each claim is stated. One entry per place a claim is made:
|
|
26
30
|
- \`mentionId\` — "<claim miniId>-m" for the first mention of a claim, then "-m2", "-m3", ... for further ones (e.g. "c1-m", "c1-m2").
|
|
27
31
|
- \`text\` — the span of the input that states the claim, COPIED CHARACTER FOR CHARACTER from the input. Never reword, summarize, translate, correct, or join separated passages with an ellipsis, and do not change capitalization or punctuation — copy the first character exactly as the input has it, upper- or lower-case. Prefer the shortest span that states the claim on its own — usually one sentence or clause. A span that is not present in the input verbatim is discarded, and the claim loses its link back to the source.
|
|
@@ -32,10 +36,12 @@ Each canonical claim carries:
|
|
|
32
36
|
- \`miniId\` — assign in order: c1, c2, c3, ...
|
|
33
37
|
- \`mentionIds\` — the \`mentionId\`s of every mention that states this claim.
|
|
34
38
|
- \`type\` — "normal" (a primary proposition), "citation" (content is "the cited source asserts X"; populate \`url\` + \`title\`, and set \`citationTypeGuess\`), or "axiomatic" (invoked as self-evident; populate \`axiom\`).
|
|
39
|
+
- \`url\` (citation claims only) — a URL copied from the input exactly as written, scheme included. Never build one from a site name, domain or title ("www.example.org" is not "https://www.example.org/"); when the input gives the source no URL, use the empty string.
|
|
35
40
|
- \`citationTypeGuess\` (citation claims only) — your best guess at the source's IEEE reference type, chosen from the allowed values in your output schema (e.g. "JournalArticle", "NewspaperArticle", "Book", "Website", "GovernmentPublication", …). Use "unknown" when no IEEE type fits or you cannot tell.
|
|
36
41
|
- \`suggestedSymbol\` — a short PascalCase-or-snake_case identifier (letters/digits/underscores, starts with a letter or underscore, under 32 chars). Avoid single letters and generic names.
|
|
37
42
|
- the extension fields your output schema requires (title, body, url, axiom — whichever apply to the claim's type).
|
|
38
43
|
- \`mentionToClaim\` — one \`{ "mentionId": "...", "claimMiniId": "..." }\` entry per mention id you used.
|
|
44
|
+
- \`sourceSupport\` — one \`{ "sourceMiniId": "...", "supportedMiniId": "..." }\` entry per citation claim and per axiomatic claim: its miniId, and the miniId of the normal claim it is offered as evidence for, or invoked to justify — usually the claim stated in the same sentence, or just before it. The supported claim must be a normal claim, never a citation or axiomatic one.
|
|
39
45
|
|
|
40
46
|
Style:
|
|
41
47
|
- Third-person, present-tense, active voice.
|
|
@@ -45,7 +51,7 @@ Output ONLY the schema-shaped object. No prose.`;
|
|
|
45
51
|
function buildExtractPrompt(ctx) {
|
|
46
52
|
const input = ctx.input;
|
|
47
53
|
const system = `<!-- stage-id: ${STAGE_IDS.extract} -->\n${EXTRACT_SYSTEM_PROMPT}`;
|
|
48
|
-
const user = `Input text:\n\n${input.text}\n\nProduce the canonicalClaims + mentions + mentionToClaim object.`;
|
|
54
|
+
const user = `Input text:\n\n${input.text}\n\nProduce the canonicalClaims + mentions + mentionToClaim + sourceSupport object.`;
|
|
49
55
|
return { system, user };
|
|
50
56
|
}
|
|
51
57
|
/**
|
|
@@ -54,7 +60,7 @@ function buildExtractPrompt(ctx) {
|
|
|
54
60
|
* so the cheap model is asked for the same extension-shaped claim
|
|
55
61
|
* records (title/body/url/axiom) scholar's canonicalizer produces —
|
|
56
62
|
* without which finalize would assemble empty claims — plus the quoted
|
|
57
|
-
* spans those claims came from.
|
|
63
|
+
* spans those claims came from, plus which claim each source supports.
|
|
58
64
|
*/
|
|
59
65
|
export function createExtractStage(extension, options) {
|
|
60
66
|
return llmStage({
|
|
@@ -70,7 +76,9 @@ export function createExtractStage(extension, options) {
|
|
|
70
76
|
}
|
|
71
77
|
/**
|
|
72
78
|
* Adapter — republish `extract`'s canonical claims under the
|
|
73
|
-
* canonicalization slot scholar's deterministic stages + finalize read
|
|
79
|
+
* canonicalization slot scholar's deterministic stages + finalize read,
|
|
80
|
+
* after `settleCitations` has checked their urls and merged citations of
|
|
81
|
+
* the same page.
|
|
74
82
|
*
|
|
75
83
|
* It picks the two keys rather than passing the whole output through:
|
|
76
84
|
* the canonicalization envelope is `additionalProperties: false`, so
|
|
@@ -86,14 +94,193 @@ export function createExtractCanonicalizationAdapterStage(extension) {
|
|
|
86
94
|
dependsOn: [STAGE_IDS.extract],
|
|
87
95
|
outputSchema: buildResponseSchema(extension),
|
|
88
96
|
fn: (ctx) => {
|
|
89
|
-
const
|
|
97
|
+
const settled = settleCitations(ctx.get(STAGE_IDS.extract), ctx.input.text, ctx.addFailure);
|
|
90
98
|
return {
|
|
91
|
-
canonicalClaims:
|
|
92
|
-
mentionToClaim:
|
|
99
|
+
canonicalClaims: settled?.canonicalClaims ?? [],
|
|
100
|
+
mentionToClaim: settled?.mentionToClaim ?? [],
|
|
93
101
|
};
|
|
94
102
|
},
|
|
95
103
|
});
|
|
96
104
|
}
|
|
105
|
+
/**
|
|
106
|
+
* `extract`'s output with its citations settled: a url the input does not
|
|
107
|
+
* contain is cleared (`SOURCE_URL_NOT_IN_TEXT_FAILURE_CODE`), one it
|
|
108
|
+
* contains in a slightly different form takes the text's form, and
|
|
109
|
+
* citations of the same page are merged into one
|
|
110
|
+
* (`SOURCE_DUPLICATE_MERGED_FAILURE_CODE`) — the first, unless it is an
|
|
111
|
+
* archive copy and the original is also cited. The kept citation takes
|
|
112
|
+
* the merged ones' mentions and supports what any of them supported.
|
|
113
|
+
*
|
|
114
|
+
* Deterministic, so every stage that reads `extract` directly can call it
|
|
115
|
+
* and see the same claim set; only one of them should report.
|
|
116
|
+
*/
|
|
117
|
+
export function settleCitations(extract, inputText, addFailure) {
|
|
118
|
+
if (extract === undefined)
|
|
119
|
+
return undefined;
|
|
120
|
+
const claims = extract.canonicalClaims.map((claim) => {
|
|
121
|
+
const url = claim.url;
|
|
122
|
+
if (claim.type !== "citation" ||
|
|
123
|
+
typeof url !== "string" ||
|
|
124
|
+
url.trim().length === 0)
|
|
125
|
+
return claim;
|
|
126
|
+
const found = findUrlInText(url.trim(), inputText);
|
|
127
|
+
if (found !== undefined)
|
|
128
|
+
return { ...claim, url: found };
|
|
129
|
+
addFailure({
|
|
130
|
+
code: SOURCE_URL_NOT_IN_TEXT_FAILURE_CODE,
|
|
131
|
+
message: `Citation "${claim.miniId}" gave the url "${url}", which does not appear in the input; the url was cleared and the citation kept.`,
|
|
132
|
+
severity: "warning",
|
|
133
|
+
context: { miniId: claim.miniId, url },
|
|
134
|
+
});
|
|
135
|
+
return { ...claim, url: "" };
|
|
136
|
+
});
|
|
137
|
+
const groups = new Map();
|
|
138
|
+
for (const claim of claims) {
|
|
139
|
+
const url = claim.url;
|
|
140
|
+
if (claim.type !== "citation" || typeof url !== "string" || url === "")
|
|
141
|
+
continue;
|
|
142
|
+
const key = citationUrlKey(url);
|
|
143
|
+
groups.set(key, [...(groups.get(key) ?? []), claim]);
|
|
144
|
+
}
|
|
145
|
+
const keptByMiniId = new Map();
|
|
146
|
+
const mergedMentions = new Map();
|
|
147
|
+
for (const group of groups.values()) {
|
|
148
|
+
if (group.length < 2)
|
|
149
|
+
continue;
|
|
150
|
+
const kept = group.find((c) => !ARCHIVE_URL.test(c.url)) ?? group[0];
|
|
151
|
+
const merged = group.filter((c) => c !== kept);
|
|
152
|
+
for (const c of merged)
|
|
153
|
+
keptByMiniId.set(c.miniId, kept.miniId);
|
|
154
|
+
mergedMentions.set(kept.miniId, [
|
|
155
|
+
...new Set(group.flatMap((c) => [...c.mentionIds])),
|
|
156
|
+
]);
|
|
157
|
+
addFailure({
|
|
158
|
+
code: SOURCE_DUPLICATE_MERGED_FAILURE_CODE,
|
|
159
|
+
message: `Citations ${merged.map((c) => `"${c.miniId}"`).join(", ")} cite the same page as "${kept.miniId}" and were merged into it.`,
|
|
160
|
+
severity: "warning",
|
|
161
|
+
context: {
|
|
162
|
+
keptMiniId: kept.miniId,
|
|
163
|
+
mergedMiniIds: merged.map((c) => c.miniId),
|
|
164
|
+
},
|
|
165
|
+
});
|
|
166
|
+
}
|
|
167
|
+
if (keptByMiniId.size === 0)
|
|
168
|
+
return { ...extract, canonicalClaims: claims };
|
|
169
|
+
const resolve = (miniId) => keptByMiniId.get(miniId) ?? miniId;
|
|
170
|
+
const seenSupport = new Set();
|
|
171
|
+
return {
|
|
172
|
+
...extract,
|
|
173
|
+
canonicalClaims: claims
|
|
174
|
+
.filter((c) => !keptByMiniId.has(c.miniId))
|
|
175
|
+
.map((c) => {
|
|
176
|
+
const mentionIds = mergedMentions.get(c.miniId);
|
|
177
|
+
return mentionIds === undefined ? c : { ...c, mentionIds };
|
|
178
|
+
}),
|
|
179
|
+
mentionToClaim: extract.mentionToClaim.map((entry) => ({
|
|
180
|
+
...entry,
|
|
181
|
+
claimMiniId: resolve(entry.claimMiniId),
|
|
182
|
+
})),
|
|
183
|
+
sourceSupport: extract.sourceSupport.flatMap((entry) => {
|
|
184
|
+
const settled = {
|
|
185
|
+
sourceMiniId: resolve(entry.sourceMiniId),
|
|
186
|
+
supportedMiniId: resolve(entry.supportedMiniId),
|
|
187
|
+
};
|
|
188
|
+
const key = `${settled.sourceMiniId}\u0000${settled.supportedMiniId}`;
|
|
189
|
+
if (seenSupport.has(key))
|
|
190
|
+
return [];
|
|
191
|
+
seenSupport.add(key);
|
|
192
|
+
return [settled];
|
|
193
|
+
}),
|
|
194
|
+
};
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Warning code for a citation url `extract` reported that the input does
|
|
198
|
+
* not contain. A model asked for a source's url will build one from a bare
|
|
199
|
+
* site name ("www.gutenberg.org" in a reference list becomes
|
|
200
|
+
* "https://www.gutenberg.org/"), and a link the author never gave is worse
|
|
201
|
+
* than none — so the url is cleared and the citation kept, since the
|
|
202
|
+
* source itself is still named in the text.
|
|
203
|
+
*/
|
|
204
|
+
export const SOURCE_URL_NOT_IN_TEXT_FAILURE_CODE = "SOURCE_URL_NOT_IN_TEXT";
|
|
205
|
+
/**
|
|
206
|
+
* Warning code for citations merged because their urls name the same page.
|
|
207
|
+
* A reference list often links one work several ways — an archive copy
|
|
208
|
+
* beside the original, `/index.html` beside `/` — and each became its own
|
|
209
|
+
* citation claim. `context` carries `keptMiniId` and `mergedMiniIds`.
|
|
210
|
+
*/
|
|
211
|
+
export const SOURCE_DUPLICATE_MERGED_FAILURE_CODE = "SOURCE_DUPLICATE_MERGED";
|
|
212
|
+
/** A Wayback Machine copy: `web.archive.org/web/<timestamp>[flag_]/<url>`. */
|
|
213
|
+
const ARCHIVE_URL = /^(?:[a-z][a-z0-9+.-]*:\/\/)?(?:www\.)?web\.archive\.org\/web\/\d+[a-z_]*\/(.+)$/i;
|
|
214
|
+
/**
|
|
215
|
+
* What two citation urls must share to name the same page: the url with
|
|
216
|
+
* an archive copy unwrapped to its original, http and https treated alike,
|
|
217
|
+
* the host lowercased and without a leading "www.", a trailing
|
|
218
|
+
* "index.html" or "index.htm" and a trailing slash dropped, and a DOI
|
|
219
|
+
* read the same through either resolver with its path percent-decoded.
|
|
220
|
+
* The fragment is kept: it names a place in the page, as a page number
|
|
221
|
+
* names one in a book.
|
|
222
|
+
*/
|
|
223
|
+
export function citationUrlKey(url) {
|
|
224
|
+
const archived = ARCHIVE_URL.exec(url.trim());
|
|
225
|
+
if (archived !== null)
|
|
226
|
+
return citationUrlKey(archived[1]);
|
|
227
|
+
const match = /^([a-z][a-z0-9+.-]*):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/i.exec(url.trim());
|
|
228
|
+
if (match === null)
|
|
229
|
+
return url.trim();
|
|
230
|
+
const scheme = match[1].toLowerCase();
|
|
231
|
+
let host = match[2].toLowerCase().replace(/^www\./, "");
|
|
232
|
+
let path = match[3].replace(/\/index\.html?$/i, "").replace(/\/$/, "");
|
|
233
|
+
if (host === "dx.doi.org" || host === "doi.org") {
|
|
234
|
+
host = "doi.org";
|
|
235
|
+
path = safeDecodeUri(path);
|
|
236
|
+
}
|
|
237
|
+
const prefix = scheme === "http" || scheme === "https" ? "" : `${scheme}:`;
|
|
238
|
+
return `${prefix}//${host}${path}${match[4] ?? ""}${match[5] ?? ""}`;
|
|
239
|
+
}
|
|
240
|
+
function safeDecodeUri(text) {
|
|
241
|
+
try {
|
|
242
|
+
return decodeURIComponent(text);
|
|
243
|
+
}
|
|
244
|
+
catch {
|
|
245
|
+
return text;
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* The url as the input writes it, if the input contains it: the same link
|
|
250
|
+
* with only differences that cannot change where it goes — the case of the
|
|
251
|
+
* scheme and host, http for https or the reverse, and a trailing slash.
|
|
252
|
+
*/
|
|
253
|
+
export function findUrlInText(url, text) {
|
|
254
|
+
const match = /^([a-z][a-z0-9+.-]*):(\/\/[^/?#]*)(.*)$/i.exec(url);
|
|
255
|
+
if (match === null)
|
|
256
|
+
return undefined;
|
|
257
|
+
const scheme = match[1].toLowerCase();
|
|
258
|
+
const isWeb = scheme === "http" || scheme === "https";
|
|
259
|
+
const authority = match[2].toLowerCase();
|
|
260
|
+
const path = match[3].replace(/\/$/, "");
|
|
261
|
+
const lowerText = text.toLowerCase();
|
|
262
|
+
for (let at = lowerText.indexOf(authority); at !== -1; at = lowerText.indexOf(authority, at + 1)) {
|
|
263
|
+
const textScheme = /([a-z][a-z0-9+.-]*):$/.exec(lowerText.slice(Math.max(0, at - 16), at))?.[1];
|
|
264
|
+
if (textScheme === undefined ||
|
|
265
|
+
(isWeb
|
|
266
|
+
? textScheme !== "http" && textScheme !== "https"
|
|
267
|
+
: textScheme !== scheme))
|
|
268
|
+
continue;
|
|
269
|
+
const rest = text.slice(at + authority.length);
|
|
270
|
+
if (!rest.startsWith(path))
|
|
271
|
+
continue;
|
|
272
|
+
// The text's link must end where this one does, give or take its
|
|
273
|
+
// own trailing slash, so neither a longer host nor a longer path
|
|
274
|
+
// matches. Punctuation closing a sentence or clause is not part of
|
|
275
|
+
// a link.
|
|
276
|
+
const trailingSlash = rest.startsWith("/", path.length) ? 1 : 0;
|
|
277
|
+
const after = rest.slice(path.length + trailingSlash);
|
|
278
|
+
if (/^[.,;:!?]?[^\s)\]>"'<.,;:!?]/.test(after))
|
|
279
|
+
continue;
|
|
280
|
+
return text.slice(at - textScheme.length - 1, at + authority.length + path.length + trailingSlash);
|
|
281
|
+
}
|
|
282
|
+
return undefined;
|
|
283
|
+
}
|
|
97
284
|
/**
|
|
98
285
|
* Adapter — republish `extract`'s mentions under the mention slot
|
|
99
286
|
* finalize resolves into each claim's source anchors.
|
|
@@ -113,18 +300,20 @@ export const extractMentionAdapterStage = deterministicStage({
|
|
|
113
300
|
}),
|
|
114
301
|
});
|
|
115
302
|
/**
|
|
116
|
-
* Adapter — derive the classification slot from
|
|
117
|
-
* records: each
|
|
118
|
-
*
|
|
119
|
-
* `
|
|
120
|
-
*
|
|
303
|
+
* Adapter — derive the classification slot from the canonical claim
|
|
304
|
+
* records: each one already carries its `type`, so the classification
|
|
305
|
+
* entry is `{ miniId, type, sourceString }`. `sourceString` is the claim's
|
|
306
|
+
* `url` when present (citation claims), else null — mirroring what
|
|
307
|
+
* scholar's classification stage records. It reads the canonicalization
|
|
308
|
+
* slot rather than `extract` itself, so a url that adapter cleared is not
|
|
309
|
+
* carried here.
|
|
121
310
|
*/
|
|
122
311
|
export const extractClassificationAdapterStage = deterministicStage({
|
|
123
312
|
id: STAGE_IDS.claimTypeClassification,
|
|
124
|
-
dependsOn: [STAGE_IDS.
|
|
313
|
+
dependsOn: [STAGE_IDS.claimCanonicalization],
|
|
125
314
|
outputSchema: ClaimTypeClassificationOutputSchema,
|
|
126
315
|
fn: (ctx) => {
|
|
127
|
-
const canon = ctx.get(STAGE_IDS.
|
|
316
|
+
const canon = ctx.get(STAGE_IDS.claimCanonicalization);
|
|
128
317
|
const claims = canon?.canonicalClaims ?? [];
|
|
129
318
|
return {
|
|
130
319
|
classifications: claims.map((c) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"extract-stage.js","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/extract-stage.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,qEAAqE;AACrE,yEAAyE;AACzE,qEAAqE;AACrE,yEAAyE;AACzE,8BAA8B;AAC9B,EAAE;AACF,sEAAsE;AACtE,yEAAyE;AACzE,oEAAoE;AACpE,qDAAqD;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAA;AAE/E,OAAO,EACH,SAAS,EACT,mBAAmB,EACnB,kCAAkC,EAClC,mCAAmC,GAItC,MAAM,4BAA4B,CAAA;AAMnC,OAAO,EACH,wBAAwB,GAE3B,MAAM,cAAc,CAAA;AAErB,MAAM,CAAC,MAAM,aAAa,GAAG,
|
|
1
|
+
{"version":3,"file":"extract-stage.js","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/extract-stage.ts"],"names":[],"mappings":"AAAA,mEAAmE;AACnE,qEAAqE;AACrE,yEAAyE;AACzE,qEAAqE;AACrE,yEAAyE;AACzE,8BAA8B;AAC9B,EAAE;AACF,sEAAsE;AACtE,yEAAyE;AACzE,oEAAoE;AACpE,qDAAqD;AAErD,OAAO,EAAE,QAAQ,EAAE,MAAM,4CAA4C,CAAA;AACrE,OAAO,EAAE,kBAAkB,EAAE,MAAM,4CAA4C,CAAA;AAE/E,OAAO,EACH,SAAS,EACT,mBAAmB,EACnB,kCAAkC,EAClC,mCAAmC,GAItC,MAAM,4BAA4B,CAAA;AAMnC,OAAO,EACH,wBAAwB,GAE3B,MAAM,cAAc,CAAA;AAErB,MAAM,CAAC,MAAM,aAAa,GAAG,WAAW,CAAA;AAExC,2DAA2D;AAC3D,MAAM,CAAC,MAAM,sBAAsB,GAA6B;IAC5D,KAAK,EAAE,aAAa;CACvB,CAAA;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gDA6BW,CAAA;AAEhD,SAAS,kBAAkB,CAAC,GAAkB;IAI1C,MAAM,KAAK,GAAG,GAAG,CAAC,KAAwB,CAAA;IAC1C,MAAM,MAAM,GAAG,kBAAkB,SAAS,CAAC,OAAO,SAAS,qBAAqB,EAAE,CAAA;IAClF,MAAM,IAAI,GAAG,kBAAkB,KAAK,CAAC,IAAI,qFAAqF,CAAA;IAC9H,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,CAAA;AAC3B,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,kBAAkB,CAC9B,SAA8B,EAC9B,OAAkC;IAElC,OAAO,QAAQ,CAAuB;QAClC,EAAE,EAAE,SAAS,CAAC,OAAO;QACrB,SAAS,EAAE,EAAE;QACb,YAAY,EAAE,wBAAwB,CAAC,SAAS,CAAC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C,uBAAuB;IACrC,SAAS,EAAE,CAAC,SAAS,CAAC,qBAAqB,CAAC;IAC5C,YAAY,EAAE,mCAAmC;IACjD,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE;QACR,MAAM,KAAK,GAAG,GAAG,CAAC,GAAG,CACjB,SAAS,CAAC,qBAAqB,CAClC,CAAA;QACD,MAAM,MAAM,GAAG,KAAK,EAAE,eAAe,IAAI,EAAE,CAAA;QAC3C,OAAO;YACH,eAAe,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE;gBAC9B,MAAM,GAAG,GAAI,CAA6B,CAAC,GAAG,CAAA;gBAC9C,MAAM,YAAY,GACd,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,CAAA;gBAC1D,OAAO,EAAE,MAAM,EAAE,CAAC,CAAC,MAAM,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,YAAY,EAAE,CAAA;YAC3D,CAAC,CAAC;SACL,CAAA;IACL,CAAC;CACJ,CAAC,CAAA"}
|
|
@@ -6,10 +6,23 @@ import type { TIngestionExtension } from "../../base/types.js";
|
|
|
6
6
|
* mention slot's, in one object. Structural rather than a `Static<>`,
|
|
7
7
|
* because the schema is built per-extension.
|
|
8
8
|
*/
|
|
9
|
-
export type TScribeExtractOutput = TClaimCanonicalizationOutput & TClaimMentionExtractionOutput
|
|
9
|
+
export type TScribeExtractOutput = TClaimCanonicalizationOutput & TClaimMentionExtractionOutput & {
|
|
10
|
+
sourceSupport: TScribeSourceSupport[];
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* One source claim (a citation or an axiom) and the normal claim it
|
|
14
|
+
* supports, as `extract` reads it off the text. `structure` never sees the text, so
|
|
15
|
+
* this is the only place the pairing is known.
|
|
16
|
+
*/
|
|
17
|
+
export declare const ScribeSourceSupportSchema: Type.TObject<{
|
|
18
|
+
sourceMiniId: Type.TString;
|
|
19
|
+
supportedMiniId: Type.TString;
|
|
20
|
+
}>;
|
|
21
|
+
export type TScribeSourceSupport = Static<typeof ScribeSourceSupportSchema>;
|
|
10
22
|
/**
|
|
11
23
|
* `extract`'s output: the per-extension canonicalization shape, plus the
|
|
12
|
-
* mentions whose quoted text becomes each claim's source anchor
|
|
24
|
+
* mentions whose quoted text becomes each claim's source anchor, plus
|
|
25
|
+
* which claim each source supports.
|
|
13
26
|
*
|
|
14
27
|
* The mentions ride along on the one stage that is given the input text,
|
|
15
28
|
* rather than coming from a stage of their own — scribe's whole point is
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/schemas.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"schemas.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/schemas.ts"],"names":[],"mappings":"AAgBA,OAAO,IAAI,EAAE,EAAE,KAAK,MAAM,EAAE,KAAK,OAAO,EAAE,MAAM,SAAS,CAAA;AAMzD,OAAO,KAAK,EACR,4BAA4B,EAC5B,6BAA6B,EAChC,MAAM,4BAA4B,CAAA;AACnC,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAA;AAE9D;;;;GAIG;AACH,MAAM,MAAM,oBAAoB,GAAG,4BAA4B,GAC3D,6BAA6B,GAAG;IAC5B,aAAa,EAAE,oBAAoB,EAAE,CAAA;CACxC,CAAA;AAEL;;;;GAIG;AACH,eAAO,MAAM,yBAAyB;;;EAMrC,CAAA;AACD,MAAM,MAAM,oBAAoB,GAAG,MAAM,CAAC,OAAO,yBAAyB,CAAC,CAAA;AAE3E;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,wBAAwB,CACpC,SAAS,EAAE,mBAAmB,GAC/B,OAAO,CAYT;AASD,eAAO,MAAM,2BAA2B;;;;;;;;;;;;;;;EAQvC,CAAA;AACD,MAAM,MAAM,sBAAsB,GAAG,MAAM,CAAC,OAAO,2BAA2B,CAAC,CAAA"}
|
|
@@ -10,13 +10,24 @@
|
|
|
10
10
|
// relation-extraction + conclusion-selection slots.
|
|
11
11
|
//
|
|
12
12
|
// `extract`'s output schema is the per-extension canonicalization
|
|
13
|
-
// schema widened with the mention slot
|
|
13
|
+
// schema widened with the mention slot and the source pairings
|
|
14
|
+
// (`buildExtractOutputSchema`);
|
|
14
15
|
// `structure` needs a bespoke schema. Both are defined here.
|
|
15
16
|
import Type, {} from "typebox";
|
|
16
17
|
import { ClaimMentionExtractionOutputSchema, RelationExtractionOutputSchema, buildResponseSchema, } from "../../base/stages/index.js";
|
|
18
|
+
/**
|
|
19
|
+
* One source claim (a citation or an axiom) and the normal claim it
|
|
20
|
+
* supports, as `extract` reads it off the text. `structure` never sees the text, so
|
|
21
|
+
* this is the only place the pairing is known.
|
|
22
|
+
*/
|
|
23
|
+
export const ScribeSourceSupportSchema = Type.Object({
|
|
24
|
+
sourceMiniId: Type.String(),
|
|
25
|
+
supportedMiniId: Type.String(),
|
|
26
|
+
}, { additionalProperties: false });
|
|
17
27
|
/**
|
|
18
28
|
* `extract`'s output: the per-extension canonicalization shape, plus the
|
|
19
|
-
* mentions whose quoted text becomes each claim's source anchor
|
|
29
|
+
* mentions whose quoted text becomes each claim's source anchor, plus
|
|
30
|
+
* which claim each source supports.
|
|
20
31
|
*
|
|
21
32
|
* The mentions ride along on the one stage that is given the input text,
|
|
22
33
|
* rather than coming from a stage of their own — scribe's whole point is
|
|
@@ -34,6 +45,7 @@ export function buildExtractOutputSchema(extension) {
|
|
|
34
45
|
return Type.Object({
|
|
35
46
|
...canonicalization.properties,
|
|
36
47
|
mentions: ClaimMentionExtractionOutputSchema.properties.mentions,
|
|
48
|
+
sourceSupport: Type.Array(ScribeSourceSupportSchema),
|
|
37
49
|
}, { additionalProperties: false });
|
|
38
50
|
}
|
|
39
51
|
// `structure` emits the relation graph (same per-relation shape as
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/schemas.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,EAAE;AACF,uEAAuE;AACvE,mEAAmE;AACnE,kEAAkE;AAClE,mEAAmE;AACnE,qCAAqC;AACrC,qEAAqE;AACrE,+DAA+D;AAC/D,wDAAwD;AACxD,EAAE;AACF,kEAAkE;AAClE,
|
|
1
|
+
{"version":3,"file":"schemas.js","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/schemas.ts"],"names":[],"mappings":"AAAA,oDAAoD;AACpD,EAAE;AACF,uEAAuE;AACvE,mEAAmE;AACnE,kEAAkE;AAClE,mEAAmE;AACnE,qCAAqC;AACrC,qEAAqE;AACrE,+DAA+D;AAC/D,wDAAwD;AACxD,EAAE;AACF,kEAAkE;AAClE,+DAA+D;AAC/D,gCAAgC;AAChC,6DAA6D;AAE7D,OAAO,IAAI,EAAE,EAA6B,MAAM,SAAS,CAAA;AACzD,OAAO,EACH,kCAAkC,EAClC,8BAA8B,EAC9B,mBAAmB,GACtB,MAAM,4BAA4B,CAAA;AAiBnC;;;;GAIG;AACH,MAAM,CAAC,MAAM,yBAAyB,GAAG,IAAI,CAAC,MAAM,CAChD;IACI,YAAY,EAAE,IAAI,CAAC,MAAM,EAAE;IAC3B,eAAe,EAAE,IAAI,CAAC,MAAM,EAAE;CACjC,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAClC,CAAA;AAGD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,UAAU,wBAAwB,CACpC,SAA8B;IAE9B,MAAM,gBAAgB,GAAG,mBAAmB,CAAC,SAAS,CAErD,CAAA;IACD,OAAO,IAAI,CAAC,MAAM,CACd;QACI,GAAG,gBAAgB,CAAC,UAAU;QAC9B,QAAQ,EAAE,kCAAkC,CAAC,UAAU,CAAC,QAAQ;QAChE,aAAa,EAAE,IAAI,CAAC,KAAK,CAAC,yBAAyB,CAAC;KACvD,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAClC,CAAA;AACL,CAAC;AAED,mEAAmE;AACnE,kEAAkE;AAClE,mEAAmE;AACnE,qEAAqE;AACrE,+DAA+D;AAC/D,8DAA8D;AAC9D,mDAAmD;AACnD,MAAM,CAAC,MAAM,2BAA2B,GAAG,IAAI,CAAC,MAAM,CAClD;IACI,SAAS,EAAE,8BAA8B,CAAC,UAAU,CAAC,SAAS;IAC9D,oBAAoB,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,MAAM,EAAE,CAAC;IAC/C,eAAe,EAAE,IAAI,CAAC,MAAM,EAAE;IAC9B,SAAS,EAAE,IAAI,CAAC,MAAM,EAAE;CAC3B,EACD,EAAE,oBAAoB,EAAE,KAAK,EAAE,CAClC,CAAA"}
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
// DAG:
|
|
12
12
|
//
|
|
13
13
|
// extract ──┬─ (adapter) claim-canonicalization ─┬─ claim-reference-validation
|
|
14
|
-
//
|
|
14
|
+
// │ └─ (adapter) claim-type-classification ┤
|
|
15
15
|
// │ └─ variable-assignment
|
|
16
16
|
// └─ (adapter) claim-mention-extraction
|
|
17
17
|
// structure ─┬─ (adapter) relation-extraction
|
|
@@ -30,7 +30,7 @@ import { INGESTION_INPUT_SCHEMA } from "../scholar/scholar.js";
|
|
|
30
30
|
import { createExtractStage, createExtractCanonicalizationAdapterStage, extractClassificationAdapterStage, extractMentionAdapterStage, EXTRACT_STAGE_DEFAULTS, } from "./extract-stage.js";
|
|
31
31
|
import { createStructureStage, structureRelationAdapterStage, structureConclusionAdapterStage, STRUCTURE_STAGE_DEFAULTS, } from "./structure-stage.js";
|
|
32
32
|
const PIPELINE_ID = "argument-ingestion-scribe";
|
|
33
|
-
const PIPELINE_VERSION = "1.
|
|
33
|
+
const PIPELINE_VERSION = "1.1.0";
|
|
34
34
|
/**
|
|
35
35
|
* Build the scribe (fast) ingestion pipeline for the supplied
|
|
36
36
|
* extension: `extract` + `structure` cheap LLM calls, their
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scribe.js","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/scribe.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,EAAE;AACF,+DAA+D;AAC/D,sEAAsE;AACtE,8DAA8D;AAC9D,sEAAsE;AACtE,iEAAiE;AACjE,oEAAoE;AACpE,qEAAqE;AACrE,EAAE;AACF,OAAO;AACP,EAAE;AACF,iFAAiF;AACjF,
|
|
1
|
+
{"version":3,"file":"scribe.js","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/scribe.ts"],"names":[],"mappings":"AAAA,kDAAkD;AAClD,EAAE;AACF,+DAA+D;AAC/D,sEAAsE;AACtE,8DAA8D;AAC9D,sEAAsE;AACtE,iEAAiE;AACjE,oEAAoE;AACpE,qEAAqE;AACrE,EAAE;AACF,OAAO;AACP,EAAE;AACF,iFAAiF;AACjF,4DAA4D;AAC5D,4EAA4E;AAC5E,oDAAoD;AACpD,gDAAgD;AAChD,iDAAiD;AACjD,+DAA+D;AAC/D,8DAA8D;AAC9D,oDAAoD;AACpD,EAAE;AACF,sEAAsE;AACtE,4CAA4C;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAA;AAG7D,OAAO,EACH,SAAS,EACT,6BAA6B,EAC7B,uBAAuB,EACvB,uBAAuB,EACvB,sBAAsB,GAEzB,MAAM,4BAA4B,CAAA;AACnC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oCAAoC,CAAA;AACvE,OAAO,EAAE,sBAAsB,EAAE,MAAM,yCAAyC,CAAA;AAMhF,OAAO,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AAC9D,OAAO,EACH,kBAAkB,EAClB,yCAAyC,EACzC,iCAAiC,EACjC,0BAA0B,EAC1B,sBAAsB,GACzB,MAAM,oBAAoB,CAAA;AAC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ACvC,QAAQ,CAAC,SAAS,CAAC,iBAAiB,CAAC;gBACrC,QAAQ,CAAC,SAAS,CAAC,wBAAwB,CAAC;gBAC5C,wDAAwD;gBACxD,sDAAsD;gBACtD,sBAAsB;gBACtB,QAAQ,CAAC,SAAS,CAAC,sBAAsB,CAAC;aAC7C;YACD,+DAA+D;YAC/D,4DAA4D;YAC5D,gEAAgE;YAChE,eAAe;YACf,EAAE;YACF,gEAAgE;YAChE,8DAA8D;YAC9D,0DAA0D;YAC1D,yDAAyD;YACzD,gEAAgE;YAChE,0BAA0B;YAC1B,GAAG,EAAE,CAAC,GAAG,EAAE,EAAE,CACT,kBAAkB,CAAC;gBACf,GAAG;gBACH,SAAS;gBACT,QAAQ,EAAE,GAAG,CAAC,GAAG,CACb,SAAS,CAAC,sBAAsB,CACnC;aACJ,CAAC;SACT;KACJ,CAAA;AACL,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { TClaimTypeClassificationEntry, TInferenceRelation } from "../../base/stages/index.js";
|
|
2
|
+
import type { TScribeExtractOutput } from "./schemas.js";
|
|
3
|
+
export declare const SOURCE_ATTACHMENT_FAILURE_CODES: {
|
|
4
|
+
readonly invalidSource: "SOURCE_ATTACHMENT_INVALID_SOURCE";
|
|
5
|
+
readonly invalidTarget: "SOURCE_ATTACHMENT_INVALID_TARGET";
|
|
6
|
+
readonly mixed: "SOURCE_ATTACHMENT_MIXED";
|
|
7
|
+
readonly unattached: "SOURCE_ATTACHMENT_UNATTACHED";
|
|
8
|
+
};
|
|
9
|
+
type TClaimType = TClaimTypeClassificationEntry["type"];
|
|
10
|
+
type TAddFailure = (failure: {
|
|
11
|
+
code: string;
|
|
12
|
+
message: string;
|
|
13
|
+
severity: "warning" | "error";
|
|
14
|
+
context?: Record<string, unknown>;
|
|
15
|
+
}) => void;
|
|
16
|
+
/**
|
|
17
|
+
* The relations that attach each citation and axiomatic claim to what it
|
|
18
|
+
* supports, to be published alongside `structure`'s own. See the file
|
|
19
|
+
* comment for the order in which a target is chosen.
|
|
20
|
+
*/
|
|
21
|
+
export declare function buildSourceRelations(args: {
|
|
22
|
+
extract: TScribeExtractOutput | undefined;
|
|
23
|
+
structureRelations: readonly TInferenceRelation[];
|
|
24
|
+
typeByMiniId: Map<string, TClaimType>;
|
|
25
|
+
inputText: string;
|
|
26
|
+
addFailure: TAddFailure;
|
|
27
|
+
}): TInferenceRelation[];
|
|
28
|
+
export {};
|
|
29
|
+
//# sourceMappingURL=source-attachment.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"source-attachment.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/pipelines/ingestion/scribe/source-attachment.ts"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAER,6BAA6B,EAC7B,kBAAkB,EACrB,MAAM,4BAA4B,CAAA;AAGnC,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAExD,eAAO,MAAM,+BAA+B;;;;;CAKlC,CAAA;AAEV,KAAK,UAAU,GAAG,6BAA6B,CAAC,MAAM,CAAC,CAAA;AAIvD,KAAK,WAAW,GAAG,CAAC,OAAO,EAAE;IACzB,IAAI,EAAE,MAAM,CAAA;IACZ,OAAO,EAAE,MAAM,CAAA;IACf,QAAQ,EAAE,SAAS,GAAG,OAAO,CAAA;IAC7B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;CACpC,KAAK,IAAI,CAAA;AA+EV;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE;IACvC,OAAO,EAAE,oBAAoB,GAAG,SAAS,CAAA;IACzC,kBAAkB,EAAE,SAAS,kBAAkB,EAAE,CAAA;IACjD,YAAY,EAAE,GAAG,CAAC,MAAM,EAAE,UAAU,CAAC,CAAA;IACrC,SAAS,EAAE,MAAM,CAAA;IACjB,UAAU,EAAE,WAAW,CAAA;CAC1B,GAAG,kBAAkB,EAAE,CA+HvB"}
|