@larsgw/formica 0.6.2 → 0.6.4

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 CHANGED
@@ -1,3 +1,21 @@
1
+ ## [0.6.4](https://github.com/identification-resources/formica/compare/v0.6.3...v0.6.4) (2024-12-16)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * **resources:** fix matching of some ICBN names ([3c18458](https://github.com/identification-resources/formica/commit/3c184586b64e2a31f1eb7298bcd7c80c1d119069))
7
+
8
+
9
+
10
+ ## [0.6.3](https://github.com/identification-resources/formica/compare/v0.6.2...v0.6.3) (2024-04-12)
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * **resources:** allow 'phylum' rank ([ff9be66](https://github.com/identification-resources/formica/commit/ff9be66abab79a86263764b54d6a2709833b14d4))
16
+
17
+
18
+
1
19
  ## [0.6.2](https://github.com/identification-resources/formica/compare/v0.6.1...v0.6.2) (2024-04-08)
2
20
 
3
21
 
@@ -398,9 +398,9 @@ var ResourceProcessor = /** @class */ (function () {
398
398
  };
399
399
  ResourceProcessor.prototype.processResourceDwc = function (resource, config) {
400
400
  return __awaiter(this, void 0, void 0, function () {
401
- var file, _a, header_1, rows, _b, _c, _i, rows_1, row, oldTaxon, taxon, filteredResults, taxonNames, names, id, name_1, result, _d, _e, results, _f, name_2, matches, _g, matches_1, match, source, currentRank, _h, _j, loirId, taxon, _k, amendResource, groupNameMatches, groupedNameMatches, amendedResource, _l, _m, _o, _p, source, matches;
402
- return __generator(this, function (_q) {
403
- switch (_q.label) {
401
+ var file, _a, header_1, rows, _b, _c, _i, rows_1, row, oldTaxon, taxon, filteredResults, taxonNames, names, id, name_1, result, _loop_2, _d, _e, results, _f, amendResource, groupNameMatches, groupedNameMatches, amendedResource, _g, _h, _j, _k, source, matches;
402
+ return __generator(this, function (_l) {
403
+ switch (_l.label) {
404
404
  case 0:
405
405
  console.log("".concat(resource.workId, ": matching ").concat(resource.id));
406
406
  if (!!config.updateMappings) return [3 /*break*/, 3];
@@ -409,7 +409,7 @@ var ResourceProcessor = /** @class */ (function () {
409
409
  _c = (_b = index_1.csv).parseCsv;
410
410
  return [4 /*yield*/, fs_1.promises.readFile(file, 'utf-8')];
411
411
  case 1:
412
- _a = _c.apply(_b, [_q.sent()]), header_1 = _a[0], rows = _a.slice(1);
412
+ _a = _c.apply(_b, [_l.sent()]), header_1 = _a[0], rows = _a.slice(1);
413
413
  for (_i = 0, rows_1 = rows; _i < rows_1.length; _i++) {
414
414
  row = rows_1[_i];
415
415
  oldTaxon = row.reduce(function (taxon, value, index) {
@@ -424,7 +424,7 @@ var ResourceProcessor = /** @class */ (function () {
424
424
  taxon.gbifAcceptedTaxonID = oldTaxon.gbifAcceptedTaxonID;
425
425
  }
426
426
  }
427
- _q.label = 2;
427
+ _l.label = 2;
428
428
  case 2: return [2 /*return*/, resource];
429
429
  case 3:
430
430
  filteredResults = {};
@@ -441,17 +441,23 @@ var ResourceProcessor = /** @class */ (function () {
441
441
  }
442
442
  return [4 /*yield*/, runGnverifier(Array.from(names).join('\n'))];
443
443
  case 4:
444
- result = _q.sent();
445
- for (_d = 0, _e = result.trim().split('\n'); _d < _e.length; _d++) {
446
- results = _e[_d];
447
- _f = JSON.parse(results), name_2 = _f.name, matches = _f.results;
444
+ result = _l.sent();
445
+ _loop_2 = function (results) {
446
+ var _m = JSON.parse(results), name_2 = _m.name, matches = _m.results;
448
447
  if (!matches) {
449
- continue;
448
+ return "continue";
450
449
  }
451
- for (_g = 0, matches_1 = matches; _g < matches_1.length; _g++) {
452
- match = matches_1[_g];
453
- source = match.dataSourceId;
454
- currentRank = match.classificationRanks.split('|').pop();
450
+ // Fix author scoring for some species, see https://github.com/gnames/gnverifier/issues/129
451
+ matches.sort(function (a, b) {
452
+ if (a.sortScore !== b.sortScore) {
453
+ return b.sortScore - a.sortScore;
454
+ }
455
+ return name_2 === a.matchedName ? -1 : name_2 === b.matchedName ? 1 : 0;
456
+ });
457
+ for (var _o = 0, matches_1 = matches; _o < matches_1.length; _o++) {
458
+ var match = matches_1[_o];
459
+ var source = match.dataSourceId;
460
+ var currentRank = match.classificationRanks.split('|').pop();
455
461
  if (match.scoreDetails.cardinalityScore === 0) {
456
462
  // Rank mismatch
457
463
  continue;
@@ -460,9 +466,9 @@ var ResourceProcessor = /** @class */ (function () {
460
466
  // GBIF species like "Nomada spec"
461
467
  continue;
462
468
  }
463
- for (_h = 0, _j = taxonNames[name_2]; _h < _j.length; _h++) {
464
- loirId = _j[_h];
465
- taxon = resource.taxa[loirId];
469
+ for (var _p = 0, _q = taxonNames[name_2]; _p < _q.length; _p++) {
470
+ var loirId = _q[_p];
471
+ var taxon = resource.taxa[loirId];
466
472
  if (source === 11 && !GBIF_RANKS.includes(taxon.taxonRank)) {
467
473
  // Exclude GBIF matches for ranks that are not in GBIF
468
474
  continue;
@@ -483,30 +489,34 @@ var ResourceProcessor = /** @class */ (function () {
483
489
  });
484
490
  }
485
491
  }
492
+ };
493
+ for (_d = 0, _e = result.trim().split('\n'); _d < _e.length; _d++) {
494
+ results = _e[_d];
495
+ _loop_2(results);
486
496
  }
487
497
  return [4 /*yield*/, Promise.resolve().then(function () { return require('../index'); })];
488
498
  case 5:
489
- _k = (_q.sent()).taxonNames, amendResource = _k.amendResource, groupNameMatches = _k.groupNameMatches;
499
+ _f = (_l.sent()).taxonNames, amendResource = _f.amendResource, groupNameMatches = _f.groupNameMatches;
490
500
  groupedNameMatches = groupNameMatches(filteredResults);
491
501
  amendedResource = __assign(__assign({}, resource), { taxa: __assign({}, resource.taxa) });
492
- _l = groupedNameMatches;
493
- _m = [];
494
- for (_o in _l)
495
- _m.push(_o);
496
- _p = 0;
497
- _q.label = 6;
502
+ _g = groupedNameMatches;
503
+ _h = [];
504
+ for (_j in _g)
505
+ _h.push(_j);
506
+ _k = 0;
507
+ _l.label = 6;
498
508
  case 6:
499
- if (!(_p < _m.length)) return [3 /*break*/, 9];
500
- _o = _m[_p];
501
- if (!(_o in _l)) return [3 /*break*/, 8];
502
- source = _o;
509
+ if (!(_k < _h.length)) return [3 /*break*/, 9];
510
+ _j = _h[_k];
511
+ if (!(_j in _g)) return [3 /*break*/, 8];
512
+ source = _j;
503
513
  return [4 /*yield*/, this.selectPrefixes(resource, groupedNameMatches, source)];
504
514
  case 7:
505
- matches = _q.sent();
515
+ matches = _l.sent();
506
516
  amendResource(amendedResource, source, matches);
507
- _q.label = 8;
517
+ _l.label = 8;
508
518
  case 8:
509
- _p++;
519
+ _k++;
510
520
  return [3 /*break*/, 6];
511
521
  case 9: return [2 /*return*/, amendedResource];
512
522
  }
@@ -16,6 +16,7 @@ var yaml = require("js-yaml");
16
16
  var work_1 = require("../catalog/tables/work");
17
17
  var diff_resource_1 = require("./diff-resource");
18
18
  var RANKS = [
19
+ 'phylum',
19
20
  'class',
20
21
  'infraclass',
21
22
  'superorder',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@larsgw/formica",
3
- "version": "0.6.2",
3
+ "version": "0.6.4",
4
4
  "description": "SDK and tools for data from the Library of Identification Resources",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -293,6 +293,15 @@ class ResourceProcessor {
293
293
  continue
294
294
  }
295
295
 
296
+ // Fix author scoring for some species, see https://github.com/gnames/gnverifier/issues/129
297
+ matches.sort((a: Record<string, any>, b: Record<string, any>) => {
298
+ if (a.sortScore !== b.sortScore) {
299
+ return b.sortScore - a.sortScore
300
+ }
301
+
302
+ return name === a.matchedName ? -1 : name === b.matchedName ? 1 : 0
303
+ })
304
+
296
305
  for (const match of matches) {
297
306
  const source = match.dataSourceId
298
307
  const currentRank = match.classificationRanks.split('|').pop()
@@ -3,6 +3,7 @@ import { Work } from '../catalog/tables/work'
3
3
  import { createDiff, ResourceDiffType } from './diff-resource'
4
4
 
5
5
  const RANKS: Rank[] = [
6
+ 'phylum',
6
7
  'class',
7
8
  'infraclass',
8
9
  'superorder',