@larsgw/formica 0.8.4 → 0.8.6
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/.github/workflows/ci.yml +1 -1
- package/CHANGELOG.md +34 -0
- package/lib/bin/generate-linked-data.js +209 -328
- 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 +6 -0
- package/lib/resources/parse-name.js +354 -0
- package/lib/resources/parse-text.js +185 -475
- package/lib/resources/resource.js +7 -25
- package/lib/taxon-names/index.js +15 -20
- package/package.json +2 -1
- package/src/bin/generate-linked-data.ts +8 -5
- package/src/bin/process-resources.ts +1 -1
- package/src/bin/validate-resources-text.ts +1 -1
- package/src/module.d.ts +4 -2
- package/src/resources/diff-resource.ts +19 -15
- package/src/resources/parse-name.ts +379 -0
- package/src/resources/parse-text.ts +150 -440
- package/test/resources.js +161 -17
- package/tsconfig.json +4 -1
|
@@ -1,35 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.Author = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return _super.call(this, values, {
|
|
4
|
+
const value_1 = require("../value");
|
|
5
|
+
const entity_1 = require("../entity");
|
|
6
|
+
class Author extends entity_1.Entity {
|
|
7
|
+
constructor(values) {
|
|
8
|
+
super(values, {
|
|
25
9
|
name: { required: true, multiple: true },
|
|
26
10
|
id: { required: true, multiple: false, format: value_1.FORMATS.AUTHOR_ID },
|
|
27
11
|
qid: { required: false, multiple: false, format: value_1.FORMATS.QID },
|
|
28
12
|
display_name: { required: true, multiple: false },
|
|
29
13
|
full_names: { required: false, multiple: true },
|
|
30
14
|
duplicate_of: { required: false, multiple: false, format: value_1.FORMATS.AUTHOR_ID }
|
|
31
|
-
})
|
|
15
|
+
});
|
|
32
16
|
}
|
|
33
|
-
|
|
34
|
-
}(entity_1.Entity));
|
|
17
|
+
}
|
|
35
18
|
exports.Author = Author;
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.TYPE_INFO = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const author_1 = require("./author");
|
|
5
|
+
const publisher_1 = require("./publisher");
|
|
6
|
+
const place_1 = require("./place");
|
|
7
|
+
const taxon_1 = require("./taxon");
|
|
8
|
+
const work_1 = require("./work");
|
|
9
9
|
exports.TYPE_INFO = {
|
|
10
10
|
authors: [author_1.Author, 'id'],
|
|
11
11
|
publishers: [publisher_1.Publisher, 'id'],
|
|
@@ -1,34 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.Place = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return _super.call(this, values, {
|
|
4
|
+
const value_1 = require("../value");
|
|
5
|
+
const entity_1 = require("../entity");
|
|
6
|
+
class Place extends entity_1.Entity {
|
|
7
|
+
constructor(values) {
|
|
8
|
+
super(values, {
|
|
25
9
|
name: { required: true, multiple: false },
|
|
26
10
|
id: { required: true, multiple: false, format: value_1.FORMATS.PLACE_ID },
|
|
27
11
|
qid: { required: false, multiple: false, format: value_1.FORMATS.QID },
|
|
28
12
|
display_name: { required: true, multiple: false },
|
|
29
13
|
duplicate_of: { required: false, multiple: false, format: value_1.FORMATS.PLACE_ID }
|
|
30
|
-
})
|
|
14
|
+
});
|
|
31
15
|
}
|
|
32
|
-
|
|
33
|
-
}(entity_1.Entity));
|
|
16
|
+
}
|
|
34
17
|
exports.Place = Place;
|
|
@@ -1,35 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.Publisher = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return _super.call(this, values, {
|
|
4
|
+
const value_1 = require("../value");
|
|
5
|
+
const entity_1 = require("../entity");
|
|
6
|
+
class Publisher extends entity_1.Entity {
|
|
7
|
+
constructor(values) {
|
|
8
|
+
super(values, {
|
|
25
9
|
name: { required: true, multiple: true },
|
|
26
10
|
id: { required: true, multiple: false, format: value_1.FORMATS.PUBLISHER_ID },
|
|
27
11
|
qid: { required: false, multiple: false, format: value_1.FORMATS.QID },
|
|
28
12
|
display_name: { required: true, multiple: false },
|
|
29
13
|
full_names: { required: false, multiple: true },
|
|
30
14
|
duplicate_of: { required: false, multiple: false, format: value_1.FORMATS.PUBLISHER_ID }
|
|
31
|
-
})
|
|
15
|
+
});
|
|
32
16
|
}
|
|
33
|
-
|
|
34
|
-
}(entity_1.Entity));
|
|
17
|
+
}
|
|
35
18
|
exports.Publisher = Publisher;
|
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.Taxon = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return _super.call(this, values, {
|
|
4
|
+
const value_1 = require("../value");
|
|
5
|
+
const entity_1 = require("../entity");
|
|
6
|
+
class Taxon extends entity_1.Entity {
|
|
7
|
+
constructor(values) {
|
|
8
|
+
super(values, {
|
|
25
9
|
name: { required: true, multiple: false },
|
|
26
10
|
id: { required: true, multiple: false, format: value_1.FORMATS.TAXON_ID },
|
|
27
11
|
qid: { required: false, multiple: false, format: value_1.FORMATS.QID },
|
|
@@ -30,8 +14,7 @@ var Taxon = /** @class */ (function (_super) {
|
|
|
30
14
|
children_gbif: { required: false, multiple: true, format: value_1.FORMATS.INTEGER },
|
|
31
15
|
ancestors_gbif: { required: false, multiple: true, format: value_1.FORMATS.INTEGER },
|
|
32
16
|
duplicate_of: { required: false, multiple: false, format: value_1.FORMATS.TAXON_ID }
|
|
33
|
-
})
|
|
17
|
+
});
|
|
34
18
|
}
|
|
35
|
-
|
|
36
|
-
}(entity_1.Entity));
|
|
19
|
+
}
|
|
37
20
|
exports.Taxon = Taxon;
|
|
@@ -1,27 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __extends = (this && this.__extends) || (function () {
|
|
3
|
-
var extendStatics = function (d, b) {
|
|
4
|
-
extendStatics = Object.setPrototypeOf ||
|
|
5
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
6
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
7
|
-
return extendStatics(d, b);
|
|
8
|
-
};
|
|
9
|
-
return function (d, b) {
|
|
10
|
-
if (typeof b !== "function" && b !== null)
|
|
11
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
12
|
-
extendStatics(d, b);
|
|
13
|
-
function __() { this.constructor = d; }
|
|
14
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
15
|
-
};
|
|
16
|
-
})();
|
|
17
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
3
|
exports.Work = void 0;
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
return _super.call(this, values, {
|
|
4
|
+
const value_1 = require("../value");
|
|
5
|
+
const entity_1 = require("../entity");
|
|
6
|
+
class Work extends entity_1.Entity {
|
|
7
|
+
constructor(values) {
|
|
8
|
+
super(values, {
|
|
25
9
|
id: { required: true, multiple: false, format: value_1.FORMATS.WORK_ID },
|
|
26
10
|
title: { required: true, multiple: value_1.CHECK.MULTILANG },
|
|
27
11
|
author: { required: false, multiple: true },
|
|
@@ -54,11 +38,11 @@ var Work = /** @class */ (function (_super) {
|
|
|
54
38
|
part_of: { required: false, multiple: true, format: value_1.FORMATS.WORK_ID },
|
|
55
39
|
version_of: { required: false, multiple: true, format: value_1.FORMATS.WORK_ID },
|
|
56
40
|
duplicate_of: { required: false, multiple: false, format: value_1.FORMATS.WORK_ID }
|
|
57
|
-
})
|
|
41
|
+
});
|
|
58
42
|
}
|
|
59
|
-
|
|
43
|
+
deriveFields() {
|
|
60
44
|
if (typeof this.fields.date === 'string') {
|
|
61
|
-
|
|
45
|
+
const year = parseInt(this.fields.date.split('-')[0]);
|
|
62
46
|
this.derivedFields.year = year.toString();
|
|
63
47
|
this.derivedFields.decade = (year - (year % 10)).toString();
|
|
64
48
|
}
|
|
@@ -66,9 +50,9 @@ var Work = /** @class */ (function (_super) {
|
|
|
66
50
|
this.derivedFields.access = 'Open license';
|
|
67
51
|
}
|
|
68
52
|
else {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
53
|
+
const info = this.fields.url;
|
|
54
|
+
const content = this.fields.fulltext_url;
|
|
55
|
+
const archive = this.fields.archive_url;
|
|
72
56
|
if (typeof content === 'string') {
|
|
73
57
|
this.derivedFields.access = 'Full text available, no license';
|
|
74
58
|
}
|
|
@@ -79,7 +63,6 @@ var Work = /** @class */ (function (_super) {
|
|
|
79
63
|
this.derivedFields.access = 'No full text available';
|
|
80
64
|
}
|
|
81
65
|
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
}(entity_1.Entity));
|
|
66
|
+
}
|
|
67
|
+
}
|
|
85
68
|
exports.Work = Work;
|
package/lib/catalog/value.js
CHANGED
|
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.CHECK = exports.FORMATS = void 0;
|
|
7
7
|
exports.parseValue = parseValue;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
const spdx_license_list_1 = __importDefault(require("spdx-license-list"));
|
|
9
|
+
const ietf_language_tag_regex_1 = __importDefault(require("ietf-language-tag-regex"));
|
|
10
|
+
const ietfTagList = (0, ietf_language_tag_regex_1.default)();
|
|
11
11
|
exports.FORMATS = {
|
|
12
12
|
ENTRY_TYPE: ['print', 'online', 'cd', 'application'],
|
|
13
13
|
KEY_TYPE: ['key', 'matrix', 'reference', 'gallery', 'checklist', 'supplement', 'collection', 'algorithm'],
|
|
@@ -24,21 +24,21 @@ 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
|
-
LICENSE
|
|
28
|
-
LANGUAGE
|
|
27
|
+
LICENSE(value) { return /^<(public domain|.+\?)>$/.test(value) || !!spdx_license_list_1.default[value]; },
|
|
28
|
+
LANGUAGE(value) { return ietfTagList.test(value); }
|
|
29
29
|
};
|
|
30
30
|
exports.CHECK = {
|
|
31
|
-
MULTILANG
|
|
31
|
+
MULTILANG(entry) {
|
|
32
32
|
return Array.isArray(entry.language) && entry.language.length > 1;
|
|
33
33
|
},
|
|
34
|
-
ISBN
|
|
34
|
+
ISBN(entry) {
|
|
35
35
|
if (!Array.isArray(entry.ISBN) || entry.ISBN.length < 2) {
|
|
36
36
|
return false;
|
|
37
37
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
const a = entry.ISBN[0].length === 10;
|
|
39
|
+
const b = entry.ISBN[0].length === 13;
|
|
40
|
+
const c = entry.ISBN[1].length === 10;
|
|
41
|
+
const d = entry.ISBN[1].length === 13;
|
|
42
42
|
return (a && d) || (b && c);
|
|
43
43
|
}
|
|
44
44
|
};
|
package/lib/csv.js
CHANGED
|
@@ -3,14 +3,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parseCsv = parseCsv;
|
|
4
4
|
exports.formatCsv = formatCsv;
|
|
5
5
|
function parseCsv(file) {
|
|
6
|
-
|
|
6
|
+
const values = file
|
|
7
7
|
.trim()
|
|
8
8
|
.match(/("([^"]|"")*?"|[^,\n]+|(?!$))(,|\n|$)/g);
|
|
9
9
|
if (values === null) {
|
|
10
10
|
throw new TypeError('Failed to parse csv');
|
|
11
11
|
}
|
|
12
|
-
return values.reduce(
|
|
13
|
-
|
|
12
|
+
return values.reduce((rows, value) => {
|
|
13
|
+
const last = rows[rows.length - 1];
|
|
14
14
|
if (value.endsWith('\n')) {
|
|
15
15
|
rows.push([]);
|
|
16
16
|
}
|
|
@@ -19,13 +19,12 @@ function parseCsv(file) {
|
|
|
19
19
|
return rows;
|
|
20
20
|
}, [[]]);
|
|
21
21
|
}
|
|
22
|
-
function formatCsv(table, delimiter) {
|
|
23
|
-
if (delimiter === void 0) { delimiter = ','; }
|
|
22
|
+
function formatCsv(table, delimiter = ',') {
|
|
24
23
|
return table
|
|
25
|
-
.map(
|
|
26
|
-
return row.map(
|
|
24
|
+
.map((row) => {
|
|
25
|
+
return row.map(value => {
|
|
27
26
|
if (/["\n]/.test(value) || value.includes(delimiter)) {
|
|
28
|
-
return "
|
|
27
|
+
return `"${value.replace(/"/g, '""')}"`;
|
|
29
28
|
}
|
|
30
29
|
else {
|
|
31
30
|
return value;
|
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
3
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
4
|
-
if (ar || !(i in from)) {
|
|
5
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
6
|
-
ar[i] = from[i];
|
|
7
|
-
}
|
|
8
|
-
}
|
|
9
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
10
|
-
};
|
|
11
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
3
|
exports.ResourceDiffType = void 0;
|
|
13
4
|
exports.createDiff = createDiff;
|
|
@@ -18,39 +9,38 @@ var ResourceDiffType;
|
|
|
18
9
|
ResourceDiffType["Modified"] = "~";
|
|
19
10
|
ResourceDiffType["Unchanged"] = "=";
|
|
20
11
|
})(ResourceDiffType || (exports.ResourceDiffType = ResourceDiffType = {}));
|
|
21
|
-
|
|
22
|
-
|
|
12
|
+
class Matrix {
|
|
13
|
+
constructor(m, n) {
|
|
23
14
|
this.values = Array(m * n).fill(0);
|
|
24
15
|
this.m = m;
|
|
25
16
|
this.n = n;
|
|
26
17
|
}
|
|
27
|
-
|
|
18
|
+
getValue(i, j) {
|
|
28
19
|
return this.values[(i * this.n) + j];
|
|
29
|
-
}
|
|
30
|
-
|
|
20
|
+
}
|
|
21
|
+
setValue(i, j, value) {
|
|
31
22
|
this.values[(i * this.n) + j] = value;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
}());
|
|
23
|
+
}
|
|
24
|
+
}
|
|
35
25
|
function LCS(X, Y) {
|
|
36
|
-
|
|
37
|
-
|
|
26
|
+
const m = X.length;
|
|
27
|
+
const n = Y.length;
|
|
38
28
|
// Build matrix
|
|
39
|
-
|
|
40
|
-
for (
|
|
41
|
-
for (
|
|
42
|
-
if (X[
|
|
43
|
-
C.setValue(
|
|
29
|
+
const C = new Matrix(m + 1, n + 1);
|
|
30
|
+
for (let i = 0; i < m; i++) {
|
|
31
|
+
for (let j = 0; j < n; j++) {
|
|
32
|
+
if (X[i] === Y[j]) {
|
|
33
|
+
C.setValue(i + 1, j + 1, C.getValue(i, j) + 1);
|
|
44
34
|
}
|
|
45
35
|
else {
|
|
46
|
-
C.setValue(
|
|
36
|
+
C.setValue(i + 1, j + 1, Math.max(C.getValue(i, j + 1), C.getValue(i + 1, j)));
|
|
47
37
|
}
|
|
48
38
|
}
|
|
49
39
|
}
|
|
50
40
|
// Backtrace
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
41
|
+
const diff = [];
|
|
42
|
+
let i = m;
|
|
43
|
+
let j = n;
|
|
54
44
|
while (i + j !== 0) {
|
|
55
45
|
if (X[i - 1] === Y[j - 1]) {
|
|
56
46
|
diff.unshift({
|
|
@@ -88,7 +78,7 @@ function tokenizeLines(text) {
|
|
|
88
78
|
}
|
|
89
79
|
function diffTokens(X, Y) {
|
|
90
80
|
// Remove common prefix
|
|
91
|
-
|
|
81
|
+
const prefix = [];
|
|
92
82
|
while (X.length && X[0] === Y[0]) {
|
|
93
83
|
prefix.push({
|
|
94
84
|
text: X[0],
|
|
@@ -98,7 +88,7 @@ function diffTokens(X, Y) {
|
|
|
98
88
|
Y.shift();
|
|
99
89
|
}
|
|
100
90
|
// Remove common suffix
|
|
101
|
-
|
|
91
|
+
const suffix = [];
|
|
102
92
|
while (X.length && X[X.length - 1] === Y[Y.length - 1]) {
|
|
103
93
|
suffix.unshift({
|
|
104
94
|
text: X[X.length - 1],
|
|
@@ -108,16 +98,19 @@ function diffTokens(X, Y) {
|
|
|
108
98
|
Y.pop();
|
|
109
99
|
}
|
|
110
100
|
// Generate diff from remains, combine with prefix and suffix
|
|
111
|
-
return
|
|
101
|
+
return [
|
|
102
|
+
...prefix,
|
|
103
|
+
...LCS(X, Y),
|
|
104
|
+
...suffix
|
|
105
|
+
];
|
|
112
106
|
}
|
|
113
107
|
function convertWordDiff(changes) {
|
|
114
108
|
var _a, _b;
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
for (
|
|
120
|
-
var change = changes_1[_i];
|
|
109
|
+
const lines = [];
|
|
110
|
+
let line = null;
|
|
111
|
+
let deletedNewlines = 0;
|
|
112
|
+
let nextLineNew = false;
|
|
113
|
+
for (const change of changes) {
|
|
121
114
|
// Start of line
|
|
122
115
|
if (line === null) {
|
|
123
116
|
deletedNewlines = 0;
|
|
@@ -169,35 +162,39 @@ function convertWordDiff(changes) {
|
|
|
169
162
|
return lines;
|
|
170
163
|
}
|
|
171
164
|
function getWordTokensFromLines(lines) {
|
|
172
|
-
return lines.flatMap(
|
|
165
|
+
return lines.flatMap(change => tokenizeWords(change.text).concat('\n'));
|
|
166
|
+
}
|
|
167
|
+
function mergeDiffPart(diffPart) {
|
|
168
|
+
if (diffPart.added.length && diffPart.deleted.length) {
|
|
169
|
+
return convertWordDiff(diffTokens(getWordTokensFromLines(diffPart.added), getWordTokensFromLines(diffPart.deleted)));
|
|
170
|
+
}
|
|
171
|
+
else if (diffPart.added.length) {
|
|
172
|
+
return diffPart.added;
|
|
173
|
+
}
|
|
174
|
+
else if (diffPart.deleted.length) {
|
|
175
|
+
return diffPart.deleted.map(change => ({ text: undefined, original: change.text, type: change.type }));
|
|
176
|
+
}
|
|
177
|
+
else {
|
|
178
|
+
return [];
|
|
179
|
+
}
|
|
173
180
|
}
|
|
174
181
|
function createDiff(a, b) {
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
for (
|
|
182
|
+
const lines = diffTokens(tokenizeLines(a.trimEnd()), tokenizeLines(b.trimEnd()));
|
|
183
|
+
const changes = [];
|
|
184
|
+
const diffPart = { added: [], deleted: [] };
|
|
185
|
+
for (let i = 0; i < lines.length; i++) {
|
|
179
186
|
if (lines[i].type === ResourceDiffType.Added) {
|
|
180
187
|
diffPart.added.push(lines[i]);
|
|
181
|
-
continue;
|
|
182
188
|
}
|
|
183
189
|
else if (lines[i].type === ResourceDiffType.Deleted) {
|
|
184
190
|
diffPart.deleted.push(lines[i]);
|
|
185
|
-
continue;
|
|
186
191
|
}
|
|
187
|
-
|
|
188
|
-
changes.push
|
|
189
|
-
diffPart.added.length = 0;
|
|
190
|
-
diffPart.deleted.length = 0;
|
|
191
|
-
}
|
|
192
|
-
else if (diffPart.added.length) {
|
|
193
|
-
changes.push.apply(changes, diffPart.added);
|
|
192
|
+
else {
|
|
193
|
+
changes.push(...mergeDiffPart(diffPart), lines[i]);
|
|
194
194
|
diffPart.added.length = 0;
|
|
195
|
-
}
|
|
196
|
-
else if (diffPart.deleted.length) {
|
|
197
|
-
changes.push.apply(changes, diffPart.deleted.map(function (change) { return ({ text: undefined, original: change.text, type: change.type }); }));
|
|
198
195
|
diffPart.deleted.length = 0;
|
|
199
196
|
}
|
|
200
|
-
changes.push(lines[i]);
|
|
201
197
|
}
|
|
198
|
+
changes.push(...mergeDiffPart(diffPart));
|
|
202
199
|
return changes;
|
|
203
200
|
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export declare class RecoverableSyntaxError<Result> extends SyntaxError {
|
|
2
|
+
result: Result;
|
|
3
|
+
constructor(message: string, result: Result);
|
|
4
|
+
}
|
|
5
|
+
export declare const RANKS: Rank[];
|
|
6
|
+
export declare function parseName(name: string, rank: Rank, parent: WorkingTaxon): WorkingTaxon;
|