glossarist 0.4.37 → 0.4.39

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.
Files changed (37) hide show
  1. package/package.json +1 -1
  2. package/src/models/base.ts +18 -1
  3. package/src/models/bibliography-data.ts +64 -0
  4. package/src/models/{bibliography-entry.js → bibliography-entry.ts} +18 -4
  5. package/src/models/citation.ts +98 -0
  6. package/src/models/{concept-reference.js → concept-reference.ts} +21 -7
  7. package/src/models/designation-relationship.ts +39 -0
  8. package/src/models/detailed-definition.ts +92 -0
  9. package/src/models/figure.ts +110 -0
  10. package/src/models/formula.ts +36 -0
  11. package/src/models/grammar-info.ts +78 -0
  12. package/src/models/{locality.js → locality.ts} +16 -4
  13. package/src/models/localized-string.ts +32 -0
  14. package/src/models/non-verb-rep.ts +48 -0
  15. package/src/models/non-verbal-entity.ts +65 -0
  16. package/src/models/non-verbal-reference.ts +73 -0
  17. package/src/models/non-verbal-references.ts +29 -0
  18. package/src/models/{pronunciation.js → pronunciation.ts} +18 -4
  19. package/src/models/registrable.ts +48 -0
  20. package/src/models/{related-concept.js → related-concept.ts} +49 -25
  21. package/src/models/shared-non-verbal-entity.ts +36 -0
  22. package/src/models/table.ts +36 -0
  23. package/src/models/bibliography-data.js +0 -48
  24. package/src/models/citation.js +0 -68
  25. package/src/models/designation-relationship.js +0 -27
  26. package/src/models/detailed-definition.js +0 -59
  27. package/src/models/figure.js +0 -75
  28. package/src/models/formula.js +0 -25
  29. package/src/models/grammar-info.js +0 -40
  30. package/src/models/localized-string.js +0 -19
  31. package/src/models/non-verb-rep.js +0 -33
  32. package/src/models/non-verbal-entity.js +0 -46
  33. package/src/models/non-verbal-reference.js +0 -35
  34. package/src/models/non-verbal-references.js +0 -16
  35. package/src/models/registrable.js +0 -25
  36. package/src/models/shared-non-verbal-entity.js +0 -28
  37. package/src/models/table.js +0 -25
@@ -1,22 +1,34 @@
1
1
  import { GlossaristModel } from './base.js';
2
2
 
