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

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.
@@ -40,23 +40,24 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
40
40
  var _default = () => ({
41
41
  name: 'Publication time, allow consequent years, years from multiple sources',
42
42
  extract: ({
43
- record
43
+ record,
44
+ recordExternal
44
45
  }) => {
45
46
  const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');
47
+ const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
46
48
  const f008Values = extractF008Values(record);
47
- debug(`${JSON.stringify(f008Values)}`);
49
+ debug(`${label} f008: ${JSON.stringify(f008Values)}`);
48
50
  const f26xValues = extractF26xValues(record);
49
- debug(`${JSON.stringify(f26xValues)}`);
51
+ debug(`${label} f26x: ${JSON.stringify(f26xValues)}`);
50
52
  const f500Values = extractF500Years(record);
51
- debug(`${JSON.stringify(f500Values)}`);
53
+ debug(`${label} f500: ${JSON.stringify(f500Values)}`);
52
54
 
53
55
  // We should get copyrightYear from f008Date2 to copyrightYears when f008YearType = 'r'
54
56
  // Is the original year (f008Date2) in f008YearType === 'r' comparable to copyrightYear?
55
57
  // We should handle unknown years (here or comparison?)
56
58
  // We should handle year ranges for continuing resources / collections
57
- // We should normalize copyright marks (etc.) out of copyrightYears
58
59
 
59
- const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => value && value !== ' '))].sort();
60
+ const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => value && value !== ' ' && value !== '||||'))].sort();
60
61
  const copyrightYears = [...new Set(f26xValues.copyrightYears)].sort();
61
62
  const reprintYears = [...new Set(f500Values)].sort();
62
63
  const combined = {
@@ -68,6 +69,7 @@ var _default = () => ({
68
69
  return combined;
69
70
  function extractF008Values(record) {
70
71
  var _record$get, _record$get$;
72
+ // Record should have only one f008 - in case of several, we handle the first one
71
73
  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
74
  if (value && (0, _matchingUtils.testStringOrNumber)(value)) {
73
75
  const f008Date1 = extractF008Date1(value);
@@ -84,48 +86,66 @@ var _default = () => ({
84
86
  f008Date2: undefined,
85
87
  f008YearType: undefined
86
88
  };
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);
89
+ function extractF008Date1(value) {
90
+ return String(value).slice(7, 11);
91
+ }
92
+ function extractF008Date2(value) {
93
+ return String(value).slice(11, 15);
94
+ }
95
+ function extractF008YearType(value) {
96
+ return String(value).slice(6, 7);
97
+ }
96
98
  }
97
99
  function extractF26xValues(record) {
98
100
  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));
101
+ const pubNormalSubFieldValues = extractPubNormalSubfieldValues(record, copyrightRegex);
108
102
  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);
103
+ const pubF264CopySubFieldValues = extractPubF264CopySubfieldValues(record);
116
104
  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));
105
+ const pubF260CopySubFieldValues = extractPubF260CopySubfieldValues(record, copyrightRegex);
124
106
  debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);
125
107
  return {
126
108
  normalYears: pubNormalSubFieldValues,
127
109
  copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues]
128
110
  };
111
+ function extractPubNormalSubfieldValues(record, copyrightRegex) {
112
+ return record.get(/^26[04]$/u).filter(field => !(field.tag === '264' && field.ind2 === '4')).map(({
113
+ subfields
114
+ }) => subfields).flat().filter(({
115
+ code
116
+ }) => code && code === 'c').filter(({
117
+ value
118
+ }) => value && !copyrightRegex.test(value)).map(({
119
+ value
120
+ }) => value).map(value => removeNonAlphaNumeric(value));
121
+ }
122
+ function extractPubF264CopySubfieldValues(record, copyrightRegex) {
123
+ return record.get(/^264$/u).filter(field => field.ind2 === '4').map(({
124
+ subfields
125
+ }) => subfields).flat().filter(({
126
+ code
127
+ }) => code && code === 'c').filter(({
128
+ value
129
+ }) => value).map(({
130
+ value
131
+ }) => value).map(value => value.replace(copyrightRegex, '')).map(value => removeNonAlphaNumeric(value));
132
+ }
133
+ function extractPubF260CopySubfieldValues(record, copyrightRegex) {
134
+ return record.get(/^260$/u).map(({
135
+ subfields
136
+ }) => subfields).flat().filter(({
137
+ code
138
+ }) => code && code === 'c').filter(({
139
+ value
140
+ }) => value && copyrightRegex.test(value)).map(({
141
+ value
142
+ }) => value).map(value => value.replace(copyrightRegex, '')).map(value => removeNonAlphaNumeric(value));
143
+ }
144
+ function removeNonAlphaNumeric(value) {
145
+ debug(`Cleaning: ${JSON.stringify(value)}`);
146
+ const nonAlphaNumericRegex = /[^A-Za-z0-9]/ug;
147
+ return value ? value.replace(nonAlphaNumericRegex, '') : value;
148
+ }
129
149
  }
