@larsgw/formica 0.10.0 → 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.
@@ -47,37 +47,38 @@ const fs_1 = require("fs");
47
47
  const path = __importStar(require("path"));
48
48
  const index_1 = require("../index");
49
49
  class TaxaValidator {
50
- constructor(taxa) {
51
- this.taxa = Array.from(taxa).filter(taxon => taxon.has('ancestors_gbif'));
50
+ constructor(taxa, fields) {
51
+ this.taxa = Array.from(taxa).filter(taxon => taxon.has(fields.ancestors));
52
+ this.fields = fields;
52
53
  this.errors = [];
53
54
  this.parentIndex = {};
54
55
  }
55
56
  validate() {
56
57
  for (const taxon of this.taxa) {
57
- const parents = taxon.get('ancestors_gbif');
58
+ const parents = taxon.get(this.fields.ancestors);
58
59
  if (parents.length > 1) {
59
60
  const id = taxon.get('id');
60
61
  for (let i = 1; i < parents.length; i++) {
61
- this.addToIndex(id, 'ancestors_gbif', parents[i], parents[i - 1]);
62
+ this.addToIndex(id, this.fields.ancestors, parents[i], parents[i - 1]);
62
63
  }
63
64
  }
64
65
  }
65
66
  for (const taxon of this.taxa) {
66
- if (taxon.has('gbif')) {
67
+ if (taxon.has(this.fields.id)) {
67
68
  const id = taxon.get('id');
68
- const parents = taxon.get('ancestors_gbif');
69
+ const parents = taxon.get(this.fields.ancestors);
69
70
  const parent = parents[parents.length - 1];
70
- this.addToIndex(id, 'gbif', taxon.get('gbif'), parent);
71
+ this.addToIndex(id, this.fields.id, taxon.get(this.fields.id), parent);
71
72
  }
72
73
  }
73
74
  for (const taxon of this.taxa) {
74
- if (taxon.has('children_gbif')) {
75
+ if (taxon.has(this.fields.children)) {
75
76
  const id = taxon.get('id');
76
- const parents = taxon.get('ancestors_gbif');
77
+ const parents = taxon.get(this.fields.ancestors);
77
78
  const parent = parents[parents.length - 1];
78
- const childIds = taxon.get('children_gbif');
79
+ const childIds = taxon.get(this.fields.children);
79
80
  for (const childId of childIds) {
80
- this.addToIndex(id, 'gbif', childId, parent);
81
+ this.addToIndex(id, this.fields.id, childId, parent);
81
82
  }
82
83
  }
83
84
  }
@@ -94,6 +95,24 @@ class TaxaValidator {
94
95
  }
95
96
  }
96
97
  }
98
+ class GbifTaxaValidator extends TaxaValidator {
99
+ constructor(taxa) {
100
+ super(taxa, {
101
+ id: 'gbif',
102
+ children: 'children_gbif',
103
+ ancestors: 'ancestors_gbif'
104
+ });
105
+ }
106
+ }
107
+ class ColTaxaValidator extends TaxaValidator {
108
+ constructor(taxa) {
109
+ super(taxa, {
110
+ id: 'col',
111
+ children: 'children_col',
112
+ ancestors: 'ancestors_col'
113
+ });
114
+ }
115
+ }
97
116
  function validateFile(arg) {
98
117
  return __awaiter(this, void 0, void 0, function* () {
99
118
  const filePath = path.resolve(arg);
@@ -116,8 +135,10 @@ function validateFile(arg) {
116
135
  }
117
136
  }
118
137
  if (sheet === 'taxa') {
119
- const validator = new TaxaValidator(entities);
120
- errors.push(...validator.validate());
138
+ // const colValidator = new ColTaxaValidator(entities)
139
+ // errors.push(...colValidator.validate())
140
+ const gbifValidator = new GbifTaxaValidator(entities);
141
+ errors.push(...gbifValidator.validate());
121
142
  }
122
143
  return errors;
123
144
  });
@@ -10,6 +10,10 @@ class Taxon extends entity_1.Entity {
10
10
  id: { required: true, multiple: false, format: value_1.FORMATS.TAXON_ID },
11
11
  qid: { required: false, multiple: false, format: value_1.FORMATS.QID },
12
12
  rank: { required: false, multiple: false },
13
+ col: { required: false, multiple: false, format: value_1.FORMATS.COL_ID },
14
+ accepted_col: { required: false, multiple: false, format: value_1.FORMATS.COL_ID },
15
+ children_col: { required: false, multiple: true, format: value_1.FORMATS.COL_ID },
16
+ ancestors_col: { required: false, multiple: true, format: value_1.FORMATS.COL_ID },
13
17
  gbif: { required: false, multiple: false, format: value_1.FORMATS.INTEGER },
14
18
  children_gbif: { required: false, multiple: true, format: value_1.FORMATS.INTEGER },
15
19
  ancestors_gbif: { required: false, multiple: true, format: value_1.FORMATS.INTEGER },
@@ -14,6 +14,7 @@ export declare const FORMATS: {
14
14
  QID: RegExp;
15
15
  URL: RegExp;
16
16
  INTEGER: RegExp;
17
+ COL_ID: RegExp;
17
18
  LICENSE(value: SingleValue): true;
18
19
  LANGUAGE(value: SingleValue): boolean;
19
20
  };
@@ -24,6 +24,7 @@ exports.FORMATS = {
24
24
  QID: /^Q[1-9][0-9]*$/,
25
25
  URL: /^(ftp|http|https):\/\/((?:[a-z0-9][a-z0-9-_]*?[a-z0-9]?\.)+(?:xn--)?[a-z0-9]+)(:\d*)?((?:\/(?:%\d\d|[!$&'()*+,\-.0-9";=@A-Z_a-z~])*)*)(\?(?:%\d\d|[!$&'()*+,\-./0-9:;=?@A-Z_a-z~])*)?(#(?:%\d\d|[!$&'()*+,\-./0-9:;=?@A-Z_a-z~])*)?/i,
26
26
  INTEGER: /^(0|[1-9]\d*)$/,
27
+ COL_ID: /^(0|[1-9A-Z][0-9A-Z]*)$/,
27
28
  LICENSE(value) { return /^<(public domain|.+\?)>$/.test(value) || !!spdx_license_list_1.default[value]; },
28
29
  LANGUAGE(value) { return ietfTagList.test(value); }
29
30
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@larsgw/formica",
3
- "version": "0.10.0",
3
+ "version": "0.10.1",
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",