glossarist 0.4.49 → 0.4.50
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/package.json +1 -1
- package/src/concept-collection.ts +7 -1
- package/src/concept-parser.ts +7 -1
- package/src/concept-serializer.ts +12 -1
- package/src/concept-writer.ts +5 -1
- package/src/diff/collection-diff.ts +49 -1
- package/src/diff/concept-diff.ts +152 -1
- package/src/diff/diff-patch.ts +17 -1
- package/src/diff/diff-renderer.ts +56 -1
- package/src/gcr-reader.ts +26 -1
- package/src/gcr-writer.ts +3 -1
- package/src/managed-concept-collection.ts +36 -1
- package/src/rdf/agents-emitter.ts +4 -1
- package/src/rdf/curie.ts +1 -2
- package/src/rdf/gloss-concept.ts +1 -1
- package/src/rdf/gloss-non-verbal-rep.ts +11 -1
- package/src/rdf/sections-builder.ts +13 -1
- package/src/rdf/shacl.ts +2 -1
- package/src/rdf/write-turtle-sync.ts +13 -1
- package/src/reference-resolver.ts +31 -1
- package/src/render-classification.ts +10 -1
- package/src/v1-reader.ts +3 -1
- package/src/validators/asset-index.ts +6 -1
- package/src/validators/concept-validator.ts +2 -2
- package/src/validators/gcr-validator.ts +2 -1
- package/src/validators/v3-rules.ts +5 -1
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
2
1
|
import { TextDiff } from './text-diff.js';
|
|
3
2
|
import { resolveMultiplicity } from '../models/multiplicity.js';
|
|
4
3
|
|
|
@@ -12,7 +11,9 @@ const COLORS = {
|
|
|
12
11
|
};
|
|
13
12
|
|
|
14
13
|
export function renderConceptDiff(diff, options = {}) {
|
|
14
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
15
15
|
const colors = options.colors ?? false;
|
|
16
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
16
17
|
const showUnchanged = options.showUnchanged ?? false;
|
|
17
18
|
const lines = [];
|
|
18
19
|
|
|
@@ -22,22 +23,30 @@ export function renderConceptDiff(diff, options = {}) {
|
|
|
22
23
|
: (diff.newId ?? diff.oldId ?? '?');
|
|
23
24
|
|
|
24
25
|
const similarityStr = colors ? colorizeSimilarity(pct) : `${pct}%`;
|
|
26
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
25
27
|
lines.push(`Concept "${idPart}" — ${similarityStr} similar`);
|
|
26
28
|
|
|
27
29
|
if (!diff.hasChanges && !showUnchanged) {
|
|
30
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
28
31
|
lines.push(' (no changes)');
|
|
29
32
|
return lines.join('\n');
|
|
30
33
|
}
|
|
31
34
|
|
|
32
35
|
if (diff.concept.hasChanges || showUnchanged) {
|
|
36
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
33
37
|
lines.push('');
|
|
38
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
34
39
|
lines.push('Concept-level:');
|
|
40
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
35
41
|
lines.push(renderConceptLevel(diff.concept, colors));
|
|
36
42
|
}
|
|
37
43
|
|
|
38
44
|
if (diff.languages.hasChanges || showUnchanged) {
|
|
45
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
39
46
|
lines.push('');
|
|
47
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
40
48
|
lines.push('Languages:');
|
|
49
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
41
50
|
lines.push(renderLanguageSet(diff.languages, colors));
|
|
42
51
|
}
|
|
43
52
|
|
|
@@ -45,8 +54,11 @@ export function renderConceptDiff(diff, options = {}) {
|
|
|
45
54
|
const lcDiff = diff.localization(lang);
|
|
46
55
|
if (!lcDiff) continue;
|
|
47
56
|
if (lcDiff.hasChanges || showUnchanged) {
|
|
57
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
48
58
|
lines.push('');
|
|
59
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
49
60
|
lines.push(`Localization (${lang}):`);
|
|
61
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
50
62
|
lines.push(renderLocalized(lcDiff, colors));
|
|
51
63
|
}
|
|
52
64
|
}
|
|
@@ -55,45 +67,64 @@ export function renderConceptDiff(diff, options = {}) {
|
|
|
55
67
|
}
|
|
56
68
|
|
|
57
69
|
export function renderCollectionDiff(diff, options = {}) {
|
|
70
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
58
71
|
const colors = options.colors ?? false;
|
|
59
72
|
const lines = [];
|
|
60
73
|
|
|
61
74
|
const pct = Math.round(diff.similarity * 100);
|
|
62
75
|
const similarityStr = colors ? colorizeSimilarity(pct) : `${pct}%`;
|
|
63
76
|
|
|
77
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
64
78
|
lines.push(`Collection comparison — ${similarityStr} similar overall`);
|
|
79
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
65
80
|
lines.push(` Old: ${diff.oldCount} concepts`);
|
|
81
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
66
82
|
lines.push(` New: ${diff.newCount} concepts`);
|
|
83
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
67
84
|
lines.push(` Matched: ${diff.matched.length}`);
|
|
85
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
68
86
|
lines.push(` Added: ${diff.added.length}`);
|
|
87
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
69
88
|
lines.push(` Removed: ${diff.removed.length}`);
|
|
70
89
|
|
|
71
90
|
if (diff.added.length > 0) {
|
|
91
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
72
92
|
lines.push('');
|
|
93
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
73
94
|
lines.push(colors ? COLORS.green('Added concepts:') : 'Added concepts:');
|
|
74
95
|
for (const entry of diff.added) {
|
|
96
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
75
97
|
lines.push(` + ${entry.value}`);
|
|
76
98
|
}
|
|
77
99
|
}
|
|
78
100
|
|
|
79
101
|
if (diff.removed.length > 0) {
|
|
102
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
80
103
|
lines.push('');
|
|
104
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
81
105
|
lines.push(colors ? COLORS.red('Removed concepts:') : 'Removed concepts:');
|
|
82
106
|
for (const entry of diff.removed) {
|
|
107
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
83
108
|
lines.push(` - ${entry.value}`);
|
|
84
109
|
}
|
|
85
110
|
}
|
|
86
111
|
|
|
87
112
|
const changedDiffs = Object.entries(diff.conceptDiffs)
|
|
113
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
88
114
|
.filter(([, d]) => d.hasChanges)
|
|
115
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
89
116
|
.sort(([, a], [, b]) => a.similarity - b.similarity);
|
|
90
117
|
|
|
91
118
|
if (changedDiffs.length > 0) {
|
|
119
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
92
120
|
lines.push('');
|
|
121
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
93
122
|
lines.push('Changed concepts:');
|
|
94
123
|
for (const [id, conceptDiff] of changedDiffs) {
|
|
124
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
95
125
|
const conceptPct = Math.round(conceptDiff.similarity * 100);
|
|
96
126
|
const pctStr = colors ? colorizeSimilarity(conceptPct) : `${conceptPct}%`;
|
|
127
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
97
128
|
lines.push(` ${id}: ${pctStr}`);
|
|
98
129
|
}
|
|
99
130
|
}
|
|
@@ -105,15 +136,19 @@ export function renderTextDiff(textDiff, options = {}) {
|
|
|
105
136
|
if (!(textDiff instanceof TextDiff)) {
|
|
106
137
|
textDiff = TextDiff.fromJSON(textDiff);
|
|
107
138
|
}
|
|
139
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
108
140
|
const colors = options.colors ?? false;
|
|
109
141
|
const lines = [];
|
|
110
142
|
|
|
111
143
|
for (const hunk of textDiff.hunks) {
|
|
112
144
|
if (hunk.type === 'equal') {
|
|
145
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
113
146
|
lines.push(` ${hunk.text}`);
|
|
114
147
|
} else if (hunk.type === 'added') {
|
|
148
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
115
149
|
lines.push(colors ? `+ ${COLORS.green(hunk.text)}` : `+ ${hunk.text}`);
|
|
116
150
|
} else if (hunk.type === 'removed') {
|
|
151
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
117
152
|
lines.push(colors ? `- ${COLORS.red(hunk.text)}` : `- ${hunk.text}`);
|
|
118
153
|
}
|
|
119
154
|
}
|
|
@@ -123,16 +158,24 @@ export function renderTextDiff(textDiff, options = {}) {
|
|
|
123
158
|
|
|
124
159
|
function renderConceptLevel(diff, colors) {
|
|
125
160
|
const lines = [];
|
|
161
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
126
162
|
lines.push(...renderListDiff('Sources', diff.sources, colors, itemLabel));
|
|
163
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
127
164
|
lines.push(...renderListDiff('Dates', diff.dates, colors, itemLabel));
|
|
165
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
128
166
|
lines.push(...renderListDiff('Related', diff.relatedConcepts, colors, itemLabel));
|
|
129
167
|
// Unified hyperedge section. Replaces the per-type sections
|
|
130
168
|
// (Partitive relations, Generic relations) — the underlying diff
|
|
131
169
|
// is a single ListDiff over the unified .relations array.
|
|
170
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
132
171
|
lines.push(...renderListDiff('Hyperedges', diff.relations, colors, relationLabel));
|
|
172
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
133
173
|
lines.push(...renderListDiff('Groups', diff.groups, colors, itemLabel));
|
|
174
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
134
175
|
lines.push(...renderListDiff('Sections', diff.sections, colors, itemLabel));
|
|
176
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
135
177
|
lines.push(...renderListDiff('Tags', diff.tags, colors, itemLabel));
|
|
178
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
136
179
|
lines.push(...renderMetadataDiff(diff.metadata));
|
|
137
180
|
return lines.filter(Boolean).join('\n');
|
|
138
181
|
}
|
|
@@ -140,9 +183,11 @@ function renderConceptLevel(diff, colors) {
|
|
|
140
183
|
function renderLanguageSet(diff, colors) {
|
|
141
184
|
const lines = [];
|
|
142
185
|
for (const entry of diff.added) {
|
|
186
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
143
187
|
lines.push(colors ? ` + ${COLORS.green(entry.value)}` : ` + ${entry.value}`);
|
|
144
188
|
}
|
|
145
189
|
for (const entry of diff.removed) {
|
|
190
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
146
191
|
lines.push(colors ? ` - ${COLORS.red(entry.value)}` : ` - ${entry.value}`);
|
|
147
192
|
}
|
|
148
193
|
return lines.join('\n');
|
|
@@ -150,13 +195,21 @@ function renderLanguageSet(diff, colors) {
|
|
|
150
195
|
|
|
151
196
|
function renderLocalized(diff, colors) {
|
|
152
197
|
const lines = [];
|
|
198
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
153
199
|
lines.push(...renderListDiff('Designations', diff.designations, colors, designationLabel));
|
|
200
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
154
201
|
lines.push(...renderListDiff('Definitions', diff.definitions, colors, definitionLabel));
|
|
202
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
155
203
|
lines.push(...renderListDiff('Notes', diff.notes, colors, definitionLabel));
|
|
204
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
156
205
|
lines.push(...renderListDiff('Examples', diff.examples, colors, definitionLabel));
|
|
206
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
157
207
|
lines.push(...renderListDiff('Sources', diff.sources, colors, itemLabel));
|
|
208
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
158
209
|
lines.push(...renderListDiff('Dates', diff.dates, colors, itemLabel));
|
|
210
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
159
211
|
lines.push(...renderListDiff('Related', diff.related, colors, itemLabel));
|
|
212
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
160
213
|
lines.push(...renderMetadataDiff(diff.metadata));
|
|
161
214
|
return lines.filter(Boolean).join('\n');
|
|
162
215
|
}
|
|
@@ -184,7 +237,9 @@ function renderMetadataDiff(metadataDiff) {
|
|
|
184
237
|
if (!metadataDiff.hasChanges) return [];
|
|
185
238
|
const lines = [` Metadata:`];
|
|
186
239
|
for (const [field, change] of Object.entries(metadataDiff.changes)) {
|
|
240
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
187
241
|
const oldVal = formatScalar(change.oldValue);
|
|
242
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
188
243
|
const newVal = formatScalar(change.newValue);
|
|
189
244
|
lines.push(` ~ ${field}: ${oldVal} → ${newVal}`);
|
|
190
245
|
}
|
package/src/gcr-reader.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
2
1
|
import JSZip from 'jszip';
|
|
3
2
|
import * as yaml from 'js-yaml';
|
|
4
3
|
import { conceptParser } from './concept-parser.js';
|
|
@@ -83,6 +82,7 @@ export async function loadGcr(input) {
|
|
|
83
82
|
export class GcrPackage {
|
|
84
83
|
/** @param {JSZip} zip */
|
|
85
84
|
constructor(zip) {
|
|
85
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
86
86
|
this._zip = zip;
|
|
87
87
|
}
|
|
88
88
|
|
|
@@ -110,8 +110,10 @@ export class GcrPackage {
|
|
|
110
110
|
*/
|
|
111
111
|
async conceptIds() {
|
|
112
112
|
const ids = [];
|
|
113
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
113
114
|
this._zip.forEach((relativePath, entry) => {
|
|
114
115
|
if (!entry.dir && relativePath.startsWith('concepts/') && relativePath.endsWith('.yaml')) {
|
|
116
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
115
117
|
ids.push(relativePath.slice('concepts/'.length, -'.yaml'.length));
|
|
116
118
|
}
|
|
117
119
|
});
|
|
@@ -151,6 +153,7 @@ export class GcrPackage {
|
|
|
151
153
|
const concepts = [];
|
|
152
154
|
for (const id of ids) {
|
|
153
155
|
const c = await this.concept(id);
|
|
156
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
154
157
|
if (c) concepts.push(c);
|
|
155
158
|
}
|
|
156
159
|
return concepts;
|
|
@@ -164,6 +167,7 @@ export class GcrPackage {
|
|
|
164
167
|
*/
|
|
165
168
|
async compiledFormats() {
|
|
166
169
|
const seen = new Set();
|
|
170
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
167
171
|
this._zip.forEach((relativePath, entry) => {
|
|
168
172
|
if (!entry.dir) {
|
|
169
173
|
const parsed = parseCompiledPath(relativePath);
|
|
@@ -181,9 +185,11 @@ export class GcrPackage {
|
|
|
181
185
|
async compiledFormatIds(format) {
|
|
182
186
|
const prefix = `compiled/${format}/`;
|
|
183
187
|
const ids = [];
|
|
188
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
184
189
|
this._zip.forEach((relativePath, entry) => {
|
|
185
190
|
if (!entry.dir && relativePath.startsWith(prefix)) {
|
|
186
191
|
const parsed = parseCompiledPath(relativePath);
|
|
192
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
187
193
|
if (parsed && parsed.format === format) ids.push(parsed.id);
|
|
188
194
|
}
|
|
189
195
|
});
|
|
@@ -198,6 +204,7 @@ export class GcrPackage {
|
|
|
198
204
|
async hasCompiledFormat(format) {
|
|
199
205
|
const prefix = `compiled/${format}/`;
|
|
200
206
|
let found = false;
|
|
207
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
201
208
|
this._zip.forEach((relativePath, entry) => {
|
|
202
209
|
if (!found && !entry.dir && relativePath.startsWith(prefix)) {
|
|
203
210
|
found = true;
|
|
@@ -223,6 +230,7 @@ export class GcrPackage {
|
|
|
223
230
|
* @returns {Promise<Uint8Array | null>}
|
|
224
231
|
*/
|
|
225
232
|
async compiledFileBuffer(format, id) {
|
|
233
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
226
234
|
const entry = this._zip.file(compiledPath(format, id));
|
|
227
235
|
if (!entry) return null;
|
|
228
236
|
return entry.async('uint8array');
|
|
@@ -262,15 +270,18 @@ export class GcrPackage {
|
|
|
262
270
|
*/
|
|
263
271
|
async datasetAssetEntries() {
|
|
264
272
|
const entries = [];
|
|
273
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
265
274
|
this._zip.forEach((relativePath, zipEntry) => {
|
|
266
275
|
if (zipEntry.dir) return;
|
|
267
276
|
const fileAsset = findFileAsset(relativePath);
|
|
268
277
|
if (fileAsset) {
|
|
278
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
269
279
|
entries.push({ path: relativePath, type: 'file', asset: fileAsset });
|
|
270
280
|
return;
|
|
271
281
|
}
|
|
272
282
|
const dirAsset = findDirectoryAssetPath(relativePath);
|
|
273
283
|
if (dirAsset) {
|
|
284
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
274
285
|
entries.push({ path: relativePath, type: 'directory', asset: dirAsset });
|
|
275
286
|
}
|
|
276
287
|
});
|
|
@@ -306,6 +317,7 @@ export class GcrPackage {
|
|
|
306
317
|
if (!asset) return false;
|
|
307
318
|
const prefix = `${asset.path}/`;
|
|
308
319
|
let found = false;
|
|
320
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
309
321
|
this._zip.forEach((relativePath, entry) => {
|
|
310
322
|
if (!found && !entry.dir && relativePath.startsWith(prefix)) {
|
|
311
323
|
found = true;
|
|
@@ -324,8 +336,10 @@ export class GcrPackage {
|
|
|
324
336
|
if (!asset) return [];
|
|
325
337
|
const prefix = `${asset.path}/`;
|
|
326
338
|
const names = [];
|
|
339
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
327
340
|
this._zip.forEach((relativePath, entry) => {
|
|
328
341
|
if (!entry.dir && relativePath.startsWith(prefix)) {
|
|
342
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
329
343
|
names.push(relativePath);
|
|
330
344
|
}
|
|
331
345
|
});
|
|
@@ -341,6 +355,7 @@ export class GcrPackage {
|
|
|
341
355
|
const asset = DATASET_ASSETS.find((a) => a.type === 'directory' && a.path === 'images');
|
|
342
356
|
if (!asset) return null;
|
|
343
357
|
const fullPath = path.startsWith(`${asset.path}/`) ? path : `${asset.path}/${path}`;
|
|
358
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
344
359
|
const entry = this._zip.file(fullPath);
|
|
345
360
|
if (!entry) return null;
|
|
346
361
|
return entry.async('uint8array');
|
|
@@ -354,6 +369,7 @@ export class GcrPackage {
|
|
|
354
369
|
async eachImageFile(callback) {
|
|
355
370
|
const names = await this.imageFileNames();
|
|
356
371
|
for (const name of names) {
|
|
372
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
357
373
|
const entry = this._zip.file(name);
|
|
358
374
|
if (entry) {
|
|
359
375
|
const content = await entry.async('uint8array');
|
|
@@ -378,6 +394,7 @@ export class GcrPackage {
|
|
|
378
394
|
* @returns {Promise<string | null>} null if the file doesn't exist
|
|
379
395
|
*/
|
|
380
396
|
async readText(filePath) {
|
|
397
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
381
398
|
const entry = this._zip.file(filePath);
|
|
382
399
|
if (!entry) return null;
|
|
383
400
|
return entry.async('text');
|
|
@@ -389,7 +406,9 @@ export class GcrPackage {
|
|
|
389
406
|
*/
|
|
390
407
|
entryPaths() {
|
|
391
408
|
const entries = [];
|
|
409
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
392
410
|
this._zip.forEach((relativePath, entry) => {
|
|
411
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
393
412
|
entries.push({ path: relativePath, dir: !!entry.dir });
|
|
394
413
|
});
|
|
395
414
|
return entries;
|
|
@@ -401,6 +420,7 @@ export class GcrPackage {
|
|
|
401
420
|
* @returns {boolean}
|
|
402
421
|
*/
|
|
403
422
|
hasEntry(filePath) {
|
|
423
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
404
424
|
return this._zip.file(filePath) != null;
|
|
405
425
|
}
|
|
406
426
|
|
|
@@ -414,8 +434,10 @@ export class GcrPackage {
|
|
|
414
434
|
async entityIds(type) {
|
|
415
435
|
const prefix = `${entityDir(type)}/`;
|
|
416
436
|
const ids = [];
|
|
437
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
417
438
|
this._zip.forEach((relativePath, entry) => {
|
|
418
439
|
if (!entry.dir && relativePath.startsWith(prefix) && relativePath.endsWith('.yaml')) {
|
|
440
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
419
441
|
ids.push(relativePath.slice(prefix.length, -'.yaml'.length));
|
|
420
442
|
}
|
|
421
443
|
});
|
|
@@ -426,6 +448,7 @@ export class GcrPackage {
|
|
|
426
448
|
const raw = await this.readText(entityPath(type, id));
|
|
427
449
|
if (raw === null) return null;
|
|
428
450
|
const yamlData = yaml.load(raw);
|
|
451
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
429
452
|
return NonVerbalEntity.fromData({ ...yamlData, type });
|
|
430
453
|
}
|
|
431
454
|
|
|
@@ -438,12 +461,14 @@ export class GcrPackage {
|
|
|
438
461
|
|
|
439
462
|
async allEntities(type) {
|
|
440
463
|
const entities = [];
|
|
464
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
441
465
|
await this.eachEntity(type, (e) => { entities.push(e); });
|
|
442
466
|
return entities;
|
|
443
467
|
}
|
|
444
468
|
|
|
445
469
|
async entityTypes() {
|
|
446
470
|
const seen = new Set();
|
|
471
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
447
472
|
this._zip.forEach((relativePath, entry) => {
|
|
448
473
|
if (!entry.dir) {
|
|
449
474
|
const parsed = parseEntityPath(relativePath);
|
package/src/gcr-writer.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
2
1
|
import JSZip from 'jszip';
|
|
3
2
|
import { conceptSerializer } from './concept-serializer.js';
|
|
4
3
|
import { InvalidInputError } from './errors.js';
|
|
@@ -55,8 +54,10 @@ export class GcrWriter {
|
|
|
55
54
|
if (metadata instanceof GcrMetadata) {
|
|
56
55
|
const meta = metadata.clone();
|
|
57
56
|
if (!meta.statistics && concepts.length > 0) {
|
|
57
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
58
58
|
meta.statistics = GcrStatistics.fromConcepts(concepts);
|
|
59
59
|
}
|
|
60
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
60
61
|
if (!meta.conceptCount) meta.conceptCount = concepts.length;
|
|
61
62
|
return meta.toJSON();
|
|
62
63
|
}
|
|
@@ -76,6 +77,7 @@ export class GcrWriter {
|
|
|
76
77
|
if (!isKnownFormat(format)) {
|
|
77
78
|
throw new RangeError(`Unknown compiled format: ${format}`);
|
|
78
79
|
}
|
|
80
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
79
81
|
const map = entries instanceof Map ? entries : new Map(Object.entries(entries));
|
|
80
82
|
for (const [id, content] of map) {
|
|
81
83
|
zip.file(compiledPath(format, id), content);
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
2
1
|
import { ConceptCollection } from './concept-collection.js';
|
|
3
2
|
import { readConcepts, readRegister } from './concept-reader.js';
|
|
4
3
|
import { writeConcepts } from './concept-writer.js';
|
|
@@ -8,87 +7,123 @@ import { BibliographyData } from './models/bibliography-data.js';
|
|
|
8
7
|
|
|
9
8
|
export class ManagedConceptCollection {
|
|
10
9
|
constructor() {
|
|
10
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
11
11
|
this._concepts = new ConceptCollection();
|
|
12
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
12
13
|
this._register = null;
|
|
14
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
13
15
|
this._bibliography = null;
|
|
16
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
14
17
|
this._images = null;
|
|
15
18
|
}
|
|
16
19
|
|
|
20
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
17
21
|
get concepts() { return this._concepts; }
|
|
22
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
18
23
|
get register() { return this._register; }
|
|
24
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
19
25
|
get bibliography() { return this._bibliography; }
|
|
26
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
20
27
|
get images() { return this._images; }
|
|
21
28
|
|
|
22
29
|
loadFromDirectory(dir) {
|
|
30
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
23
31
|
this._concepts = new ConceptCollection(readConcepts(dir));
|
|
32
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
24
33
|
this._register = readRegister(dir);
|
|
25
34
|
return this;
|
|
26
35
|
}
|
|
27
36
|
|
|
28
37
|
async loadFromGcr(input) {
|
|
29
38
|
const pkg = await loadGcr(input);
|
|
39
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
30
40
|
this._concepts = new ConceptCollection(await pkg.allConcepts());
|
|
41
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
31
42
|
this._register = await pkg.register();
|
|
43
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
32
44
|
this._bibliography = await pkg.bibliography();
|
|
45
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
33
46
|
this._images = await pkg.allImageFiles();
|
|
34
47
|
return this;
|
|
35
48
|
}
|
|
36
49
|
|
|
37
50
|
saveToDirectory(dir, options = {}) {
|
|
51
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
38
52
|
writeConcepts(dir, this._concepts, {
|
|
53
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
39
54
|
register: this._register ?? undefined,
|
|
55
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
40
56
|
format: options.format,
|
|
41
57
|
});
|
|
42
58
|
}
|
|
43
59
|
|
|
44
60
|
async saveToGcr(options = {}) {
|
|
45
61
|
return GcrWriter.createBuffer({
|
|
62
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
46
63
|
concepts: this._concepts,
|
|
64
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
47
65
|
metadata: options.metadata,
|
|
66
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
48
67
|
register: this._register,
|
|
68
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
49
69
|
format: options.format,
|
|
70
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
50
71
|
compiledFormats: options.compiledFormats,
|
|
72
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
51
73
|
bibliography: this._bibliography,
|
|
74
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
52
75
|
images: this._images,
|
|
53
76
|
});
|
|
54
77
|
}
|
|
55
78
|
|
|
56
79
|
add(concept) {
|
|
80
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
57
81
|
const existing = this._concepts.byId(concept.id);
|
|
58
82
|
if (existing) {
|
|
83
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
59
84
|
const idx = this._concepts.indexOf(existing);
|
|
85
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
60
86
|
this._concepts.set(idx, concept);
|
|
61
87
|
} else {
|
|
88
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
62
89
|
this._concepts.push(concept);
|
|
63
90
|
}
|
|
64
91
|
return this;
|
|
65
92
|
}
|
|
66
93
|
|
|
67
94
|
remove(id) {
|
|
95
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
68
96
|
const idx = this._concepts.findIndex(c => c.id === id);
|
|
97
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
69
98
|
if (idx >= 0) this._concepts.splice(idx, 1);
|
|
70
99
|
return this;
|
|
71
100
|
}
|
|
72
101
|
|
|
73
102
|
setRegister(data) {
|
|
103
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
74
104
|
this._register = data;
|
|
75
105
|
return this;
|
|
76
106
|
}
|
|
77
107
|
|
|
78
108
|
setBibliography(bib) {
|
|
79
109
|
if (bib instanceof BibliographyData) {
|
|
110
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
80
111
|
this._bibliography = bib;
|
|
81
112
|
} else if (typeof bib === 'string') {
|
|
113
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
82
114
|
this._bibliography = BibliographyData.fromYAML(bib);
|
|
83
115
|
} else if (bib == null) {
|
|
116
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
84
117
|
this._bibliography = null;
|
|
85
118
|
} else {
|
|
119
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
86
120
|
this._bibliography = new BibliographyData(bib);
|
|
87
121
|
}
|
|
88
122
|
return this;
|
|
89
123
|
}
|
|
90
124
|
|
|
91
125
|
setImages(images) {
|
|
126
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
92
127
|
this._images = images instanceof Map ? images : new Map(Object.entries(images));
|
|
93
128
|
return this;
|
|
94
129
|
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
2
1
|
// Agents emitter — emits foaf:Person / prov:Organization from
|
|
3
2
|
// contributor declarations. Mirrors concept-browser's agents-emitter.ts.
|
|
4
3
|
//
|
|
@@ -100,6 +99,7 @@ export function* agentsToQuads(agents: Record<string, unknown>[], options: Recor
|
|
|
100
99
|
const emittedOrgs = new Set();
|
|
101
100
|
|
|
102
101
|
for (const a of agents ?? []) {
|
|
102
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
103
103
|
const person = namedNode(a.agentIri);
|
|
104
104
|
yield quad(person, namedNode(RDF_TYPE), namedNode(FOAF.Person));
|
|
105
105
|
yield quad(person, namedNode(RDF_TYPE), namedNode(PROV.Person));
|
|
@@ -110,9 +110,11 @@ export function* agentsToQuads(agents: Record<string, unknown>[], options: Recor
|
|
|
110
110
|
yield quad(person, namedNode(FOAF.mbox), namedNode(`mailto:${(a as Record<string, unknown>).email as string}`));
|
|
111
111
|
}
|
|
112
112
|
if (a.url) {
|
|
113
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
113
114
|
yield quad(person, namedNode(RDFS.seeAlso), namedNode(a.url));
|
|
114
115
|
}
|
|
115
116
|
if (a.role) {
|
|
117
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
116
118
|
yield quad(person, namedNode(DCTERMS.description), literal(a.role));
|
|
117
119
|
}
|
|
118
120
|
|
|
@@ -127,6 +129,7 @@ export function* agentsToQuads(agents: Record<string, unknown>[], options: Recor
|
|
|
127
129
|
yield quad(org, namedNode(RDF_TYPE), namedNode(FOAF.Organization));
|
|
128
130
|
yield quad(org, namedNode(RDF_TYPE), namedNode(PROV.Organization));
|
|
129
131
|
yield quad(org, namedNode(RDF_TYPE), namedNode(PROV.Agent));
|
|
132
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
130
133
|
yield quad(org, namedNode(FOAF.name), literal(a.organization));
|
|
131
134
|
}
|
|
132
135
|
}
|
package/src/rdf/curie.ts
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
2
|
-
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
3
1
|
// CURIE helpers — resolve/compact IRIs against the canonical PREFIXES.
|
|
4
2
|
//
|
|
5
3
|
// Single source of truth for CURIE ↔ IRI conversion. Previously
|
|
@@ -33,6 +31,7 @@ export function compactIri(iri: string, prefixes: Record<string, string> = PREFI
|
|
|
33
31
|
let bestLen = 0;
|
|
34
32
|
for (const [prefix, base] of Object.entries(prefixes)) {
|
|
35
33
|
if (iri.startsWith(base) && base.length > bestLen) {
|
|
34
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
36
35
|
best = `${prefix}:${iri.slice(base.length)}`;
|
|
37
36
|
bestLen = base.length;
|
|
38
37
|
}
|
package/src/rdf/gloss-concept.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
2
1
|
// Concept → RDF quads. Mirrors glossarist-ruby's `Rdf::GlossConcept`.
|
|
3
2
|
//
|
|
4
3
|
// URI shape: `<uriBase>/<registerId>/concept/<conceptId>`.
|
|
@@ -19,6 +18,7 @@ import { namedNode, literal, quad } from './terms.js';
|
|
|
19
18
|
// (2) add one entry here. Per TODO Phase 6e this should be a
|
|
20
19
|
// self-registering registry; for the two current types, the dispatch
|
|
21
20
|
// table is simpler and keeps the dependency graph acyclic.
|
|
21
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
22
22
|
const HYPEREDGE_EMITTERS: Map<unknown, Record<string, unknown>> = new Map([
|
|
23
23
|
[PartitiveHyperedge, {
|
|
24
24
|
linkPredicate: PRED.gloss.hasPartitiveRelation,
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
2
1
|
// NonVerbal entity → RDF quads. Mirrors the v3.1.0 concept-model
|
|
3
2
|
// NonVerbal class hierarchy. Two distinct shapes:
|
|
4
3
|
//
|
|
@@ -46,12 +45,15 @@ export function* nonVerbalRepToQuads(nvr, { parentUri, index, language = null })
|
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
47
|
if (nvr.caption) {
|
|
48
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
49
49
|
yield quad(namedNode(subject), namedNode(PRED.gloss.caption), literal(nvr.caption, language));
|
|
50
50
|
}
|
|
51
51
|
if (nvr.description) {
|
|
52
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
52
53
|
yield quad(namedNode(subject), namedNode(DCTERMS_DESCRIPTION), literal(nvr.description, language));
|
|
53
54
|
}
|
|
54
55
|
if (nvr.alt) {
|
|
56
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
55
57
|
yield quad(namedNode(subject), namedNode(PRED.gloss.altText), literal(nvr.alt, language));
|
|
56
58
|
}
|
|
57
59
|
|
|
@@ -85,12 +87,15 @@ export function* nonVerbalEntityToQuads(entity, options) {
|
|
|
85
87
|
yield quad(s, namedNode(WELL_KNOWN.rdfType), namedNode(`${PRED.gloss.$ns}${entity.rdfClass()}`));
|
|
86
88
|
|
|
87
89
|
if (entity.caption) {
|
|
90
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
88
91
|
yield quad(s, namedNode(PRED.gloss.caption), literal(entity.caption, null));
|
|
89
92
|
}
|
|
90
93
|
if (entity.description) {
|
|
94
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
91
95
|
yield quad(s, namedNode(DCTERMS_DESCRIPTION), literal(entity.description, null));
|
|
92
96
|
}
|
|
93
97
|
if (entity.alt) {
|
|
98
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
94
99
|
yield quad(s, namedNode(PRED.gloss.altText), literal(entity.alt, null));
|
|
95
100
|
}
|
|
96
101
|
|
|
@@ -152,12 +157,15 @@ function* subfigureQuads(figure, subjectUri, _options) {
|
|
|
152
157
|
yield quad(s, namedNode(WELL_KNOWN.rdfType), namedNode(`${PRED.gloss.$ns}${figure.rdfClass()}`));
|
|
153
158
|
|
|
154
159
|
if (figure.caption) {
|
|
160
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
155
161
|
yield quad(s, namedNode(PRED.gloss.caption), literal(figure.caption, null));
|
|
156
162
|
}
|
|
157
163
|
if (figure.description) {
|
|
164
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
158
165
|
yield quad(s, namedNode(DCTERMS_DESCRIPTION), literal(figure.description, null));
|
|
159
166
|
}
|
|
160
167
|
if (figure.alt) {
|
|
168
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
161
169
|
yield quad(s, namedNode(PRED.gloss.altText), literal(figure.alt, null));
|
|
162
170
|
}
|
|
163
171
|
|
|
@@ -175,6 +183,7 @@ function* subfigureQuads(figure, subjectUri, _options) {
|
|
|
175
183
|
|
|
176
184
|
function* tableQuads(table, s) {
|
|
177
185
|
if (table.content) {
|
|
186
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
178
187
|
yield quad(s, namedNode(PRED.gloss.content), literal(table.content, null));
|
|
179
188
|
}
|
|
180
189
|
if (table.format) {
|
|
@@ -184,6 +193,7 @@ function* tableQuads(table, s) {
|
|
|
184
193
|
|
|
185
194
|
function* formulaQuads(formula, s) {
|
|
186
195
|
if (formula.expression) {
|
|
196
|
+
// @ts-expect-error TODO(Phase 2e): type this fully
|
|
187
197
|
yield quad(s, namedNode(PRED.gloss.expression), literal(formula.expression, null));
|
|
188
198
|
}
|
|
189
199
|
if (formula.notation) {
|