@natlibfi/melinda-record-matching 4.0.1-alpha.1 → 4.1.0-alpha.2

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.
@@ -63,6 +63,18 @@ Object.defineProperty(exports, "publicationTime", {
63
63
  return _publicationTime.default;
64
64
  }
65
65
  });
66
+ Object.defineProperty(exports, "publicationTimeAllowConsYears", {
67
+ enumerable: true,
68
+ get: function () {
69
+ return _publicationTimeAllowConsYears.default;
70
+ }
71
+ });
72
+ Object.defineProperty(exports, "publicationTimeAllowConsYearsMulti", {
73
+ enumerable: true,
74
+ get: function () {
75
+ return _publicationTimeAllowConsYearsMulti.default;
76
+ }
77
+ });
66
78
  Object.defineProperty(exports, "recordType", {
67
79
  enumerable: true,
68
80
  get: function () {
@@ -90,6 +102,8 @@ var _titleVersionOriginal = _interopRequireDefault(require("./title-version-orig
90
102
  var _authors = _interopRequireDefault(require("./authors"));
91
103
  var _recordType = _interopRequireDefault(require("./record-type"));
92
104
  var _publicationTime = _interopRequireDefault(require("./publication-time"));
105
+ var _publicationTimeAllowConsYears = _interopRequireDefault(require("./publication-time-allow-cons-years"));
106
+ var _publicationTimeAllowConsYearsMulti = _interopRequireDefault(require("./publication-time-allow-cons-years-multi"));
93
107
  var _language = _interopRequireDefault(require("./language"));
94
108
  var _bibliographicLevel = _interopRequireDefault(require("./bibliographic-level"));
95
109
  var _melindaId = _interopRequireDefault(require("./melinda-id"));
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/match-detection/features/bib/index.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nexport {default as hostComponent} from './host-component';\nexport {default as isbn} from './isbn';\nexport {default as issn} from './issn';\nexport {default as otherStandardIdentifier} from './other-standard-identifier';\nexport {default as title} from './title';\nexport {default as titleVersionOriginal} from './title-version-original';\nexport {default as authors} from './authors';\nexport {default as recordType} from './record-type';\nexport {default as publicationTime} from './publication-time';\nexport {default as language} from './language';\nexport {default as bibliographicLevel} from './bibliographic-level';\nexport {default as melindaId} from './melinda-id';\nexport {default as allSourceIds} from './all-source-ids';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAyD"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../../src/match-detection/features/bib/index.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nexport {default as hostComponent} from './host-component';\nexport {default as isbn} from './isbn';\nexport {default as issn} from './issn';\nexport {default as otherStandardIdentifier} from './other-standard-identifier';\nexport {default as title} from './title';\nexport {default as titleVersionOriginal} from './title-version-original';\nexport {default as authors} from './authors';\nexport {default as recordType} from './record-type';\nexport {default as publicationTime} from './publication-time';\nexport {default as publicationTimeAllowConsYears} from './publication-time-allow-cons-years';\nexport {default as publicationTimeAllowConsYearsMulti} from './publication-time-allow-cons-years-multi';\nexport {default as language} from './language';\nexport {default as bibliographicLevel} from './bibliographic-level';\nexport {default as melindaId} from './melinda-id';\nexport {default as allSourceIds} from './all-source-ids';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAyD"}
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _debug = _interopRequireDefault(require("debug"));
8
+ var _matchingUtils = require("../../../matching-utils");
8
9
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
9
10
  /**
10
11
  *
@@ -12,7 +13,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
12
13
  *
13
14
  * Melinda record matching modules for Javascript
14
15
  *
15
- * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
16
+ * Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
16
17
  *
17
18
  * This file is part of melinda-record-matching-js
18
19
  *
@@ -46,17 +47,13 @@ var _default = () => ({
46
47
  const value008 = get008Value();
47
48
  const values041 = get041Values();
48
49
  debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);
49
- if (value008 && values041.length > 0) {
50
- debugData(`${label} There's both 008 and 041, searching for value in both`);
51
- const correspondingValue = values041.find(v => v === value008);
52
- debugData(`${label} Corresponding value: ${correspondingValue}`);
53
- return correspondingValue ? [correspondingValue] : [];
54
- }
55
50
  if (!value008 && values041.length < 1) {
56
51
  debugData(`{$label} No actual values found`);
57
52
  return [];
58
53
  }
59
- return value008 ? [value008] : [values041[0]];
54
+ const allValues = value008 === undefined ? values041 : values041.concat(value008);
55
+ const uniqueSortedValues = [...new Set(allValues)].sort();
56
+ return uniqueSortedValues;
60
57
  function get008Value() {
61
58
  var _record$get, _record$get$;
62
59
  const value = ((_record$get = record.get(/^008$/u)) === null || _record$get === void 0 ? void 0 : (_record$get$ = _record$get[0]) === null || _record$get$ === void 0 ? void 0 : _record$get$.value) || undefined;
@@ -66,11 +63,9 @@ var _default = () => ({
66
63
  }
67
64
  const code = value.slice(35, 38);
68
65
  debugData(`${label} 008 code: ${code}`);
69
- return code === '|||' || code === ' ' || code === '^^^' ? undefined : code;
66
+ return isLangCodeForALanguage(code) ? code : undefined;
70
67
  }
71
68
 
72
- // Main language for the resource: in the first f041 $a or f041 $d
73
- // Should we get all $a or $d languages instead of just the first?
74
69
  // Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes
75
70
 
76
71
  function get041Values() {
@@ -80,22 +75,67 @@ var _default = () => ({
80
75
  subfields
81
76
  }) => subfields).flat().filter(({
82
77
  code
83
- }) => code === 'a' || code === 'd').map(({
78
+ }) => code === 'a' || code === 'd').filter(({
79
+ value
80
+ }) => value && isLangCodeForALanguage(value)).map(({
84
81
  value
85
82
  }) => value);
86
83
  }
84
+
85
+ // Check if a string is a possible, validly formed language code for a single language
86
+ // Currently accept also codes in capitals
87
+ function isLangCodeForALanguage(code) {
88
+ if (code.length !== 3) {
89
+ debugData(`Code ${code} is not correct length (3) for a language code.`);
90
+ return false;
91
+ }
92
+ if (code === '|||' || code === ' ' || code === '^^^' || code === 'mul' || code === 'zxx') {
93
+ debugData(`Code ${code} is not code for a spesific language.`);
94
+ return false;
95
+ }
96
+ const langCodePattern = /^[a-z][a-z][a-z]$/ui;
97
+ if (!langCodePattern.test(code)) {
98
+ debugData(`Code ${code} is not valid as a language code`);
99
+ return false;
100
+ }
101
+ return true;
102
+ }
87
103
  },
104
+ // eslint-disable-next-line max-statements
88
105
  compare: (a, b) => {
89
- debugData(`Comparing ${JSON.stringify(a[0])} and ${JSON.stringify(b[0])}`);
106
+ debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);
90
107
  if (a.length === 0 || b.length === 0) {
91
108
  debugData(`No language to compare`);
92
109
  return 0;
93
110
  }
94
- debugData(`There are languages to compare`);
95
- if (a[0] === b[0]) {
111
+ if (a.length === b.length && a.every((element, index) => element === b[index])) {
112
+ debugData(`All languages match`);
96
113
  return 0.1;
97
114
  }
98
- return a[0] === 'und' || b[0] === 'und' ? 0.0 : -1.0;
115
+ const {
116
+ matchingValues,
117
+ possibleMatchValues,
118
+ maxValues
119
+ } = (0, _matchingUtils.getMatchCounts)(a, b);
120
+ if (matchingValues < 1) {
121
+ debug(`Both have languages, but none of these match.`);
122
+ return -1.0;
123
+ }
124
+ debug(`Both have languages, ${matchingValues}/${possibleMatchValues} valid languages match.`);
125
+ // ignore non-matches if there is mismatching amount of values
126
+ debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);
127
+ //we give some kind of penalty for mismatching amount of values instead of simple divide?
128
+ const missingCount = maxValues - possibleMatchValues;
129
+ const misMatchCount = possibleMatchValues - matchingValues;
130
+ debug(`\t missing: ${missingCount}`);
131
+ debug(`\t mismatches: ${misMatchCount}`);
132
+ const penaltyForMissing = 0.02 * (maxValues - possibleMatchValues);
133
+ const penaltyForMisMatch = 0.05 * (possibleMatchValues - matchingValues);
134
+ debug(`\t points: penaltyForMissing: ${penaltyForMissing}`);
135
+ debug(`\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);
136
+ const points = Number(Number(0.1 - penaltyForMisMatch - penaltyForMissing).toFixed(2));
137
+ debug(`Total points: ${points}`);
138
+ return points;
99
139
  }
100
140
  });
101
141
  exports.default = _default;
@@ -1 +1 @@
1
- {"version":3,"file":"language.js","names":["debug","createDebugLogger","debugData","extend","name","extract","record","recordExternal","label","value008","get008Value","values041","get041Values","JSON","stringify","length","correspondingValue","find","v","value","get","undefined","code","slice","filter","ind2","map","subfields","flat","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/language.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:language');\nconst debugData = debug.extend('data');\n\nexport default () => ({\n name: 'Language',\n extract: ({record, recordExternal}) => {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n\n const value008 = get008Value();\n const values041 = get041Values();\n debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);\n\n if (value008 && values041.length > 0) {\n debugData(`${label} There's both 008 and 041, searching for value in both`);\n const correspondingValue = values041.find(v => v === value008);\n debugData(`${label} Corresponding value: ${correspondingValue}`);\n return correspondingValue ? [correspondingValue] : [];\n }\n\n if (!value008 && values041.length < 1) {\n debugData(`{$label} No actual values found`);\n return [];\n }\n\n return value008 ? [value008] : [values041[0]];\n\n function get008Value() {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n debugData(`${label} 008 value: ${value}`);\n\n if (!value) {\n return undefined;\n }\n\n const code = value.slice(35, 38);\n debugData(`${label} 008 code: ${code}`);\n return code === '|||' || code === ' ' || code === '^^^' ? undefined : code;\n }\n\n // Main language for the resource: in the first f041 $a or f041 $d\n // Should we get all $a or $d languages instead of just the first?\n // Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes\n\n function get041Values() {\n return record.get(/^041$/u)\n .filter(({ind2}) => ind2 === ' ')\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'a' || code === 'd')\n .map(({value}) => value);\n }\n },\n compare: (a, b) => {\n debugData(`Comparing ${JSON.stringify(a[0])} and ${JSON.stringify(b[0])}`);\n\n if (a.length === 0 || b.length === 0) {\n debugData(`No language to compare`);\n return 0;\n }\n\n debugData(`There are languages to compare`);\n\n if (a[0] === b[0]) {\n return 0.1;\n }\n\n return a[0] === 'und' || b[0] === 'und' ? 0.0 : -1.0;\n }\n});\n"],"mappings":";;;;;;AA4BA;AAAsC;AA5BtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,MAAMA,KAAK,GAAG,IAAAC,cAAiB,EAAC,qEAAqE,CAAC;AACtG,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;AAAC,eAExB,OAAO;EACpBC,IAAI,EAAE,UAAU;EAChBC,OAAO,EAAE,CAAC;IAACC,MAAM;IAAEC;EAAc,CAAC,KAAK;IACrC,MAAMC,KAAK,GAAGD,cAAc,IAAIA,cAAc,CAACC,KAAK,GAAGD,cAAc,CAACC,KAAK,GAAG,QAA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AAK,IAAIA,IAAI,KAAK,KAAK,GAAGD,SAAS,GAAGC,IAAI;IAC9E;;IAEA;IACA;IACA;;IAEA,SAASV,YAAY,GAAG;MACtB,OAAON,MAAM,CAACc,GAAG,CAAC,QAAQ,CAAC,CACxBI,MAAM,CAAC,CAAC;QAACC;MAAI,CAAC,KAAKA,IAAI,KAAK,GAAG,CAAC,CAChCC,GAAG,CAAC,CAAC;QAACC;MAAS,CAAC,KAAKA,SAAS,CAAC,CAC/BC,IAAI,EAAE,CACNJ,MAAM,CAAC,CAAC;QAACF;MAAI,CAAC,KAAKA,IAAI,KAAK,GAAG,IAAIA,IAAI,KAAK,GAAG,CAAC,CAChDI,GAAG,CAAC,CAAC;QAACP;MAAK,CAAC,KAAKA,KAAK,CAAC;IAC5B;EACF,CAAC;EACDU,OAAO,EAAE,CAACC,CAAC,EAAEC,CAAC,KAAK;IACjB7B,SAAS,CAAE,aAAYW,IAAI,CAACC,SAAS,CAACgB,CAAC,CAAC,CAAC,CAAC,CAAE,QAAOjB,IAAI,CAACC,SAAS,CAACiB,CAAC,CAAC,CAAC,CAAC,CAAE,EAAC,CAAC;IAE1E,IAAID,CAAC,CAACf,MAAM,KAAK,CAAC,IAAIgB,CAAC,CAAChB,MAAM,KAAK,CAAC,EAAE;MACpCb,SAAS,CAAE,wBAAuB,CAAC;MACnC,OAAO,CAAC;IACV;IAEAA,SAAS,CAAE,gCAA+B,CAAC;IAE3C,IAAI4B,CAAC,CAAC,CAAC,CAAC,KAAKC,CAAC,CAAC,CAAC,CAAC,EAAE;MACjB,OAAO,GAAG;IACZ;IAEA,OAAOD,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,IAAIC,CAAC,CAAC,CAAC,CAAC,KAAK,KAAK,GAAG,GAAG,GAAG,CAAC,GAAG;EACtD;AACF,CAAC,CAAC;AAAA"}
1
+ {"version":3,"file":"language.js","names":["debug","createDebugLogger","debugData","extend","name","extract","record","recordExternal","label","value008","get008Value","values041","get041Values","JSON","stringify","length","allValues","undefined","concat","uniqueSortedValues","Set","sort","value","get","code","slice","isLangCodeForALanguage","filter","ind2","map","subfields","flat","langCodePattern","test","compare","a","b","every","element","index","matchingValues","possibleMatchValues","maxValues","getMatchCounts","missingCount","misMatchCount","penaltyForMissing","penaltyForMisMatch","points","Number","toFixed"],"sources":["../../../../src/match-detection/features/bib/language.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\nimport {getMatchCounts} from '../../../matching-utils';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:language');\nconst debugData = debug.extend('data');\n\nexport default () => ({\n name: 'Language',\n extract: ({record, recordExternal}) => {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n\n const value008 = get008Value();\n const values041 = get041Values();\n debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);\n\n if (!value008 && values041.length < 1) {\n debugData(`{$label} No actual values found`);\n return [];\n }\n\n const allValues = value008 === undefined ? values041 : values041.concat(value008);\n const uniqueSortedValues = [...new Set(allValues)].sort();\n\n return uniqueSortedValues;\n\n function get008Value() {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n debugData(`${label} 008 value: ${value}`);\n\n if (!value) {\n return undefined;\n }\n\n const code = value.slice(35, 38);\n debugData(`${label} 008 code: ${code}`);\n return isLangCodeForALanguage(code) ? code : undefined;\n }\n\n // Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes\n\n function get041Values() {\n return record.get(/^041$/u)\n .filter(({ind2}) => ind2 === ' ')\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'a' || code === 'd')\n .filter(({value}) => value && isLangCodeForALanguage(value))\n .map(({value}) => value);\n }\n\n // Check if a string is a possible, validly formed language code for a single language\n // Currently accept also codes in capitals\n function isLangCodeForALanguage(code) {\n if (code.length !== 3) {\n debugData(`Code ${code} is not correct length (3) for a language code.`);\n return false;\n }\n if (code === '|||' || code === ' ' || code === '^^^' || code === 'mul' || code === 'zxx') {\n debugData(`Code ${code} is not code for a spesific language.`);\n return false;\n }\n const langCodePattern = /^[a-z][a-z][a-z]$/ui;\n if (!langCodePattern.test(code)) {\n debugData(`Code ${code} is not valid as a language code`);\n return false;\n }\n return true;\n }\n\n },\n // eslint-disable-next-line max-statements\n compare: (a, b) => {\n debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);\n\n if (a.length === 0 || b.length === 0) {\n debugData(`No language to compare`);\n return 0;\n }\n\n if (a.length === b.length && a.every((element, index) => element === b[index])) {\n debugData(`All languages match`);\n return 0.1;\n }\n\n const {matchingValues, possibleMatchValues, maxValues} = getMatchCounts(a, b);\n\n if (matchingValues < 1) {\n debug(`Both have languages, but none of these match.`);\n return -1.0;\n }\n debug(`Both have languages, ${matchingValues}/${possibleMatchValues} valid languages match.`);\n // ignore non-matches if there is mismatching amount of values\n debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);\n //we give some kind of penalty for mismatching amount of values instead of simple divide?\n const missingCount = maxValues - possibleMatchValues;\n const misMatchCount = possibleMatchValues - matchingValues;\n debug(`\\t missing: ${missingCount}`);\n debug(`\\t mismatches: ${misMatchCount}`);\n\n const penaltyForMissing = 0.02 * (maxValues - possibleMatchValues);\n const penaltyForMisMatch = 0.05 * (possibleMatchValues - matchingValues);\n debug(`\\t points: penaltyForMissing: ${penaltyForMissing}`);\n debug(`\\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);\n\n const points = Number(Number(0.1 - penaltyForMisMatch - penaltyForMissing).toFixed(2));\n debug(`Total points: ${points}`);\n\n return points;\n }\n});\n"],"mappings":";;;;;;AA4BA;AACA;AAAuD;AA7BvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAKA,MAAMA,KAAK,GAAG,IAAAC,cAAiB,EAAC,qEAAqE,CAAC;AACtG,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;AAAC,eAExB,OAAO;EACpBC,IAAI,EAAE,UAAU;EAChBC,OAAO,EAAE,CAAC;IAACC,MAAM;IAAEC;EAAc,CAAC,KAAK;IACrC,MAAMC,KAAK,GAAGD,cAAc,IAAIA,cAAc,CAACC,KAAK,GAAGD,cAAc,CAACC,KAAK,GAAG,QAAQ;IAEtF,MAAMC,QAAQ,GAAGC,WAAW,EAAE;IAC9B,MAAMC,SAAS,GAAGC,YAAY,EAAE;IAChCV,SAAS,CAAE,GAAEM,KAAM,SAAQK,IAAI,CAACC,SAAS,CAACL,QAAQ,CAAE,UAASI,IAAI,CAACC,SAAS,CAACH,SAAS,CAAE,EAAC,CAAC;IAEzF,IAAI,CAACF,QAAQ,IAAIE,SAAS,CAACI,MAAM,GAAG,CAAC,EAAE;MACrCb,SAAS,CAAE,iCAAgC,CAAC;MAC5C,OAAO,EAAE;IACX;IAEA,MAAMc,SAAS,GAAGP,QAAQ,KAAKQ,SAAS,GAAGN,SAAS,GAAGA,SAAS,CAACO,MAAM,CAACT,QAAQ,CAAC;IACjF,MAAMU,kBAAkB,GAAG,CAAC,GAAG,IAA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AGC,mBAAoB,yBAAwB,CAAC;IAC7F;IACAzC,KAAK,CAAE,qBAAoByC,mBAAoB,IAAGC,SAAU,EAAC,CAAC;IAC9D;IACA,MAAME,YAAY,GAAGF,SAAS,GAAGD,mBAAmB;IACpD,MAAMI,aAAa,GAAGJ,mBAAmB,GAAGD,cAAc;IAC1DxC,KAAK,CAAE,eAAc4C,YAAa,EAAC,CAAC;IACpC5C,KAAK,CAAE,kBAAiB6C,aAAc,EAAC,CAAC;IAExC,MAAMC,iBAAiB,GAAG,IAAI,IAAIJ,SAAS,GAAGD,mBAAmB,CAAC;IAClE,MAAMM,kBAAkB,GAAG,IAAI,IAAIN,mBAAmB,GAAGD,cAAc,CAAC;IACxExC,KAAK,CAAE,iCAAgC8C,iBAAkB,EAAC,CAAC;IAC3D9C,KAAK,CAAE,kCAAiC+C,kBAAmB,EAAC,CAAC;IAE7D,MAAMC,MAAM,GAAGC,MAAM,CAACA,MAAM,CAAC,GAAG,GAAGF,kBAAkB,GAAGD,iBAAiB,CAAC,CAACI,OAAO,CAAC,CAAC,CAAC,CAAC;IACtFlD,KAAK,CAAE,iBAAgBgD,MAAO,EAAC,CAAC;IAEhC,OAAOA,MAAM;EACf;AACF,CAAC,CAAC;AAAA"}
@@ -0,0 +1,227 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _matchingUtils = require("../../../matching-utils");
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ /**
11
+ *
12
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
13
+ *
14
+ * Melinda record matching modules for Javascript
15
+ *
16
+ * Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
17
+ *
18
+ * This file is part of melinda-record-matching-js
19
+ *
20
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
21
+ * it under the terms of the GNU Lesser General Public License as
22
+ * published by the Free Software Foundation, either version 3 of the
23
+ * License, or (at your option) any later version.
24
+ *
25
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
26
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
+ * GNU Lesser General Public License for more details.
29
+ *
30
+ * You should have received a copy of the GNU Affero General Public License
31
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
32
+ *
33
+ * @licend The above is the entire license notice
34
+ * for the JavaScript code in this file.
35
+ *
36
+ */
37
+ // We should also get copyright time and copyright/publication times from 26x
38
+ // We should also get publishing time type from f008
39
+ // We should get reprint times from f500 $a "Lisäpainos/Lisäpainokset:"
40
+ var _default = () => ({
41
+ name: 'Publication time, allow consequent years, years from multiple sources',
42
+ extract: ({
43
+ record
44
+ }) => {
45
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');
46
+ const f008Values = extractF008Values(record);
47
+ debug(`${JSON.stringify(f008Values)}`);
48
+ const f26xValues = extractF26xValues(record);
49
+ debug(`${JSON.stringify(f26xValues)}`);
50
+ const f500Values = extractF500Years(record);
51
+ debug(`${JSON.stringify(f500Values)}`);
52
+
53
+ // We should get copyrightYear from f008Date2 to copyrightYears when f008YearType = 'r'
54
+ // Is the original year (f008Date2) in f008YearType === 'r' comparable to copyrightYear?
55
+ // We should handle unknown years (here or comparison?)
56
+ // We should handle year ranges for continuing resources / collections
57
+ // We should normalize copyright marks (etc.) out of copyrightYears
58
+
59
+ const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => value && value !== ' '))].sort();
60
+ const copyrightYears = [...new Set(f26xValues.copyrightYears)].sort();
61
+ const reprintYears = [...new Set(f500Values)].sort();
62
+ const combined = {
63
+ normalYears,
64
+ copyrightYears,
65
+ reprintYears
66
+ };
67
+ debug(`Combined: ${JSON.stringify(combined)}`);
68
+ return combined;
69
+ function extractF008Values(record) {
70
+ var _record$get, _record$get$;
71
+ const value = ((_record$get = record.get(/^008$/u)) === null || _record$get === void 0 ? void 0 : (_record$get$ = _record$get[0]) === null || _record$get$ === void 0 ? void 0 : _record$get$.value) || undefined;
72
+ if (value && (0, _matchingUtils.testStringOrNumber)(value)) {
73
+ const f008Date1 = extractF008Date1(value);
74
+ const f008Date2 = extractF008Date2(value);
75
+ const f008YearType = extractF008YearType(value);
76
+ return {
77
+ f008Date1,
78
+ f008Date2,
79
+ f008YearType
80
+ };
81
+ }
82
+ return {
83
+ f008Date1: undefined,
84
+ f008Date2: undefined,
85
+ f008YearType: undefined
86
+ };
87
+ }
88
+ function extractF008Date1(value) {
89
+ return String(value).slice(7, 11);
90
+ }
91
+ function extractF008Date2(value) {
92
+ return String(value).slice(11, 15);
93
+ }
94
+ function extractF008YearType(value) {
95
+ return String(value).slice(6, 7);
96
+ }
97
+ function extractF26xValues(record) {
98
+ const copyrightRegex = /^(?<copyrightPrefix>cop|cop.|c|©|p|℗)/u;
99
+ const pubNormalSubFieldValues = record.get(/^26[04]$/u).filter(field => !(field.tag === '264' && field.ind2 === '4')).map(({
100
+ subfields
101
+ }) => subfields).flat().filter(({
102
+ code
103
+ }) => code === 'c').map(({
104
+ value
105
+ }) => value).filter(({
106
+ value
107
+ }) => !copyrightRegex.test(value));
108
+ debug(`Normal years: ${JSON.stringify(pubNormalSubFieldValues)}`);
109
+ const pubF264CopySubFieldValues = record.get(/^264$/u).filter(field => field.ind2 === '4').map(({
110
+ subfields
111
+ }) => subfields).flat().filter(({
112
+ code
113
+ }) => code === 'c').map(({
114
+ value
115
+ }) => value);
116
+ debug(`F264 copyright years: ${JSON.stringify(pubF264CopySubFieldValues)}`);
117
+ const pubF260CopySubFieldValues = record.get(/^260$/u).map(({
118
+ subfields
119
+ }) => subfields).flat().filter(({
120
+ code
121
+ }) => code === 'c').filter(({
122
+ value
123
+ }) => copyrightRegex.test(value));
124
+ debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);
125
+ return {
126
+ normalYears: pubNormalSubFieldValues,
127
+ copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues]
128
+ };
129
+ }
130
+ function extractF500Years(record) {
131
+ const reprintRegex = /(?<reprint>Lisäpainokset:|Lisäpainos:)/u;
132
+ const reprintFieldContents = record.get(/^500$/u).map(({
133
+ subfields
134
+ }) => subfields).flat().filter(({
135
+ code
136
+ }) => code === 'a').map(({
137
+ value
138
+ }) => value);
139
+ //.filter(value => value.test(reprintRegex));
140
+
141
+ debug(`f500 reprint field contents: ${JSON.stringify(reprintFieldContents)}`);
142
+ const filteredF500 = reprintFieldContents.filter(content => content && content.match(reprintRegex));
143
+ debug(`f500 reprint field contents (filtered): ${JSON.stringify(filteredF500)}`);
144
+ const reprintYears = extractReprintYears(filteredF500);
145
+ return reprintYears;
146
+ }
147
+ function extractReprintYears(contents) {
148
+ const yearRegex = /[0-9][0-9][0-9][0-9]/gu;
149
+ const years = contents.map(content => content.match(yearRegex)).flat();
150
+ debug(`${JSON.stringify(years)}`);
151
+ const uniqYears = [...new Set(years)].sort();
152
+ debug(`${JSON.stringify(uniqYears)}`);
153
+ return uniqYears;
154
+ }
155
+ },
156
+ // eslint-disable-next-line max-statements
157
+ compare: (a, b) => {
158
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');
159
+ debug(`Comparing ${JSON.stringify(a)} to ${JSON.stringify(b)}`);
160
+ const [firstA] = a.normalYears ? a.normalYears : a;
161
+ const [firstB] = b.normalYears ? b.normalYears : b;
162
+ debug(`Comparing ${JSON.stringify(firstA)} to ${JSON.stringify(firstB)}`);
163
+ if (firstA === firstB) {
164
+ return 0.1;
165
+ }
166
+
167
+ // If either of years is a non string/number, values are not comparable
168
+ if (!(0, _matchingUtils.testStringOrNumber)(firstA) || !(0, _matchingUtils.testStringOrNumber)(firstB)) {
169
+ return 0;
170
+ }
171
+ const firstANumber = parseInt(firstA, 10);
172
+ const firstBNumber = parseInt(firstB, 10);
173
+ if (isNaN(firstANumber) || isNaN(firstBNumber)) {
174
+ return -1;
175
+ }
176
+
177
+ // Handle consequent years as a match
178
+ // see publication-time for a version that does not handle consequent years as a match
179
+ if (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber) {
180
+ return 0.1;
181
+ }
182
+ const bNormalInAReprint = a.reprintYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));
183
+ const aNormalInBReprint = b.reprintYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));
184
+ debug(`BNorm in AReprint: ${JSON.stringify(bNormalInAReprint)}`);
185
+ debug(`ANorm in BReprint: ${JSON.stringify(aNormalInBReprint)}`);
186
+ if (bNormalInAReprint > 0 || aNormalInBReprint > 0) {
187
+ return 0;
188
+ }
189
+ return -1;
190
+ }
191
+ }); // https://www.loc.gov/marc/bibliographic/bd008.html
192
+ // field 008
193
+ // 06 - Type of date/Publication status
194
+ // 07-10 - Date 1
195
+ // 11-14 - Date 2
196
+ //
197
+ // 06 - Type of date/Publication status
198
+ // b - No dates given; B.C. date involved
199
+ // c - Continuing resource currently published
200
+ // d - Continuing resource ceased publication
201
+ // e - Detailed date
202
+ // i - Inclusive dates of collection
203
+ // k - Range of years of bulk of collection
204
+ // m - Multiple dates
205
+ // n - Dates unknown
206
+ // p - Date of distribution/release/issue and production/recording session when different
207
+ // q - Questionable date
208
+ // r - Reprint/reissue date and original date
209
+ // s - Single known date/probable date
210
+ // t - Publication date and copyright date
211
+ // u - Continuing resource status unknown
212
+ // | - No attempt to code
213
+ //
214
+ // 07-10 - Date 1
215
+ // 1-9 - Date digit
216
+ // # - Date element is not applicable
217
+ // u - Date element is totally or partially unknown
218
+ // |||| - No attempt to code
219
+ //
220
+ // 11-14 - Date 2
221
+ // 1-9 - Date digit
222
+ // # - Date element is not applicable
223
+ // u - Date element is totally or partially unknown
224
+ // |||| - No attempt to code
225
+ //
226
+ exports.default = _default;
227
+ //# sourceMappingURL=publication-time-allow-cons-years-multi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publication-time-allow-cons-years-multi.js","names":["name","extract","record","debug","createDebugLogger","f008Values","extractF008Values","JSON","stringify","f26xValues","extractF26xValues","f500Values","extractF500Years","normalYears","Set","concat","f008Date1","filter","value","sort","copyrightYears","reprintYears","combined","get","undefined","testStringOrNumber","extractF008Date1","f008Date2","extractF008Date2","f008YearType","extractF008YearType","String","slice","copyrightRegex","pubNormalSubFieldValues","field","tag","ind2","map","subfields","flat","code","test","pubF264CopySubFieldValues","pubF260CopySubFieldValues","reprintRegex","reprintFieldContents","filteredF500","content","match","extractReprintYears","contents","yearRegex","years","uniqYears","compare","a","b","firstA","firstB","firstANumber","parseInt","firstBNumber","isNaN","bNormalInAReprint","aValue","some","bValue","aNormalInBReprint"],"sources":["../../../../src/match-detection/features/bib/publication-time-allow-cons-years-multi.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {testStringOrNumber} from '../../../matching-utils';\nimport createDebugLogger from 'debug';\n\n// We should also get copyright time and copyright/publication times from 26x\n// We should also get publishing time type from f008\n// We should get reprint times from f500 $a \"Lisäpainos/Lisäpainokset:\"\n\nexport default () => ({\n name: 'Publication time, allow consequent years, years from multiple sources',\n extract: ({record}) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');\n\n const f008Values = extractF008Values(record);\n debug(`${JSON.stringify(f008Values)}`);\n\n const f26xValues = extractF26xValues(record);\n debug(`${JSON.stringify(f26xValues)}`);\n\n const f500Values = extractF500Years(record);\n debug(`${JSON.stringify(f500Values)}`);\n\n // We should get copyrightYear from f008Date2 to copyrightYears when f008YearType = 'r'\n // Is the original year (f008Date2) in f008YearType === 'r' comparable to copyrightYear?\n // We should handle unknown years (here or comparison?)\n // We should handle year ranges for continuing resources / collections\n // We should normalize copyright marks (etc.) out of copyrightYears\n\n const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => value && value !== ' '))].sort();\n const copyrightYears = [...new Set(f26xValues.copyrightYears)].sort();\n const reprintYears = [...new Set(f500Values)].sort();\n\n const combined = {normalYears, copyrightYears, reprintYears};\n\n debug(`Combined: ${JSON.stringify(combined)}`);\n\n return combined;\n\n function extractF008Values(record) {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n if (value && testStringOrNumber(value)) {\n const f008Date1 = extractF008Date1(value);\n const f008Date2 = extractF008Date2(value);\n const f008YearType = extractF008YearType(value);\n return {f008Date1, f008Date2, f008YearType};\n }\n return {f008Date1: undefined, f008Date2: undefined, f008YearType: undefined};\n }\n\n function extractF008Date1(value) {\n return String(value).slice(7, 11);\n }\n\n function extractF008Date2(value) {\n return String(value).slice(11, 15);\n }\n\n function extractF008YearType(value) {\n return String(value).slice(6, 7);\n }\n\n function extractF26xValues(record) {\n const copyrightRegex = /^(?<copyrightPrefix>cop|cop.|c|©|p|℗)/u;\n\n const pubNormalSubFieldValues = record.get(/^26[04]$/u)\n .filter((field) => !(field.tag === '264' && field.ind2 === '4'))\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'c')\n .map(({value}) => value)\n .filter(({value}) => !copyrightRegex.test(value));\n\n debug(`Normal years: ${JSON.stringify(pubNormalSubFieldValues)}`);\n\n const pubF264CopySubFieldValues = record.get(/^264$/u)\n .filter((field) => field.ind2 === '4')\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'c')\n .map(({value}) => value);\n debug(`F264 copyright years: ${JSON.stringify(pubF264CopySubFieldValues)}`);\n\n const pubF260CopySubFieldValues = record.get(/^260$/u)\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'c')\n .filter(({value}) => copyrightRegex.test(value));\n debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);\n\n return {normalYears: pubNormalSubFieldValues, copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues]};\n }\n\n function extractF500Years(record) {\n\n const reprintRegex = /(?<reprint>Lisäpainokset:|Lisäpainos:)/u;\n const reprintFieldContents = record.get(/^500$/u)\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'a')\n .map(({value}) => value);\n //.filter(value => value.test(reprintRegex));\n\n debug(`f500 reprint field contents: ${JSON.stringify(reprintFieldContents)}`);\n\n const filteredF500 = reprintFieldContents.filter((content) => content && content.match(reprintRegex));\n\n debug(`f500 reprint field contents (filtered): ${JSON.stringify(filteredF500)}`);\n\n const reprintYears = extractReprintYears(filteredF500);\n\n return reprintYears;\n }\n\n function extractReprintYears(contents) {\n const yearRegex = /[0-9][0-9][0-9][0-9]/gu;\n const years = contents.map(content => content.match(yearRegex))\n .flat();\n debug(`${JSON.stringify(years)}`);\n const uniqYears = [...new Set(years)].sort();\n debug(`${JSON.stringify(uniqYears)}`);\n return uniqYears;\n }\n\n },\n // eslint-disable-next-line max-statements\n compare: (a, b) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');\n debug(`Comparing ${JSON.stringify(a)} to ${JSON.stringify(b)}`);\n\n const [firstA] = a.normalYears ? a.normalYears : a;\n const [firstB] = b.normalYears ? b.normalYears : b;\n\n debug(`Comparing ${JSON.stringify(firstA)} to ${JSON.stringify(firstB)}`);\n\n if (firstA === firstB) {\n return 0.1;\n }\n\n // If either of years is a non string/number, values are not comparable\n if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {\n return 0;\n }\n\n const firstANumber = parseInt(firstA, 10);\n const firstBNumber = parseInt(firstB, 10);\n\n if (isNaN(firstANumber) || isNaN(firstBNumber)) {\n return -1;\n }\n\n // Handle consequent years as a match\n // see publication-time for a version that does not handle consequent years as a match\n if (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber) {\n return 0.1;\n }\n\n const bNormalInAReprint = a.reprintYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));\n const aNormalInBReprint = b.reprintYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));\n debug(`BNorm in AReprint: ${JSON.stringify(bNormalInAReprint)}`);\n debug(`ANorm in BReprint: ${JSON.stringify(aNormalInBReprint)}`);\n\n if (bNormalInAReprint > 0 || aNormalInBReprint > 0) {\n return 0;\n }\n\n return -1;\n\n }\n});\n\n// https://www.loc.gov/marc/bibliographic/bd008.html\n// field 008\n// 06 - Type of date/Publication status\n// 07-10 - Date 1\n// 11-14 - Date 2\n//\n// 06 - Type of date/Publication status\n// b - No dates given; B.C. date involved\n// c - Continuing resource currently published\n// d - Continuing resource ceased publication\n// e - Detailed date\n// i - Inclusive dates of collection\n// k - Range of years of bulk of collection\n// m - Multiple dates\n// n - Dates unknown\n// p - Date of distribution/release/issue and production/recording session when different\n// q - Questionable date\n// r - Reprint/reissue date and original date\n// s - Single known date/probable date\n// t - Publication date and copyright date\n// u - Continuing resource status unknown\n// | - No attempt to code\n//\n// 07-10 - Date 1\n// 1-9 - Date digit\n// # - Date element is not applicable\n// u - Date element is totally or partially unknown\n// |||| - No attempt to code\n//\n// 11-14 - Date 2\n// 1-9 - Date digit\n// # - Date element is not applicable\n// u - Date element is totally or partially unknown\n// |||| - No attempt to code\n//\n\n"],"mappings":";;;;;;AA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AC;IACX;;IAEA;IACA;IACA,IAAIF,YAAY,GAAG,CAAC,KAAKE,YAAY,IAAIF,YAAY,GAAG,CAAC,KAAKE,YAAY,EAAE;MAC1E,OAAO,GAAG;IACZ;IAEA,MAAME,iBAAiB,GAAGR,CAAC,CAACnC,YAAY,CAACJ,MAAM,CAACgD,MAAM,IAAIR,CAAC,CAAC5C,WAAW,CAACqD,IAAI,CAACC,MAAM,IAAIF,MAAM,KAAKE,MAAM,CAAC,CAAC;IAC1G,MAAMC,iBAAiB,GAAGX,CAAC,CAACpC,YAAY,CAACJ,MAAM,CAACkD,MAAM,IAAIX,CAAC,CAAC3C,WAAW,CAACqD,IAAI,CAACD,MAAM,IAAIE,MAAM,KAAKF,MAAM,CAAC,CAAC;IAC1G9D,KAAK,CAAE,sBAAqBI,IAAI,CAACC,SAAS,CAACwD,iBAAiB,CAAE,EAAC,CAAC;IAChE7D,KAAK,CAAE,sBAAqBI,IAAI,CAACC,SAAS,CAAC4D,iBAAiB,CAAE,EAAC,CAAC;IAEhE,IAAIJ,iBAAiB,GAAG,CAAC,IAAII,iBAAiB,GAAG,CAAC,EAAE;MAClD,OAAO,CAAC;IACV;IAEA,OAAO,CAAC,CAAC;EAEX;AACF,CAAC,CAAC,EAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAAA"}
@@ -0,0 +1,72 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _matchingUtils = require("../../../matching-utils");
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
10
+ /**
11
+ *
12
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
13
+ *
14
+ * Melinda record matching modules for Javascript
15
+ *
16
+ * Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
17
+ *
18
+ * This file is part of melinda-record-matching-js
19
+ *
20
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
21
+ * it under the terms of the GNU Lesser General Public License as
22
+ * published by the Free Software Foundation, either version 3 of the
23
+ * License, or (at your option) any later version.
24
+ *
25
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
26
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
27
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28
+ * GNU Lesser General Public License for more details.
29
+ *
30
+ * You should have received a copy of the GNU Affero General Public License
31
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
32
+ *
33
+ * @licend The above is the entire license notice
34
+ * for the JavaScript code in this file.
35
+ *
36
+ */
37
+ // We should also get copyright time and copyright/publication times from 26x
38
+ var _default = () => ({
39
+ name: 'Publication time, allow consequent years',
40
+ extract: ({
41
+ record
42
+ }) => {
43
+ var _record$get, _record$get$;
44
+ const value = ((_record$get = record.get(/^008$/u)) === null || _record$get === void 0 ? void 0 : (_record$get$ = _record$get[0]) === null || _record$get$ === void 0 ? void 0 : _record$get$.value) || undefined;
45
+ return (0, _matchingUtils.testStringOrNumber)(value) ? [String(value).slice(7, 11)] : [];
46
+ },
47
+ compare: (a, b) => {
48
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years');
49
+ debug(`Comparing ${a[0]} to ${b[0]}`);
50
+ const [firstA] = a;
51
+ const [firstB] = b;
52
+ if (firstA === firstB) {
53
+ return 0.1;
54
+ }
55
+
56
+ // If either of years is a non string/number, values are not comparable
57
+ if (!(0, _matchingUtils.testStringOrNumber)(firstA) || !(0, _matchingUtils.testStringOrNumber)(firstB)) {
58
+ return 0;
59
+ }
60
+ const firstANumber = parseInt(firstA, 10);
61
+ const firstBNumber = parseInt(firstB, 10);
62
+ if (isNaN(firstANumber) || isNaN(firstBNumber)) {
63
+ return -1;
64
+ }
65
+
66
+ // Handle consequent years as a match
67
+ // see publication-time for a version that does not handle consequent years as a match
68
+ return firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber ? 0.1 : -1;
69
+ }
70
+ });
71
+ exports.default = _default;
72
+ //# sourceMappingURL=publication-time-allow-cons-years.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"publication-time-allow-cons-years.js","names":["name","extract","record","value","get","undefined","testStringOrNumber","String","slice","compare","a","b","debug","createDebugLogger","firstA","firstB","firstANumber","parseInt","firstBNumber","isNaN"],"sources":["../../../../src/match-detection/features/bib/publication-time-allow-cons-years.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {testStringOrNumber} from '../../../matching-utils';\nimport createDebugLogger from 'debug';\n\n// We should also get copyright time and copyright/publication times from 26x\n\nexport default () => ({\n name: 'Publication time, allow consequent years',\n extract: ({record}) => {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];\n },\n compare: (a, b) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years');\n debug(`Comparing ${a[0]} to ${b[0]}`);\n\n const [firstA] = a;\n const [firstB] = b;\n\n if (firstA === firstB) {\n return 0.1;\n }\n\n // If either of years is a non string/number, values are not comparable\n if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {\n return 0;\n }\n\n const firstANumber = parseInt(firstA, 10);\n const firstBNumber = parseInt(firstB, 10);\n\n if (isNaN(firstANumber) || isNaN(firstBNumber)) {\n return -1;\n }\n\n // Handle consequent years as a match\n // see publication-time for a version that does not handle consequent years as a match\n return firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber ? 0.1 : -1;\n }\n});\n"],"mappings":";;;;;;AA4BA;AACA;AAAsC;AA7BtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKA;AAAA,eAEe,OAAO;EACpBA,IAAI,EAAE,0CAA0C;EAChDC,OAAO,EAAE,CAAC;IAACC;EAAM,CAAC,KAAK;IAAA;IACrB,MAAMC,KAAK,GAAG,gBAAAD,MAAM,CAACE,GAAG,CAAC,QAAQ,CAAC,gEAApB,YAAuB,CAAC,CAAC,iDAAzB,aAA2BD,KAAK,KAAIE,SAAS;IAC3D,OAAO,IAAAC,iCAAkB,EAACH,KAAK,CAAC,GAAG,CAACI,MAAM,CAACJ,KAAK,CAAC,CAACK,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE;EACtE,CAAC;EACDC,OAAO,EAAE,CAACC,CAAC,EAAEC,CAAC,KAAK;IACjB,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,kGAAkG,CAAC;IACnID,KAAK,CAAE,aAAYF,CAAC,CAAC,CAAC,CAAE,OAAMC,CAAC,CAAC,CAAC,CAAE,EAAC,CAAC;IAErC,MAAM,CAACG,MAAM,CAAC,GAAGJ,CAAC;IAClB,MAAM,CAACK,MAAM,CAAC,GAAGJ,CAAC;IAElB,IAAIG,MAAM,KAAKC,MAAM,EAAE;MACrB,OAAO,GAAG;IACZ;;IAEA;IACA,IAAI,CAAC,IAAAT,iCAAkB,EAACQ,MAAM,CAAC,IAAI,CAAC,IAAAR,iCAAkB,EAACS,MAAM,CAAC,EAAE;MAC9D,OAAO,CAAC;IACV;IAEA,MAAMC,YAAY,GAAGC,QAAQ,CAACH,MAAM,EAAE,EAAE,CAAC;IACzC,MAAMI,YAAY,GAAGD,QAAQ,CAACF,MAAM,EAAE,EAAE,CAAC;IAEzC,IAAII,KAAK,CAACH,YAAY,CAAC,IAAIG,KAAK,CAACD,YAAY,CAAC,EAAE;MAC9C,OAAO,CAAC,CAAC;IACX;;IAEA;IACA;IACA,OAAOF,YAAY,GAAG,CAAC,KAAKE,YAAY,IAAIF,YAAY,GAAG,CAAC,KAAKE,YAAY,GAAG,GAAG,GAAG,CAAC,CAAC;EAC1F;AACF,CAAC,CAAC;AAAA"}
@@ -33,7 +33,7 @@ var _matchingUtils = require("../../../matching-utils");
33
33
  *
