@larsgw/formica 0.6.4 → 0.6.5
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 +11 -0
- package/lib/bin/process-resources.js +4 -4
- package/lib/resources/parse-text.js +18 -10
- package/package.json +1 -1
- package/src/bin/process-resources.ts +18 -2
- package/src/resources/parse-text.ts +19 -10
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,14 @@
|
|
|
1
|
+
## [0.6.5](https://github.com/identification-resources/formica/compare/v0.6.4...v0.6.5) (2024-12-20)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* **resources:** ignore empty lines in diff mode ([3fb027e](https://github.com/identification-resources/formica/commit/3fb027e8968196910fff2e574e700ac0abee996c))
|
|
7
|
+
* **resources:** improve (ICBN) author parsing ([d3e3faf](https://github.com/identification-resources/formica/commit/d3e3faf411d1a7dccd528a5ee78bd0823a5883b4)), closes [#13](https://github.com/identification-resources/formica/issues/13) [#14](https://github.com/identification-resources/formica/issues/14)
|
|
8
|
+
* **resources:** support "et al." in author name ([82993bf](https://github.com/identification-resources/formica/commit/82993bffac5e7f3ed00d00c28c836f347b264a43))
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
1
12
|
## [0.6.4](https://github.com/identification-resources/formica/compare/v0.6.3...v0.6.4) (2024-12-16)
|
|
2
13
|
|
|
3
14
|
|
|
@@ -454,8 +454,8 @@ var ResourceProcessor = /** @class */ (function () {
|
|
|
454
454
|
}
|
|
455
455
|
return name_2 === a.matchedName ? -1 : name_2 === b.matchedName ? 1 : 0;
|
|
456
456
|
});
|
|
457
|
-
for (var _o = 0,
|
|
458
|
-
var match =
|
|
457
|
+
for (var _o = 0, _p = matches; _o < _p.length; _o++) {
|
|
458
|
+
var match = _p[_o];
|
|
459
459
|
var source = match.dataSourceId;
|
|
460
460
|
var currentRank = match.classificationRanks.split('|').pop();
|
|
461
461
|
if (match.scoreDetails.cardinalityScore === 0) {
|
|
@@ -466,8 +466,8 @@ var ResourceProcessor = /** @class */ (function () {
|
|
|
466
466
|
// GBIF species like "Nomada spec"
|
|
467
467
|
continue;
|
|
468
468
|
}
|
|
469
|
-
for (var
|
|
470
|
-
var loirId = _q
|
|
469
|
+
for (var _q = 0, _r = taxonNames[name_2]; _q < _r.length; _q++) {
|
|
470
|
+
var loirId = _r[_q];
|
|
471
471
|
var taxon = resource.taxa[loirId];
|
|
472
472
|
if (source === 11 && !GBIF_RANKS.includes(taxon.taxonRank)) {
|
|
473
473
|
// Exclude GBIF matches for ranks that are not in GBIF
|
|
@@ -93,6 +93,18 @@ var RANK_LABELS_REVERSE = {
|
|
|
93
93
|
'ssp': 'subspecies',
|
|
94
94
|
'subsp': 'subspecies'
|
|
95
95
|
};
|
|
96
|
+
/**
|
|
97
|
+
* 1. Any number of
|
|
98
|
+
* - capitalized words
|
|
99
|
+
* - "&"
|
|
100
|
+
* - " in "
|
|
101
|
+
* - " ex "
|
|
102
|
+
* - lowercase name particles
|
|
103
|
+
* 2. Followed by a capitalized word
|
|
104
|
+
* 3. Optionally, followed by "et al."
|
|
105
|
+
*/
|
|
106
|
+
var LOWERCASE_NAME_PARTICLES = ['y', 'der', 'den', 'de', 'van'].join('|');
|
|
107
|
+
var SIMPLE_AUTHOR_PATTERN = '(?:(?:\\p{Lu}\\S*|&|in|ex|' + LOWERCASE_NAME_PARTICLES + ')\\s*)*\\p{Lu}\\S+(?:\\s+et\\s+al\\.)?';
|
|
96
108
|
var NAME_PATTERN = new RegExp('^' +
|
|
97
109
|
// $1 main name part
|
|
98
110
|
'(\\S+)' +
|
|
@@ -101,20 +113,14 @@ var NAME_PATTERN = new RegExp('^' +
|
|
|
101
113
|
// but not auct(t)., etc.
|
|
102
114
|
'(?!auctt?\\.|(?:syn|comb|sp|spec)\\. n(?:ov)?\\.|s(?:ens[.u]|\\.))' +
|
|
103
115
|
'(' +
|
|
104
|
-
// $2.1 anything in parentheses
|
|
105
|
-
'\\(.+?\\)' +
|
|
116
|
+
// $2.1 anything in parentheses, followed by optional revising author(s)
|
|
117
|
+
'\\(.+?\\)(?:\\s+' + SIMPLE_AUTHOR_PATTERN + ')?' +
|
|
106
118
|
'|' +
|
|
107
119
|
// $2.2 anything followed by a year
|
|
108
120
|
'.+?\\d{4}\\)?' +
|
|
109
121
|
'|' +
|
|
110
|
-
// $2.3
|
|
111
|
-
|
|
112
|
-
'|' +
|
|
113
|
-
// $2.4 name y name
|
|
114
|
-
'\\S+ [yY] \\S+' +
|
|
115
|
-
'|' +
|
|
116
|
-
// $2.5 name( in name)
|
|
117
|
-
'\\p{Lu}\\S*(?: in \\S+)?' +
|
|
122
|
+
// $2.3 author(s)
|
|
123
|
+
SIMPLE_AUTHOR_PATTERN +
|
|
118
124
|
'))?' +
|
|
119
125
|
// $3 optional notes
|
|
120
126
|
'(?:,? (.+))?' +
|
|
@@ -541,6 +547,8 @@ function parseFile(file, id, old) {
|
|
|
541
547
|
var diff;
|
|
542
548
|
if (oldResources[index]) {
|
|
543
549
|
diff = (0, diff_resource_1.createDiff)(content, parseResource(oldResources[index])[1]);
|
|
550
|
+
// Ignore empty lines
|
|
551
|
+
diff = diff.filter(function (line) { return line.text !== ''; });
|
|
544
552
|
}
|
|
545
553
|
else {
|
|
546
554
|
diff = (0, diff_resource_1.createDiff)(content, content);
|
package/package.json
CHANGED
|
@@ -287,6 +287,22 @@ class ResourceProcessor {
|
|
|
287
287
|
|
|
288
288
|
const result = await runGnverifier(Array.from(names).join('\n'))
|
|
289
289
|
for (const results of result.trim().split('\n')) {
|
|
290
|
+
interface MatchScoreDetails {
|
|
291
|
+
cardinalityScore: number;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
interface Match {
|
|
295
|
+
currentRecordId: string;
|
|
296
|
+
dataSourceId: number;
|
|
297
|
+
matchedName: string;
|
|
298
|
+
recordId: string;
|
|
299
|
+
sortScore: number;
|
|
300
|
+
isSynonym: boolean;
|
|
301
|
+
classificationPath: string;
|
|
302
|
+
classificationRanks: string;
|
|
303
|
+
scoreDetails: MatchScoreDetails;
|
|
304
|
+
}
|
|
305
|
+
|
|
290
306
|
const { name, results: matches } = JSON.parse(results)
|
|
291
307
|
|
|
292
308
|
if (!matches) {
|
|
@@ -294,7 +310,7 @@ class ResourceProcessor {
|
|
|
294
310
|
}
|
|
295
311
|
|
|
296
312
|
// Fix author scoring for some species, see https://github.com/gnames/gnverifier/issues/129
|
|
297
|
-
matches.sort((a:
|
|
313
|
+
matches.sort((a: Match, b: Match) => {
|
|
298
314
|
if (a.sortScore !== b.sortScore) {
|
|
299
315
|
return b.sortScore - a.sortScore
|
|
300
316
|
}
|
|
@@ -302,7 +318,7 @@ class ResourceProcessor {
|
|
|
302
318
|
return name === a.matchedName ? -1 : name === b.matchedName ? 1 : 0
|
|
303
319
|
})
|
|
304
320
|
|
|
305
|
-
for (const match of matches) {
|
|
321
|
+
for (const match of matches as Match[]) {
|
|
306
322
|
const source = match.dataSourceId
|
|
307
323
|
const currentRank = match.classificationRanks.split('|').pop()
|
|
308
324
|
|
|
@@ -87,6 +87,19 @@ const RANK_LABELS_REVERSE: Record<string, Rank> = {
|
|
|
87
87
|
'subsp': 'subspecies'
|
|
88
88
|
}
|
|
89
89
|
|
|
90
|
+
/**
|
|
91
|
+
* 1. Any number of
|
|
92
|
+
* - capitalized words
|
|
93
|
+
* - "&"
|
|
94
|
+
* - " in "
|
|
95
|
+
* - " ex "
|
|
96
|
+
* - lowercase name particles
|
|
97
|
+
* 2. Followed by a capitalized word
|
|
98
|
+
* 3. Optionally, followed by "et al."
|
|
99
|
+
*/
|
|
100
|
+
const LOWERCASE_NAME_PARTICLES = ['y', 'der', 'den', 'de', 'van'].join('|')
|
|
101
|
+
const SIMPLE_AUTHOR_PATTERN = '(?:(?:\\p{Lu}\\S*|&|in|ex|' + LOWERCASE_NAME_PARTICLES + ')\\s*)*\\p{Lu}\\S+(?:\\s+et\\s+al\\.)?'
|
|
102
|
+
|
|
90
103
|
const NAME_PATTERN = new RegExp(
|
|
91
104
|
'^' +
|
|
92
105
|
// $1 main name part
|
|
@@ -96,20 +109,14 @@ const NAME_PATTERN = new RegExp(
|
|
|
96
109
|
// but not auct(t)., etc.
|
|
97
110
|
'(?!auctt?\\.|(?:syn|comb|sp|spec)\\. n(?:ov)?\\.|s(?:ens[.u]|\\.))' +
|
|
98
111
|
'(' +
|
|
99
|
-
// $2.1 anything in parentheses
|
|
100
|
-
'\\(.+?\\)' +
|
|
112
|
+
// $2.1 anything in parentheses, followed by optional revising author(s)
|
|
113
|
+
'\\(.+?\\)(?:\\s+' + SIMPLE_AUTHOR_PATTERN + ')?' +
|
|
101
114
|
'|' +
|
|
102
115
|
// $2.2 anything followed by a year
|
|
103
116
|
'.+?\\d{4}\\)?' +
|
|
104
117
|
'|' +
|
|
105
|
-
// $2.3
|
|
106
|
-
|
|
107
|
-
'|' +
|
|
108
|
-
// $2.4 name y name
|
|
109
|
-
'\\S+ [yY] \\S+' +
|
|
110
|
-
'|' +
|
|
111
|
-
// $2.5 name( in name)
|
|
112
|
-
'\\p{Lu}\\S*(?: in \\S+)?' +
|
|
118
|
+
// $2.3 author(s)
|
|
119
|
+
SIMPLE_AUTHOR_PATTERN +
|
|
113
120
|
'))?' +
|
|
114
121
|
// $3 optional notes
|
|
115
122
|
'(?:,? (.+))?' +
|
|
@@ -573,6 +580,8 @@ export function parseFile (file: string, id: WorkId, old?: ResourceHistory): Res
|
|
|
573
580
|
let diff
|
|
574
581
|
if (oldResources[index]) {
|
|
575
582
|
diff = createDiff(content, parseResource(oldResources[index])[1])
|
|
583
|
+
// Ignore empty lines
|
|
584
|
+
diff = diff.filter(line => line.text !== '')
|
|
576
585
|
} else {
|
|
577
586
|
diff = createDiff(content, content)
|
|
578
587
|
}
|