3
+ export interface LocalityJson {
4
+ type?: string | null;
5
+ reference_from?: string | null;
6
+ referenceFrom?: string | null;
7
+ reference_to?: string | null;
8
+ referenceTo?: string | null;
9
+ }
10
+
3
11
  export class Locality extends GlossaristModel {
4
- constructor(data = {}) {
12
+ readonly type: string | null;
13
+ readonly referenceFrom: string | null;
14
+ readonly referenceTo: string | null;
15
+
16
+ constructor(data: LocalityJson = {}) {
5
17
  super();
6
18
  this.type = data.type ?? null;
7
19
  this.referenceFrom = data.reference_from ?? data.referenceFrom ?? null;
8
20
  this.referenceTo = data.reference_to ?? data.referenceTo ?? null;
9
21
  }
10
22
 
11
- toJSON() {
12
- const obj = {};
23
+ override toJSON(): LocalityJson {
24
+ const obj: LocalityJson = {};
13
25
  if (this.type != null) obj.type = this.type;
14
26
  if (this.referenceFrom != null) obj.reference_from = this.referenceFrom;
15
27
  if (this.referenceTo != null) obj.reference_to = this.referenceTo;
16
28
  return obj;
17
29
  }
18
30
 
19
- static fromJSON(data) {
31
+ static override fromJSON(data: LocalityJson): Locality {
20
32
  return new Locality(data);
21
33
  }
22
34
  }
@@ -0,0 +1,32 @@
1
+ const FALLBACK_LANG = 'eng';
2
+
3
+ export type LocalizedStringHash = Readonly<Record<string, string>>;
4
+
5
+ export function fetchLocalizedString(
6
+ hash: LocalizedStringHash | null | undefined,
7
+ lang: string,
8
+ fallback: string | null = FALLBACK_LANG,
9
+ ): string | null {
10
+ if (hash == null || typeof hash !== 'object') return null;
11
+ const direct = hash[lang] ?? hash[String(lang)];
12
+ if (direct != null) return direct;
13
+ if (fallback != null && fallback !== lang) {
14
+ return hash[fallback] ?? hash[String(fallback)] ?? null;
15
+ }
16
+ return null;
17
+ }
18
+
19
+ export function localizedStringIsEmpty(
20
+ hash: LocalizedStringHash | null | undefined,
21
+ ): boolean {
22
+ return (
23
+ hash == null ||
24
+ (typeof hash === 'object' && Object.keys(hash).length === 0)
25
+ );
26
+ }
27
+
28
+ export function localizedStringIsPresent(
29
+ hash: LocalizedStringHash | null | undefined,
30
+ ): boolean {
31
+ return !localizedStringIsEmpty(hash);
32
+ }
@@ -0,0 +1,48 @@
1
+ import { NonVerbalEntity } from './non-verbal-entity.js';
2
+ import type { NonVerbalEntityJson } from './non-verbal-entity.js';
3
+ import { FigureImage } from './figure.js';
4
+ import type { FigureImageJson } from './figure.js';
5
+
6
+ export const NON_VERBAL_TYPES: ReadonlyArray<string> = Object.freeze([
7
+ 'image', 'table', 'formula',
8
+ ]);
9
+
10
+ export interface NonVerbRepJson extends NonVerbalEntityJson {
11
+ type?: string | null;
12
+ images?: ReadonlyArray<FigureImageJson | FigureImage>;
13
+ }
14
+
15
+ export class NonVerbRep extends NonVerbalEntity {
16
+ readonly type: string | null;
17
+ protected readonly _rawImages: ReadonlyArray<FigureImageJson | FigureImage>;
18
+ protected _images: ReadonlyArray<FigureImage> | null = null;
19
+
20
+ constructor(data: NonVerbRepJson = {}) {
21
+ super(data);
22
+ this.type = data.type ?? null;
23
+ this._rawImages = data.images ?? [];
24
+ }
25
+
26
+ override rdfClass(): string {
27
+ return 'NonVerbalRepresentation';
28
+ }
29
+
30
+ get images(): ReadonlyArray<FigureImage> {
31
+ return this._lazy<FigureImage>(
32
+ '_images',
33
+ '_rawImages',
34
+ (i) => (i instanceof FigureImage ? i : new FigureImage(i as FigureImageJson)),
35
+ );
36
+ }
37
+
38
+ override toJSON(): NonVerbRepJson {
39
+ const obj = super.toJSON() as NonVerbRepJson;
40
+ if (this.type != null) obj.type = this.type;
41
+ this._serialize(obj as unknown as Record<string, unknown>, 'images', '_images', '_rawImages');
42
+ return obj;
43
+ }
44
+
45
+ static override fromJSON(data: NonVerbRepJson): NonVerbRep {
46
+ return new NonVerbRep(data);
47
+ }
48
+ }
@@ -0,0 +1,65 @@
1
+ import { RegistrableModel } from './registrable.js';
2
+ import { ConceptSource } from './concept-source.js';
3
+ import type { ConceptSourceJson } from './concept-source.js';
4
+
5
+ export interface NonVerbalEntityJson {
6
+ caption?: string | null;
7
+ description?: string | null;
8
+ alt?: string | null;
9
+ sources?: ReadonlyArray<ConceptSourceJson | ConceptSource>;
10
+ type?: string | null;
11
+ }
12
+
13
+ export class NonVerbalEntity extends RegistrableModel {
14
+ readonly caption: string | null;
15
+ readonly description: string | null;
16
+ readonly alt: string | null;
17
+ protected readonly _rawSources: ReadonlyArray<ConceptSourceJson | ConceptSource>;
18
+ protected _sources: ReadonlyArray<ConceptSource> | null = null;
19
+
20
+ constructor(data: NonVerbalEntityJson = {}) {
21
+ super();
22
+ this.caption = data.caption ?? null;
23
+ this.description = data.description ?? null;
24
+ this.alt = data.alt ?? null;
25
+ this._rawSources = data.sources ?? [];
26
+ }
27
+
28
+ get sources(): ReadonlyArray<ConceptSource> {
29
+ return this._lazy<ConceptSource>(
30
+ '_sources',
31
+ '_rawSources',
32
+ (s) => (s instanceof ConceptSource ? s : new ConceptSource(s as ConceptSourceJson)),
33
+ );
34
+ }
35
+
36
+ /**
37
+ * Ontology class local-name. Subtypes override to return their specific
38
+ * class (Figure/Table/Formula). Used by the RDF emitter so a new subtype
39
+ * registers without editing the emitter (OCP).
40
+ */
41
+ rdfClass(): string {
42
+ return 'NonVerbalEntity';
43
+ }
44
+
45
+ findById(_targetId: string): NonVerbalEntity | null {
46
+ return null;
47
+ }
48
+
49
+ allIds(): string[] {
50
+ return [];
51
+ }
52
+
53
+ override toJSON(): NonVerbalEntityJson {
54
+ const obj: NonVerbalEntityJson = {};
55
+ if (this.caption != null) obj.caption = this.caption;
56
+ if (this.description != null) obj.description = this.description;
57
+ if (this.alt != null) obj.alt = this.alt;
58
+ this._serialize(obj as unknown as Record<string, unknown>, 'sources', '_sources', '_rawSources');
59
+ return obj;
60
+ }
61
+
62
+ static override fromJSON(data: NonVerbalEntityJson): NonVerbalEntity {
63
+ return NonVerbalEntity.fromData(data);
64
+ }
65
+ }
@@ -0,0 +1,73 @@
1
+ import { RegistrableModel } from './registrable.js';
2
+
3
+ export interface NonVerbalReferenceJson {
4
+ entityId?: string | null;
5
+ entity_id?: string | null;
6
+ ref?: string | null;
7
+ id?: string | null;
8
+ display?: string | null;
9
+ type?: string;
10
+ }
11
+
12
+ /**
13
+ * Polymorphic JSON for NonVerbalReference: either a bare string (the
14
+ * entity id) or an object with `{ ref, display?, type? }`.
15
+ */
16
+ export type NonVerbalReferenceInput =
17
+ | NonVerbalReferenceJson
18
+ | string
19
+ | NonVerbalReference;
20
+
21
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
+ type AnyCtor = new (...args: any[]) => any;
23
+
24
+ export class NonVerbalReference extends RegistrableModel {
25
+ readonly entityId: string | null;
26
+ readonly display: string | null;
27
+
28
+ constructor(data: NonVerbalReferenceJson = {}) {
29
+ super();
30
+ this.entityId = data.entityId ?? data.entity_id ?? data.ref ?? data.id ?? null;
31
+ this.display = data.display ?? null;
32
+ }
33
+
34
+ get dedupKey(): [string, string | null] {
35
+ return [this.constructor.name, this.entityId];
36
+ }
37
+
38
+ override toJSON(): NonVerbalReferenceJson | string {
39
+ if (this.display != null) {
40
+ return { ref: this.entityId ?? '', display: this.display };
41
+ }
42
+ return this.entityId ?? '';
43
+ }
44
+
45
+ static override fromJSON<T extends NonVerbalReference>(
46
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
47
+ this: new (...args: any[]) => T,
48
+ data: NonVerbalReferenceInput,
49
+ ): T | NonVerbalReference {
50
+ if (data instanceof NonVerbalReference) return data;
51
+ if (typeof data === 'string') {
52
+ return new (this as new (d: NonVerbalReferenceJson) => T)({ entityId: data });
53
+ }
54
+ const entityId =
55
+ data.entityId ?? data.entity_id ?? data.ref ?? data.id ?? null;
56
+ const display = data.display ?? null;
57
+ const type = data.type;
58
+ const Self = this as unknown as { _registry(): Map<string, AnyCtor> };
59
+ if (type) {
60
+ const Cls = Self._registry().get(type);
61
+ if (Cls) {
62
+ return new (Cls as new (d: NonVerbalReferenceJson) => T)({
63
+ entityId: entityId ?? undefined,
64
+ display: display ?? undefined,
65
+ });
66
+ }
67
+ }
68
+ return new (this as new (d: NonVerbalReferenceJson) => T)({
69
+ entityId: entityId ?? undefined,
70
+ display: display ?? undefined,
71
+ });
72
+ }
73
+ }
@@ -0,0 +1,29 @@
1
+ import { NonVerbalReference } from './non-verbal-reference.js';
2
+ import type { NonVerbalReferenceInput } from './non-verbal-reference.js';
3
+
4
+ export class FigureReference extends NonVerbalReference {
5
+ static override fromJSON(
6
+ data: NonVerbalReferenceInput,
7
+ ): FigureReference | NonVerbalReference {
8
+ return NonVerbalReference.fromJSON(data) as FigureReference | NonVerbalReference;
9
+ }
10
+ }
11
+ NonVerbalReference.register('figure', FigureReference);
12
+
13
+ export class TableReference extends NonVerbalReference {
14
+ static override fromJSON(
15
+ data: NonVerbalReferenceInput,
16
+ ): TableReference | NonVerbalReference {
17
+ return NonVerbalReference.fromJSON(data) as TableReference | NonVerbalReference;
18
+ }
19
+ }
20
+ NonVerbalReference.register('table', TableReference);
21
+
22
+ export class FormulaReference extends NonVerbalReference {
23
+ static override fromJSON(
24
+ data: NonVerbalReferenceInput,
25
+ ): FormulaReference | NonVerbalReference {
26
+ return NonVerbalReference.fromJSON(data) as FormulaReference | NonVerbalReference;
27
+ }
28
+ }
29
+ NonVerbalReference.register('formula', FormulaReference);
@@ -1,7 +1,21 @@
1
1
  import { GlossaristModel } from './base.js';
2
2
 
3
+ export interface PronunciationJson {
4
+ content?: string | null;
5
+ language?: string | null;
6
+ script?: string | null;
7
+ system?: string | null;
8
+ country?: string | null;
9
+ }
10
+
3
11
  export class Pronunciation extends GlossaristModel {
4
- constructor(data = {}) {
12
+ readonly content: string | null;
13
+ readonly language: string | null;
14
+ readonly script: string | null;
15
+ readonly system: string | null;
16
+ readonly country: string | null;
17
+
18
+ constructor(data: PronunciationJson = {}) {
5
19
  super();
6
20
  this.content = data.content ?? null;
7
21
  this.language = data.language ?? null;
@@ -10,8 +24,8 @@ export class Pronunciation extends GlossaristModel {
10
24
  this.country = data.country ?? null;
11
25
  }
12
26
 
13
- toJSON() {
14
- const obj = {};
27
+ override toJSON(): PronunciationJson {
28
+ const obj: PronunciationJson = {};
15
29
  if (this.content != null) obj.content = this.content;
16
30
  if (this.language != null) obj.language = this.language;
17
31
  if (this.script != null) obj.script = this.script;
@@ -20,7 +34,7 @@ export class Pronunciation extends GlossaristModel {
20
34
  return obj;
21
35
  }
22
36
 
23
- static fromJSON(data) {
37
+ static override fromJSON(data: PronunciationJson): Pronunciation {
24
38
  return new Pronunciation(data);
25
39
  }
26
40
  }
@@ -0,0 +1,48 @@
1
+ import { GlossaristModel } from './base.js';
2
+
3
+ /**
4
+ * Per-class registry of named subtypes. The registry is keyed by
5
+ * `type` discriminator and maps to the constructor function. Used by
6
+ * NonVerbalEntity (Figure/Table/Formula), NonVerbalReference
7
+ * (Figure/Table/Formula references), and any future RegistrableModel
8
+ * subclass that needs polymorphic dispatch on a string discriminator.
9
+ *
10
+ * Stored as a WeakMap keyed by the base class function, so each base
11
+ * gets its own namespace (NonVerbalEntity.register does not collide
12
+ * with NonVerbalReference.register).
13
+ *
14
+ * The registry stores constructors as `Function` because TS's strict
15
+ * variance on constructor params makes a typed constraint reject
16
+ * subclasses with narrower param types. The dispatch site casts the
17
+ * result back to the specific subclass.
18
+ */
19
+
20
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- see docstring.
21
+ type AnyCtor = new (...args: any[]) => any;
22
+
23
+ const _registries = new WeakMap<object, Map<string, AnyCtor>>();
24
+
25
+ export class RegistrableModel extends GlossaristModel {
26
+ static _registry(): Map<string, AnyCtor> {
27
+ const existing = _registries.get(this) ?? new Map();
28
+ if (!_registries.has(this)) _registries.set(this, existing);
29
+ return existing;
30
+ }
31
+
32
+ static register(type: string, cls: AnyCtor): void {
33
+ this._registry().set(type, cls);
34
+ }
35
+
36
+ static fromData<T extends RegistrableModel>(
37
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any -- any ctor signature accepted.
38
+ this: new (...args: any[]) => T,
39
+ data: unknown,
40
+ ): T {
41
+ if (data instanceof this) return data;
42
+ const type = (data as { type?: string } | null)?.type;
43
+ const Self = this as unknown as { _registry(): Map<string, AnyCtor> };
44
+ const registry = Self._registry();
45
+ const Cls = type ? (registry.get(type) ?? (this as AnyCtor)) : (this as AnyCtor);
46
+ return new (Cls as new (data: unknown) => T)(data);
47
+ }
48
+ }
@@ -1,7 +1,9 @@
1
1
  import { GlossaristModel } from './base.js';
2
2
  import { ConceptRef } from './concept-ref.js';
3
+ import type { ConceptRefJson } from './concept-ref.js';
4
+ import type { LocalizedString } from './generic-member.js';
3
5
 
4
- export const RELATIONSHIP_TYPES = Object.freeze([
6
+ export const RELATIONSHIP_TYPES: ReadonlyArray<string> = Object.freeze([
5
7
  // Lifecycle (ISO 10241-1)
6
8
  'deprecates', 'deprecated_by', 'supersedes', 'superseded_by',
7
9
  'replaces', 'replaced_by', 'invalidates', 'invalidated_by',
@@ -25,10 +27,9 @@ export const RELATIONSHIP_TYPES = Object.freeze([
25
27
  // Associative (ISO 10241-1 / ISO 25964)
26
28
  'see', 'related_concept', 'related_concept_broader', 'related_concept_narrower',
27
29
  'references',
28
- // ExternalConcept resolution (Glossarist extension — v2 partitive-relation)
29
- // Direction: real concept `provides` substance for an external concept;
30
- // external concept `provided_by` real concept. Stored on the
31
- // ExternalConcept. See TODO.partitive-relation-v2 item 07.
30
+ // ExternalConcept resolution (Glossarist extension). Direction: real
31
+ // concept `provides` substance for an external concept; external concept
32
+ // `provided_by` real concept. Stored on the ExternalConcept.
32
33
  'provides', 'provided_by',
33
34
  // Comparative (ISO 10241-1)
34
35
  'compare', 'contrast',
@@ -38,56 +39,79 @@ export const RELATIONSHIP_TYPES = Object.freeze([
38
39
  'homograph', 'false_friend',
39
40
  ]);
40
41
 
42
+ export type RelationshipType = string;
43
+
44
+ export interface RelatedConceptJson {
45
+ type?: RelationshipType;
46
+ content?: LocalizedString | string | null;
47
+ ref?: ConceptRefJson | ConceptRef | null;
48
+ }
49
+
41
50
  export class RelatedConcept extends GlossaristModel {
42
- constructor(data = {}) {
51
+ readonly type: RelationshipType;
52
+ readonly content: LocalizedString | null;
53
+ readonly ref: ConceptRef | null;
54
+
55
+ constructor(data: RelatedConceptJson = {}) {
43
56
  super();
44
57
  this.type = data.type ?? 'see';
45
- this.content = normalizeContent(data.content);
58
+ this.content = _normalizeContent(data.content);
46
59
  this.ref = data.ref
47
- ? (data.ref instanceof ConceptRef ? data.ref : new ConceptRef(data.ref))
60
+ ? data.ref instanceof ConceptRef
61
+ ? data.ref
62
+ : new ConceptRef(data.ref)
48
63
  : null;
49
64
  }
50
65
 
51
- // Convenience reader: returns the first available string value
52
- // from the localized hash, or null if absent. Mirrors
53
- // PartitiveHyperedge#contentString.
54
- get contentString() {
66
+ /**
67
+ * Convenience reader: returns the first available string value from
68
+ * the localized hash, or null if absent.
69
+ */
70
+ get contentString(): string | null {
55
71
  if (!this.content) return null;
56
72
  const values = Object.values(this.content);
57
- return values.length > 0 ? values[0] : null;
73
+ return values.length > 0 ? (values[0] ?? null) : null;
58
74
  }
59
75
 
60
- toJSON() {
61
- const obj = { type: this.type };
76
+ override toJSON(): RelatedConceptJson {
77
+ const obj: RelatedConceptJson = { type: this.type };
62
78
  if (this.content != null) obj.content = this.content;
63
79
  if (this.ref != null) obj.ref = this.ref.toJSON();
64
80
  return obj;
65
81
  }
66
82
 
67
- static identityOf(value) {
83
+ static identityOf(
84
+ value: {
85
+ type?: string;
86
+ ref?: { source?: string | null; id?: string | null } | null;
87
+ } | null | undefined,
88
+ ): string {
68
89
  const v = value ?? {};
69
- const ref = v?.ref;
90
+ const ref = v.ref;
70
91
  return `${v.type ?? ''}|${ref?.source ?? ''}|${ref?.id ?? ''}`;
71
92
  }
72
93
 
73
- identity() {
94
+ override identity(): string {
74
95
  return RelatedConcept.identityOf(this);
75
96
  }
76
97
 
77
- static fromJSON(data) {
98
+ static override fromJSON(data: RelatedConceptJson): RelatedConcept {
78
99
  return new RelatedConcept(data);
79
100
  }
80
101
  }
81
102
 
82
- // Content is a localized string (language → text). Plain strings on
83
- // input are normalized to `{ default: '...' }` so callers always see
84
- // the same shape. Mirrors PartitiveHyperedge's normalizeContent.
85
- function normalizeContent(value) {
103
+ function _normalizeContent(
104
+ value: LocalizedString | string | null | undefined,
105
+ ): LocalizedString | null {
86
106
  if (value == null) return null;
87
107
  if (typeof value === 'string') return { default: value };
88
108
  if (typeof value === 'object') {
89
- const entries = Object.entries(value).filter(([, v]) => typeof v === 'string');
90
- return entries.length > 0 ? Object.fromEntries(entries) : null;
109
+ const entries = Object.entries(value).filter(
110
+ ([, v]) => typeof v === 'string',
111
+ );
112
+ return entries.length > 0
113
+ ? (Object.fromEntries(entries) as LocalizedString)
114
+ : null;
91
115
  }
92
116
  return null;
93
117
  }
@@ -0,0 +1,36 @@
1
+ import { NonVerbalEntity } from './non-verbal-entity.js';
2
+ import type { NonVerbalEntityJson } from './non-verbal-entity.js';
3
+
4
+ export interface SharedNonVerbalEntityJson extends NonVerbalEntityJson {
5
+ id?: string | null;
6
+ identifier?: string | null;
7
+ }
8
+
9
+ export class SharedNonVerbalEntity extends NonVerbalEntity {
10
+ readonly id: string | null;
11
+ readonly identifier: string | null;
12
+
13
+ constructor(data: SharedNonVerbalEntityJson = {}) {
14
+ super(data);
15
+ this.id = data.id ?? null;
16
+ this.identifier = data.identifier ?? null;
17
+ }
18
+
19
+ override findById(targetId: string): this | null {
20
+ return this.id === targetId ? this : null;
21
+ }
22
+ override allIds(): string[] {
23
+ return this.id != null ? [this.id] : [];
24
+ }
25
+
26
+ override toJSON(): SharedNonVerbalEntityJson {
27
+ const obj = super.toJSON() as SharedNonVerbalEntityJson;
28
+ if (this.id != null) obj.id = this.id;
29
+ if (this.identifier != null) obj.identifier = this.identifier;
30
+ return obj;
31
+ }
32
+
33
+ static override fromJSON(data: SharedNonVerbalEntityJson): SharedNonVerbalEntity {
34
+ return SharedNonVerbalEntity.fromData(data);
35
+ }
36
+ }
@@ -0,0 +1,36 @@
1
+ import { SharedNonVerbalEntity } from './shared-non-verbal-entity.js';
2
+ import type { SharedNonVerbalEntityJson } from './shared-non-verbal-entity.js';
3
+ import { NonVerbalEntity } from './non-verbal-entity.js';
4
+
5
+ export interface TableJson extends SharedNonVerbalEntityJson {
6
+ content?: string | null;
7
+ format?: string | null;
8
+ }
9
+
10
+ export class Table extends SharedNonVerbalEntity {
11
+ readonly content: string | null;
12
+ readonly format: string | null;
13
+
14
+ constructor(data: TableJson = {}) {
15
+ super(data);
16
+ this.content = data.content ?? null;
17
+ this.format = data.format ?? null;
18
+ }
19
+
20
+ override rdfClass(): string {
21
+ return 'Table';
22
+ }
23
+
24
+ override toJSON(): TableJson {
25
+ const obj = super.toJSON() as TableJson;
26
+ if (this.content != null) obj.content = this.content;
27
+ if (this.format != null) obj.format = this.format;
28
+ return obj;
29
+ }
30
+
31
+ static override fromJSON(data: TableJson): Table {
32
+ return new Table(data);
33
+ }
34
+ }
35
+
36
+ NonVerbalEntity.register('table', Table);
@@ -1,48 +0,0 @@
1
- import * as yaml from 'js-yaml';
2
- import { GlossaristModel } from './base.js';
3
- import { BibliographyEntry } from './bibliography-entry.js';
4
-
5
- export class BibliographyData extends GlossaristModel {
6
- constructor(data = {}) {
7
- super();
8
- let entriesData;
9
- if (Array.isArray(data)) {
10
- entriesData = data;
11
- } else {
12
- entriesData = data?.bibliography ?? data?.entries ?? [];
13
- }
14
- this._rawEntries = Array.isArray(entriesData) ? entriesData : [];
15
- this._entries = null;
16
- }
17
-
18
- get entries() {
19
- return this._lazy('_entries', '_rawEntries',
20
- e => e instanceof BibliographyEntry ? e : new BibliographyEntry(e));
21
- }
22
-
23
- find(id) {
24
- return this.entries.find(e => e.id === id) ?? null;
25
- }
26
-
27
- get keys() {
28
- return this.entries.map(e => e.id);
29
- }
30
-
31
- toJSON() {
32
- if (this.entries.length === 0) return { bibliography: [] };
33
- return { bibliography: this.entries.map(e => e.toJSON()) };
34
- }
35
-
36
- toYAML() {
37
- return yaml.dump(this.toJSON());
38
- }
39
-
40
- static fromYAML(yamlString) {
41
- const parsed = yaml.load(yamlString);
42
- return new BibliographyData(parsed ?? {});
43
- }
44
-
45
- static fromJSON(data) {
46
- return new BibliographyData(data);
47
- }
48
- }