34
34
  */
35
35
  // We should also get copyright time and copyright/publication times from 26x
36
- // We could also enable matching of records which have consequent publication years
36
+ // see publication-time-allow-cons-years for a version allowing consequent years to match
37
37
  var _default = () => ({
38
38
  name: 'Publication time',
39
39
  extract: ({
@@ -1 +1 @@
1
- {"version":3,"file":"publication-time.js","names":["name","extract","record","value","get","undefined","testStringOrNumber","String","slice","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/publication-time.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {testStringOrNumber} from '../../../matching-utils';\n\n// We should also get copyright time and copyright/publication times from 26x\n// We could also enable matching of records which have consequent publication years\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(7, 11)] : [];\n },\n compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0\n});\n"],"mappings":";;;;;;AA4BA;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA;AACA;AAAA,eAEe,OAAO;EACpBA,IAAI,EAAE,kBAAkB;EACxBC,OAAO,EAAE,CAAC;IAACC;EAAM,CAAC,KAAK;IAAA;IACrB,MAAMC,KAAK,GAAG,gBAAAD,MAAM,CAACE,GAAG,CAAC,QAAQ,CAAC,gEAApB,YAAuB,CAAC,CAAC,iDAAzB,aAA2BD,KAAK,KAAIE,SAAS;IAC3D,OAAO,IAAAC,iCAAkB,EAACH,KAAK,CAAC,GAAG,CAACI,MAAM,CAACJ,KAAK,CAAC,CAACK,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE;EACtE,CAAC;EACDC,OAAO,EAAE,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAAC,CAAC,CAAC,KAAKC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;AAC5C,CAAC,CAAC;AAAA"}
1
+ {"version":3,"file":"publication-time.js","names":["name","extract","record","value","get","undefined","testStringOrNumber","String","slice","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/publication-time.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {testStringOrNumber} from '../../../matching-utils';\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(7, 11)] : [];\n },\n compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0\n});\n"],"mappings":";;;;;;AA4BA;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA;AACA;AAAA,eAEe,OAAO;EACpBA,IAAI,EAAE,kBAAkB;EACxBC,OAAO,EAAE,CAAC;IAACC;EAAM,CAAC,KAAK;IAAA;IACrB,MAAMC,KAAK,GAAG,gBAAAD,MAAM,CAACE,GAAG,CAAC,QAAQ,CAAC,gEAApB,YAAuB,CAAC,CAAC,iDAAzB,aAA2BD,KAAK,KAAIE,SAAS;IAC3D,OAAO,IAAAC,iCAAkB,EAACH,KAAK,CAAC,GAAG,CAACI,MAAM,CAACJ,KAAK,CAAC,CAACK,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,EAAE;EACtE,CAAC;EACDC,OAAO,EAAE,CAACC,CAAC,EAAEC,CAAC,KAAKD,CAAC,CAAC,CAAC,CAAC,KAAKC,CAAC,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;AAC5C,CAAC,CAAC;AAAA"}
@@ -4,6 +4,7 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.extractSubfieldsFromField = extractSubfieldsFromField;
7
+ exports.getMatchCounts = getMatchCounts;
7
8
  exports.getMelindaIdsF035 = getMelindaIdsF035;
8
9
  exports.getSubfieldValues = getSubfieldValues;
9
10
  exports.testStringOrNumber = testStringOrNumber;
@@ -116,4 +117,27 @@ function uniqueSubfields(subfields) {
116
117
  return arr;
117
118
  }, []);
118
119
  }
120
+ function getMatchCounts(aValues, bValues) {
121
+ const matchingValues = getMatchingValuesAmount(aValues, bValues);
122
+ return {
123
+ maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,
124
+ // possibleMatchingValues: amount of identifiers in set of less identifiers (we cannot more values than these)
125
+ possibleMatchValues: aValues.length > bValues.length ? bValues.length : aValues.length,
126
+ matchingValues
127
+ };
128
+ function getMatchingValuesAmount(aValues, bValues) {
129
+ if (bValues.length > aValues.length) {
130
+ return aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
131
+ }
132
+ if (aValues.length > bValues.length) {
133
+ return bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
134
+ }
135
+
136
+ // If we have same amount of values, we'll check matches both ways, to avoid mixups in cases
137
+ // there would be duplicate values
138
+ const aToB = aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
139
+ const bToA = bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
140
+ return aToB < bToA ? aToB : bToA;
141
+ }
142
+ }
119
143
  //# sourceMappingURL=matching-utils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"matching-utils.js","names":["debug","createDebugLogger","debugData","extend","getMelindaIdsF035","record","f035s","getFields","length","allF035MelindaIds","concat","map","toMelindaIds","f035MelindaIds","Set","JSON","stringify","subfields","melindaIdRegExp","filter","sub","includes","code","testStringOrNumber","value","test","String","replace","validateSidFieldSubfieldCounts","field","countC","countSubfields","countB","subfieldCode","getSubfieldValues","extractSubfieldsFromField","subfieldCodes","undefined","resultSubfields","uniqueSubfields","reduce","arr","e","find","item","newArr"],"sources":["../src/matching-utils.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');\nconst debugData = debug.extend('data');\n\nexport function getMelindaIdsF035(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:melinda-id');\n const debugData = debug.extend('data');\n\n const f035s = record.getFields('035');\n\n if (f035s.length < 1) {\n debug(`No f035s found.`);\n return [];\n }\n\n const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));\n const f035MelindaIds = [...new Set(allF035MelindaIds)];\n\n debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);\n debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);\n debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);\n\n return f035MelindaIds;\n\n function toMelindaIds({subfields}) {\n const melindaIdRegExp = /^(?<prefix>\\(FI-MELINDA\\)|FCC)(?<id>\\d{9})$/u;\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code))\n .filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))\n .map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');\n\n }\n}\n\nexport function validateSidFieldSubfieldCounts(field) {\n // Valid SID-fields have just one $c and one $b\n debugData(`Validating SID field ${JSON.stringify(field)}`);\n const countC = countSubfields(field, 'c');\n const countB = countSubfields(field, 'b');\n debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);\n\n return countC === 1 && countB === 1;\n}\n\nfunction countSubfields(field, subfieldCode) {\n // debug(`Counting subfields ${subfieldCode}`);\n return field.subfields.filter(({code}) => code === subfieldCode).length;\n}\n\nexport function getSubfieldValues(field, subfieldCode) {\n debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);\n return field.subfields\n .filter(({code}) => code === subfieldCode)\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value);\n}\n\nexport function testStringOrNumber(value) {\n if (typeof value === 'string' || typeof value === 'number') {\n return true;\n }\n return false;\n}\n\nexport function extractSubfieldsFromField(field, subfieldCodes) {\n if (field === undefined || field.subfields === undefined) {\n return [];\n }\n const resultSubfields = field.subfields\n .filter(({code}) => subfieldCodes.includes(code))\n .map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value) : ''}))\n .filter(value => value);\n return resultSubfields;\n}\n\nexport function uniqueSubfields(subfields) {\n return subfields.reduce((arr, e) => {\n if (!arr.find(item => item.code === e.code && item.value === e.value)) {\n const newArr = arr.concat(e);\n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,KAAKkB,CAAC,CAAClB,KAAK,CAAC,EAAE;MACrE,MAAMqB,MAAM,GAAGJ,GAAG,CAAC/B,MAAM,CAACgC,CAAC,CAAC;MAC5B,OAAOG,MAAM;IACf;IACA,OAAOJ,GAAG;EACZ,CAAC,EAAE,EAAE,CAAC;AACR"}
1
+ {"version":3,"file":"matching-utils.js","names":["debug","createDebugLogger","debugData","extend","getMelindaIdsF035","record","f035s","getFields","length","allF035MelindaIds","concat","map","toMelindaIds","f035MelindaIds","Set","JSON","stringify","subfields","melindaIdRegExp","filter","sub","includes","code","testStringOrNumber","value","test","String","replace","validateSidFieldSubfieldCounts","field","countC","countSubfields","countB","subfieldCode","getSubfieldValues","extractSubfieldsFromField","subfieldCodes","undefined","resultSubfields","uniqueSubfields","reduce","arr","e","find","item","newArr","getMatchCounts","aValues","bValues","matchingValues","getMatchingValuesAmount","maxValues","possibleMatchValues","aValue","some","bValue","aToB","bToA"],"sources":["../src/matching-utils.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');\nconst debugData = debug.extend('data');\n\nexport function getMelindaIdsF035(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:melinda-id');\n const debugData = debug.extend('data');\n\n const f035s = record.getFields('035');\n\n if (f035s.length < 1) {\n debug(`No f035s found.`);\n return [];\n }\n\n const allF035MelindaIds = [].concat(...f035s.map(toMelindaIds));\n const f035MelindaIds = [...new Set(allF035MelindaIds)];\n\n debugData(`Fields (${f035s.length}): ${JSON.stringify(f035s)}`);\n debugData(`Ids (${allF035MelindaIds.length}): ${JSON.stringify(allF035MelindaIds)}`);\n debugData(`Unique ids (${f035MelindaIds.length}): ${JSON.stringify(f035MelindaIds)}`);\n\n return f035MelindaIds;\n\n function toMelindaIds({subfields}) {\n const melindaIdRegExp = /^(?<prefix>\\(FI-MELINDA\\)|FCC)(?<id>\\d{9})$/u;\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code))\n .filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))\n .map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');\n\n }\n}\n\nexport function validateSidFieldSubfieldCounts(field) {\n // Valid SID-fields have just one $c and one $b\n debugData(`Validating SID field ${JSON.stringify(field)}`);\n const countC = countSubfields(field, 'c');\n const countB = countSubfields(field, 'b');\n debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);\n\n return countC === 1 && countB === 1;\n}\n\nfunction countSubfields(field, subfieldCode) {\n // debug(`Counting subfields ${subfieldCode}`);\n return field.subfields.filter(({code}) => code === subfieldCode).length;\n}\n\nexport function getSubfieldValues(field, subfieldCode) {\n debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);\n return field.subfields\n .filter(({code}) => code === subfieldCode)\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value);\n}\n\nexport function testStringOrNumber(value) {\n if (typeof value === 'string' || typeof value === 'number') {\n return true;\n }\n return false;\n}\n\nexport function extractSubfieldsFromField(field, subfieldCodes) {\n if (field === undefined || field.subfields === undefined) {\n return [];\n }\n const resultSubfields = field.subfields\n .filter(({code}) => subfieldCodes.includes(code))\n .map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value) : ''}))\n .filter(value => value);\n return resultSubfields;\n}\n\nexport function uniqueSubfields(subfields) {\n return subfields.reduce((arr, e) => {\n if (!arr.find(item => item.code === e.code && item.value === e.value)) {\n const newArr = arr.concat(e);\n return newArr;\n }\n return arr;\n }, []);\n}\n\nexport function getMatchCounts(aValues, bValues) {\n\n const matchingValues = getMatchingValuesAmount(aValues, bValues);\n\n return {\n maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,\n // possibleMatchingValues: amount of identifiers in set of less identifiers (we cannot more values than these)\n possibleMatchValues: aValues.length > bValues.length ? bValues.length : aValues.length,\n matchingValues\n };\n\n function getMatchingValuesAmount(aValues, bValues) {\n if (bValues.length > aValues.length) {\n return aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;\n }\n if (aValues.length > bValues.length) {\n return bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;\n }\n\n // If we have same amount of values, we'll check matches both ways, to avoid mixups in cases\n // there would be duplicate values\n const aToB = aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;\n const bToA = bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;\n\n return aToB < bToA ? aToB : bToA;\n }\n}\n"],"mappings":";;;;;;;;;;;;AA4BA;AAAsC;AA5BtC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAIA,MAAMA,KAAK,GAAG,IAAAC,cAAiB,EAAC,yCAAyC,CAAC;AAC1E,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;AAE/B,SAASC,iBAAiB,CAACC,MAAM,EAAE;EAExC,MAAML,KAAK,GAAG,IAAAC,cAAiB,EAAC,8CAA8C,CAAC;EAC/E,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ACxC,MAAM;IAC5E;IACA4C,mBAAmB,EAAEL,OAAO,CAACvC,MAAM,GAAGwC,OAAO,CAACxC,MAAM,GAAGwC,OAAO,CAACxC,MAAM,GAAGuC,OAAO,CAACvC,MAAM;IACtFyC;EACF,CAAC;EAED,SAASC,uBAAuB,CAACH,OAAO,EAAEC,OAAO,EAAE;IACjD,IAAIA,OAAO,CAACxC,MAAM,GAAGuC,OAAO,CAACvC,MAAM,EAAE;MACnC,OAAOuC,OAAO,CAAC5B,MAAM,CAACkC,MAAM,IAAIL,OAAO,CAACM,IAAI,CAACC,MAAM,IAAIF,MAAM,KAAKE,MAAM,CAAC,CAAC,CAAC/C,MAAM;IACnF;IACA,IAAIuC,OAAO,CAACvC,MAAM,GAAGwC,OAAO,CAACxC,MAAM,EAAE;MACnC,OAAOwC,OAAO,CAAC7B,MAAM,CAACoC,MAAM,IAAIR,OAAO,CAACO,IAAI,CAACD,MAAM,IAAIE,MAAM,KAAKF,MAAM,CAAC,CAAC,CAAC7C,MAAM;IACnF;;IAEA;IACA;IACA,MAAMgD,IAAI,GAAGT,OAAO,CAAC5B,MAAM,CAACkC,MAAM,IAAIL,OAAO,CAACM,IAAI,CAACC,MAAM,IAAIF,MAAM,KAAKE,MAAM,CAAC,CAAC,CAAC/C,MAAM;IACvF,MAAMiD,IAAI,GAAGT,OAAO,CAAC7B,MAAM,CAACoC,MAAM,IAAIR,OAAO,CAACO,IAAI,CAACD,MAAM,IAAIE,MAAM,KAAKF,MAAM,CAAC,CAAC,CAAC7C,MAAM;IAEvF,OAAOgD,IAAI,GAAGC,IAAI,GAAGD,IAAI,GAAGC,IAAI;EAClC;AACF"}
package/package.json CHANGED
@@ -14,7 +14,7 @@
14
14
  "url": "git@github.com:natlibfi/melinda-record-matching-js.git"
15
15
  },
16
16
  "license": "LGPL-3.0+",
17
- "version": "4.0.1-alpha.1",
17
+ "version": "4.1.0-alpha.2",
18
18
  "main": "./dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=18"
@@ -38,12 +38,12 @@
38
38
  "dependencies": {
39
39
  "@natlibfi/marc-record": "^7.2.2",
40
40
  "@natlibfi/marc-record-serializers": "^9.0.4",
41
- "@natlibfi/melinda-commons": "^12.0.9",
41
+ "@natlibfi/melinda-commons": "^13.0.2",
42
42
  "@natlibfi/sru-client": "^5.0.4",
43
43
  "debug": "^4.3.4",
44
- "isbn3": "^1.1.30",
44
+ "isbn3": "^1.1.33",
45
45
  "moment": "^2.29.4",
46
- "natural": "^6.1.4",
46
+ "natural": "^6.2.0",
47
47
  "uuid": "^9.0.0",
48
48
  "winston": "^3.8.2"
49
49
  },
@@ -51,7 +51,7 @@
51
51
  "@babel/cli": "^7.20.7",
52
52
  "@babel/core": "^7.20.12",
53
53
  "@babel/eslint-parser": "^7.19.1",
54
- "@babel/node": "^7.20.0",
54
+ "@babel/node": "^7.20.7",
55
55
  "@babel/preset-env": "^7.20.2",
56
56
  "@babel/register": "^7.18.9",
57
57
  "@natlibfi/eslint-config-melinda-backend": "^2.0.2",
@@ -63,7 +63,7 @@
63
63
  "chai": "^4.3.7",
64
64
  "chai-as-promised": "^7.1.1",
65
65
  "cross-env": "^7.0.3",
66
- "eslint": "^8.32.0",
66
+ "eslint": "^8.34.0",
67
67
  "mocha": "^10.2.0",
68
68
  "nodemon": "^2.0.20",
69
69
  "nyc": "^15.1.0"
@@ -35,6 +35,8 @@ export {default as titleVersionOriginal} from './title-version-original';
35
35
  export {default as authors} from './authors';
36
36
  export {default as recordType} from './record-type';
37
37
  export {default as publicationTime} from './publication-time';
38
+ export {default as publicationTimeAllowConsYears} from './publication-time-allow-cons-years';
39
+ export {default as publicationTimeAllowConsYearsMulti} from './publication-time-allow-cons-years-multi';
38
40
  export {default as language} from './language';
39
41
  export {default as bibliographicLevel} from './bibliographic-level';
40
42
  export {default as melindaId} from './melinda-id';
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Melinda record matching modules for Javascript
6
6
  *
7
- * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
7
+ * Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
8
8
  *
9
9
  * This file is part of melinda-record-matching-js
10
10
  *
@@ -27,6 +27,7 @@
27
27
  */
28
28
 
29
29
  import createDebugLogger from 'debug';
30
+ import {getMatchCounts} from '../../../matching-utils';
30
31
 
31
32
  const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:language');
32
33
  const debugData = debug.extend('data');
@@ -40,19 +41,15 @@ export default () => ({
40
41
  const values041 = get041Values();
41
42
  debugData(`${label} 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);
42
43
 
43
- if (value008 && values041.length > 0) {
44
- debugData(`${label} There's both 008 and 041, searching for value in both`);
45
- const correspondingValue = values041.find(v => v === value008);
46
- debugData(`${label} Corresponding value: ${correspondingValue}`);
47
- return correspondingValue ? [correspondingValue] : [];
48
- }
49
-
50
44
  if (!value008 && values041.length < 1) {
51
45
  debugData(`{$label} No actual values found`);
52
46
  return [];
53
47
  }
54
48
 
55
- return value008 ? [value008] : [values041[0]];
49
+ const allValues = value008 === undefined ? values041 : values041.concat(value008);
50
+ const uniqueSortedValues = [...new Set(allValues)].sort();
51
+
52
+ return uniqueSortedValues;
56
53
 
57
54
  function get008Value() {
58
55
  const value = record.get(/^008$/u)?.[0]?.value || undefined;
@@ -64,11 +61,9 @@ export default () => ({
64
61
 
65
62
  const code = value.slice(35, 38);
66
63
  debugData(`${label} 008 code: ${code}`);
67
- return code === '|||' || code === ' ' || code === '^^^' ? undefined : code;
64
+ return isLangCodeForALanguage(code) ? code : undefined;
68
65
  }
69
66
 
70
- // Main language for the resource: in the first f041 $a or f041 $d
71
- // Should we get all $a or $d languages instead of just the first?
72
67
  // Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes
73
68
 
74
69
  function get041Values() {
@@ -77,23 +72,67 @@ export default () => ({
77
72
  .map(({subfields}) => subfields)
78
73
  .flat()
79
74
  .filter(({code}) => code === 'a' || code === 'd')
75
+ .filter(({value}) => value && isLangCodeForALanguage(value))
80
76
  .map(({value}) => value);
81
77
  }
78
+
79
+ // Check if a string is a possible, validly formed language code for a single language
80
+ // Currently accept also codes in capitals
81
+ function isLangCodeForALanguage(code) {
82
+ if (code.length !== 3) {
83
+ debugData(`Code ${code} is not correct length (3) for a language code.`);
84
+ return false;
85
+ }
86
+ if (code === '|||' || code === ' ' || code === '^^^' || code === 'mul' || code === 'zxx') {
87
+ debugData(`Code ${code} is not code for a spesific language.`);
88
+ return false;
89
+ }
90
+ const langCodePattern = /^[a-z][a-z][a-z]$/ui;
91
+ if (!langCodePattern.test(code)) {
92
+ debugData(`Code ${code} is not valid as a language code`);
93
+ return false;
94
+ }
95
+ return true;
96
+ }
97
+
82
98
  },
99
+ // eslint-disable-next-line max-statements
83
100
  compare: (a, b) => {
84
- debugData(`Comparing ${JSON.stringify(a[0])} and ${JSON.stringify(b[0])}`);
101
+ debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);
85
102
 
86
103
  if (a.length === 0 || b.length === 0) {
87
104
  debugData(`No language to compare`);
88
105
  return 0;
89
106
  }
90
107
 
91
- debugData(`There are languages to compare`);
92
-
93
- if (a[0] === b[0]) {
108
+ if (a.length === b.length && a.every((element, index) => element === b[index])) {
109
+ debugData(`All languages match`);
94
110
  return 0.1;
95
111
  }
96
112
 
97
- return a[0] === 'und' || b[0] === 'und' ? 0.0 : -1.0;
113
+ const {matchingValues, possibleMatchValues, maxValues} = getMatchCounts(a, b);
114
+
115
+ if (matchingValues < 1) {
116
+ debug(`Both have languages, but none of these match.`);
117
+ return -1.0;
118
+ }
119
+ debug(`Both have languages, ${matchingValues}/${possibleMatchValues} valid languages match.`);
120
+ // ignore non-matches if there is mismatching amount of values
121
+ debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);
122
+ //we give some kind of penalty for mismatching amount of values instead of simple divide?
123
+ const missingCount = maxValues - possibleMatchValues;
124
+ const misMatchCount = possibleMatchValues - matchingValues;
125
+ debug(`\t missing: ${missingCount}`);
126
+ debug(`\t mismatches: ${misMatchCount}`);
127
+
128
+ const penaltyForMissing = 0.02 * (maxValues - possibleMatchValues);
129
+ const penaltyForMisMatch = 0.05 * (possibleMatchValues - matchingValues);
130
+ debug(`\t points: penaltyForMissing: ${penaltyForMissing}`);
131
+ debug(`\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);
132
+
133
+ const points = Number(Number(0.1 - penaltyForMisMatch - penaltyForMissing).toFixed(2));
134
+ debug(`Total points: ${points}`);
135
+
136
+ return points;
98
137
  }
99
138
  });
@@ -0,0 +1,233 @@
1
+ /**
2
+ *
3
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
4
+ *
5
+ * Melinda record matching modules for Javascript
6
+ *
7
+ * Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
8
+ *
9
+ * This file is part of melinda-record-matching-js
10
+ *
11
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
12
+ * it under the terms of the GNU Lesser General Public License as
13
+ * published by the Free Software Foundation, either version 3 of the
14
+ * License, or (at your option) any later version.
15
+ *
16
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU Lesser General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU Affero General Public License
22
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+ *
24
+ * @licend The above is the entire license notice
25
+ * for the JavaScript code in this file.
26
+ *
27
+ */
28
+
29
+ import {testStringOrNumber} from '../../../matching-utils';
30
+ import createDebugLogger from 'debug';
31
+
32
+ // We should also get copyright time and copyright/publication times from 26x
33
+ // We should also get publishing time type from f008
34
+ // We should get reprint times from f500 $a "Lisäpainos/Lisäpainokset:"
35
+
36
+ export default () => ({
37
+ name: 'Publication time, allow consequent years, years from multiple sources',
38
+ extract: ({record}) => {
39
+ const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');
40
+
41
+ const f008Values = extractF008Values(record);
42
+ debug(`${JSON.stringify(f008Values)}`);
43
+
44
+ const f26xValues = extractF26xValues(record);
45
+ debug(`${JSON.stringify(f26xValues)}`);
46
+
47
+ const f500Values = extractF500Years(record);
48
+ debug(`${JSON.stringify(f500Values)}`);
49
+
50
+ // We should get copyrightYear from f008Date2 to copyrightYears when f008YearType = 'r'
51
+ // Is the original year (f008Date2) in f008YearType === 'r' comparable to copyrightYear?
52
+ // We should handle unknown years (here or comparison?)
53
+ // We should handle year ranges for continuing resources / collections
54
+ // We should normalize copyright marks (etc.) out of copyrightYears
55
+
56
+ const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => value && value !== ' '))].sort();
57
+ const copyrightYears = [...new Set(f26xValues.copyrightYears)].sort();
58
+ const reprintYears = [...new Set(f500Values)].sort();
59
+
60
+ const combined = {normalYears, copyrightYears, reprintYears};
61
+
62
+ debug(`Combined: ${JSON.stringify(combined)}`);
63
+
64
+ return combined;
65
+
66
+ function extractF008Values(record) {
67
+ const value = record.get(/^008$/u)?.[0]?.value || undefined;
68
+ if (value && testStringOrNumber(value)) {
69
+ const f008Date1 = extractF008Date1(value);
70
+ const f008Date2 = extractF008Date2(value);
71
+ const f008YearType = extractF008YearType(value);
72
+ return {f008Date1, f008Date2, f008YearType};
73
+ }
74
+ return {f008Date1: undefined, f008Date2: undefined, f008YearType: undefined};
75
+ }
76
+
77
+ function extractF008Date1(value) {
78
+ return String(value).slice(7, 11);
79
+ }
80
+
81
+ function extractF008Date2(value) {
82
+ return String(value).slice(11, 15);
83
+ }
84
+
85
+ function extractF008YearType(value) {
86
+ return String(value).slice(6, 7);
87
+ }
88
+
89
+ function extractF26xValues(record) {
90
+ const copyrightRegex = /^(?<copyrightPrefix>cop|cop.|c|©|p|℗)/u;
91
+
92
+ const pubNormalSubFieldValues = record.get(/^26[04]$/u)
93
+ .filter((field) => !(field.tag === '264' && field.ind2 === '4'))
94
+ .map(({subfields}) => subfields)
95
+ .flat()
96
+ .filter(({code}) => code === 'c')
97
+ .map(({value}) => value)
98
+ .filter(({value}) => !copyrightRegex.test(value));
99
+
100
+ debug(`Normal years: ${JSON.stringify(pubNormalSubFieldValues)}`);
101
+
102
+ const pubF264CopySubFieldValues = record.get(/^264$/u)
103
+ .filter((field) => field.ind2 === '4')
104
+ .map(({subfields}) => subfields)
105
+ .flat()
106
+ .filter(({code}) => code === 'c')
107
+ .map(({value}) => value);
108
+ debug(`F264 copyright years: ${JSON.stringify(pubF264CopySubFieldValues)}`);
109
+
110
+ const pubF260CopySubFieldValues = record.get(/^260$/u)
111
+ .map(({subfields}) => subfields)
112
+ .flat()
113
+ .filter(({code}) => code === 'c')
114
+ .filter(({value}) => copyrightRegex.test(value));
115
+ debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);
116
+
117
+ return {normalYears: pubNormalSubFieldValues, copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues]};
118
+ }
119
+
120
+ function extractF500Years(record) {
121
+
122
+ const reprintRegex = /(?<reprint>Lisäpainokset:|Lisäpainos:)/u;
123
+ const reprintFieldContents = record.get(/^500$/u)
124
+ .map(({subfields}) => subfields)
125
+ .flat()
126
+ .filter(({code}) => code === 'a')
127
+ .map(({value}) => value);
128
+ //.filter(value => value.test(reprintRegex));
129
+
130
+ debug(`f500 reprint field contents: ${JSON.stringify(reprintFieldContents)}`);
131
+
132
+ const filteredF500 = reprintFieldContents.filter((content) => content && content.match(reprintRegex));
133
+
134
+ debug(`f500 reprint field contents (filtered): ${JSON.stringify(filteredF500)}`);
135
+
136
+ const reprintYears = extractReprintYears(filteredF500);
137
+
138
+ return reprintYears;
139
+ }
140
+
141
+ function extractReprintYears(contents) {
142
+ const yearRegex = /[0-9][0-9][0-9][0-9]/gu;
143
+ const years = contents.map(content => content.match(yearRegex))
144
+ .flat();
145
+ debug(`${JSON.stringify(years)}`);
146
+ const uniqYears = [...new Set(years)].sort();
147
+ debug(`${JSON.stringify(uniqYears)}`);
148
+ return uniqYears;
149
+ }
150
+
151
+ },
152
+ // eslint-disable-next-line max-statements
153
+ compare: (a, b) => {
154
+ const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');
155
+ debug(`Comparing ${JSON.stringify(a)} to ${JSON.stringify(b)}`);
156
+
157
+ const [firstA] = a.normalYears ? a.normalYears : a;
158
+ const [firstB] = b.normalYears ? b.normalYears : b;
159
+
160
+ debug(`Comparing ${JSON.stringify(firstA)} to ${JSON.stringify(firstB)}`);
161
+
162
+ if (firstA === firstB) {
163
+ return 0.1;
164
+ }
165
+
166
+ // If either of years is a non string/number, values are not comparable
167
+ if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {
168
+ return 0;
169
+ }
170
+
171
+ const firstANumber = parseInt(firstA, 10);
172
+ const firstBNumber = parseInt(firstB, 10);
173
+
174
+ if (isNaN(firstANumber) || isNaN(firstBNumber)) {
175
+ return -1;
176
+ }
177
+
178
+ // Handle consequent years as a match
179
+ // see publication-time for a version that does not handle consequent years as a match
180
+ if (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber) {
181
+ return 0.1;
182
+ }
183
+
184
+ const bNormalInAReprint = a.reprintYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));
185
+ const aNormalInBReprint = b.reprintYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));
186
+ debug(`BNorm in AReprint: ${JSON.stringify(bNormalInAReprint)}`);
187
+ debug(`ANorm in BReprint: ${JSON.stringify(aNormalInBReprint)}`);
188
+
189
+ if (bNormalInAReprint > 0 || aNormalInBReprint > 0) {
190
+ return 0;
191
+ }
192
+
193
+ return -1;
194
+
195
+ }
196
+ });
197
+
198
+ // https://www.loc.gov/marc/bibliographic/bd008.html
199
+ // field 008
200
+ // 06 - Type of date/Publication status
201
+ // 07-10 - Date 1
202
+ // 11-14 - Date 2
203
+ //
204
+ // 06 - Type of date/Publication status
205
+ // b - No dates given; B.C. date involved
206
+ // c - Continuing resource currently published
207
+ // d - Continuing resource ceased publication
208
+ // e - Detailed date
209
+ // i - Inclusive dates of collection
210
+ // k - Range of years of bulk of collection
211
+ // m - Multiple dates
212
+ // n - Dates unknown
213
+ // p - Date of distribution/release/issue and production/recording session when different
214
+ // q - Questionable date
215
+ // r - Reprint/reissue date and original date
216
+ // s - Single known date/probable date
217
+ // t - Publication date and copyright date
218
+ // u - Continuing resource status unknown
219
+ // | - No attempt to code
220
+ //
221
+ // 07-10 - Date 1
222
+ // 1-9 - Date digit
223
+ // # - Date element is not applicable
224
+ // u - Date element is totally or partially unknown
225
+ // |||| - No attempt to code
226
+ //
227
+ // 11-14 - Date 2
228
+ // 1-9 - Date digit
229
+ // # - Date element is not applicable
230
+ // u - Date element is totally or partially unknown
231
+ // |||| - No attempt to code
232
+ //
233
+
@@ -0,0 +1,67 @@
1
+ /**
2
+ *
3
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
4
+ *
5
+ * Melinda record matching modules for Javascript
6
+ *
7
+ * Copyright (C) 2020-2023 University Of Helsinki (The National Library Of Finland)
8
+ *
9
+ * This file is part of melinda-record-matching-js
10
+ *
11
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
12
+ * it under the terms of the GNU Lesser General Public License as
13
+ * published by the Free Software Foundation, either version 3 of the
14
+ * License, or (at your option) any later version.
15
+ *
16
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU Lesser General Public License for more details.
20
+ *
21
+ * You should have received a copy of the GNU Affero General Public License
22
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+ *
24
+ * @licend The above is the entire license notice
25
+ * for the JavaScript code in this file.
26
+ *
27
+ */
28
+
29
+ import {testStringOrNumber} from '../../../matching-utils';
30
+ import createDebugLogger from 'debug';
31
+
32
+ // We should also get copyright time and copyright/publication times from 26x
33
+
34
+ export default () => ({
35
+ name: 'Publication time, allow consequent years',
36
+ extract: ({record}) => {
37
+ const value = record.get(/^008$/u)?.[0]?.value || undefined;
38
+ return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];
39
+ },
40
+ compare: (a, b) => {
41
+ const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years');
42
+ debug(`Comparing ${a[0]} to ${b[0]}`);
43
+
44
+ const [firstA] = a;
45
+ const [firstB] = b;
46
+
47
+ if (firstA === firstB) {
48
+ return 0.1;
49
+ }
50
+
51
+ // If either of years is a non string/number, values are not comparable
52
+ if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {
53
+ return 0;
54
+ }
55
+
56
+ const firstANumber = parseInt(firstA, 10);
57
+ const firstBNumber = parseInt(firstB, 10);
58
+
59
+ if (isNaN(firstANumber) || isNaN(firstBNumber)) {
60
+ return -1;
61
+ }
62
+
63
+ // Handle consequent years as a match
64
+ // see publication-time for a version that does not handle consequent years as a match
65
+ return firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber ? 0.1 : -1;
66
+ }
67
+ });
@@ -29,7 +29,7 @@
29
29
  import {testStringOrNumber} from '../../../matching-utils';
30
30
 
31
31
  // We should also get copyright time and copyright/publication times from 26x
32
- // We could also enable matching of records which have consequent publication years
32
+ // see publication-time-allow-cons-years for a version allowing consequent years to match
33
33
 
34
34
  export default () => ({
35
35
  name: 'Publication time',
@@ -113,3 +113,31 @@ export function uniqueSubfields(subfields) {
113
113
  return arr;
114
114
  }, []);
115
115
  }
116
+
117
+ export function getMatchCounts(aValues, bValues) {
118
+
119
+ const matchingValues = getMatchingValuesAmount(aValues, bValues);
120
+
121
+ return {
122
+ maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,
123
+ // possibleMatchingValues: amount of identifiers in set of less identifiers (we cannot more values than these)
124
+ possibleMatchValues: aValues.length > bValues.length ? bValues.length : aValues.length,
125
+ matchingValues
126
+ };
127
+
128
+ function getMatchingValuesAmount(aValues, bValues) {
129
+ if (bValues.length > aValues.length) {
130
+ return aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
131
+ }
132
+ if (aValues.length > bValues.length) {
133
+ return bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
134
+ }
135
+
136
+ // If we have same amount of values, we'll check matches both ways, to avoid mixups in cases
137
+ // there would be duplicate values
138
+ const aToB = aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
139
+ const bToA = bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
140
+
141
+ return aToB < bToA ? aToB : bToA;
142
+ }
143
+ }