130
150
  function extractF500Years(record) {
131
151
  const reprintRegex = /(?<reprint>Lisäpainokset:|Lisäpainos:)/u;
@@ -170,15 +190,25 @@ var _default = () => ({
170
190
  }
171
191
  const firstANumber = parseInt(firstA, 10);
172
192
  const firstBNumber = parseInt(firstB, 10);
173
- if (isNaN(firstANumber) || isNaN(firstBNumber)) {
174
- return -1;
175
- }
176
193
 
177
194
  // Handle consequent years as a match
178
195
  // see publication-time for a version that does not handle consequent years as a match
179
- if (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber) {
196
+ if (!(isNaN(firstANumber) || isNaN(firstBNumber)) && (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber)) {
180
197
  return 0.1;
181
198
  }
199
+
200
+ // We should do something with copyrightYears, too
201
+
202
+ // Do not give minus points if a normal publishing year is found in normal years
203
+ const bNormalInANormal = a.normalYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));
204
+ const aNormalInBNormal = b.normalYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));
205
+ debug(`BNorm in ANorm: ${JSON.stringify(bNormalInANormal)}`);
206
+ debug(`ANorm in BNorm: ${JSON.stringify(aNormalInBNormal)}`);
207
+ if (bNormalInANormal > 0 || aNormalInBNormal > 0) {
208
+ return 0;
209
+ }
210
+
211
+ // Do not give minus points if a normal publishing year is found in reprint years
182
212
  const bNormalInAReprint = a.reprintYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));
183
213
  const aNormalInBReprint = b.reprintYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));
184
214
  debug(`BNorm in AReprint: ${JSON.stringify(bNormalInAReprint)}`);
