@larsgw/formica 0.9.2 → 0.10.1

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 (53) hide show
  1. package/lib/bin/process-resources-index.js +0 -0
  2. package/lib/bin/process-resources.d.ts +6 -1
  3. package/lib/bin/process-resources.js +116 -25
  4. package/lib/bin/validate-catalog.js +34 -13
  5. package/lib/bin/validate-resources-text.js +3 -1
  6. package/lib/catalog/tables/taxon.js +4 -0
  7. package/lib/catalog/value.d.ts +1 -0
  8. package/lib/catalog/value.js +1 -0
  9. package/lib/resources/parse-text.js +6 -3
  10. package/lib/taxon-names/index.js +1 -1
  11. package/package.json +15 -13
  12. package/.gitattributes +0 -1
  13. package/.github/workflows/ci.yml +0 -27
  14. package/CHANGELOG.md +0 -390
  15. package/eslint.config.js +0 -34
  16. package/lib/bin/SHEETS.js +0 -0
  17. package/lib/bin/clean-links.d.ts +0 -2
  18. package/lib/bin/clean-links.js +0 -170
  19. package/lib/bin/download-place-shapes.js +0 -188
  20. package/lib/bin/index-place-shapes.js +0 -115
  21. package/lib/bin/process-resources-problems.js +0 -177
  22. package/lib/bin/validate-linked-data.js +0 -0
  23. package/lib/resources/content/clavis.js +0 -10
  24. package/lib/resources/content/index.js +0 -0
  25. package/lib/resources/content/sdd.js +0 -151
  26. package/lib/resources/sdd.js +0 -78
  27. package/src/bin/generate-linked-data.ts +0 -762
  28. package/src/bin/process-resources-index.ts +0 -100
  29. package/src/bin/process-resources.ts +0 -510
  30. package/src/bin/util.ts +0 -74
  31. package/src/bin/validate-catalog.ts +0 -122
  32. package/src/bin/validate-resources-text.ts +0 -25
  33. package/src/catalog/entities.ts +0 -62
  34. package/src/catalog/entity.ts +0 -116
  35. package/src/catalog/index.ts +0 -33
  36. package/src/catalog/tables/author.ts +0 -15
  37. package/src/catalog/tables/index.ts +0 -14
  38. package/src/catalog/tables/place.ts +0 -14
  39. package/src/catalog/tables/publisher.ts +0 -15
  40. package/src/catalog/tables/taxon.ts +0 -17
  41. package/src/catalog/tables/work.ts +0 -65
  42. package/src/catalog/value.ts +0 -51
  43. package/src/csv.ts +0 -33
  44. package/src/index.ts +0 -4
  45. package/src/module.d.ts +0 -148
  46. package/src/resources/diff-resource.ts +0 -226
  47. package/src/resources/index.ts +0 -4
  48. package/src/resources/parse-name.ts +0 -392
  49. package/src/resources/parse-text.ts +0 -408
  50. package/src/resources/resource.ts +0 -10
  51. package/src/taxon-names/index.ts +0 -79
  52. package/test/resources.js +0 -374
  53. package/tsconfig.json +0 -15
