glossarist 0.2.1 → 0.2.2

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glossarist",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "JavaScript SDK for Glossarist GCR packages — read, write, validate, and manage terminology concepts",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
@@ -70,6 +70,8 @@ export class ConceptParser {
70
70
  id: String(mc.data.identifier),
71
71
  term: null,
72
72
  localizations,
73
+ domains: mc.data.domains,
74
+ groups: mc.data.groups,
73
75
  raw: mc,
74
76
  });
75
77
  }
@@ -39,6 +39,10 @@ export class ConceptSerializer {
39
39
  id: genId(),
40
40
  };
41
41
 
42
+ if (concept.domains.length > 0) {
43
+ mainDoc.data.domains = concept.domains.map(d => d.toJSON());
44
+ }
45
+
42
46
  const parts = [
43
47
  '---\n' + yaml.dump(mainDoc, DUMP_OPTS),
44
48
  ...langDocs.map(d => '---\n' + yaml.dump(d, DUMP_OPTS)),
package/src/index.js CHANGED
@@ -30,7 +30,7 @@ export {
30
30
  GlossaristModel,
31
31
  Concept, LocalizedConcept,
32
32
  Designation, Expression, Abbreviation, Symbol, GraphicalSymbol,
33
- Citation, ConceptSource, RelatedConcept, ConceptDate,
33
+ Citation, ConceptSource, RelatedConcept, ConceptReference, ConceptDate,
34
34
  DetailedDefinition, NonVerbRep,
35
35
  GcrMetadata, GcrStatistics,
36
36
  RELATIONSHIP_TYPES, DATE_TYPES,
@@ -0,0 +1,36 @@
1
+ import { GlossaristModel } from './base.js';
2
+
3
+ export class ConceptReference extends GlossaristModel {
4
+ constructor(data = {}) {
5
+ super();
6
+ this.conceptId = data.concept_id ?? data.conceptId ?? null;
7
+ this.refType = data.ref_type ?? data.refType ?? null;
8
+ this.source = data.source ?? null;
9
+ this.urn = data.urn ?? null;
10
+ }
11
+
12
+ get isLocal() {
13
+ return this.urn == null && this.source == null;
14
+ }
15
+
16
+ get isExternal() {
17
+ return !this.isLocal;
18
+ }
19
+
20
+ static domain(conceptId) {
21
+ return new ConceptReference({ concept_id: conceptId, ref_type: 'domain' });
22
+ }
23
+
24
+ toJSON() {
25
+ const obj = {};
26
+ if (this.conceptId != null) obj.concept_id = this.conceptId;
27
+ if (this.refType != null) obj.ref_type = this.refType;
28
+ if (this.source != null) obj.source = this.source;
29
+ if (this.urn != null) obj.urn = this.urn;
30
+ return obj;
31
+ }
32
+
33
+ static fromJSON(data) {
34
+ return new ConceptReference(data);
35
+ }
36
+ }
@@ -1,6 +1,7 @@
1
1
  import { GlossaristModel } from './base.js';
2
2
  import { LocalizedConcept } from './localized-concept.js';
3
3
  import { RelatedConcept } from './related-concept.js';
4
+ import { ConceptReference } from './concept-reference.js';
4
5
  import { ConceptDate } from './concept-date.js';
5
6
  import { ConceptSource } from './concept-source.js';
6
7
 
@@ -13,6 +14,7 @@ export class Concept extends GlossaristModel {
13
14
  this._cache = {};
14
15
 
15
16
  this.relatedConcepts = _mapInstances(data.relatedConcepts ?? data.related_concepts ?? [], RelatedConcept);
17
+ this.domains = _normalizeDomains(data.domains, data.groups);
16
18
  this.dates = _mapInstances(data.dates ?? [], ConceptDate);
17
19
  this.sources = _mapInstances(data.sources ?? [], ConceptSource);
18
20
  this.status = data.status ?? null;
@@ -84,6 +86,9 @@ export class Concept extends GlossaristModel {
84
86
  if (this.relatedConcepts.length > 0) {
85
87
  obj.relatedConcepts = this.relatedConcepts.map(rc => rc.toJSON());
86
88
  }
89
+ if (this.domains.length > 0) {
90
+ obj.domains = this.domains.map(d => d.toJSON());
91
+ }
87
92
  if (this.dates.length > 0) {
88
93
  obj.dates = this.dates.map(d => d.toJSON());
89
94
  }
@@ -102,3 +107,15 @@ export class Concept extends GlossaristModel {
102
107
  function _mapInstances(arr, Cls) {
103
108
  return arr.map(item => item instanceof Cls ? item : new Cls(item));
104
109
  }
110
+
111
+ function _normalizeDomains(domains, groups) {
112
+ if (domains) {
113
+ return domains.map(d => d instanceof ConceptReference ? d : new ConceptReference(d));
114
+ }
115
+ if (groups) {
116
+ return groups.map(g => typeof g === 'string'
117
+ ? ConceptReference.domain(g)
118
+ : new ConceptReference(g));
119
+ }
120
+ return [];
121
+ }
@@ -13,6 +13,7 @@ export class Concept extends GlossaristModel {
13
13
  readonly localizations: Record<string, any>;
14
14
  readonly raw: Record<string, unknown> | null;
15
15
  readonly relatedConcepts: RelatedConcept[];
16
+ readonly domains: ConceptReference[];
16
17
  readonly dates: ConceptDate[];
17
18
  readonly sources: ConceptSource[];
18
19
  readonly status: string | null;
@@ -34,6 +35,7 @@ export class LocalizedConcept extends GlossaristModel {
34
35
  readonly examples: { content: string }[];
35
36
  readonly sources: ConceptSource[];
36
37
  readonly entryStatus: string | null;
38
+ readonly domain: string | null;
37
39
  readonly primaryDesignation: string | null;
38
40
  readonly primaryDefinition: string | null;
39
41
  static fromJSON(data: Record<string, unknown>): LocalizedConcept;
@@ -88,6 +90,17 @@ export class RelatedConcept extends GlossaristModel {
88
90
  readonly ref: Citation | null;
89
91
  }
90
92
 
93
+ export class ConceptReference extends GlossaristModel {
94
+ readonly conceptId: string | null;
95
+ readonly refType: string | null;
96
+ readonly source: string | null;
97
+ readonly urn: string | null;
98
+ readonly isLocal: boolean;
99
+ readonly isExternal: boolean;
100
+ static domain(conceptId: string): ConceptReference;
101
+ static fromJSON(data: Record<string, unknown>): ConceptReference;
102
+ }
103
+
91
104
  export const DATE_TYPES: readonly string[];
92
105
  export class ConceptDate extends GlossaristModel {
93
106
  readonly date: string | null;
@@ -5,6 +5,7 @@ export { Designation, Expression, Abbreviation, Symbol, GraphicalSymbol } from '
5
5
  export { Citation } from './citation.js';
6
6
  export { ConceptSource } from './concept-source.js';
7
7
  export { RelatedConcept, RELATIONSHIP_TYPES } from './related-concept.js';
8
+ export { ConceptReference } from './concept-reference.js';
8
9
  export { ConceptDate, DATE_TYPES } from './concept-date.js';
9
10
  export { DetailedDefinition } from './detailed-definition.js';
10
11
  export { NonVerbRep } from './non-verb-rep.js';
@@ -15,6 +15,7 @@ export class LocalizedConcept extends GlossaristModel {
15
15
  this.entryStatus = data.entry_status ?? data.entryStatus ?? null;
16
16
  this.reviewType = data.review_type ?? data.reviewType ?? null;
17
17
  this.classification = data.classification ?? null;
18
+ this.domain = data.domain ?? null;
18
19
 
19
20
  this._terms = null;
20
21
  this._definitions = null;
@@ -83,6 +84,7 @@ export class LocalizedConcept extends GlossaristModel {
83
84
  if (this.entryStatus != null) obj.entry_status = this.entryStatus;
84
85
  if (this.reviewType != null) obj.review_type = this.reviewType;
85
86
  if (this.classification != null) obj.classification = this.classification;
87
+ if (this.domain != null) obj.domain = this.domain;
86
88
  return obj;
87
89
  }
88
90