@@ -1 +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":";;;;;;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;AACA;AACA;AAAA,eAEe,OAAO;EACpBA,IAAI,EAAE,uEAAuE;EAC7EC,OAAO,EAAE,CAAC;IAACC;EAAM,CAAC,KAAK;IACrB,MAAMC,KAAK,GAAG,IAAAC,cAAiB,E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G,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"}
1
+ {"version":3,"file":"publication-time-allow-cons-years-multi.js","names":["name","extract","record","recordExternal","debug","createDebugLogger","label","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","extractPubNormalSubfieldValues","pubF264CopySubFieldValues","extractPubF264CopySubfieldValues","pubF260CopySubFieldValues","extractPubF260CopySubfieldValues","field","tag","ind2","map","subfields","flat","code","test","removeNonAlphaNumeric","replace","nonAlphaNumericRegex","reprintRegex","reprintFieldContents","filteredF500","content","match","extractReprintYears","contents","yearRegex","years","uniqYears","compare","a","b","firstA","firstB","firstANumber","parseInt","firstBNumber","isNaN","bNormalInANormal","aValue","some","bValue","aNormalInBNormal","bNormalInAReprint","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, recordExternal}) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n\n const f008Values = extractF008Values(record);\n debug(`${label} f008: ${JSON.stringify(f008Values)}`);\n\n const f26xValues = extractF26xValues(record);\n debug(`${label} f26x: ${JSON.stringify(f26xValues)}`);\n\n const f500Values = extractF500Years(record);\n debug(`${label} f500: ${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\n const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => 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 // Record should have only one f008 - in case of several, we handle the first one\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 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\n function extractF26xValues(record) {\n const copyrightRegex = /^(?<copyrightPrefix>cop|cop.|c|©|p|℗)/u;\n\n const pubNormalSubFieldValues = extractPubNormalSubfieldValues(record, copyrightRegex);\n debug(`Normal years: ${JSON.stringify(pubNormalSubFieldValues)}`);\n\n const pubF264CopySubFieldValues = extractPubF264CopySubfieldValues(record);\n debug(`F264 copyright years: ${JSON.stringify(pubF264CopySubFieldValues)}`);\n\n const pubF260CopySubFieldValues = extractPubF260CopySubfieldValues(record, copyrightRegex);\n debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);\n\n return {normalYears: pubNormalSubFieldValues, copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues]};\n\n function extractPubNormalSubfieldValues(record, copyrightRegex) {\n return record.get(/^26[04]$/u)\n .filter((field) => !(field.tag === '264' && field.ind2 === '4'))\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code && code === 'c')\n .filter(({value}) => value && !copyrightRegex.test(value))\n .map(({value}) => value)\n .map((value) => removeNonAlphaNumeric(value));\n }\n\n function extractPubF264CopySubfieldValues(record, copyrightRegex) {\n return record.get(/^264$/u)\n .filter((field) => field.ind2 === '4')\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code && code === 'c')\n .filter(({value}) => value)\n .map(({value}) => value)\n .map((value) => value.replace(copyrightRegex, ''))\n .map((value) => removeNonAlphaNumeric(value));\n }\n\n function extractPubF260CopySubfieldValues(record, copyrightRegex) {\n return record.get(/^260$/u)\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code && code === 'c')\n .filter(({value}) => value && copyrightRegex.test(value))\n .map(({value}) => value)\n .map((value) => value.replace(copyrightRegex, ''))\n .map((value) => removeNonAlphaNumeric(value));\n }\n\n function removeNonAlphaNumeric(value) {\n debug(`Cleaning: ${JSON.stringify(value)}`);\n const nonAlphaNumericRegex = /[^A-Za-z0-9]/ug;\n return value ? value.replace(nonAlphaNumericRegex, '') : value;\n }\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 // Handle consequent years as a match\n // see publication-time for a version that does not handle consequent years as a match\n if (!(isNaN(firstANumber) || isNaN(firstBNumber)) &&\n (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber)) {\n return 0.1;\n }\n\n // We should do something with copyrightYears, too\n\n // Do not give minus points if a normal publishing year is found in normal years\n const bNormalInANormal = a.normalYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));\n const aNormalInBNormal = b.normalYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));\n debug(`BNorm in ANorm: ${JSON.stringify(bNormalInANormal)}`);\n debug(`ANorm in BNorm: ${JSON.stringify(aNormalInBNormal)}`);\n\n if (bNormalInANormal > 0 || aNormalInBNormal > 0) {\n return 0;\n }\n\n // Do not give minus points if a normal publishing year is found in reprint years\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":";;;;;;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;AACA;AACA;AAAA,eAEe,OAAO;EACpBA,IAAI,EAAE,uEAAuE;EAC7EC,OAAO,EAAE,CAAC;IAACC,MAAM;IAAEC;EAAc,CAAC,KAAK;IACrC,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,wGAAwG,CAAC;IACzI,MAAMC,KAAK,GAAGH,cAAc,IAAIA,cAAc,CAACG,KAAK,GAAGH,cAAc,CAACG,KAAK,GAAG,QAAQ;IAEtF,MAAMC,UAAU,GAAGC,iBAAiB,CAACN,MAAM,CAAC;IAC5CE,KAAK,CAAE,GAAEE,KAAM,UAASG,IAAI,CAACC,SAAS,CAACH,UAAU,CAAE,EAAC,CAAC;IAErD,MAAMI,UAAU,GAAGC,iBAAiB,CAACV,MAAM,CAAC;IAC5CE,KAAK,CAAE,GAAEE,KAAM,UAASG,IAAI,CAACC,SAAS,CAACC,UAAU,CAAE,EAAC,CAAC;IAErD,MAAME,UAAU,GAAGC,gBAAgB,CAACZ,MAAM,CAAC;IAC3CE,KAAK,CAAE,G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gBAAgB,GAAG,CAAC,EAAE;MAChD,OAAO,CAAC;IACV;;IAEA;IACA,MAAMC,iBAAiB,GAAGb,CAAC,CAACzC,YAAY,CAACJ,MAAM,CAACsD,MAAM,IAAIR,CAAC,CAAClD,WAAW,CAAC2D,IAAI,CAACC,MAAM,IAAIF,MAAM,KAAKE,MAAM,CAAC,CAAC;IAC1G,MAAMG,iBAAiB,GAAGb,CAAC,CAAC1C,YAAY,CAACJ,MAAM,CAACwD,MAAM,IAAIX,CAAC,CAACjD,WAAW,CAAC2D,IAAI,CAACD,MAAM,IAAIE,MAAM,KAAKF,MAAM,CAAC,CAAC;IAC1GrE,KAAK,CAAE,sBAAqBK,IAAI,CAACC,SAAS,CAACmE,iBAAiB,CAAE,EAAC,CAAC;IAChEzE,KAAK,CAAE,sBAAqBK,IAAI,CAACC,SAAS,CAACoE,iBAAiB,CAAE,EAAC,CAAC;IAEhE,IAAID,iBAAiB,GAAG,CAAC,IAAIC,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"}
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.1.0-alpha.2",
17
+ "version": "4.1.0",
18
18
  "main": "./dist/index.js",
19
19
  "engines": {
20
20
  "node": ">=18"
@@ -35,25 +35,25 @@ import createDebugLogger from 'debug';
35
35
 
36
36
  export default () => ({
37
37
  name: 'Publication time, allow consequent years, years from multiple sources',
38
- extract: ({record}) => {
38
+ extract: ({record, recordExternal}) => {
39
39
  const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi');
40
+ const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';
40
41
 
41
42
  const f008Values = extractF008Values(record);
42
- debug(`${JSON.stringify(f008Values)}`);
43
+ debug(`${label} f008: ${JSON.stringify(f008Values)}`);
43
44
 
44
45
  const f26xValues = extractF26xValues(record);
45
- debug(`${JSON.stringify(f26xValues)}`);
46
+ debug(`${label} f26x: ${JSON.stringify(f26xValues)}`);
46
47
 
47
48
  const f500Values = extractF500Years(record);
48
- debug(`${JSON.stringify(f500Values)}`);
49
+ debug(`${label} f500: ${JSON.stringify(f500Values)}`);
49
50
 
50
51
  // We should get copyrightYear from f008Date2 to copyrightYears when f008YearType = 'r'
51
52
  // Is the original year (f008Date2) in f008YearType === 'r' comparable to copyrightYear?
52
53
  // We should handle unknown years (here or comparison?)
53
54
  // We should handle year ranges for continuing resources / collections
54
- // We should normalize copyright marks (etc.) out of copyrightYears
55
55
 
56
- const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => value && value !== ' '))].sort();
56
+ const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter(value => value && value !== ' ' && value !== '||||'))].sort();
57
57
  const copyrightYears = [...new Set(f26xValues.copyrightYears)].sort();
58
58
  const reprintYears = [...new Set(f500Values)].sort();
59
59
 
@@ -64,6 +64,7 @@ export default () => ({
64
64
  return combined;
65
65
 
66
66
  function extractF008Values(record) {
67
+ // Record should have only one f008 - in case of several, we handle the first one
67
68
  const value = record.get(/^008$/u)?.[0]?.value || undefined;
68
69
  if (value && testStringOrNumber(value)) {
69
70
  const f008Date1 = extractF008Date1(value);
@@ -72,49 +73,73 @@ export default () => ({
72
73
  return {f008Date1, f008Date2, f008YearType};
73
74
  }
74
75
  return {f008Date1: undefined, f008Date2: undefined, f008YearType: undefined};
75
- }
76
76
 
77
- function extractF008Date1(value) {
78
- return String(value).slice(7, 11);
79
- }
77
+ function extractF008Date1(value) {
78
+ return String(value).slice(7, 11);
79
+ }
80
80
 
81
- function extractF008Date2(value) {
82
- return String(value).slice(11, 15);
83
- }
81
+ function extractF008Date2(value) {
82
+ return String(value).slice(11, 15);
83
+ }
84
84
 
85
- function extractF008YearType(value) {
86
- return String(value).slice(6, 7);
85
+ function extractF008YearType(value) {
86
+ return String(value).slice(6, 7);
87
+ }
87
88
  }
88
89
 
89
90
  function extractF26xValues(record) {
90
91
  const copyrightRegex = /^(?<copyrightPrefix>cop|cop.|c|©|p|℗)/u;
91
92
 
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
-
93
+ const pubNormalSubFieldValues = extractPubNormalSubfieldValues(record, copyrightRegex);
100
94
  debug(`Normal years: ${JSON.stringify(pubNormalSubFieldValues)}`);
101
95
 
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);
96
+ const pubF264CopySubFieldValues = extractPubF264CopySubfieldValues(record);
108
97
  debug(`F264 copyright years: ${JSON.stringify(pubF264CopySubFieldValues)}`);
109
98
 
110
- const pubF260CopySubFieldValues = record.get(/^260$/u)
111
- .map(({subfields}) => subfields)
112
- .flat()
113
- .filter(({code}) => code === 'c')
114
- .filter(({value}) => copyrightRegex.test(value));
99
+ const pubF260CopySubFieldValues = extractPubF260CopySubfieldValues(record, copyrightRegex);
115
100
  debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);
116
101
 
117
102
  return {normalYears: pubNormalSubFieldValues, copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues]};
103
+
104
+ function extractPubNormalSubfieldValues(record, copyrightRegex) {
105
+ return record.get(/^26[04]$/u)
106
+ .filter((field) => !(field.tag === '264' && field.ind2 === '4'))
107
+ .map(({subfields}) => subfields)
108
+ .flat()
109
+ .filter(({code}) => code && code === 'c')
110
+ .filter(({value}) => value && !copyrightRegex.test(value))
111
+ .map(({value}) => value)
112
+ .map((value) => removeNonAlphaNumeric(value));
113
+ }
114
+
115
+ function extractPubF264CopySubfieldValues(record, copyrightRegex) {
116
+ return record.get(/^264$/u)
117
+ .filter((field) => field.ind2 === '4')
118
+ .map(({subfields}) => subfields)
119
+ .flat()
120
+ .filter(({code}) => code && code === 'c')
121
+ .filter(({value}) => value)
122
+ .map(({value}) => value)
123
+ .map((value) => value.replace(copyrightRegex, ''))
124
+ .map((value) => removeNonAlphaNumeric(value));
125
+ }
126
+
127
+ function extractPubF260CopySubfieldValues(record, copyrightRegex) {
128
+ return record.get(/^260$/u)
129
+ .map(({subfields}) => subfields)
130
+ .flat()
131
+ .filter(({code}) => code && code === 'c')
132
+ .filter(({value}) => value && copyrightRegex.test(value))
133
+ .map(({value}) => value)
134
+ .map((value) => value.replace(copyrightRegex, ''))
135
+ .map((value) => removeNonAlphaNumeric(value));
136
+ }
137
+
138
+ function removeNonAlphaNumeric(value) {
139
+ debug(`Cleaning: ${JSON.stringify(value)}`);
140
+ const nonAlphaNumericRegex = /[^A-Za-z0-9]/ug;
141
+ return value ? value.replace(nonAlphaNumericRegex, '') : value;
142
+ }
118
143
  }
119
144
 
120
145
  function extractF500Years(record) {
@@ -171,16 +196,26 @@ export default () => ({
171
196
  const firstANumber = parseInt(firstA, 10);
172
197
  const firstBNumber = parseInt(firstB, 10);
173
198
 
174
- if (isNaN(firstANumber) || isNaN(firstBNumber)) {
175
- return -1;
176
- }
177
-
178
199
  // Handle consequent years as a match
179
200
  // see publication-time for a version that does not handle consequent years as a match
180
- if (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber) {
201
+ if (!(isNaN(firstANumber) || isNaN(firstBNumber)) &&
202
+ (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber)) {
181
203
  return 0.1;
182
204
  }
183
205
 
206
+ // We should do something with copyrightYears, too
207
+
208
+ // Do not give minus points if a normal publishing year is found in normal years
209
+ const bNormalInANormal = a.normalYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));
210
+ const aNormalInBNormal = b.normalYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));
211
+ debug(`BNorm in ANorm: ${JSON.stringify(bNormalInANormal)}`);
212
+ debug(`ANorm in BNorm: ${JSON.stringify(aNormalInBNormal)}`);
213
+
214
+ if (bNormalInANormal > 0 || aNormalInBNormal > 0) {
215
+ return 0;
216
+ }
217
+
218
+ // Do not give minus points if a normal publishing year is found in reprint years
184
219
  const bNormalInAReprint = a.reprintYears.filter(aValue => b.normalYears.some(bValue => aValue === bValue));
185
220
  const aNormalInBReprint = b.reprintYears.filter(bValue => a.normalYears.some(aValue => bValue === aValue));
186
221
  debug(`BNorm in AReprint: ${JSON.stringify(bNormalInAReprint)}`);