@larsgw/formica 0.8.5 → 0.8.7
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/CHANGELOG.md +24 -0
- package/lib/bin/generate-linked-data.js +200 -323
- package/lib/bin/process-resources-index.js +59 -130
- package/lib/bin/process-resources.js +303 -524
- package/lib/bin/util.js +21 -56
- package/lib/bin/validate-catalog.js +26 -70
- package/lib/bin/validate-resources-text.js +17 -61
- package/lib/catalog/entities.js +28 -84
- package/lib/catalog/entity.js +36 -50
- package/lib/catalog/index.js +11 -12
- package/lib/catalog/tables/author.js +7 -24
- package/lib/catalog/tables/index.js +5 -5
- package/lib/catalog/tables/place.js +7 -24
- package/lib/catalog/tables/publisher.js +7 -24
- package/lib/catalog/tables/taxon.js +7 -24
- package/lib/catalog/tables/work.js +13 -30
- package/lib/catalog/value.js +11 -11
- package/lib/csv.js +7 -8
- package/lib/resources/diff-resource.js +52 -55
- package/lib/resources/parse-name.d.ts +4 -0
- package/lib/resources/parse-name.js +56 -54
- package/lib/resources/parse-text.js +121 -116
- package/lib/resources/resource.js +7 -25
- package/lib/taxon-names/index.js +15 -20
- package/package.json +1 -1
- package/src/resources/diff-resource.ts +19 -15
- package/src/resources/parse-name.ts +24 -19
- package/src/resources/parse-text.ts +35 -6
- package/test/resources.js +182 -89
- package/tsconfig.json +4 -1
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
var __assign = (this && this.__assign) || function () {
|
|
4
|
-
__assign = Object.assign || function(t) {
|
|
5
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
6
|
-
s = arguments[i];
|
|
7
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
8
|
-
t[p] = s[p];
|
|
9
|
-
}
|
|
10
|
-
return t;
|
|
11
|
-
};
|
|
12
|
-
return __assign.apply(this, arguments);
|
|
13
|
-
};
|
|
14
3
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
15
4
|
if (k2 === undefined) k2 = k;
|
|
16
5
|
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
@@ -53,45 +42,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
53
42
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
54
43
|
});
|
|
55
44
|
};
|
|
56
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
57
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
58
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
59
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
60
|
-
function step(op) {
|
|
61
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
62
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
63
|
-
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;
|
|
64
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
65
|
-
switch (op[0]) {
|
|
66
|
-
case 0: case 1: t = op; break;
|
|
67
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
68
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
69
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
70
|
-
default:
|
|
71
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
72
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
73
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
74
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
75
|
-
if (t[2]) _.ops.pop();
|
|
76
|
-
_.trys.pop(); continue;
|
|
77
|
-
}
|
|
78
|
-
op = body.call(thisArg, _);
|
|
79
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
80
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
81
|
-
}
|
|
82
|
-
};
|
|
83
45
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
46
|
+
const fs_1 = require("fs");
|
|
47
|
+
const path = __importStar(require("path"));
|
|
48
|
+
const index_1 = require("../index");
|
|
49
|
+
const util_1 = require("./util");
|
|
88
50
|
function alphabeticSort(a, b) {
|
|
89
51
|
return a > b ? 1 : a < b ? -1 : 0;
|
|
90
52
|
}
|
|
91
53
|
function sortObject(object, sorter) {
|
|
92
|
-
|
|
93
|
-
for (
|
|
94
|
-
var key = _a[_i];
|
|
54
|
+
const sorted = {};
|
|
55
|
+
for (const key of Object.keys(object).sort(sorter !== null && sorter !== void 0 ? sorter : util_1.numericSort)) {
|
|
95
56
|
sorted[key] = object[key];
|
|
96
57
|
}
|
|
97
58
|
return sorted;
|
|
@@ -104,93 +65,61 @@ function addTaxon(index, id, taxon) {
|
|
|
104
65
|
index[id].sort(util_1.numericSort);
|
|
105
66
|
}
|
|
106
67
|
function main(args) {
|
|
107
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
colId = taxon[colColumn];
|
|
161
|
-
if (colId) {
|
|
162
|
-
addTaxon(colIndex, colId, taxon);
|
|
163
|
-
if (taxon[colAcceptedColumn] !== taxon[colColumn]) {
|
|
164
|
-
addTaxon(colIndex, taxon[colAcceptedColumn], taxon);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
amendedResource.taxonCount += 1;
|
|
168
|
-
}
|
|
169
|
-
resourceIndex[amendedResource.id] = amendedResource;
|
|
170
|
-
return [2 /*return*/];
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
});
|
|
174
|
-
}))];
|
|
175
|
-
}
|
|
176
|
-
});
|
|
177
|
-
});
|
|
178
|
-
}))];
|
|
179
|
-
case 2:
|
|
180
|
-
_a.sent();
|
|
181
|
-
return [4 /*yield*/, Promise.all([
|
|
182
|
-
fs_1.promises.writeFile(path.join(REPO_ROOT, 'gbif.index.json'), JSON.stringify(sortObject(gbifIndex), null, 2)),
|
|
183
|
-
fs_1.promises.writeFile(path.join(REPO_ROOT, 'col.index.json'), JSON.stringify(sortObject(colIndex, alphabeticSort), null, 2)),
|
|
184
|
-
fs_1.promises.writeFile(path.join(REPO_ROOT, 'index.json'), JSON.stringify(sortObject(resourceIndex), null, 2))
|
|
185
|
-
])];
|
|
186
|
-
case 3:
|
|
187
|
-
_a.sent();
|
|
188
|
-
return [2 /*return*/];
|
|
189
|
-
}
|
|
190
|
-
});
|
|
68
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
69
|
+
const REPO_ROOT = path.resolve(args[0]);
|
|
70
|
+
const files = yield fs_1.promises.readdir(path.join(REPO_ROOT, 'txt'));
|
|
71
|
+
const gbifIndex = {};
|
|
72
|
+
const colIndex = {};
|
|
73
|
+
const resourceIndex = {};
|
|
74
|
+
yield Promise.all(files.map(function (fileName) {
|
|
75
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
76
|
+
if (!fileName.endsWith('.txt')) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
const id = fileName.slice(0, -4);
|
|
80
|
+
const file = yield fs_1.promises.readFile(path.join(REPO_ROOT, 'txt', fileName), 'utf-8');
|
|
81
|
+
return Promise.all(index_1.resources.parseTextFileHeader(file).map(function (resource, index) {
|
|
82
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
83
|
+
const amendedResource = Object.assign(Object.assign({}, resource), { id: `${id}:${index + 1}`, taxonCount: 0 });
|
|
84
|
+
const dwcFile = path.join(REPO_ROOT, 'dwc', `${id}-${index + 1}.csv`);
|
|
85
|
+
if (!(0, fs_1.existsSync)(dwcFile)) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
const [header, ...dwc] = index_1.csv.parseCsv(yield fs_1.promises.readFile(dwcFile, 'utf-8'));
|
|
89
|
+
const gbifColumn = header.indexOf('gbifTaxonID');
|
|
90
|
+
const gbifAcceptedColumn = header.indexOf('gbifAcceptedTaxonID');
|
|
91
|
+
const colColumn = header.indexOf('colTaxonID');
|
|
92
|
+
const colAcceptedColumn = header.indexOf('colAcceptedTaxonID');
|
|
93
|
+
for (const taxon of dwc) {
|
|
94
|
+
const gbifId = taxon[gbifColumn];
|
|
95
|
+
if (gbifId) {
|
|
96
|
+
addTaxon(gbifIndex, gbifId, taxon);
|
|
97
|
+
if (taxon[gbifAcceptedColumn] !== taxon[gbifColumn]) {
|
|
98
|
+
addTaxon(gbifIndex, taxon[gbifAcceptedColumn], taxon);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
const colId = taxon[colColumn];
|
|
102
|
+
if (colId) {
|
|
103
|
+
addTaxon(colIndex, colId, taxon);
|
|
104
|
+
if (taxon[colAcceptedColumn] !== taxon[colColumn]) {
|
|
105
|
+
addTaxon(colIndex, taxon[colAcceptedColumn], taxon);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
amendedResource.taxonCount += 1;
|
|
109
|
+
}
|
|
110
|
+
resourceIndex[amendedResource.id] = amendedResource;
|
|
111
|
+
});
|
|
112
|
+
}));
|
|
113
|
+
});
|
|
114
|
+
}));
|
|
115
|
+
yield Promise.all([
|
|
116
|
+
fs_1.promises.writeFile(path.join(REPO_ROOT, 'gbif.index.json'), JSON.stringify(sortObject(gbifIndex), null, 2)),
|
|
117
|
+
fs_1.promises.writeFile(path.join(REPO_ROOT, 'col.index.json'), JSON.stringify(sortObject(colIndex, alphabeticSort), null, 2)),
|
|
118
|
+
fs_1.promises.writeFile(path.join(REPO_ROOT, 'index.json'), JSON.stringify(sortObject(resourceIndex), null, 2))
|
|
119
|
+
]);
|
|
191
120
|
});
|
|
192
121
|
}
|
|
193
|
-
main(process.argv.slice(2)).catch(
|
|
122
|
+
main(process.argv.slice(2)).catch(error => {
|
|
194
123
|
console.error(error);
|
|
195
124
|
process.exit(1);
|
|
196
125
|
});
|