@natlibfi/melinda-record-matching 3.0.2-alpha.1 → 3.0.3-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/candidate-search/query-list/bib.js +63 -4
- package/dist/candidate-search/query-list/bib.js.map +1 -1
- package/dist/match-detection/features/bib/isbn.js +2 -28
- package/dist/match-detection/features/bib/isbn.js.map +1 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js +25 -126
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -1
- package/dist/matching-utils.js +0 -26
- package/dist/matching-utils.js.map +1 -1
- package/package.json +1 -2
- package/src/candidate-search/query-list/bib.js +69 -3
- package/src/match-detection/features/bib/isbn.js +2 -21
- package/src/match-detection/features/bib/standard-identifier-factory.js +23 -106
- package/src/matching-utils.js +0 -21
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
+
exports.bibAuthors = bibAuthors;
|
|
6
7
|
exports.bibHostComponents = bibHostComponents;
|
|
7
8
|
exports.bibMelindaIds = bibMelindaIds;
|
|
8
9
|
exports.bibSourceIds = bibSourceIds;
|
|
@@ -171,20 +172,78 @@ function bibTitle(record) {
|
|
|
171
172
|
|
|
172
173
|
// use word search for titles starting with a boolean
|
|
173
174
|
const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));
|
|
174
|
-
// Prevent too many matches by having a minimum length
|
|
175
|
-
|
|
175
|
+
// Prevent too many matches by having a minimum length
|
|
176
|
+
// Note that currently this fails matching if there are no matches from previous matchers
|
|
177
|
+
if (formatted.length >= 5) {
|
|
178
|
+
return [`dc.title="${useWordSearch ? '' : '^'}${formatted}*"`];
|
|
179
|
+
}
|
|
180
|
+
return addAuthorsToSearch(`dc.title="${useWordSearch ? '' : '^'}${formatted}*"`);
|
|
176
181
|
}
|
|
177
182
|
return [];
|
|
183
|
+
function addAuthorsToSearch(titleQuery) {
|
|
184
|
+
const [authorQuery] = bibAuthors(record);
|
|
185
|
+
if (authorQuery !== undefined) {
|
|
186
|
+
return [`${authorQuery} AND ${titleQuery}`];
|
|
187
|
+
}
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
178
190
|
function getTitle() {
|
|
179
191
|
const [field] = record.get(/^245$/u);
|
|
180
192
|
if (field) {
|
|
181
|
-
|
|
193
|
+
const titleString = field.subfields
|
|
194
|
+
//.filter(({code}) => ['a', 'b', 'n', 'p'].includes(code))
|
|
195
|
+
.filter(({
|
|
196
|
+
code
|
|
197
|
+
}) => ['a', 'b'].includes(code))
|
|
198
|
+
//.filter(({code}) => ['a'].includes(code))
|
|
199
|
+
.map(({
|
|
200
|
+
value
|
|
201
|
+
}) => (0, _matchingUtils.testStringOrNumber)(value) ? String(value) : '').filter(value => value)
|
|
202
|
+
// In Melinda's index subfield separators are indexed as ' '
|
|
203
|
+
.join(' ');
|
|
204
|
+
return titleString;
|
|
205
|
+
}
|
|
206
|
+
return false;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
function bibAuthors(record) {
|
|
210
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:candidate-search:query:bibAuthors');
|
|
211
|
+
const debugData = debug.extend('data');
|
|
212
|
+
debug(`Creating query for the first author`);
|
|
213
|
+
//debugData(record);
|
|
214
|
+
|
|
215
|
+
const author = getAuthor(record);
|
|
216
|
+
const booleanStartWords = ['and', 'or', 'nor', 'not'];
|
|
217
|
+
if ((0, _matchingUtils.testStringOrNumber)(author)) {
|
|
218
|
+
const formatted = String(author).replace(/[^\w\s\p{Alphabetic}]/gu, '')
|
|
219
|
+
// Clean up concurrent spaces from fe. subfield changes
|
|
220
|
+
.replace(/ +/gu, ' ').trim().slice(0, 30).trim();
|
|
221
|
+
|
|
222
|
+
// use word search for authors starting with a boolean
|
|
223
|
+
const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));
|
|
224
|
+
// Prevent too many matches by having a minimum length
|
|
225
|
+
debugData(`Author string: ${formatted}`);
|
|
226
|
+
if (formatted.length >= 5) {
|
|
227
|
+
return [`dc.author="${useWordSearch ? '' : '^'}${formatted}*"`];
|
|
228
|
+
}
|
|
229
|
+
return [];
|
|
230
|
+
}
|
|
231
|
+
return [];
|
|
232
|
+
function getAuthor(record) {
|
|
233
|
+
//debugData(record);
|
|
234
|
+
// eslint-disable-next-line prefer-named-capture-group
|
|
235
|
+
const [field] = record.get(/^(100)|(110)|(111)|(700)|(710)|(711)$/u);
|
|
236
|
+
//debugData(field);
|
|
237
|
+
|
|
238
|
+
if (field) {
|
|
239
|
+
const authorString = field.subfields.filter(({
|
|
182
240
|
code
|
|
183
|
-
}) => ['a'
|
|
241
|
+
}) => ['a'].includes(code)).map(({
|
|
184
242
|
value
|
|
185
243
|
}) => (0, _matchingUtils.testStringOrNumber)(value) ? String(value) : '').filter(value => value)
|
|
186
244
|
// In Melinda's index subfield separators are indexed as ' '
|
|
187
245
|
.join(' ');
|
|
246
|
+
return authorString;
|
|
188
247
|
}
|
|
189
248
|
return false;
|
|
190
249
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bib.js","names":["bibSourceIds","record","debug","createDebugLogger","debugData","extend","fSids","get","length","JSON","stringify","toSidQueries","sidStrings","getSidStrings","sidQueries","toQueries","map","toSidString","filter","nonEmptySid","field","validateSidFieldSubfieldCounts","createSidString","sfC","getSubfieldValues","sfB","cleanedSfC","removeSourcePrefix","normalizeSidSubfieldValue","cleanedSfB","concat","subfieldValue","sourcePrefixRegex","normalizedValue","testStringOrNumber","String","replace","normalizeAwayRegex","bibMelindaIds","melindaIds","getMelindaIdsF035","bibHostComponents","id","getHostId","value","subfields","find","code","test","bibTitle","title","getTitle","booleanStartWords","formatted","trim","slice","useWordSearch","some","word","toLowerCase","startsWith","includes","join","bibStandardIdentifiers","fields","identifiers","toIdentifiers","uniqueIdentifiers","Set","tag","issnIsbnReqExp","otherIdReqExp","sub"],"sources":["../../../src/candidate-search/query-list/bib.js"],"sourcesContent":["\n/**\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*/\nimport createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils';\n\n\nexport function bibSourceIds(record) {\n\n /* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records\n SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:\n\n SID__ $c 123457 $b helka\n SID__ $c (ANDL100020)1077305 $b sata\n SID__ $c VER999999 $ FI-KV\n SID__ $c /10024/508126 $ REPO_THESEUS\n\n In melinda.sourceid -index case is kept, sourceprefixes in brackets and hyphens are normalized away:\n Note: slashes are not normalized away, but a SRU-search-string including slashes needs to be quoted\n\n 1234567helka\n 1077305sata\n VER999999FIKV\n /10024/508126REPO_THESEUS\n\n Note: All Melinda records that have a matching records in a local db do NOT have SID for that local records,\n existence of a SID field depends on how the record has been added to Melinda and how it has been handled\n afterwards. SIDs are also not reliably maintained. A record might or might not have a SID for a local db\n after the matching record is removed from the local db.\n\n */\n\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:source-ids');\n const debugData = debug.extend('data');\n //const debugInfo = debug.extend('info');\n\n debug(`Creating queries for sourceid's`);\n\n const fSids = record.get('SID');\n debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);\n\n return fSids.length > 0 ? toSidQueries(fSids) : [];\n\n function toSidQueries(fSids) {\n debug(`Creating actual queries for sourceid's`);\n\n const sidStrings = getSidStrings(fSids);\n\n if (sidStrings.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n const sidQueries = toQueries(sidStrings, 'melinda.sourceid');\n\n return sidQueries;\n\n function getSidStrings(fSids) {\n debug(`Getting Sid strings from SID fields`);\n\n // Map SID fields to valid sidStrings, filter out empty strings\n const sidStrings = fSids.map(toSidString).filter(nonEmptySid => nonEmptySid);\n return sidStrings;\n\n function toSidString(field) {\n debug(`Getting string from a field`);\n\n return validateSidFieldSubfieldCounts(field) ? createSidString(field) : '';\n\n function createSidString(field) {\n debug(`Creating string from a field`);\n const [sfC] = getSubfieldValues(field, 'c');\n const [sfB] = getSubfieldValues(field, 'b');\n\n const cleanedSfC = removeSourcePrefix(normalizeSidSubfieldValue(sfC));\n const cleanedSfB = normalizeSidSubfieldValue(sfB);\n\n debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);\n return cleanedSfC.concat(cleanedSfB);\n }\n\n function removeSourcePrefix(subfieldValue) {\n const sourcePrefixRegex = (/^(?<sourcePrefix>\\([A-Za-z0-9-]+\\))(?<id>.+)$/u);\n const normalizedValue = testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(sourcePrefixRegex, '$<id>') : '';\n debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);\n return normalizedValue;\n }\n\n function normalizeSidSubfieldValue(subfieldValue) {\n debugData(`Normalizing ${subfieldValue}`);\n const normalizeAwayRegex = (/[- ]/u);\n return testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(normalizeAwayRegex, '') : '';\n }\n\n }\n }\n }\n}\n\nexport function bibMelindaIds(record) {\n // Melinda's SRU-index melinda.melindaid includes f001 controlnumbers and old Melinda-IDs from f035z's for all non-deleted Melinda-records\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibMelindaIds');\n const debugData = debug.extend('data');\n debug(`Creating queries for MelindaIds`);\n\n // Note: Melinda-ID's for search queries are created just from records f035a's and f035z's\n // Both (FI-MELINDA)- and FCC-prefixed forms are found\n // f001 controlnumber is not currently included, even if record's f003 is FI-MELINDA\n const melindaIds = getMelindaIdsF035(record);\n\n debugData(`Unique identifiers (${melindaIds.length}): ${JSON.stringify(melindaIds)}`);\n\n if (melindaIds.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(melindaIds, 'melinda.melindaid');\n}\n\n\n// bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05\n// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?\nexport function bibHostComponents(record) {\n const id = getHostId();\n return testStringOrNumber(id) ? [`melinda.partsofhost=${id}`] : [];\n\n function getHostId() {\n const [field] = record.get(/^773$/u);\n\n if (field) {\n const {value} = field.subfields.find(({code}) => code === 'w') || {};\n\n if (testStringOrNumber(value) && (/^\\(FI-MELINDA\\)/u).test(String(value))) {\n return String(value).replace(/^\\(FI-MELINDA\\)/u, '');\n }\n\n if (testStringOrNumber(value) && (/^\\(FIN01\\)/u).test(String(value))) {\n return String(value).replace(/^\\(FIN01\\)/u, '');\n }\n\n return false;\n }\n return false;\n }\n}\n\n// SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to\n// (probably) to *headings* index TIT\n// - Aleph cannot currently handle headings searches starting with a boolean - in these cases use word search\n\n// Headings index TIT drops articles etc. from the start of the title according to the filing indicator\n// Currently filing indicator is not implemented - if the title starts with an article and the Melinda\n// record is correctly catalogued using a filing indicator -> dc.title search won't match\n\nexport function bibTitle(record) {\n const title = getTitle();\n const booleanStartWords = ['and', 'or', 'nor', 'not'];\n\n if (testStringOrNumber(title)) {\n const formatted = String(title)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for titles starting with a boolean\n const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));\n // Prevent too many matches by having a minimum length requirement\n return formatted.length >= 5 ? [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`] : [];\n }\n\n return [];\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n return field.subfields\n .filter(({code}) => ['a', 'b'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n }\n return false;\n }\n}\n\nexport function bibStandardIdentifiers(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');\n const debugData = debug.extend('data');\n debug(`Creating queries for standard identifiers`);\n\n const fields = record.get(/^(?<def>020|022|024)$/u);\n const identifiers = [].concat(...fields.map(toIdentifiers));\n const uniqueIdentifiers = [...new Set(identifiers)];\n\n debugData(`Standard identifier fields: ${JSON.stringify(fields)}`);\n debugData(`Identifiers (${identifiers.length}): ${JSON.stringify(identifiers)}`);\n debugData(`Unique identifiers (${uniqueIdentifiers.length}): ${JSON.stringify(uniqueIdentifiers)}`);\n\n if (uniqueIdentifiers.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(uniqueIdentifiers, 'dc.identifier');\n\n function toIdentifiers({tag, subfields}) {\n const issnIsbnReqExp = (/^[A-Za-z0-9-]+$/u);\n const otherIdReqExp = (/^[A-Za-z0-9-:]+$/u);\n\n if (tag === '022') {\n return subfields\n .filter(sub => ['a', 'z', 'y'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n if (tag === '020') {\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n}\n"],"mappings":";;;;;;;;;;AA4BA;AACA;AACA;AAA8H;AA7B9H;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;;AAMO,SAASA,YAAY,CAACC,MAAM,EAAE;EAEnC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;EAQE,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAC,qEAAqE,CAAC;EACtG,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;EACtC;;EAEAH,KAAK,CAAE,iCAAgC,CAAC;EAExC,MAAMI,KAAK,GAAGL,MAAM,CAACM,GAAG,CAAC,KAAK,CAAC;EAC/BH,SAAS,CAAE,eAAcE,KAAK,CAACE,MAAO,MAAKC,IAAI,CAACC,SAAS,CAACJ,KAAK,CAAE,EAAC,CAAC;EAEnE,OAAOA,KAAK,CAACE,MAAM,GAAG,CAAC,GAAGG,YAAY,CAACL,KAAK,CAAC,GAAG,EAAE;EAElD,SAASK,YAAY,CAACL,KAAK,EAAE;IAC3BJ,KAAK,CAAE,wCAAuC,CAAC;IAE/C,MAAMU,UAAU,GAAGC,aAAa,CAACP,KAAK,CAAC;IAEvC,IAAIM,UAAU,CAACJ,MAAM,GAAG,CAAC,EAAE;MACzBN,KAAK,CAAE,2CAA0C,CAAC;MAClD,OAAO,EAAE;IACX;IAEA,MAAMY,UAAU,GAAG,IAAAC,+BAAS,EAACH,UAAU,EAAE,kBAAkB,CAAC;IAE5D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CAAC,CAAC;IACpC;IAEA,OAAOC,SAAS,CACb3B,MAAM,CAACsD,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACX,QAAQ,CAACW,GAAG,CAACzB,IAAI,CAAC,IAAI,IAAAb,iCAAkB,EAACsC,GAAG,CAAC5B,KAAK,CAAC,IAAI2B,aAAa,CAACvB,IAAI,CAACb,MAAM,CAACqC,GAAG,CAAC5B,KAAK,CAAC,CAAC,CAAC,CACtH5B,GAAG,CAAC,CAAC;MAAC4B;IAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;EACpC;AACF"}
|
|
1
|
+
{"version":3,"file":"bib.js","names":["bibSourceIds","record","debug","createDebugLogger","debugData","extend","fSids","get","length","JSON","stringify","toSidQueries","sidStrings","getSidStrings","sidQueries","toQueries","map","toSidString","filter","nonEmptySid","field","validateSidFieldSubfieldCounts","createSidString","sfC","getSubfieldValues","sfB","cleanedSfC","removeSourcePrefix","normalizeSidSubfieldValue","cleanedSfB","concat","subfieldValue","sourcePrefixRegex","normalizedValue","testStringOrNumber","String","replace","normalizeAwayRegex","bibMelindaIds","melindaIds","getMelindaIdsF035","bibHostComponents","id","getHostId","value","subfields","find","code","test","bibTitle","title","getTitle","booleanStartWords","formatted","trim","slice","useWordSearch","some","word","toLowerCase","startsWith","addAuthorsToSearch","titleQuery","authorQuery","bibAuthors","undefined","titleString","includes","join","author","getAuthor","authorString","bibStandardIdentifiers","fields","identifiers","toIdentifiers","uniqueIdentifiers","Set","tag","issnIsbnReqExp","otherIdReqExp","sub"],"sources":["../../../src/candidate-search/query-list/bib.js"],"sourcesContent":["\n/**\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*/\nimport createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils';\n\n\nexport function bibSourceIds(record) {\n\n /* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records\n SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:\n\n SID__ $c 123457 $b helka\n SID__ $c (ANDL100020)1077305 $b sata\n SID__ $c VER999999 $ FI-KV\n SID__ $c /10024/508126 $ REPO_THESEUS\n\n In melinda.sourceid -index case is kept, sourceprefixes in brackets and hyphens are normalized away:\n Note: slashes are not normalized away, but a SRU-search-string including slashes needs to be quoted\n\n 1234567helka\n 1077305sata\n VER999999FIKV\n /10024/508126REPO_THESEUS\n\n Note: All Melinda records that have a matching records in a local db do NOT have SID for that local records,\n existence of a SID field depends on how the record has been added to Melinda and how it has been handled\n afterwards. SIDs are also not reliably maintained. A record might or might not have a SID for a local db\n after the matching record is removed from the local db.\n\n */\n\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:source-ids');\n const debugData = debug.extend('data');\n //const debugInfo = debug.extend('info');\n\n debug(`Creating queries for sourceid's`);\n\n const fSids = record.get('SID');\n debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);\n\n return fSids.length > 0 ? toSidQueries(fSids) : [];\n\n function toSidQueries(fSids) {\n debug(`Creating actual queries for sourceid's`);\n\n const sidStrings = getSidStrings(fSids);\n\n if (sidStrings.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n const sidQueries = toQueries(sidStrings, 'melinda.sourceid');\n\n return sidQueries;\n\n function getSidStrings(fSids) {\n debug(`Getting Sid strings from SID fields`);\n\n // Map SID fields to valid sidStrings, filter out empty strings\n const sidStrings = fSids.map(toSidString).filter(nonEmptySid => nonEmptySid);\n return sidStrings;\n\n function toSidString(field) {\n debug(`Getting string from a field`);\n\n return validateSidFieldSubfieldCounts(field) ? createSidString(field) : '';\n\n function createSidString(field) {\n debug(`Creating string from a field`);\n const [sfC] = getSubfieldValues(field, 'c');\n const [sfB] = getSubfieldValues(field, 'b');\n\n const cleanedSfC = removeSourcePrefix(normalizeSidSubfieldValue(sfC));\n const cleanedSfB = normalizeSidSubfieldValue(sfB);\n\n debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);\n return cleanedSfC.concat(cleanedSfB);\n }\n\n function removeSourcePrefix(subfieldValue) {\n const sourcePrefixRegex = (/^(?<sourcePrefix>\\([A-Za-z0-9-]+\\))(?<id>.+)$/u);\n const normalizedValue = testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(sourcePrefixRegex, '$<id>') : '';\n debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);\n return normalizedValue;\n }\n\n function normalizeSidSubfieldValue(subfieldValue) {\n debugData(`Normalizing ${subfieldValue}`);\n const normalizeAwayRegex = (/[- ]/u);\n return testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(normalizeAwayRegex, '') : '';\n }\n\n }\n }\n }\n}\n\nexport function bibMelindaIds(record) {\n // Melinda's SRU-index melinda.melindaid includes f001 controlnumbers and old Melinda-IDs from f035z's for all non-deleted Melinda-records\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibMelindaIds');\n const debugData = debug.extend('data');\n debug(`Creating queries for MelindaIds`);\n\n // Note: Melinda-ID's for search queries are created just from records f035a's and f035z's\n // Both (FI-MELINDA)- and FCC-prefixed forms are found\n // f001 controlnumber is not currently included, even if record's f003 is FI-MELINDA\n const melindaIds = getMelindaIdsF035(record);\n\n debugData(`Unique identifiers (${melindaIds.length}): ${JSON.stringify(melindaIds)}`);\n\n if (melindaIds.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(melindaIds, 'melinda.melindaid');\n}\n\n\n// bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05\n// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?\nexport function bibHostComponents(record) {\n const id = getHostId();\n return testStringOrNumber(id) ? [`melinda.partsofhost=${id}`] : [];\n\n function getHostId() {\n const [field] = record.get(/^773$/u);\n\n if (field) {\n const {value} = field.subfields.find(({code}) => code === 'w') || {};\n\n if (testStringOrNumber(value) && (/^\\(FI-MELINDA\\)/u).test(String(value))) {\n return String(value).replace(/^\\(FI-MELINDA\\)/u, '');\n }\n\n if (testStringOrNumber(value) && (/^\\(FIN01\\)/u).test(String(value))) {\n return String(value).replace(/^\\(FIN01\\)/u, '');\n }\n\n return false;\n }\n return false;\n }\n}\n\n// SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to\n// (probably) to *headings* index TIT\n// - Aleph cannot currently handle headings searches starting with a boolean - in these cases use word search\n\n// Headings index TIT drops articles etc. from the start of the title according to the filing indicator\n// Currently filing indicator is not implemented - if the title starts with an article and the Melinda\n// record is correctly catalogued using a filing indicator -> dc.title search won't match\n\nexport function bibTitle(record) {\n const title = getTitle();\n const booleanStartWords = ['and', 'or', 'nor', 'not'];\n\n if (testStringOrNumber(title)) {\n const formatted = String(title)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for titles starting with a boolean\n const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));\n // Prevent too many matches by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= 5) {\n return [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n return addAuthorsToSearch(`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`);\n }\n\n return [];\n\n function addAuthorsToSearch(titleQuery) {\n const [authorQuery] = bibAuthors(record);\n if (authorQuery !== undefined) {\n return [`${authorQuery} AND ${titleQuery}`];\n }\n return [];\n }\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n const titleString = field.subfields\n //.filter(({code}) => ['a', 'b', 'n', 'p'].includes(code))\n .filter(({code}) => ['a', 'b'].includes(code))\n //.filter(({code}) => ['a'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return titleString;\n }\n return false;\n }\n}\n\nexport function bibAuthors(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibAuthors');\n const debugData = debug.extend('data');\n debug(`Creating query for the first author`);\n //debugData(record);\n\n const author = getAuthor(record);\n const booleanStartWords = ['and', 'or', 'nor', 'not'];\n\n\n if (testStringOrNumber(author)) {\n const formatted = String(author)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for authors starting with a boolean\n const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));\n // Prevent too many matches by having a minimum length\n debugData(`Author string: ${formatted}`);\n if (formatted.length >= 5) {\n return [`dc.author=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n return [];\n }\n\n return [];\n\n function getAuthor(record) {\n //debugData(record);\n // eslint-disable-next-line prefer-named-capture-group\n const [field] = record.get(/^(100)|(110)|(111)|(700)|(710)|(711)$/u);\n //debugData(field);\n\n if (field) {\n const authorString = field.subfields\n .filter(({code}) => ['a'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return authorString;\n }\n return false;\n }\n}\n\n\nexport function bibStandardIdentifiers(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');\n const debugData = debug.extend('data');\n debug(`Creating queries for standard identifiers`);\n\n const fields = record.get(/^(?<def>020|022|024)$/u);\n const identifiers = [].concat(...fields.map(toIdentifiers));\n const uniqueIdentifiers = [...new Set(identifiers)];\n\n debugData(`Standard identifier fields: ${JSON.stringify(fields)}`);\n debugData(`Identifiers (${identifiers.length}): ${JSON.stringify(identifiers)}`);\n debugData(`Unique identifiers (${uniqueIdentifiers.length}): ${JSON.stringify(uniqueIdentifiers)}`);\n\n if (uniqueIdentifiers.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(uniqueIdentifiers, 'dc.identifier');\n\n function toIdentifiers({tag, subfields}) {\n const issnIsbnReqExp = (/^[A-Za-z0-9-]+$/u);\n const otherIdReqExp = (/^[A-Za-z0-9-:]+$/u);\n\n if (tag === '022') {\n return subfields\n .filter(sub => ['a', 'z', 'y'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n if (tag === '020') {\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n}\n"],"mappings":";;;;;;;;;;;AA4BA;AACA;AACA;AAA8H;AA7B9H;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;;AAMO,SAASA,YAAY,CAACC,MAAM,EAAE;EAE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C+D,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACd,QAAQ,CAACc,GAAG,CAAClC,IAAI,CAAC,IAAI,IAAAb,iCAAkB,EAAC+C,GAAG,CAACrC,KAAK,CAAC,IAAImC,cAAc,CAAC/B,IAAI,CAACb,MAAM,CAAC8C,GAAG,CAACrC,KAAK,CAAC,CAAC,CAAC,CACvH5B,GAAG,CAAC,CAAC;QAAC4B;MAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;IACpC;IAEA,OAAOC,SAAS,CACb3B,MAAM,CAAC+D,GAAG,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,CAACd,QAAQ,CAACc,GAAG,CAAClC,IAAI,CAAC,IAAI,IAAAb,iCAAkB,EAAC+C,GAAG,CAACrC,KAAK,CAAC,IAAIoC,aAAa,CAAChC,IAAI,CAACb,MAAM,CAAC8C,GAAG,CAACrC,KAAK,CAAC,CAAC,CAAC,CACtH5B,GAAG,CAAC,CAAC;MAAC4B;IAAK,CAAC,KAAKT,MAAM,CAACS,KAAK,CAAC,CAAC;EACpC;AACF"}
|
|
@@ -5,8 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
var _standardIdentifierFactory = _interopRequireDefault(require("./standard-identifier-factory"));
|
|
8
|
-
var _isbn = require("isbn3");
|
|
9
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
10
8
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
9
|
/**
|
|
12
10
|
*
|
|
@@ -35,42 +33,18 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
35
33
|
* for the JavaScript code in this file.
|
|
36
34
|
*
|
|
37
35
|
*/
|
|
38
|
-
|
|
39
|
-
const debug = (0, _debug.default)(`@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers:ISBN`);
|
|
40
|
-
const debugData = debug.extend('data');
|
|
41
36
|
var _default = () => {
|
|
42
|
-
const IDENTIFIER_NAME = 'ISBN';
|
|
43
|
-
function validatorAndNormalizer(string) {
|
|
44
|
-
const isbnParseResult = (0, _isbn.parse)(string);
|
|
45
|
-
debugData(`isbnParseResult: ${JSON.stringify(isbnParseResult)}`);
|
|
46
|
-
if (isbnParseResult === null) {
|
|
47
|
-
debug(`Not parseable ISBN, just removing hyphens`);
|
|
48
|
-
return {
|
|
49
|
-
valid: false,
|
|
50
|
-
value: string.replace(/-/ug, '')
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
debug(`Parseable ISBN, normalizing to ISBN-13`);
|
|
54
|
-
return {
|
|
55
|
-
valid: true,
|
|
56
|
-
value: isbnParseResult.isbn13
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
37
|
const {
|
|
60
38
|
extract,
|
|
61
39
|
compare
|
|
62
40
|
} = (0, _standardIdentifierFactory.default)({
|
|
63
|
-
identifier: IDENTIFIER_NAME,
|
|
64
41
|
pattern: /^020$/u,
|
|
65
|
-
subfieldCodes: ['a', 'z']
|
|
66
|
-
validIdentifierSubfieldCodes: ['a'],
|
|
67
|
-
invalidIdentifierSubfieldCodes: ['z'],
|
|
68
|
-
validatorAndNormalizer
|
|
42
|
+
subfieldCodes: ['a', 'z']
|
|
69
43
|
});
|
|
70
44
|
return {
|
|
71
45
|
extract,
|
|
72
46
|
compare,
|
|
73
|
-
name:
|
|
47
|
+
name: 'ISBN'
|
|
74
48
|
};
|
|
75
49
|
};
|
|
76
50
|
exports.default = _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isbn.js","names":["
|
|
1
|
+
{"version":3,"file":"isbn.js","names":["extract","compare","createInterface","pattern","subfieldCodes","name"],"sources":["../../../../src/match-detection/features/bib/isbn.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\nimport createInterface from './standard-identifier-factory';\n\nexport default () => {\n const {extract, compare} = createInterface({pattern: /^020$/u, subfieldCodes: ['a', 'z']});\n return {extract, compare, name: 'ISBN'};\n};\n"],"mappings":";;;;;;AA4BA;AAA4D;AA5B5D;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;AA1BA,eA8Be,MAAM;EACnB,MAAM;IAACA,OAAO;IAAEC;EAAO,CAAC,GAAG,IAAAC,kCAAe,EAAC;IAACC,OAAO,EAAE,QAAQ;IAAEC,aAAa,EAAE,CAAC,GAAG,EAAE,GAAG;EAAC,CAAC,CAAC;EAC1F,OAAO;IAACJ,OAAO;IAAEC,OAAO;IAAEI,IAAI,EAAE;EAAM,CAAC;AACzC,CAAC;AAAA"}
|
|
@@ -7,7 +7,6 @@ exports.default = void 0;
|
|
|
7
7
|
var _debug = _interopRequireDefault(require("debug"));
|
|
8
8
|
var _matchingUtils = require("../../../matching-utils");
|
|
9
9
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
10
|
-
/* eslint-disable max-statements */
|
|
11
10
|
/**
|
|
12
11
|
*
|
|
13
12
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -35,172 +34,72 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
35
34
|
* for the JavaScript code in this file.
|
|
36
35
|
*
|
|
37
36
|
*/
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
// 2. Formally valid standardIdentifiers that are used in a wrong resource
|
|
42
|
-
// 3. Canceled standardIdentifiers
|
|
43
|
-
// Matcher could and should check that a standardIdentifier found in a subfield for a valid identifier is formally valid, and if it's not formally valid, handle it as an invalid standardIdentifier
|
|
44
|
-
// Formally valid standardIdentifiers found in subfield for invalid identifier cannot be handled as valid standardIdentifiers, because they can be a case of type 2) or 3) invalid standardIdentifiers
|
|
45
|
-
// We could also do a separate handling for formally valid an formally invalid standardIdentifiers
|
|
37
|
+
|
|
38
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');
|
|
39
|
+
const debugData = debug.extend('data');
|
|
46
40
|
var _default = ({
|
|
47
41
|
pattern,
|
|
48
|
-
subfieldCodes
|
|
49
|
-
identifier,
|
|
50
|
-
validIdentifierSubfieldCodes = ['a'],
|
|
51
|
-
invalidIdentifierSubfieldCodes = ['z'],
|
|
52
|
-
validatorAndNormalizer = undefined
|
|
42
|
+
subfieldCodes
|
|
53
43
|
}) => {
|
|
54
|
-
const debug = (0, _debug.default)(`@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers:${identifier}`);
|
|
55
|
-
const debugData = debug.extend('data');
|
|
56
44
|
return {
|
|
57
45
|
extract,
|
|
58
46
|
compare
|
|
59
47
|
};
|
|
60
48
|
function extract({
|
|
61
|
-
record
|
|
62
|
-
recordExternal
|
|
49
|
+
record
|
|
63
50
|
}) {
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
debugData(`${label}: IDs from fields (${identifiersFromFields.length}): ${JSON.stringify(identifiersFromFields)}`);
|
|
71
|
-
const allIdentifiers = identifiersFromFields.flat();
|
|
72
|
-
debugData(`${label}: Flat IDs from fields (${allIdentifiers.length}): ${JSON.stringify(allIdentifiers)}`);
|
|
73
|
-
const validatedAndNormalizedIdentifiers = validateAndNormalizeIdentifiers({
|
|
74
|
-
identifierSubs: allIdentifiers,
|
|
75
|
-
validatorAndNormalizer,
|
|
76
|
-
validIdentifierSubfieldCodes,
|
|
77
|
-
invalidIdentifierSubfieldCodes
|
|
78
|
-
});
|
|
79
|
-
const identifiers = (0, _matchingUtils.uniqueSubfields)(validatedAndNormalizedIdentifiers);
|
|
80
|
-
debugData(`${label}: Unique IDs from fields (${identifiers.length}): ${JSON.stringify(identifiers)}`);
|
|
81
|
-
return identifiers;
|
|
82
|
-
function validateAndNormalizeIdentifiers({
|
|
83
|
-
identifierSubs,
|
|
84
|
-
validatorAndNormalizer,
|
|
85
|
-
validIdentifierSubfieldCodes,
|
|
86
|
-
invalidIdentifierSubfieldCodes
|
|
87
|
-
}) {
|
|
88
|
-
if (validatorAndNormalizer) {
|
|
89
|
-
return identifierSubs.map(idSub => validateAndNormalizeIdentifier({
|
|
90
|
-
idSub,
|
|
91
|
-
validatorAndNormalizer,
|
|
92
|
-
validIdentifierSubfieldCodes,
|
|
93
|
-
invalidIdentifierSubfieldCodes
|
|
94
|
-
}));
|
|
95
|
-
}
|
|
96
|
-
return identifierSubs.map(idSub => normalizeHyphens(idSub));
|
|
97
|
-
}
|
|
98
|
-
function validateAndNormalizeIdentifier({
|
|
99
|
-
idSub,
|
|
100
|
-
validatorAndNormalizer,
|
|
101
|
-
validIdentifierSubfieldCodes,
|
|
102
|
-
invalidIdentifierSubfieldCodes
|
|
103
|
-
}) {
|
|
104
|
-
const {
|
|
105
|
-
valid,
|
|
106
|
-
value
|
|
107
|
-
} = validatorAndNormalizer(idSub.value);
|
|
108
|
-
if (validIdentifierSubfieldCodes.includes(idSub.code) && valid === false) {
|
|
109
|
-
const [code] = invalidIdentifierSubfieldCodes;
|
|
110
|
-
return {
|
|
111
|
-
code,
|
|
112
|
-
value
|
|
113
|
-
};
|
|
114
|
-
}
|
|
115
|
-
return {
|
|
116
|
-
code: idSub.code,
|
|
51
|
+
const [field] = record.get(pattern);
|
|
52
|
+
if (field) {
|
|
53
|
+
return field.subfields.filter(({
|
|
54
|
+
code
|
|
55
|
+
}) => subfieldCodes.includes(code)).map(({
|
|
56
|
+
code,
|
|
117
57
|
value
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
code: idSub.code,
|
|
123
|
-
value: idSub.value.replace(/-/ug, '')
|
|
124
|
-
};
|
|
58
|
+
}) => ({
|
|
59
|
+
code,
|
|
60
|
+
value: (0, _matchingUtils.testStringOrNumber)(value) ? String(value).replace(/-/ug, '') : ''
|
|
61
|
+
})).filter(value => value);
|
|
125
62
|
}
|
|
63
|
+
return [];
|
|
126
64
|
}
|
|
127
65
|
function compare(a, b) {
|
|
128
|
-
debug(`Comparing A and B`);
|
|
129
66
|
if (a.length === 0 || b.length === 0) {
|
|
130
|
-
debugData(`No standardidentifiers
|
|
67
|
+
debugData(`No standardidentifiers to compare`);
|
|
131
68
|
return 0;
|
|
132
69
|
}
|
|
133
|
-
debugData(`A: ${JSON.stringify(a)}`);
|
|
134
|
-
debugData(`B: ${JSON.stringify(b)}`);
|
|
135
70
|
if (bothHaveValidIdentifiers()) {
|
|
136
|
-
// Compare only valid identifiers, if both have valid idenfiers
|
|
137
71
|
const {
|
|
138
72
|
maxValues,
|
|
139
|
-
possibleMatchValues,
|
|
140
73
|
matchingValues
|
|
141
74
|
} = getValueCount(true);
|
|
142
|
-
|
|
143
|
-
debug(`Both have valid standardidentifiers (${identifier}), but none of these match.`);
|
|
144
|
-
return -0.75;
|
|
145
|
-
}
|
|
146
|
-
debug(`Both have valid standardidentifiers (${identifier}), ${matchingValues}/${possibleMatchValues} valid identifiers match.`);
|
|
147
|
-
// ignore non-matches if there is mismatching amount of values
|
|
148
|
-
debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);
|
|
149
|
-
//we give some kind of penalty for mismatching amount of values instead of simple divide?
|
|
150
|
-
const penaltyForMissing = 0.1 * (maxValues - possibleMatchValues);
|
|
151
|
-
const penaltyForMisMatch = 0.2 * (possibleMatchValues - matchingValues);
|
|
152
|
-
debug(`\t points: penaltyForMissing: ${penaltyForMissing}`);
|
|
153
|
-
debug(`\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);
|
|
154
|
-
return 0.75 - penaltyForMisMatch - penaltyForMissing;
|
|
155
|
-
//return matchingValues / possibleMatchValues * 0.75;
|
|
75
|
+
return matchingValues / maxValues * 0.75;
|
|
156
76
|
}
|
|
157
|
-
// If both do not have valid identifiers, compare all identifiers
|
|
158
77
|
const {
|
|
159
78
|
maxValues,
|
|
160
79
|
matchingValues
|
|
161
80
|
} = getValueCount();
|
|
162
|
-
debug(`Both do NOT have valid standardidentifiers (${identifier}), ${matchingValues}/${maxValues} valid/invalid identifiers match.`);
|
|
163
81
|
return matchingValues / maxValues * 0.2;
|
|
164
82
|
function bothHaveValidIdentifiers() {
|
|
165
83
|
const aValues = a.filter(({
|
|
166
84
|
code
|
|
167
|
-
}) =>
|
|
85
|
+
}) => code === 'a');
|
|
168
86
|
const bValues = a.filter(({
|
|
169
87
|
code
|
|
170
|
-
}) =>
|
|
171
|
-
debug(`A: ${aValues.length} valid ${identifier} identifiers`);
|
|
172
|
-
debug(`B: ${bValues.length} valid ${identifier} identifiers`);
|
|
88
|
+
}) => code === 'a');
|
|
173
89
|
return aValues.length > 0 && bValues.length > 0;
|
|
174
90
|
}
|
|
175
91
|
function getValueCount(validOnly = false) {
|
|
176
|
-
const aValues = getIdentifiers(a
|
|
177
|
-
const bValues = getIdentifiers(b
|
|
178
|
-
const matchingValues = getMatchingValuesAmount(aValues, bValues);
|
|
92
|
+
const aValues = getIdentifiers(a);
|
|
93
|
+
const bValues = getIdentifiers(b);
|
|
179
94
|
return {
|
|
180
95
|
maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,
|
|
181
|
-
|
|
182
|
-
possibleMatchValues: aValues.length > bValues.length ? bValues.length : aValues.length,
|
|
183
|
-
matchingValues
|
|
96
|
+
matchingValues: aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length
|
|
184
97
|
};
|
|
185
|
-
function
|
|
186
|
-
if (bValues.length > aValues.length) {
|
|
187
|
-
return aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
|
|
188
|
-
}
|
|
189
|
-
if (aValues.length > bValues.length) {
|
|
190
|
-
return bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
|
|
191
|
-
}
|
|
192
|
-
|
|
193
|
-
// If we have same amount of values, we'll check matches both ways, to avoid mixups in cases
|
|
194
|
-
// there would be duplicate values
|
|
195
|
-
const aToB = aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
|
|
196
|
-
const bToA = bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
|
|
197
|
-
return aToB < bToA ? aToB : bToA;
|
|
198
|
-
}
|
|
199
|
-
function getIdentifiers(values, validOnly) {
|
|
98
|
+
function getIdentifiers(values) {
|
|
200
99
|
if (validOnly) {
|
|
201
100
|
return values.filter(({
|
|
202
101
|
code
|
|
203
|
-
}) =>
|
|
102
|
+
}) => code === 'a').map(({
|
|
204
103
|
value
|
|
205
104
|
}) => value);
|
|
206
105
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard-identifier-factory.js","names":["pattern","subfieldCodes","identifier","validIdentifierSubfieldCodes","invalidIdentifierSubfieldCodes","validatorAndNormalizer","undefined","debug","createDebugLogger","debugData","extend","extract","compare","record","recordExternal","label","fields","get","length","identifiersFromFields","map","field","extractSubfieldsFromField","JSON","stringify","allIdentifiers","flat","validatedAndNormalizedIdentifiers","validateAndNormalizeIdentifiers","identifierSubs","identifiers","uniqueSubfields","idSub","validateAndNormalizeIdentifier","normalizeHyphens","valid","value","includes","code","replace","a","b","bothHaveValidIdentifiers","maxValues","possibleMatchValues","matchingValues","getValueCount","penaltyForMissing","penaltyForMisMatch","aValues","filter","bValues","validOnly","getIdentifiers","getMatchingValuesAmount","aValue","some","bValue","aToB","bToA","values"],"sources":["../../../../src/match-detection/features/bib/standard-identifier-factory.js"],"sourcesContent":["/* eslint-disable max-statements */\n/**\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';\nimport {extractSubfieldsFromField, uniqueSubfields} from '../../../matching-utils';\n\n// Note about validity of standardIdentifiers:\n// We have three types of invalid standardIdentifiers:\n// 1. Formally invalid standardIdentifiers (ie. typos either in the resource or the record)\n// 2. Formally valid standardIdentifiers that are used in a wrong resource\n// 3. Canceled standardIdentifiers\n\n// Matcher could and should check that a standardIdentifier found in a subfield for a valid identifier is formally valid, and if it's not formally valid, handle it as an invalid standardIdentifier\n// Formally valid standardIdentifiers found in subfield for invalid identifier cannot be handled as valid standardIdentifiers, because they can be a case of type 2) or 3) invalid standardIdentifiers\n// We could also do a separate handling for formally valid an formally invalid standardIdentifiers\n\nexport default ({pattern, subfieldCodes, identifier, validIdentifierSubfieldCodes = ['a'], invalidIdentifierSubfieldCodes = ['z'], validatorAndNormalizer = undefined}) => {\n const debug = createDebugLogger(`@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers:${identifier}`);\n const debugData = debug.extend('data');\n\n return {extract, compare};\n\n function extract({record, recordExternal}) {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n const fields = record.get(pattern);\n debugData(`${label}: ${fields.length} ${identifier}-fields `);\n\n // extractIdentifierSubfield normalizes hyphens away from the subfield values\n const identifiersFromFields = fields.map(field => extractSubfieldsFromField(field, subfieldCodes));\n debugData(`${label}: IDs from fields (${identifiersFromFields.length}): ${JSON.stringify(identifiersFromFields)}`);\n const allIdentifiers = identifiersFromFields.flat();\n debugData(`${label}: Flat IDs from fields (${allIdentifiers.length}): ${JSON.stringify(allIdentifiers)}`);\n\n const validatedAndNormalizedIdentifiers = validateAndNormalizeIdentifiers({identifierSubs: allIdentifiers, validatorAndNormalizer, validIdentifierSubfieldCodes, invalidIdentifierSubfieldCodes});\n\n const identifiers = uniqueSubfields(validatedAndNormalizedIdentifiers);\n\n debugData(`${label}: Unique IDs from fields (${identifiers.length}): ${JSON.stringify(identifiers)}`);\n return identifiers;\n\n function validateAndNormalizeIdentifiers({identifierSubs, validatorAndNormalizer, validIdentifierSubfieldCodes, invalidIdentifierSubfieldCodes}) {\n if (validatorAndNormalizer) {\n return identifierSubs.map((idSub) => validateAndNormalizeIdentifier({idSub, validatorAndNormalizer, validIdentifierSubfieldCodes, invalidIdentifierSubfieldCodes}));\n }\n return identifierSubs.map((idSub) => normalizeHyphens(idSub));\n }\n\n function validateAndNormalizeIdentifier({idSub, validatorAndNormalizer, validIdentifierSubfieldCodes, invalidIdentifierSubfieldCodes}) {\n const {valid, value} = validatorAndNormalizer(idSub.value);\n if (validIdentifierSubfieldCodes.includes(idSub.code) && valid === false) {\n const [code] = invalidIdentifierSubfieldCodes;\n return {code, value};\n }\n return {code: idSub.code, value};\n }\n\n function normalizeHyphens(idSub) {\n return {code: idSub.code, value: idSub.value.replace(/-/ug, '')};\n }\n\n\n }\n\n function compare(a, b) {\n debug(`Comparing A and B`);\n if (a.length === 0 || b.length === 0) {\n debugData(`No standardidentifiers (${identifier}) to compare`);\n return 0;\n }\n\n debugData(`A: ${JSON.stringify(a)}`);\n debugData(`B: ${JSON.stringify(b)}`);\n\n\n if (bothHaveValidIdentifiers()) {\n // Compare only valid identifiers, if both have valid idenfiers\n const {maxValues, possibleMatchValues, matchingValues} = getValueCount(true);\n if (matchingValues < 1) {\n debug(`Both have valid standardidentifiers (${identifier}), but none of these match.`);\n return -0.75;\n }\n debug(`Both have valid standardidentifiers (${identifier}), ${matchingValues}/${possibleMatchValues} valid identifiers 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 penaltyForMissing = 0.1 * (maxValues - possibleMatchValues);\n const penaltyForMisMatch = 0.2 * (possibleMatchValues - matchingValues);\n debug(`\\t points: penaltyForMissing: ${penaltyForMissing}`);\n debug(`\\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);\n\n return 0.75 - penaltyForMisMatch - penaltyForMissing;\n //return matchingValues / possibleMatchValues * 0.75;\n }\n // If both do not have valid identifiers, compare all identifiers\n const {maxValues, matchingValues} = getValueCount();\n debug(`Both do NOT have valid standardidentifiers (${identifier}), ${matchingValues}/${maxValues} valid/invalid identifiers match.`);\n\n return matchingValues / maxValues * 0.2;\n\n function bothHaveValidIdentifiers() {\n const aValues = a.filter(({code}) => validIdentifierSubfieldCodes.includes(code));\n const bValues = a.filter(({code}) => validIdentifierSubfieldCodes.includes(code));\n debug(`A: ${aValues.length} valid ${identifier} identifiers`);\n debug(`B: ${bValues.length} valid ${identifier} identifiers`);\n return aValues.length > 0 && bValues.length > 0;\n }\n\n function getValueCount(validOnly = false) {\n const aValues = getIdentifiers(a, validOnly);\n const bValues = getIdentifiers(b, validOnly);\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 function getIdentifiers(values, validOnly) {\n if (validOnly) {\n return values\n .filter(({code}) => validIdentifierSubfieldCodes.includes(code))\n .map(({value}) => value);\n }\n\n return values.map(({value}) => value);\n }\n }\n }\n};\n"],"mappings":";;;;;;AA6BA;AACA;AAAmF;AA9BnF;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;AAKA;AACA;AACA;AACA;AACA;AAEA;AACA;AACA;AAAA,eAEe,CAAC;EAACA,OAAO;EAAEC,aAAa;EAAEC,UAAU;EAAEC,4BAA4B,GAAG,CAAC,GAAG,CAAC;EAAEC,8BAA8B,GAAG,CAAC,GAAG,CAAC;EAAEC,sBAAsB,GAAGC;AAAS,CAAC,KAAK;EACzK,MAAMC,KAAK,GAAG,IAAAC,cAAiB,EAAE,mFAAkFN,UAAW,EAAC,CAAC;EAChI,MAAMO,SAAS,GAAGF,KAAK,CAACG,MAAM,CAAC,MAAM,CAAC;EAEtC,OAAO;IAACC,OAAO;IAAEC;EAAO,CAAC;EAEzB,SAASD,OAAO,CAAC;IAACE,MAAM;IAAEC;EAAc,CAAC,EAAE;IACzC,MAAMC,KAAK,GAAGD,cAAc,IAAIA,cAAc,CAACC,KAAK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AM,CAAC,CAAC,CAACvC,MAAM;QACvF,MAAMyC,IAAI,GAAGR,OAAO,CAACD,MAAM,CAACO,MAAM,IAAIR,OAAO,CAACO,IAAI,CAACD,MAAM,IAAIE,MAAM,KAAKF,MAAM,CAAC,CAAC,CAACrC,MAAM;QAEvF,OAAOwC,IAAI,GAAGC,IAAI,GAAGD,IAAI,GAAGC,IAAI;MAClC;MAEA,SAASN,cAAc,CAACO,MAAM,EAAER,SAAS,EAAE;QACzC,IAAIA,SAAS,EAAE;UACb,OAAOQ,MAAM,CACVV,MAAM,CAAC,CAAC;YAACZ;UAAI,CAAC,KAAKnC,4BAA4B,CAACkC,QAAQ,CAACC,IAAI,CAAC,CAAC,CAC/DlB,GAAG,CAAC,CAAC;YAACgB;UAAK,CAAC,KAAKA,KAAK,CAAC;QAC5B;QAEA,OAAOwB,MAAM,CAACxC,GAAG,CAAC,CAAC;UAACgB;QAAK,CAAC,KAAKA,KAAK,CAAC;MACvC;IACF;EACF;AACF,CAAC;AAAA"}
|
|
1
|
+
{"version":3,"file":"standard-identifier-factory.js","names":["debug","createDebugLogger","debugData","extend","pattern","subfieldCodes","extract","compare","record","field","get","subfields","filter","code","includes","map","value","testStringOrNumber","String","replace","a","b","length","bothHaveValidIdentifiers","maxValues","matchingValues","getValueCount","aValues","bValues","validOnly","getIdentifiers","aValue","some","bValue","values"],"sources":["../../../../src/match-detection/features/bib/standard-identifier-factory.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';\nimport {testStringOrNumber} from '../../../matching-utils';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');\nconst debugData = debug.extend('data');\n\nexport default ({pattern, subfieldCodes}) => {\n return {extract, compare};\n\n function extract({record}) {\n const [field] = record.get(pattern);\n\n if (field) {\n return field.subfields\n .filter(({code}) => subfieldCodes.includes(code))\n .map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value).replace(/-/ug, '') : ''}))\n .filter(value => value);\n }\n\n return [];\n }\n\n function compare(a, b) {\n if (a.length === 0 || b.length === 0) {\n debugData(`No standardidentifiers to compare`);\n return 0;\n }\n\n if (bothHaveValidIdentifiers()) {\n const {maxValues, matchingValues} = getValueCount(true);\n return matchingValues / maxValues * 0.75;\n }\n\n const {maxValues, matchingValues} = getValueCount();\n return matchingValues / maxValues * 0.2;\n\n function bothHaveValidIdentifiers() {\n const aValues = a.filter(({code}) => code === 'a');\n const bValues = a.filter(({code}) => code === 'a');\n return aValues.length > 0 && bValues.length > 0;\n }\n\n function getValueCount(validOnly = false) {\n const aValues = getIdentifiers(a);\n const bValues = getIdentifiers(b);\n\n return {\n maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,\n matchingValues: aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length\n };\n\n function getIdentifiers(values) {\n if (validOnly) {\n return values\n .filter(({code}) => code === 'a')\n .map(({value}) => value);\n }\n\n return values.map(({value}) => value);\n }\n }\n }\n};\n"],"mappings":";;;;;;AA4BA;AACA;AAA2D;AA7B3D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;A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esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.extractSubfieldsFromField = extractSubfieldsFromField;
|
|
7
6
|
exports.getMelindaIdsF035 = getMelindaIdsF035;
|
|
8
7
|
exports.getSubfieldValues = getSubfieldValues;
|
|
9
8
|
exports.testStringOrNumber = testStringOrNumber;
|
|
10
|
-
exports.uniqueSubfields = uniqueSubfields;
|
|
11
9
|
exports.validateSidFieldSubfieldCounts = validateSidFieldSubfieldCounts;
|
|
12
10
|
var _debug = _interopRequireDefault(require("debug"));
|
|
13
11
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
@@ -92,28 +90,4 @@ function testStringOrNumber(value) {
|
|
|
92
90
|
}
|
|
93
91
|
return false;
|
|
94
92
|
}
|
|
95
|
-
function extractSubfieldsFromField(field, subfieldCodes) {
|
|
96
|
-
if (field === undefined || field.subfields === undefined) {
|
|
97
|
-
return [];
|
|
98
|
-
}
|
|
99
|
-
const resultSubfields = field.subfields.filter(({
|
|
100
|
-
code
|
|
101
|
-
}) => subfieldCodes.includes(code)).map(({
|
|
102
|
-
code,
|
|
103
|
-
value
|
|
104
|
-
}) => ({
|
|
105
|
-
code,
|
|
106
|
-
value: testStringOrNumber(value) ? String(value) : ''
|
|
107
|
-
})).filter(value => value);
|
|
108
|
-
return resultSubfields;
|
|
109
|
-
}
|
|
110
|
-
function uniqueSubfields(subfields) {
|
|
111
|
-
return subfields.reduce((arr, e) => {
|
|
112
|
-
if (!arr.find(item => item.code === e.code && item.value === e.value)) {
|
|
113
|
-
const newArr = arr.concat(e);
|
|
114
|
-
return newArr;
|
|
115
|
-
}
|
|
116
|
-
return arr;
|
|
117
|
-
}, []);
|
|
118
|
-
}
|
|
119
93
|
//# 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"
|
|
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"],"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"],"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,MA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AAK,CAAC;AAC3B;AAEO,SAASD,kBAAkB,CAACC,KAAK,EAAE;EACxC,IAAI,OAAOA,KAAK,KAAK,QAAQ,IAAI,OAAOA,KAAK,KAAK,QAAQ,EAAE;IAC1D,OAAO,IAAI;EACb;EACA,OAAO,KAAK;AACd"}
|
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": "3.0.
|
|
17
|
+
"version": "3.0.3-alpha.1",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14"
|
|
@@ -41,7 +41,6 @@
|
|
|
41
41
|
"@natlibfi/melinda-commons": "^12.0.6",
|
|
42
42
|
"@natlibfi/sru-client": "^5.0.3",
|
|
43
43
|
"debug": "^4.3.4",
|
|
44
|
-
"isbn3": "^1.1.28",
|
|
45
44
|
"moment": "^2.29.4",
|
|
46
45
|
"natural": "^5.2.3",
|
|
47
46
|
"uuid": "^9.0.0",
|
|
@@ -196,27 +196,93 @@ export function bibTitle(record) {
|
|
|
196
196
|
|
|
197
197
|
// use word search for titles starting with a boolean
|
|
198
198
|
const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));
|
|
199
|
-
// Prevent too many matches by having a minimum length
|
|
200
|
-
|
|
199
|
+
// Prevent too many matches by having a minimum length
|
|
200
|
+
// Note that currently this fails matching if there are no matches from previous matchers
|
|
201
|
+
if (formatted.length >= 5) {
|
|
202
|
+
return [`dc.title="${useWordSearch ? '' : '^'}${formatted}*"`];
|
|
203
|
+
}
|
|
204
|
+
return addAuthorsToSearch(`dc.title="${useWordSearch ? '' : '^'}${formatted}*"`);
|
|
201
205
|
}
|
|
202
206
|
|
|
203
207
|
return [];
|
|
204
208
|
|
|
209
|
+
function addAuthorsToSearch(titleQuery) {
|
|
210
|
+
const [authorQuery] = bibAuthors(record);
|
|
211
|
+
if (authorQuery !== undefined) {
|
|
212
|
+
return [`${authorQuery} AND ${titleQuery}`];
|
|
213
|
+
}
|
|
214
|
+
return [];
|
|
215
|
+
}
|
|
216
|
+
|
|
205
217
|
function getTitle() {
|
|
206
218
|
const [field] = record.get(/^245$/u);
|
|
207
219
|
|
|
208
220
|
if (field) {
|
|
209
|
-
|
|
221
|
+
const titleString = field.subfields
|
|
222
|
+
//.filter(({code}) => ['a', 'b', 'n', 'p'].includes(code))
|
|
210
223
|
.filter(({code}) => ['a', 'b'].includes(code))
|
|
224
|
+
//.filter(({code}) => ['a'].includes(code))
|
|
225
|
+
.map(({value}) => testStringOrNumber(value) ? String(value) : '')
|
|
226
|
+
.filter(value => value)
|
|
227
|
+
// In Melinda's index subfield separators are indexed as ' '
|
|
228
|
+
.join(' ');
|
|
229
|
+
return titleString;
|
|
230
|
+
}
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
export function bibAuthors(record) {
|
|
236
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibAuthors');
|
|
237
|
+
const debugData = debug.extend('data');
|
|
238
|
+
debug(`Creating query for the first author`);
|
|
239
|
+
//debugData(record);
|
|
240
|
+
|
|
241
|
+
const author = getAuthor(record);
|
|
242
|
+
const booleanStartWords = ['and', 'or', 'nor', 'not'];
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
if (testStringOrNumber(author)) {
|
|
246
|
+
const formatted = String(author)
|
|
247
|
+
.replace(/[^\w\s\p{Alphabetic}]/gu, '')
|
|
248
|
+
// Clean up concurrent spaces from fe. subfield changes
|
|
249
|
+
.replace(/ +/gu, ' ')
|
|
250
|
+
.trim()
|
|
251
|
+
.slice(0, 30)
|
|
252
|
+
.trim();
|
|
253
|
+
|
|
254
|
+
// use word search for authors starting with a boolean
|
|
255
|
+
const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));
|
|
256
|
+
// Prevent too many matches by having a minimum length
|
|
257
|
+
debugData(`Author string: ${formatted}`);
|
|
258
|
+
if (formatted.length >= 5) {
|
|
259
|
+
return [`dc.author="${useWordSearch ? '' : '^'}${formatted}*"`];
|
|
260
|
+
}
|
|
261
|
+
return [];
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
return [];
|
|
265
|
+
|
|
266
|
+
function getAuthor(record) {
|
|
267
|
+
//debugData(record);
|
|
268
|
+
// eslint-disable-next-line prefer-named-capture-group
|
|
269
|
+
const [field] = record.get(/^(100)|(110)|(111)|(700)|(710)|(711)$/u);
|
|
270
|
+
//debugData(field);
|
|
271
|
+
|
|
272
|
+
if (field) {
|
|
273
|
+
const authorString = field.subfields
|
|
274
|
+
.filter(({code}) => ['a'].includes(code))
|
|
211
275
|
.map(({value}) => testStringOrNumber(value) ? String(value) : '')
|
|
212
276
|
.filter(value => value)
|
|
213
277
|
// In Melinda's index subfield separators are indexed as ' '
|
|
214
278
|
.join(' ');
|
|
279
|
+
return authorString;
|
|
215
280
|
}
|
|
216
281
|
return false;
|
|
217
282
|
}
|
|
218
283
|
}
|
|
219
284
|
|
|
285
|
+
|
|
220
286
|
export function bibStandardIdentifiers(record) {
|
|
221
287
|
|
|
222
288
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');
|
|
@@ -27,27 +27,8 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import createInterface from './standard-identifier-factory';
|
|
30
|
-
import {parse as isbnParse} from 'isbn3';
|
|
31
|
-
import createDebugLogger from 'debug';
|
|
32
|
-
|
|
33
|
-
const debug = createDebugLogger(`@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers:ISBN`);
|
|
34
|
-
const debugData = debug.extend('data');
|
|
35
30
|
|
|
36
31
|
export default () => {
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
function validatorAndNormalizer(string) {
|
|
40
|
-
const isbnParseResult = isbnParse(string);
|
|
41
|
-
debugData(`isbnParseResult: ${JSON.stringify(isbnParseResult)}`);
|
|
42
|
-
if (isbnParseResult === null) {
|
|
43
|
-
debug(`Not parseable ISBN, just removing hyphens`);
|
|
44
|
-
return {valid: false, value: string.replace(/-/ug, '')};
|
|
45
|
-
}
|
|
46
|
-
debug(`Parseable ISBN, normalizing to ISBN-13`);
|
|
47
|
-
return {valid: true, value: isbnParseResult.isbn13};
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const {extract, compare} = createInterface({identifier: IDENTIFIER_NAME, pattern: /^020$/u, subfieldCodes: ['a', 'z'], validIdentifierSubfieldCodes: ['a'], invalidIdentifierSubfieldCodes: ['z'], validatorAndNormalizer});
|
|
51
|
-
return {extract, compare, name: IDENTIFIER_NAME};
|
|
32
|
+
const {extract, compare} = createInterface({pattern: /^020$/u, subfieldCodes: ['a', 'z']});
|
|
33
|
+
return {extract, compare, name: 'ISBN'};
|
|
52
34
|
};
|
|
53
|
-
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
/* eslint-disable max-statements */
|
|
2
1
|
/**
|
|
3
2
|
*
|
|
4
3
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
@@ -28,142 +27,60 @@
|
|
|
28
27
|
*/
|
|
29
28
|
|
|
30
29
|
import createDebugLogger from 'debug';
|
|
31
|
-
import {
|
|
30
|
+
import {testStringOrNumber} from '../../../matching-utils';
|
|
32
31
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
// 1. Formally invalid standardIdentifiers (ie. typos either in the resource or the record)
|
|
36
|
-
// 2. Formally valid standardIdentifiers that are used in a wrong resource
|
|
37
|
-
// 3. Canceled standardIdentifiers
|
|
38
|
-
|
|
39
|
-
// Matcher could and should check that a standardIdentifier found in a subfield for a valid identifier is formally valid, and if it's not formally valid, handle it as an invalid standardIdentifier
|
|
40
|
-
// Formally valid standardIdentifiers found in subfield for invalid identifier cannot be handled as valid standardIdentifiers, because they can be a case of type 2) or 3) invalid standardIdentifiers
|
|
41
|
-
// We could also do a separate handling for formally valid an formally invalid standardIdentifiers
|
|
42
|
-
|
|
43
|
-
export default ({pattern, subfieldCodes, identifier, validIdentifierSubfieldCodes = ['a'], invalidIdentifierSubfieldCodes = ['z'], validatorAndNormalizer = undefined}) => {
|
|
44
|
-
const debug = createDebugLogger(`@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers:${identifier}`);
|
|
45
|
-
const debugData = debug.extend('data');
|
|
32
|
+
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');
|
|
33
|
+
const debugData = debug.extend('data');
|
|
46
34
|
|
|
35
|
+
export default ({pattern, subfieldCodes}) => {
|
|
47
36
|
return {extract, compare};
|
|
48
37
|
|
|
49
|
-
function extract({record
|
|
50
|
-
const
|
|
51
|
-
const fields = record.get(pattern);
|
|
52
|
-
debugData(`${label}: ${fields.length} ${identifier}-fields `);
|
|
53
|
-
|
|
54
|
-
// extractIdentifierSubfield normalizes hyphens away from the subfield values
|
|
55
|
-
const identifiersFromFields = fields.map(field => extractSubfieldsFromField(field, subfieldCodes));
|
|
56
|
-
debugData(`${label}: IDs from fields (${identifiersFromFields.length}): ${JSON.stringify(identifiersFromFields)}`);
|
|
57
|
-
const allIdentifiers = identifiersFromFields.flat();
|
|
58
|
-
debugData(`${label}: Flat IDs from fields (${allIdentifiers.length}): ${JSON.stringify(allIdentifiers)}`);
|
|
59
|
-
|
|
60
|
-
const validatedAndNormalizedIdentifiers = validateAndNormalizeIdentifiers({identifierSubs: allIdentifiers, validatorAndNormalizer, validIdentifierSubfieldCodes, invalidIdentifierSubfieldCodes});
|
|
38
|
+
function extract({record}) {
|
|
39
|
+
const [field] = record.get(pattern);
|
|
61
40
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
function validateAndNormalizeIdentifiers({identifierSubs, validatorAndNormalizer, validIdentifierSubfieldCodes, invalidIdentifierSubfieldCodes}) {
|
|
68
|
-
if (validatorAndNormalizer) {
|
|
69
|
-
return identifierSubs.map((idSub) => validateAndNormalizeIdentifier({idSub, validatorAndNormalizer, validIdentifierSubfieldCodes, invalidIdentifierSubfieldCodes}));
|
|
70
|
-
}
|
|
71
|
-
return identifierSubs.map((idSub) => normalizeHyphens(idSub));
|
|
41
|
+
if (field) {
|
|
42
|
+
return field.subfields
|
|
43
|
+
.filter(({code}) => subfieldCodes.includes(code))
|
|
44
|
+
.map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value).replace(/-/ug, '') : ''}))
|
|
45
|
+
.filter(value => value);
|
|
72
46
|
}
|
|
73
47
|
|
|
74
|
-
|
|
75
|
-
const {valid, value} = validatorAndNormalizer(idSub.value);
|
|
76
|
-
if (validIdentifierSubfieldCodes.includes(idSub.code) && valid === false) {
|
|
77
|
-
const [code] = invalidIdentifierSubfieldCodes;
|
|
78
|
-
return {code, value};
|
|
79
|
-
}
|
|
80
|
-
return {code: idSub.code, value};
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
function normalizeHyphens(idSub) {
|
|
84
|
-
return {code: idSub.code, value: idSub.value.replace(/-/ug, '')};
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
|
|
48
|
+
return [];
|
|
88
49
|
}
|
|
89
50
|
|
|
90
51
|
function compare(a, b) {
|
|
91
|
-
debug(`Comparing A and B`);
|
|
92
52
|
if (a.length === 0 || b.length === 0) {
|
|
93
|
-
debugData(`No standardidentifiers
|
|
53
|
+
debugData(`No standardidentifiers to compare`);
|
|
94
54
|
return 0;
|
|
95
55
|
}
|
|
96
56
|
|
|
97
|
-
debugData(`A: ${JSON.stringify(a)}`);
|
|
98
|
-
debugData(`B: ${JSON.stringify(b)}`);
|
|
99
|
-
|
|
100
|
-
|
|
101
57
|
if (bothHaveValidIdentifiers()) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (matchingValues < 1) {
|
|
105
|
-
debug(`Both have valid standardidentifiers (${identifier}), but none of these match.`);
|
|
106
|
-
return -0.75;
|
|
107
|
-
}
|
|
108
|
-
debug(`Both have valid standardidentifiers (${identifier}), ${matchingValues}/${possibleMatchValues} valid identifiers match.`);
|
|
109
|
-
// ignore non-matches if there is mismatching amount of values
|
|
110
|
-
debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);
|
|
111
|
-
//we give some kind of penalty for mismatching amount of values instead of simple divide?
|
|
112
|
-
const penaltyForMissing = 0.1 * (maxValues - possibleMatchValues);
|
|
113
|
-
const penaltyForMisMatch = 0.2 * (possibleMatchValues - matchingValues);
|
|
114
|
-
debug(`\t points: penaltyForMissing: ${penaltyForMissing}`);
|
|
115
|
-
debug(`\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);
|
|
116
|
-
|
|
117
|
-
return 0.75 - penaltyForMisMatch - penaltyForMissing;
|
|
118
|
-
//return matchingValues / possibleMatchValues * 0.75;
|
|
58
|
+
const {maxValues, matchingValues} = getValueCount(true);
|
|
59
|
+
return matchingValues / maxValues * 0.75;
|
|
119
60
|
}
|
|
120
|
-
// If both do not have valid identifiers, compare all identifiers
|
|
121
|
-
const {maxValues, matchingValues} = getValueCount();
|
|
122
|
-
debug(`Both do NOT have valid standardidentifiers (${identifier}), ${matchingValues}/${maxValues} valid/invalid identifiers match.`);
|
|
123
61
|
|
|
62
|
+
const {maxValues, matchingValues} = getValueCount();
|
|
124
63
|
return matchingValues / maxValues * 0.2;
|
|
125
64
|
|
|
126
65
|
function bothHaveValidIdentifiers() {
|
|
127
|
-
const aValues = a.filter(({code}) =>
|
|
128
|
-
const bValues = a.filter(({code}) =>
|
|
129
|
-
debug(`A: ${aValues.length} valid ${identifier} identifiers`);
|
|
130
|
-
debug(`B: ${bValues.length} valid ${identifier} identifiers`);
|
|
66
|
+
const aValues = a.filter(({code}) => code === 'a');
|
|
67
|
+
const bValues = a.filter(({code}) => code === 'a');
|
|
131
68
|
return aValues.length > 0 && bValues.length > 0;
|
|
132
69
|
}
|
|
133
70
|
|
|
134
71
|
function getValueCount(validOnly = false) {
|
|
135
|
-
const aValues = getIdentifiers(a
|
|
136
|
-
const bValues = getIdentifiers(b
|
|
137
|
-
|
|
138
|
-
const matchingValues = getMatchingValuesAmount(aValues, bValues);
|
|
72
|
+
const aValues = getIdentifiers(a);
|
|
73
|
+
const bValues = getIdentifiers(b);
|
|
139
74
|
|
|
140
75
|
return {
|
|
141
76
|
maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,
|
|
142
|
-
|
|
143
|
-
possibleMatchValues: aValues.length > bValues.length ? bValues.length : aValues.length,
|
|
144
|
-
matchingValues
|
|
77
|
+
matchingValues: aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length
|
|
145
78
|
};
|
|
146
79
|
|
|
147
|
-
function
|
|
148
|
-
if (bValues.length > aValues.length) {
|
|
149
|
-
return aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
|
|
150
|
-
}
|
|
151
|
-
if (aValues.length > bValues.length) {
|
|
152
|
-
return bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
// If we have same amount of values, we'll check matches both ways, to avoid mixups in cases
|
|
156
|
-
// there would be duplicate values
|
|
157
|
-
const aToB = aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length;
|
|
158
|
-
const bToA = bValues.filter(bValue => aValues.some(aValue => bValue === aValue)).length;
|
|
159
|
-
|
|
160
|
-
return aToB < bToA ? aToB : bToA;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
function getIdentifiers(values, validOnly) {
|
|
80
|
+
function getIdentifiers(values) {
|
|
164
81
|
if (validOnly) {
|
|
165
82
|
return values
|
|
166
|
-
.filter(({code}) =>
|
|
83
|
+
.filter(({code}) => code === 'a')
|
|
167
84
|
.map(({value}) => value);
|
|
168
85
|
}
|
|
169
86
|
|
package/src/matching-utils.js
CHANGED
|
@@ -92,24 +92,3 @@ export function testStringOrNumber(value) {
|
|
|
92
92
|
}
|
|
93
93
|
return false;
|
|
94
94
|
}
|
|
95
|
-
|
|
96
|
-
export function extractSubfieldsFromField(field, subfieldCodes) {
|
|
97
|
-
if (field === undefined || field.subfields === undefined) {
|
|
98
|
-
return [];
|
|
99
|
-
}
|
|
100
|
-
const resultSubfields = field.subfields
|
|
101
|
-
.filter(({code}) => subfieldCodes.includes(code))
|
|
102
|
-
.map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value) : ''}))
|
|
103
|
-
.filter(value => value);
|
|
104
|
-
return resultSubfields;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function uniqueSubfields(subfields) {
|
|
108
|
-
return subfields.reduce((arr, e) => {
|
|
109
|
-
if (!arr.find(item => item.code === e.code && item.value === e.value)) {
|
|
110
|
-
const newArr = arr.concat(e);
|
|
111
|
-
return newArr;
|
|
112
|
-
}
|
|
113
|
-
return arr;
|
|
114
|
-
}, []);
|
|
115
|
-
}
|