@larsgw/formica 0.1.0
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/.eslintrc.js +16 -0
- package/LICENSE +21 -0
- package/README.md +19 -0
- package/lib/bin/process-resources-index.d.ts +1 -0
- package/lib/bin/process-resources-index.js +142 -0
- package/lib/bin/process-resources.d.ts +1 -0
- package/lib/bin/process-resources.js +594 -0
- package/lib/bin/util.d.ts +16 -0
- package/lib/bin/util.js +125 -0
- package/lib/bin/validate-catalog.d.ts +2 -0
- package/lib/bin/validate-catalog.js +92 -0
- package/lib/bin/validate-resources-text.d.ts +2 -0
- package/lib/bin/validate-resources-text.js +78 -0
- package/lib/catalog/entities.d.ts +12 -0
- package/lib/catalog/entities.js +111 -0
- package/lib/catalog/entity.d.ts +13 -0
- package/lib/catalog/entity.js +103 -0
- package/lib/catalog/index.d.ts +4 -0
- package/lib/catalog/index.js +33 -0
- package/lib/catalog/tables/author.d.ts +4 -0
- package/lib/catalog/tables/author.js +33 -0
- package/lib/catalog/tables/index.d.ts +2 -0
- package/lib/catalog/tables/index.js +13 -0
- package/lib/catalog/tables/place.d.ts +4 -0
- package/lib/catalog/tables/place.js +32 -0
- package/lib/catalog/tables/publisher.d.ts +4 -0
- package/lib/catalog/tables/publisher.js +33 -0
- package/lib/catalog/tables/work.d.ts +5 -0
- package/lib/catalog/tables/work.js +82 -0
- package/lib/catalog/value.d.ts +19 -0
- package/lib/catalog/value.js +49 -0
- package/lib/csv.d.ts +2 -0
- package/lib/csv.js +37 -0
- package/lib/index.d.ts +3 -0
- package/lib/index.js +6 -0
- package/lib/resources/diff-resource.d.ts +7 -0
- package/lib/resources/diff-resource.js +152 -0
- package/lib/resources/index.d.ts +1 -0
- package/lib/resources/index.js +6 -0
- package/lib/resources/parse-text.d.ts +2 -0
- package/lib/resources/parse-text.js +499 -0
- package/lib/types.d.ts +62 -0
- package/lib/types.js +0 -0
- package/package.json +42 -0
- package/src/bin/process-resources-index.ts +73 -0
- package/src/bin/process-resources.ts +406 -0
- package/src/bin/util.ts +74 -0
- package/src/bin/validate-catalog.ts +37 -0
- package/src/bin/validate-resources-text.ts +25 -0
- package/src/catalog/entities.ts +62 -0
- package/src/catalog/entity.ts +113 -0
- package/src/catalog/index.ts +32 -0
- package/src/catalog/tables/author.ts +13 -0
- package/src/catalog/tables/index.ts +12 -0
- package/src/catalog/tables/place.ts +12 -0
- package/src/catalog/tables/publisher.ts +13 -0
- package/src/catalog/tables/work.ts +62 -0
- package/src/catalog/value.ts +48 -0
- package/src/csv.ts +33 -0
- package/src/index.ts +3 -0
- package/src/module.d.ts +105 -0
- package/src/resources/diff-resource.ts +155 -0
- package/src/resources/index.ts +4 -0
- package/src/resources/parse-text.ts +519 -0
- package/tsconfig.json +11 -0
package/.eslintrc.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
module.exports = {
|
|
2
|
+
extends: ['eslint:recommended', 'plugin:@typescript-eslint/recommended'],
|
|
3
|
+
parser: '@typescript-eslint/parser',
|
|
4
|
+
plugins: ['@typescript-eslint'],
|
|
5
|
+
root: true,
|
|
6
|
+
|
|
7
|
+
rules: {
|
|
8
|
+
indent: ['error', 4, { SwitchCase: 1 }],
|
|
9
|
+
'no-unused-vars': 'off',
|
|
10
|
+
'@typescript-eslint/no-unused-vars': ['warn', {
|
|
11
|
+
argsIgnorePattern: '^_',
|
|
12
|
+
varsIgnorePattern: '^_',
|
|
13
|
+
caughtErrorsIgnorePattern: '^_'
|
|
14
|
+
}]
|
|
15
|
+
}
|
|
16
|
+
}
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Lars Willighagen
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
# Formica
|
|
2
|
+
|
|
3
|
+
**Formica** is an SDK and a collection of tools for the data in the Library of
|
|
4
|
+
Identification Resources.
|
|
5
|
+
|
|
6
|
+
## Tools
|
|
7
|
+
|
|
8
|
+
- `loir-validate-catalog [./catalog.csv ./authors.csv ./places.csv ./publishers.csv]`:
|
|
9
|
+
Validate the CSV files containing metadata ([schema](https://github.com/identification-resources/catalog/blob/main/docs/tools-resources.md)).
|
|
10
|
+
- `loir-validate-resources [./B1234.txt]`:
|
|
11
|
+
Validate the `.txt` files containing information on the taxonomic scope of keys
|
|
12
|
+
([documentation](https://github.com/identification-resources/catalog/blob/main/docs/resources-txt.md)).
|
|
13
|
+
- `loir-resources-process [./resources]`:
|
|
14
|
+
Interactive tool to convert the aforementioned `.txt` files to Darwin Core archives
|
|
15
|
+
([documentation](https://github.com/identification-resources/catalog/blob/main/docs/resources-dwc.md)),
|
|
16
|
+
and link the taxa to GBIF and Catalogue of Life identifiers. Use the `-u` or
|
|
17
|
+
`--update` flag in a Git repo to update existing Darwin Core files while keeping
|
|
18
|
+
the identifiers stable (in most cases).
|
|
19
|
+
- `loir-resources-index [./resources]`: Create indices of the Darwin Core archives.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
14
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
15
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
16
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
17
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
18
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
19
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
20
|
+
});
|
|
21
|
+
};
|
|
22
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
23
|
+
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
|
24
|
+
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
25
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
26
|
+
function step(op) {
|
|
27
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
28
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
29
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
30
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
31
|
+
switch (op[0]) {
|
|
32
|
+
case 0: case 1: t = op; break;
|
|
33
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
34
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
35
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
36
|
+
default:
|
|
37
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
38
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
39
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
40
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
41
|
+
if (t[2]) _.ops.pop();
|
|
42
|
+
_.trys.pop(); continue;
|
|
43
|
+
}
|
|
44
|
+
op = body.call(thisArg, _);
|
|
45
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
46
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
50
|
+
var fs_1 = require("fs");
|
|
51
|
+
var path = require("path");
|
|
52
|
+
var index_1 = require("../index");
|
|
53
|
+
var util_1 = require("./util");
|
|
54
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
55
|
+
function sortObject(object) {
|
|
56
|
+
var sorted = {};
|
|
57
|
+
for (var _i = 0, _a = Object.keys(object).sort(util_1.numericSort); _i < _a.length; _i++) {
|
|
58
|
+
var key = _a[_i];
|
|
59
|
+
sorted[key] = object[key];
|
|
60
|
+
}
|
|
61
|
+
return sorted;
|
|
62
|
+
}
|
|
63
|
+
/* eslint-enable @typescript-eslint/no-explicit-any */
|
|
64
|
+
function main(args) {
|
|
65
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
66
|
+
var REPO_ROOT, files, gbifIndex, resourceIndex;
|
|
67
|
+
return __generator(this, function (_a) {
|
|
68
|
+
switch (_a.label) {
|
|
69
|
+
case 0:
|
|
70
|
+
REPO_ROOT = path.resolve(args[0]);
|
|
71
|
+
return [4 /*yield*/, fs_1.promises.readdir(path.join(REPO_ROOT, 'txt'))];
|
|
72
|
+
case 1:
|
|
73
|
+
files = _a.sent();
|
|
74
|
+
gbifIndex = {};
|
|
75
|
+
resourceIndex = {};
|
|
76
|
+
return [4 /*yield*/, Promise.all(files.map(function (fileName) {
|
|
77
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
78
|
+
var id, file;
|
|
79
|
+
return __generator(this, function (_a) {
|
|
80
|
+
switch (_a.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
if (!fileName.endsWith('.txt')) {
|
|
83
|
+
return [2 /*return*/];
|
|
84
|
+
}
|
|
85
|
+
id = fileName.slice(0, -4);
|
|
86
|
+
return [4 /*yield*/, fs_1.promises.readFile(path.join(REPO_ROOT, 'txt', fileName), 'utf-8')];
|
|
87
|
+
case 1:
|
|
88
|
+
file = _a.sent();
|
|
89
|
+
return [2 /*return*/, Promise.all(index_1.resources.parseTextFileHeader(file).map(function (resource, index) {
|
|
90
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
91
|
+
var amendedResource, dwcFile, _a, _header, dwc, _b, _c, _i, dwc_1, taxon, gbifId;
|
|
92
|
+
return __generator(this, function (_d) {
|
|
93
|
+
switch (_d.label) {
|
|
94
|
+
case 0:
|
|
95
|
+
amendedResource = __assign(__assign({}, resource), { id: "".concat(id, ":").concat(index + 1), taxonCount: 0 });
|
|
96
|
+
dwcFile = path.join(REPO_ROOT, 'dwc', "".concat(id, "-").concat(index + 1, ".csv"));
|
|
97
|
+
if (!(0, fs_1.existsSync)(dwcFile)) {
|
|
98
|
+
return [2 /*return*/];
|
|
99
|
+
}
|
|
100
|
+
_c = (_b = index_1.csv).parseCsv;
|
|
101
|
+
return [4 /*yield*/, fs_1.promises.readFile(dwcFile, 'utf-8')];
|
|
102
|
+
case 1:
|
|
103
|
+
_a = _c.apply(_b, [_d.sent()]), _header = _a[0], dwc = _a.slice(1);
|
|
104
|
+
for (_i = 0, dwc_1 = dwc; _i < dwc_1.length; _i++) {
|
|
105
|
+
taxon = dwc_1[_i];
|
|
106
|
+
gbifId = taxon[25];
|
|
107
|
+
if (gbifId) {
|
|
108
|
+
if (!(gbifId in gbifIndex)) {
|
|
109
|
+
gbifIndex[gbifId] = [];
|
|
110
|
+
}
|
|
111
|
+
gbifIndex[gbifId].push(taxon[0]);
|
|
112
|
+
gbifIndex[gbifId].sort(util_1.numericSort);
|
|
113
|
+
}
|
|
114
|
+
amendedResource.taxonCount += 1;
|
|
115
|
+
}
|
|
116
|
+
resourceIndex[amendedResource.id] = amendedResource;
|
|
117
|
+
return [2 /*return*/];
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}))];
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}))];
|
|
126
|
+
case 2:
|
|
127
|
+
_a.sent();
|
|
128
|
+
return [4 /*yield*/, Promise.all([
|
|
129
|
+
fs_1.promises.writeFile(path.join(REPO_ROOT, 'gbif.index.json'), JSON.stringify(sortObject(gbifIndex), null, 2)),
|
|
130
|
+
fs_1.promises.writeFile(path.join(REPO_ROOT, 'index.json'), JSON.stringify(sortObject(resourceIndex), null, 2))
|
|
131
|
+
])];
|
|
132
|
+
case 3:
|
|
133
|
+
_a.sent();
|
|
134
|
+
return [2 /*return*/];
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
main(process.argv.slice(2)).catch(function (error) {
|
|
140
|
+
console.error(error);
|
|
141
|
+
process.exit(1);
|
|
142
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|