glossarist 0.4.41 → 0.4.43
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/{compiled-format.js → compiled-format.ts} +1 -0
- package/src/{concept-collection.js → concept-collection.ts} +1 -0
- package/src/{concept-diff.js → concept-diff.ts} +1 -0
- package/src/{concept-parser.js → concept-parser.ts} +1 -0
- package/src/{concept-reader.js → concept-reader.ts} +1 -0
- package/src/{concept-serializer.js → concept-serializer.ts} +1 -0
- package/src/{concept-writer.js → concept-writer.ts} +1 -0
- package/src/{dataset-asset.js → dataset-asset.ts} +1 -0
- package/src/diff/{canonical-json.js → canonical-json.ts} +8 -10
- package/src/diff/change.ts +175 -0
- package/src/diff/{collection-diff.js → collection-diff.ts} +1 -0
- package/src/diff/{concept-diff.js → concept-diff.ts} +1 -0
- package/src/diff/{diff-patch.js → diff-patch.ts} +1 -0
- package/src/diff/{diff-renderer.js → diff-renderer.ts} +1 -0
- package/src/diff/identity.ts +33 -0
- package/src/diff/{index.js → index.ts} +1 -0
- package/src/diff/list-diff.ts +231 -0
- package/src/diff/{similarity.js → similarity.ts} +3 -7
- package/src/diff/text-diff.ts +167 -0
- package/src/{entity-directory.js → entity-directory.ts} +1 -0
- package/src/{errors.js → errors.ts} +1 -0
- package/src/{gcr-reader.js → gcr-reader.ts} +1 -0
- package/src/{gcr-writer.js → gcr-writer.ts} +1 -0
- package/src/{index.js → index.ts} +1 -0
- package/src/{managed-concept-collection.js → managed-concept-collection.ts} +1 -0
- package/src/migration/{hyperedge-migrator.js → hyperedge-migrator.ts} +1 -0
- package/src/rdf/{agents-emitter.js → agents-emitter.ts} +1 -0
- package/src/rdf/{bibliography-emitter.js → bibliography-emitter.ts} +1 -0
- package/src/rdf/{bnode-id.js → bnode-id.ts} +1 -0
- package/src/rdf/{build-activity-emitter.js → build-activity-emitter.ts} +1 -0
- package/src/rdf/{curie.js → curie.ts} +1 -0
- package/src/rdf/{dataset-emitter.js → dataset-emitter.ts} +1 -0
- package/src/rdf/{deterministic-id.js → deterministic-id.ts} +1 -0
- package/src/rdf/{document-writer.js → document-writer.ts} +1 -0
- package/src/rdf/{gloss-concept.js → gloss-concept.ts} +1 -0
- package/src/rdf/{gloss-designation.js → gloss-designation.ts} +1 -0
- package/src/rdf/{gloss-detailed-definition.js → gloss-detailed-definition.ts} +1 -0
- package/src/rdf/{gloss-generic-hyperedge.js → gloss-generic-hyperedge.ts} +1 -0
- package/src/rdf/{gloss-localized-concept.js → gloss-localized-concept.ts} +1 -0
- package/src/rdf/{gloss-non-verbal-rep.js → gloss-non-verbal-rep.ts} +1 -0
- package/src/rdf/{gloss-partitive-member.js → gloss-partitive-member.ts} +1 -0
- package/src/rdf/{gloss-partitive-relation.js → gloss-partitive-relation.ts} +1 -0
- package/src/rdf/{gloss-source.js → gloss-source.ts} +1 -0
- package/src/rdf/{group-emitter.js → group-emitter.ts} +1 -0
- package/src/rdf/{image-variant-emitter.js → image-variant-emitter.ts} +1 -0
- package/src/rdf/{index.js → index.ts} +1 -0
- package/src/rdf/{normalize-enum.js → normalize-enum.ts} +1 -0
- package/src/rdf/{prefixes.js → prefixes.ts} +1 -0
- package/src/rdf/{provenance-emitter.js → provenance-emitter.ts} +1 -0
- package/src/rdf/{sections-builder.js → sections-builder.ts} +1 -0
- package/src/rdf/{shacl-entry.js → shacl-entry.ts} +1 -0
- package/src/rdf/{shacl.js → shacl.ts} +1 -0
- package/src/rdf/{terms.js → terms.ts} +1 -0
- package/src/rdf/{version-emitter.js → version-emitter.ts} +1 -0
- package/src/rdf/{vocabulary-emitter.js → vocabulary-emitter.ts} +1 -0
- package/src/rdf/{write-turtle-sync.js → write-turtle-sync.ts} +1 -0
- package/src/{reference-mention.js → reference-mention.ts} +1 -0
- package/src/{reference-resolver.js → reference-resolver.ts} +1 -0
- package/src/{render-classification.js → render-classification.ts} +1 -0
- package/src/{sort.js → sort.ts} +1 -0
- package/src/transforms/{concept-to-gloss.transform.js → concept-to-gloss.transform.ts} +1 -0
- package/src/transforms/index.ts +2 -0
- package/src/{uuid.js → uuid.ts} +1 -0
- package/src/{v1-reader.js → v1-reader.ts} +1 -0
- package/src/validators/{asset-index.js → asset-index.ts} +1 -0
- package/src/validators/{binary-has-part-redundancy-rule.js → binary-has-part-redundancy-rule.ts} +1 -0
- package/src/validators/{concept-validator.js → concept-validator.ts} +1 -0
- package/src/validators/{delimiting-coherence-rule.js → delimiting-coherence-rule.ts} +1 -0
- package/src/validators/{external-concept-shape-rule.js → external-concept-shape-rule.ts} +1 -0
- package/src/validators/{gcr-validator.js → gcr-validator.ts} +1 -0
- package/src/validators/{hyperedge-coherence-rule.js → hyperedge-coherence-rule.ts} +1 -0
- package/src/validators/{index.js → index.ts} +1 -0
- package/src/validators/{partitive-relation-coherence-rule.js → partitive-relation-coherence-rule.ts} +1 -0
- package/src/validators/{ref-keys.js → ref-keys.ts} +1 -0
- package/src/validators/{register-validator.js → register-validator.ts} +1 -0
- package/src/validators/{relationship-type-rule.js → relationship-type-rule.ts} +1 -0
- package/src/validators/{sourced-from-locality-rule.js → sourced-from-locality-rule.ts} +1 -0
- package/src/validators/{v3-rules.js → v3-rules.ts} +1 -0
- package/src/validators/{validation-error.js → validation-error.ts} +1 -0
- package/src/validators/{validation-result.js → validation-result.ts} +1 -0
- package/src/validators/{validation-rule.js → validation-rule.ts} +1 -0
- package/src/diff/change.js +0 -139
- package/src/diff/identity.js +0 -22
- package/src/diff/list-diff.js +0 -227
- package/src/diff/text-diff.js +0 -128
- package/src/transforms/index.js +0 -1
- /package/src/models/{index.js → index.ts} +0 -0
- /package/src/rdf/{predicates.js → predicates.ts} +0 -0
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { GlossaristModel } from '../models/base.js';
|
|
2
|
+
|
|
3
|
+
const HUNK_EQUAL = 'equal';
|
|
4
|
+
const HUNK_ADDED = 'added';
|
|
5
|
+
const HUNK_REMOVED = 'removed';
|
|
6
|
+
|
|
7
|
+
export type TextHunkType = typeof HUNK_EQUAL | typeof HUNK_ADDED | typeof HUNK_REMOVED;
|
|
8
|
+
|
|
9
|
+
const TOKEN_RE = /(\s+)|(\S+)/g;
|
|
10
|
+
|
|
11
|
+
export interface TextHunkJson {
|
|
12
|
+
type: TextHunkType;
|
|
13
|
+
text: string;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export class TextHunk extends GlossaristModel {
|
|
17
|
+
readonly type: TextHunkType;
|
|
18
|
+
readonly text: string;
|
|
19
|
+
|
|
20
|
+
constructor(data: TextHunkJson = { type: HUNK_EQUAL, text: '' }) {
|
|
21
|
+
super();
|
|
22
|
+
if (![HUNK_EQUAL, HUNK_ADDED, HUNK_REMOVED].includes(data.type)) {
|
|
23
|
+
throw new Error(`TextHunk type must be 'equal', 'added', or 'removed' (got ${data.type})`);
|
|
24
|
+
}
|
|
25
|
+
this.type = data.type;
|
|
26
|
+
this.text = data.text ?? '';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
override toJSON(): TextHunkJson {
|
|
30
|
+
return { type: this.type, text: this.text };
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
static override fromJSON(data: TextHunkJson): TextHunk {
|
|
34
|
+
return new TextHunk(data);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface TextDiffJson {
|
|
39
|
+
oldText?: string;
|
|
40
|
+
old_text?: string;
|
|
41
|
+
newText?: string;
|
|
42
|
+
new_text?: string;
|
|
43
|
+
hunks?: ReadonlyArray<TextHunkJson | TextHunk>;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export class TextDiff extends GlossaristModel {
|
|
47
|
+
readonly oldText: string;
|
|
48
|
+
readonly newText: string;
|
|
49
|
+
private readonly _hunks: ReadonlyArray<TextHunk>;
|
|
50
|
+
|
|
51
|
+
constructor(data: TextDiffJson = {}) {
|
|
52
|
+
super();
|
|
53
|
+
this.oldText = data.oldText ?? data.old_text ?? '';
|
|
54
|
+
this.newText = data.newText ?? data.new_text ?? '';
|
|
55
|
+
this._hunks = (data.hunks ?? []).map((h) =>
|
|
56
|
+
h instanceof TextHunk ? h : new TextHunk(h),
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get hunks(): ReadonlyArray<TextHunk> {
|
|
61
|
+
return this._hunks;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
get hasChanges(): boolean {
|
|
65
|
+
return this._hunks.some((h) => h.type !== HUNK_EQUAL);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
get addedText(): string {
|
|
69
|
+
return this._hunks
|
|
70
|
+
.filter((h) => h.type === HUNK_ADDED)
|
|
71
|
+
.map((h) => h.text)
|
|
72
|
+
.join('');
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
get removedText(): string {
|
|
76
|
+
return this._hunks
|
|
77
|
+
.filter((h) => h.type === HUNK_REMOVED)
|
|
78
|
+
.map((h) => h.text)
|
|
79
|
+
.join('');
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
override toJSON(): TextDiffJson & { old_text: string; new_text: string; hunks: ReadonlyArray<TextHunkJson> } {
|
|
83
|
+
return {
|
|
84
|
+
old_text: this.oldText,
|
|
85
|
+
new_text: this.newText,
|
|
86
|
+
hunks: this._hunks.map((h) => h.toJSON()),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
static override fromJSON(data: TextDiffJson): TextDiff {
|
|
91
|
+
return new TextDiff(data);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function diffText(oldText: string | null | undefined, newText: string | null | undefined): TextDiff {
|
|
96
|
+
const oldStr = String(oldText ?? '');
|
|
97
|
+
const newStr = String(newText ?? '');
|
|
98
|
+
const oldTokens = tokenize(oldStr);
|
|
99
|
+
const newTokens = tokenize(newStr);
|
|
100
|
+
const hunks = lcsHunks(oldTokens, newTokens);
|
|
101
|
+
return new TextDiff({ oldText: oldStr, newText: newStr, hunks });
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function tokenize(text: string): string[] {
|
|
105
|
+
if (text.length === 0) return [];
|
|
106
|
+
return text.match(TOKEN_RE) ?? [];
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function lcsHunks(a: string[], b: string[]): TextHunk[] {
|
|
110
|
+
const n = a.length;
|
|
111
|
+
const m = b.length;
|
|
112
|
+
|
|
113
|
+
if (n === 0) return m === 0 ? [] : [new TextHunk({ type: HUNK_ADDED, text: b.join('') })];
|
|
114
|
+
if (m === 0) return [new TextHunk({ type: HUNK_REMOVED, text: a.join('') })];
|
|
115
|
+
|
|
116
|
+
const dp = Array.from({ length: n + 1 }, () => new Uint32Array(m + 1));
|
|
117
|
+
for (let i = 1; i <= n; i++) {
|
|
118
|
+
for (let j = 1; j <= m; j++) {
|
|
119
|
+
dp[i]![j]! =
|
|
120
|
+
a[i - 1] === b[j - 1]
|
|
121
|
+
? dp[i - 1]![j - 1]! + 1
|
|
122
|
+
: Math.max(dp[i - 1]![j]!, dp[i]![j - 1]!);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const raw: Array<{ type: TextHunkType; text: string }> = [];
|
|
127
|
+
let i = n;
|
|
128
|
+
let j = m;
|
|
129
|
+
while (i > 0 && j > 0) {
|
|
130
|
+
if (a[i - 1] === b[j - 1]) {
|
|
131
|
+
raw.push({ type: HUNK_EQUAL, text: a[i - 1]! });
|
|
132
|
+
i--; j--;
|
|
133
|
+
} else if ((dp[i - 1]![j] ?? 0) >= (dp[i]![j - 1] ?? 0)) {
|
|
134
|
+
raw.push({ type: HUNK_REMOVED, text: a[i - 1]! });
|
|
135
|
+
i--;
|
|
136
|
+
} else {
|
|
137
|
+
raw.push({ type: HUNK_ADDED, text: b[j - 1]! });
|
|
138
|
+
j--;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
while (i > 0) {
|
|
142
|
+
raw.push({ type: HUNK_REMOVED, text: a[i - 1]! });
|
|
143
|
+
i--;
|
|
144
|
+
}
|
|
145
|
+
while (j > 0) {
|
|
146
|
+
raw.push({ type: HUNK_ADDED, text: b[j - 1]! });
|
|
147
|
+
j--;
|
|
148
|
+
}
|
|
149
|
+
raw.reverse();
|
|
150
|
+
|
|
151
|
+
return coalesce(raw).map((h) => new TextHunk(h));
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function coalesce(
|
|
155
|
+
raw: ReadonlyArray<{ type: TextHunkType; text: string }>,
|
|
156
|
+
): Array<{ type: TextHunkType; text: string }> {
|
|
157
|
+
const out: Array<{ type: TextHunkType; text: string }> = [];
|
|
158
|
+
for (const r of raw) {
|
|
159
|
+
const last = out[out.length - 1];
|
|
160
|
+
if (last && last.type === r.type) {
|
|
161
|
+
last.text += r.text;
|
|
162
|
+
} else {
|
|
163
|
+
out.push({ type: r.type, text: r.text });
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
return out;
|
|
167
|
+
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
// Designation → RDF quads. Mirrors glossarist-ruby's
|
|
2
3
|
// `Rdf::GlossDesignation` + the per-subtype classes (GlossExpression,
|
|
3
4
|
// GlossAbbreviation, etc.). The ontology class for each subtype is
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
// DetailedDefinition → RDF quads. Mirrors glossarist-ruby's
|
|
2
3
|
// `Rdf::GlossDetailedDefinition`. Used for definitions, notes, examples,
|
|
3
4
|
// and annotations — they all share the same shape (content + optional
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
// ConceptSource → RDF quads. Mirrors glossarist-ruby's
|
|
2
3
|
// `Rdf::GlossConceptSource` + `Rdf::GlossCitation`. Sources are reified
|
|
3
4
|
// resources linked from their parent (concept or localized concept or
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
// Helpers for normalizing enumeration values that get interpolated into
|
|
2
3
|
// URIs. Source data may contain compound forms ("preferred/admitted") or
|
|
3
4
|
// path-like values that must be reduced to a single local name before
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
// Re-export prefix map and predicate constants generated from the vendored
|
|
2
3
|
// concept-model JSON-LD context. Downstream code should never duplicate
|
|
3
4
|
// prefix bindings — always import from here.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
// Node-only SHACL validator entry. Separated from glossarist/rdf so that
|
|
2
3
|
// browser bundles can import RDF emitters/writers without pulling in
|
|
3
4
|
// node:fs/promises, node:path, node:url.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
// SHACL validator wrapper. Loads vendored concept-model shapes once and
|
|
2
3
|
// validates any RDFJS Dataset against them. Mirrors the mechanics of
|
|
3
4
|
// glossarist-ruby's `Glossarist::Validation::ShaclValidator`.
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
// Vocabulary graph emitter — emits SKOS ConceptSchemes for the
|
|
2
3
|
// enumeration IRIs that glossarist emits in instance data
|
|
3
4
|
// (gloss:status/*, gloss:entstatus/*, gloss:norm/*, gloss:srcstatus/*,
|
package/src/{sort.js → sort.ts}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
// ConceptToGlossTransform — JS port of glossarist-ruby's
|
|
2
3
|
// `Transforms::ConceptToGlossTransform`. Converts a Concept model into
|
|
3
4
|
// ontology-faithful RDF (Turtle, JSON-LD, N-Triples).
|
package/src/{uuid.js → uuid.ts}
RENAMED
package/src/validators/{binary-has-part-redundancy-rule.js → binary-has-part-redundancy-rule.ts}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
// Warns when binary `has_part` / `is_part_of` edges duplicate
|
|
2
3
|
// PartitiveHyperedge members, or when a concept has many binary
|
|
3
4
|
// has_part edges that should be consolidated into a PartitiveHyperedge.
|
package/src/validators/{partitive-relation-coherence-rule.js → partitive-relation-coherence-rule.ts}
RENAMED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
// Deprecated. This rule has been generalized and renamed to
|
|
2
3
|
// HyperedgeCoherenceRule (see ./hyperedge-coherence-rule.js). The
|
|
3
4
|
// new rule is type-blind — it validates every AbstractHyperedge
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
import { ValidationRule } from './validation-rule.js';
|
|
2
3
|
import { RELATIONSHIP_TYPES } from '../models/related-concept.js';
|
|
3
4
|
import { DESIGNATION_RELATIONSHIP_TYPES } from '../models/designation-relationship.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
// @ts-nocheck — TEMPORARY during TS migration. TODO(Phase 2e): remove and type fully.
|
|
1
2
|
// Validates that every ConceptSource#sourced_from Citation includes a
|
|
2
3
|
// locality. Per concept-model commit 9c065df ("sourced_from citations
|
|
3
4
|
// must include locality"), a sourced_from entry without a locality is
|