package/src/module.d.ts DELETED
@@ -1,148 +0,0 @@
1
- type Schema = Record<string, FieldSpecification>
2
- type FieldSpecification = {
3
- required: boolean,
4
- multiple: boolean | FieldSpecificationCallbackMultiple
5
- format?: string[] | RegExp | FieldSpecificationCallbackFormat
6
- }
7
-
8
- type Value = string[] | string
9
- type SingleValue = string
10
- type FieldSpecificationCallbackMultiple = (entry: Record<string, Value>) => boolean;
11
- type FieldSpecificationCallbackFormat = (value: SingleValue) => boolean;
12
-
13
- interface FieldError {
14
- field: string,
15
- error: string
16
- }
17
-
18
- interface WorkError extends FieldError {
19
- entity: WorkId
20
- }
21
-
22
- type Rank = string
23
- type DwcRank = Rank
24
- type TaxonStatus = string
25
-
26
- type TaxonId = string
27
- type ResourceId = string
28
- type WorkId = string
29
-
30
- interface TaxonBase {
31
- scientificNameID?: TaxonId,
32
- scientificName?: string,
33
- scientificNameAuthorship?: string,
34
- genericName?: string,
35
- infragenericEpithet?: string,
36
- specificEpithet?: string,
37
- infraspecificEpithet?: string,
38
-
39
- taxonRank?: Rank,
40
- taxonRemarks?: string,
41
- collectionCode?: ResourceId,
42
-
43
- taxonomicStatus?: TaxonStatus,
44
- acceptedNameUsageID?: TaxonId,
45
- acceptedNameUsage?: string,
46
-
47
- parentNameUsageID?: TaxonId,
48
- parentNameUsage?: string,
49
- kingdom?: string,
50
- phylum?: string,
51
- class?: string,
52
- order?: string,
53
- family?: string,
54
- subfamily?: string,
55
- genus?: string,
56
- subgenus?: string,
57
- higherClassification?: string,
58
- verbatimIdentification?: string,
59
- dynamicProperties?: string,
60
- }
61
-
62
- interface WorkingTaxon extends TaxonBase {
63
- // Non-standard
64
- scientificNameOnly?: string,
65
- incorrect?: WorkingTaxon,
66
- cluster?: string
67
- }
68
-
69
- interface Taxon extends TaxonBase {
70
- scientificNameID: TaxonId,
71
- scientificName: string,
72
- taxonRank: Rank,
73
- collectionCode: ResourceId,
74
- taxonomicStatus: string,
75
- verbatimIdentification: string
76
- }
77
-
78
- type ResourceFlag = string;
79
-
80
- interface ResourceMetadata {
81
- levels: Rank[],
82
- flags?: ResourceFlag[],
83
- catalog?: Record<string, Value>
84
- }
85
-
86
- interface Resource {
87
- id: string,
88
- file: string,
89
- workId: string,
90
- metadata: ResourceMetadata,
91
- taxa: Record<TaxonId, Taxon>
92
- }
93
-
94
- interface ResourceHistory {
95
- txt: string,
96
- dwc: Array<string[][]>
97
- }
98
-
99
- type ResourceDiff = ResourceDiffPart[]
100
-
101
- interface ResourceDiffPart {
102
- text?: string,
103
- original?: string,
104
- type: ResourceDiffType
105
- }
106
-
107
- declare enum ResourceDiffType {
108
- Added = '+',
109
- Deleted = '-',
110
- Modified = '~',
111
- Unchanged = '='
112
- }
113
-
114
- interface AmendedTaxon extends Taxon {
115
- colTaxonID?: string,
116
- colAcceptedTaxonID?: string,
117
- gbifTaxonID?: string,
118
- gbifAcceptedTaxonID?: string
119
- }
120
-
121
- interface AmendedResource extends Resource {
122
- taxa: Record<TaxonId, AmendedTaxon>
123
- }
124
-
125
- interface TaxonMatch {
126
- source: number,
127
- id: string,
128
- currentId?: string,
129
- classificationPath: string[]
130
- }
131
-
132
- type GroupedNameMatches = Record<string, Record<string, Record<TaxonId, TaxonMatch>>>
133
-
134
- declare enum ResourceProcessorSource {
135
- All = 'all',
136
- Unprocessed = 'unprocessed',
137
- Modified = 'modified'
138
- }
139
-
140
- interface ResourceProcessorConfig {
141
- update: boolean,
142
- updateMappings: boolean
143
- }
144
-
145
- declare module 'ietf-language-tag-regex' {
146
- function createLanguageTagRegex(): RegExp
147
- export = createLanguageTagRegex
148
- }
@@ -1,226 +0,0 @@
1
- export enum ResourceDiffType {
2
- Added = '+',
3
- Deleted = '-',
4
- Modified = '~',
5
- Unchanged = '='
6
- }
7
-
8
- interface DiffPart {
9
- text: string,
10
- type: ResourceDiffType
11
- }
12
-
13
- class Matrix {
14
- values: Array<number>
15
- m: number
16
- n: number
17
-
18
- constructor (m: number, n: number) {
19
- this.values = Array(m * n).fill(0)
20
- this.m = m
21
- this.n = n
22
- }
23
-
24
- getValue (i: number, j: number) {
25
- return this.values[(i * this.n) + j]
26
- }
27
-
28
- setValue (i: number, j: number, value: number) {
29
- this.values[(i * this.n) + j] = value
30
- }
31
- }
32
-
33
- function LCS (X: string[], Y: string[]): DiffPart[] {
34
- const m = X.length
35
- const n = Y.length
36
-
37
- // Build matrix
38
- const C = new Matrix(m + 1, n + 1)
39
- for (let i = 0; i < m; i++) {
40
- for (let j = 0; j < n; j++) {
41
- if (X[i] === Y[j]) {
42
- C.setValue(i + 1, j + 1, C.getValue(i, j) + 1)
43
- } else {
44
- C.setValue(i + 1, j + 1, Math.max(C.getValue(i, j + 1), C.getValue(i + 1, j)))
45
- }
46
- }
47
- }
48
-
49
- // Backtrace
50
- const diff = []
51
- let i = m
52
- let j = n
53
- while (i + j !== 0) {
54
- if (X[i - 1] === Y[j - 1]) {
55
- diff.unshift({
56
- text: X[i - 1],
57
- type: ResourceDiffType.Unchanged
58
- })
59
- i--
60
- j--
61
- } else if (i !== 0 && (j === 0 || C.getValue(i - 1, j) > C.getValue(i, j - 1))) {
62
- diff.unshift({
63
- text: X[i - 1],
64
- type: ResourceDiffType.Added
65
- })
66
- i--
67
- } else {
68
- diff.unshift({
69
- text: Y[j - 1],
70
- type: ResourceDiffType.Deleted
71
- })
72
- j--
73
- }
74
- }
75
-
76
- return diff
77
- }
78
-
79
- function tokenizeWords (text: string): string[] {
80
- if (text.length === 0) {
81
- return []
82
- }
83
- return text.match(/\S+|\n|[\r\t\f\v \u00a0\u1680\u2000-\u200a\u2028\u2029\u202f\u205f\u3000\ufeff]+/g) as string[]
84
- }
85
-
86
- function tokenizeLines (text: string): string[] {
87
- return text.split('\n')
88
- }
89
-
90
- function diffTokens (X: string[], Y: string[]): ResourceDiff {
91
- // Remove common prefix
92
- const prefix = []
93
- while (X.length && X[0] === Y[0]) {
94
- prefix.push({
95
- text: X[0],
96
- type: ResourceDiffType.Unchanged
97
- })
98
- X.shift()
99
- Y.shift()
100
- }
101
-
102
- // Remove common suffix
103
- const suffix = []
104
- while (X.length && X[X.length - 1] === Y[Y.length - 1]) {
105
- suffix.unshift({
106
- text: X[X.length - 1],
107
- type: ResourceDiffType.Unchanged
108
- })
109
- X.pop()
110
- Y.pop()
111
- }
112
-
113
- // Generate diff from remains, combine with prefix and suffix
114
- return [
115
- ...prefix,
116
- ...LCS(X, Y),
117
- ...suffix
118
- ]
119
- }
120
-
121
- function convertWordDiff (changes: ResourceDiff): ResourceDiff {
122
- const lines: ResourceDiff = []
123
- let line: ResourceDiffPart|null = null
124
- let deletedNewlines = 0
125
- let nextLineNew = false
126
-
127
- for (const change of changes) {
128
- // Start of line
129
- if (line === null) {
130
- deletedNewlines = 0
131
- line = { type: change.type }
132
- }
133
-
134
- // End of line (could be same token)
135
- if (change.text === '\n') {
136
- if (change.type === ResourceDiffType.Deleted) {
137
- // Keep track of deleted newlines. These indicate the merging of
138
- // lines. To keep the taxon identifiers consistent, it is
139
- // important that deleted taxa are tracked.
140
- deletedNewlines++
141
- continue
142
- }
143
-
144
- // If there is a new newline, there is a new... line. If the current
145
- // line is not seen as new, the next one should be marked as new.
146
- if (nextLineNew) {
147
- line.type = ResourceDiffType.Added
148
- nextLineNew = false
149
- }
150
- if (change.type === ResourceDiffType.Added && line.type !== ResourceDiffType.Added) {
151
- nextLineNew = true
152
- }
153
-
154
- // Line ended
155
- lines.push(line)
156
- line = null
157
-
158
- // Add placeholders for deleted lines
159
- while (deletedNewlines--) {
160
- lines.push({
161
- text: undefined,
162
- original: '',
163
- type: ResourceDiffType.Deleted
164
- })
165
- }
166
-
167
- continue
168
- }
169
-
170
- // Added/Deleted/Unchanged on the same line -> line is modified but did
171
- // already exist.
172
- if (change.type !== line.type) {
173
- line.type = ResourceDiffType.Modified
174
- }
175
-
176
- if (change.type !== ResourceDiffType.Deleted) {
177
- line.text = (line.text ?? '') + change.text
178
- }
179
-
180
- if (change.type !== ResourceDiffType.Added) {
181
- line.original = (line.original ?? '') + change.text
182
- }
183
- }
184
-
185
- return lines
186
- }
187
-
188
- function getWordTokensFromLines (lines: ResourceDiff): string[] {
189
- return lines.flatMap(change => tokenizeWords(change.text as string).concat('\n'))
190
- }
191
-
192
- type MultilineDiffPart = { added: ResourceDiff, deleted: ResourceDiff }
193
-
194
- function mergeDiffPart (diffPart: MultilineDiffPart): ResourceDiff {
195
- if (diffPart.added.length && diffPart.deleted.length) {
196
- return convertWordDiff(diffTokens(getWordTokensFromLines(diffPart.added), getWordTokensFromLines(diffPart.deleted)))
197
- } else if (diffPart.added.length) {
198
- return diffPart.added
199
- } else if (diffPart.deleted.length) {
200
- return diffPart.deleted.map(change => ({ text: undefined, original: change.text, type: change.type }))
201
- } else {
202
- return []
203
- }
204
- }
205
-
206
- export function createDiff (a: string, b: string): ResourceDiff {
207
- const lines: ResourceDiff = diffTokens(tokenizeLines(a.trimEnd()), tokenizeLines(b.trimEnd()))
208
-
209
- const changes: ResourceDiff = []
210
- const diffPart: MultilineDiffPart = { added: [], deleted: [] }
211
- for (let i = 0; i < lines.length; i++) {
212
- if (lines[i].type === ResourceDiffType.Added) {
213
- diffPart.added.push(lines[i])
214
- } else if (lines[i].type === ResourceDiffType.Deleted) {
215
- diffPart.deleted.push(lines[i])
216
- } else {
217
- changes.push(...mergeDiffPart(diffPart), lines[i])
218
- diffPart.added.length = 0
219
- diffPart.deleted.length = 0
220
- }
221
- }
222
-
223
- changes.push(...mergeDiffPart(diffPart))
224
-
225
- return changes
226
- }
@@ -1,4 +0,0 @@
1
- export {
2
- parseFile as parseTextFile,
3
- parseFileHeader as parseTextFileHeader
4
- } from './parse-text'