@natlibfi/melinda-record-matching 5.0.2-alpha.1 → 5.0.3-alpha.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.
|
@@ -2,9 +2,51 @@ import { testStringOrNumber } from "../../../matching-utils.js";
|
|
|
2
2
|
export default () => ({
|
|
3
3
|
name: "Publication time",
|
|
4
4
|
extract: ({ record }) => {
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
return getDateData();
|
|
6
|
+
function getDateData() {
|
|
7
|
+
const [f008] = record.get(/^008$/u);
|
|
8
|
+
if (!f008 || f008.value.length < 16) {
|
|
9
|
+
return splitDateData("| ");
|
|
10
|
+
}
|
|
11
|
+
return splitDateData(f008.value.slice(6, 15));
|
|
12
|
+
}
|
|
13
|
+
function splitDateData(data) {
|
|
14
|
+
const typeOfDate = data[0];
|
|
15
|
+
const date1 = data.slice(1, 5);
|
|
16
|
+
const date2 = data.slice(5);
|
|
17
|
+
return { typeOfDate, date1, date2 };
|
|
18
|
+
}
|
|
7
19
|
},
|
|
8
|
-
compare: (
|
|
20
|
+
compare: (aa, bb) => {
|
|
21
|
+
if (aa.typeOfDate === "b") {
|
|
22
|
+
if (bb.typeOfDate === "b") {
|
|
23
|
+
return 0;
|
|
24
|
+
}
|
|
25
|
+
return -1;
|
|
26
|
+
}
|
|
27
|
+
if (aa.typeOfDate === "n" || bb.typeOfDate === "n") {
|
|
28
|
+
return 0;
|
|
29
|
+
}
|
|
30
|
+
const skipList = [" ", "||||", "uuuu"];
|
|
31
|
+
if (skipList.includes(aa.date1) || skipList.includes(bb.date1)) {
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
if (matchingYears(aa.date1, bb.date1)) {
|
|
35
|
+
return 0.1;
|
|
36
|
+
}
|
|
37
|
+
return -1;
|
|
38
|
+
function matchingYears(yyyy1, yyyy2) {
|
|
39
|
+
if (yyyy1.length === 0) {
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
if (yyyy1[0] === "u" || yyyy2[0] === "u") {
|
|
43
|
+
return matchingYears(yyyy1.slice(1), yyyy2.slice(1));
|
|
44
|
+
}
|
|
45
|
+
if (yyyy1[0] !== yyyy2[0]) {
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
return matchingYears(yyyy1.slice(1), yyyy2.slice(1));
|
|
49
|
+
}
|
|
50
|
+
}
|
|
9
51
|
});
|
|
10
52
|
//# sourceMappingURL=publication-time.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/match-detection/features/bib/publication-time.js"],
|
|
4
|
-
"sourcesContent": ["\n\nimport {testStringOrNumber} from '../../../matching-utils.js';\n\n// We should also get copyright time and copyright/publication times from 26x\n// see publication-time-allow-cons-years for a version allowing consequent years to match\n\nexport default () => ({\n name: 'Publication time',\n extract: ({record}) => {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n return testStringOrNumber(value) ? [String(value).slice(
|
|
5
|
-
"mappings": "AAEA,SAAQ,0BAAyB;AAKjC,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,OAAM,MAAM;AACrB,
|
|
4
|
+
"sourcesContent": ["\n\nimport {testStringOrNumber} from '../../../matching-utils.js';\n\n// We should also get copyright time and copyright/publication times from 26x\n// see publication-time-allow-cons-years for a version allowing consequent years to match\n\nexport default () => ({\n name: 'Publication time',\n extract: ({record}) => {\n return getDateData();\n //const value = record.get(/^008$/u)?.[0]?.value || undefined;\n //return testStringOrNumber(value) ? [String(value).slice(6, 15)] : [];\n\n function getDateData() {\n const [f008] = record.get(/^008$/u);\n if (!f008 || f008.value.length < 16) {\n return splitDateData('| ');\n }\n return splitDateData(f008.value.slice(6, 15));\n }\n\n function splitDateData(data) {\n const typeOfDate = data[0]; // 008/06\n const date1 = data.slice(1,5); // 008/07-10\n const date2 = data.slice(5); // 008/11-14\n return {typeOfDate, date1, date2};\n }\n },\n\n compare: (aa, bb) => {\n if (aa.typeOfDate === 'b') { // Berfore Christ. No really makes sense in our domain, though.\n if (bb.typeOfDate === 'b') {\n return 0;\n }\n return -1.0;\n }\n if (aa.typeOfDate === 'n' || bb.typeOfDate === 'n') { // n=unknown\n return 0;\n }\n\n const skipList = [' ', '||||', 'uuuu'];\n if (skipList.includes(aa.date1) || skipList.includes(bb.date1)) { // 008/07-10 carries no information\n return 0;\n }\n\n if (matchingYears(aa.date1, bb.date1)) { // 'u' support\n return 0.1;\n }\n\n // TODO: add $q support here\n\n return -1.0;\n\n function matchingYears(yyyy1, yyyy2) {\n if (yyyy1.length === 0) { // All digits have been succesfully consumed -> success\n return true;\n }\n if (yyyy1[0] === 'u' || yyyy2[0] === 'u') { // Ignore 'u' (it refers to unknown millenia, century, decade or year)\n return matchingYears(yyyy1.slice(1), yyyy2.slice(1));\n }\n if (yyyy1[0] !== yyyy2[0]) {\n return false;\n }\n // Should we require that yyyy[0] is a digit at this point?\n return matchingYears(yyyy1.slice(1), yyyy2.slice(1));\n }\n\n /*\n function hasFourDigits(yyyy) { // Will be needed by 'q' support\n return yyyy.match(/^[0-9]{4}$/u);\n }\n */\n }\n\n});\n\n\n"],
|
|
5
|
+
"mappings": "AAEA,SAAQ,0BAAyB;AAKjC,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,OAAM,MAAM;AACrB,WAAO,YAAY;AAInB,aAAS,cAAc;AACrB,YAAM,CAAC,IAAI,IAAI,OAAO,IAAI,QAAQ;AAClC,UAAI,CAAC,QAAQ,KAAK,MAAM,SAAS,IAAI;AACnC,eAAO,cAAc,WAAW;AAAA,MAClC;AACA,aAAO,cAAc,KAAK,MAAM,MAAM,GAAG,EAAE,CAAC;AAAA,IAC9C;AAEA,aAAS,cAAc,MAAM;AAC3B,YAAM,aAAa,KAAK,CAAC;AACzB,YAAM,QAAQ,KAAK,MAAM,GAAE,CAAC;AAC5B,YAAM,QAAQ,KAAK,MAAM,CAAC;AAC1B,aAAO,EAAC,YAAY,OAAO,MAAK;AAAA,IAClC;AAAA,EACF;AAAA,EAEA,SAAS,CAAC,IAAI,OAAO;AACnB,QAAI,GAAG,eAAe,KAAK;AACzB,UAAI,GAAG,eAAe,KAAK;AACzB,eAAO;AAAA,MACT;AACA,aAAO;AAAA,IACT;AACA,QAAI,GAAG,eAAe,OAAO,GAAG,eAAe,KAAK;AAClD,aAAO;AAAA,IACT;AAEA,UAAM,WAAW,CAAC,QAAQ,QAAQ,MAAM;AACxC,QAAI,SAAS,SAAS,GAAG,KAAK,KAAK,SAAS,SAAS,GAAG,KAAK,GAAG;AAC9D,aAAO;AAAA,IACT;AAEA,QAAI,cAAc,GAAG,OAAO,GAAG,KAAK,GAAG;AACrC,aAAO;AAAA,IACT;AAIA,WAAO;AAEP,aAAS,cAAc,OAAO,OAAO;AACnC,UAAI,MAAM,WAAW,GAAG;AACtB,eAAO;AAAA,MACT;AACA,UAAI,MAAM,CAAC,MAAM,OAAO,MAAM,CAAC,MAAM,KAAK;AACxC,eAAO,cAAc,MAAM,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,CAAC;AAAA,MACrD;AACA,UAAI,MAAM,CAAC,MAAM,MAAM,CAAC,GAAG;AACzB,eAAO;AAAA,MACT;AAEA,aAAO,cAAc,MAAM,MAAM,CAAC,GAAG,MAAM,MAAM,CAAC,CAAC;AAAA,IACrD;AAAA,EAOF;AAEF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
"url": "https://github.com/NatLibFi/melinda-record-matching-js"
|
|
14
14
|
},
|
|
15
15
|
"license": "MIT",
|
|
16
|
-
"version": "5.0.
|
|
16
|
+
"version": "5.0.3-alpha.1",
|
|
17
17
|
"type": "module",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"bin": "./dist/cli.js",
|
|
@@ -39,13 +39,13 @@
|
|
|
39
39
|
"dependencies": {
|
|
40
40
|
"@natlibfi/marc-record": "^10.0.1",
|
|
41
41
|
"@natlibfi/marc-record-serializers": "^11.0.1",
|
|
42
|
-
"@natlibfi/marc-record-validators-melinda": "^12.0.
|
|
42
|
+
"@natlibfi/marc-record-validators-melinda": "^12.0.7",
|
|
43
43
|
"@natlibfi/melinda-commons": "^14.0.2",
|
|
44
44
|
"@natlibfi/sru-client": "^7.0.1",
|
|
45
45
|
"debug": "^4.4.3",
|
|
46
|
-
"isbn3": "^2.0.
|
|
46
|
+
"isbn3": "^2.0.6",
|
|
47
47
|
"moment": "^2.30.1",
|
|
48
|
-
"natural": "^8.1.
|
|
48
|
+
"natural": "^8.1.1",
|
|
49
49
|
"uuid": "^13.0.0",
|
|
50
50
|
"yargs": "^18.0.0"
|
|
51
51
|
},
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@natlibfi/fixugen-http-client": "^4.0.2",
|
|
55
55
|
"@natlibfi/fixura": "^4.0.0",
|
|
56
56
|
"cross-env": "^10.1.0",
|
|
57
|
-
"esbuild": "^0.27.
|
|
58
|
-
"eslint": "^
|
|
57
|
+
"esbuild": "^0.27.3",
|
|
58
|
+
"eslint": "^10.0.2"
|
|
59
59
|
},
|
|
60
60
|
"overrides": {
|
|
61
61
|
"nanoid": "^3.3.8"
|
|
@@ -8,8 +8,71 @@ import {testStringOrNumber} from '../../../matching-utils.js';
|
|
|
8
8
|
export default () => ({
|
|
9
9
|
name: 'Publication time',
|
|
10
10
|
extract: ({record}) => {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
return getDateData();
|
|
12
|
+
//const value = record.get(/^008$/u)?.[0]?.value || undefined;
|
|
13
|
+
//return testStringOrNumber(value) ? [String(value).slice(6, 15)] : [];
|
|
14
|
+
|
|
15
|
+
function getDateData() {
|
|
16
|
+
const [f008] = record.get(/^008$/u);
|
|
17
|
+
if (!f008 || f008.value.length < 16) {
|
|
18
|
+
return splitDateData('| ');
|
|
19
|
+
}
|
|
20
|
+
return splitDateData(f008.value.slice(6, 15));
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function splitDateData(data) {
|
|
24
|
+
const typeOfDate = data[0]; // 008/06
|
|
25
|
+
const date1 = data.slice(1,5); // 008/07-10
|
|
26
|
+
const date2 = data.slice(5); // 008/11-14
|
|
27
|
+
return {typeOfDate, date1, date2};
|
|
28
|
+
}
|
|
13
29
|
},
|
|
14
|
-
|
|
30
|
+
|
|
31
|
+
compare: (aa, bb) => {
|
|
32
|
+
if (aa.typeOfDate === 'b') { // Berfore Christ. No really makes sense in our domain, though.
|
|
33
|
+
if (bb.typeOfDate === 'b') {
|
|
34
|
+
return 0;
|
|
35
|
+
}
|
|
36
|
+
return -1.0;
|
|
37
|
+
}
|
|
38
|
+
if (aa.typeOfDate === 'n' || bb.typeOfDate === 'n') { // n=unknown
|
|
39
|
+
return 0;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const skipList = [' ', '||||', 'uuuu'];
|
|
43
|
+
if (skipList.includes(aa.date1) || skipList.includes(bb.date1)) { // 008/07-10 carries no information
|
|
44
|
+
return 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (matchingYears(aa.date1, bb.date1)) { // 'u' support
|
|
48
|
+
return 0.1;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// TODO: add $q support here
|
|
52
|
+
|
|
53
|
+
return -1.0;
|
|
54
|
+
|
|
55
|
+
function matchingYears(yyyy1, yyyy2) {
|
|
56
|
+
if (yyyy1.length === 0) { // All digits have been succesfully consumed -> success
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
if (yyyy1[0] === 'u' || yyyy2[0] === 'u') { // Ignore 'u' (it refers to unknown millenia, century, decade or year)
|
|
60
|
+
return matchingYears(yyyy1.slice(1), yyyy2.slice(1));
|
|
61
|
+
}
|
|
62
|
+
if (yyyy1[0] !== yyyy2[0]) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
// Should we require that yyyy[0] is a digit at this point?
|
|
66
|
+
return matchingYears(yyyy1.slice(1), yyyy2.slice(1));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/*
|
|
70
|
+
function hasFourDigits(yyyy) { // Will be needed by 'q' support
|
|
71
|
+
return yyyy.match(/^[0-9]{4}$/u);
|
|
72
|
+
}
|
|
73
|
+
*/
|
|
74
|
+
}
|
|
75
|
+
|
|
15
76
|
});
|
|
77
|
+
|
|
78
|
+
|