@natlibfi/melinda-record-matching 2.1.0 → 2.2.0-alpha.3
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/index.js +40 -10
- package/dist/candidate-search/index.js.map +1 -1
- package/dist/candidate-search/index.spec.js +16 -2
- package/dist/candidate-search/index.spec.js.map +1 -1
- package/dist/candidate-search/query-list/bib.js +2 -2
- package/dist/candidate-search/query-list/bib.js.map +1 -1
- package/dist/index.js +139 -39
- package/dist/index.js.map +1 -1
- package/dist/index.spec.js +12 -6
- package/dist/index.spec.js.map +1 -1
- package/dist/match-detection/features/bib/authors.js +1 -1
- package/dist/match-detection/features/bib/authors.js.map +1 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js +3 -2
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -1
- package/dist/match-detection/index.js +36 -30
- package/dist/match-detection/index.js.map +1 -1
- package/dist/match-detection/index.spec.js +20 -2
- package/dist/match-detection/index.spec.js.map +1 -1
- package/dist/matching-utils.js +1 -1
- package/dist/matching-utils.js.map +1 -1
- package/package.json +16 -15
- package/src/candidate-search/index.js +36 -14
- package/src/candidate-search/index.spec.js +13 -3
- package/src/candidate-search/query-list/bib.js +2 -2
- package/src/index.js +94 -35
- package/src/index.spec.js +10 -6
- package/src/match-detection/features/bib/authors.js +1 -1
- package/src/match-detection/features/bib/standard-identifier-factory.js +2 -1
- package/src/match-detection/index.js +29 -19
- package/src/match-detection/index.spec.js +17 -3
- package/src/matching-utils.js +1 -1
package/dist/index.spec.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.spec.js"],"names":["debug","debugData","extend","describe","callback","path","__dirname","recurse","fixura","reader","READERS","JSON","getFixture","options","enabled","expectedMatchStatus","expectedStopReason","record","MarcRecord","subfieldValues","expectedMatches","expectedNonMatches","match","formatOptions","matches","matchStatus","nonMatches","length","status","stopReason","
|
|
1
|
+
{"version":3,"sources":["../src/index.spec.js"],"names":["debug","debugData","extend","describe","callback","path","__dirname","recurse","fixura","reader","READERS","JSON","getFixture","options","enabled","expectedMatchStatus","expectedStopReason","expectedFailures","record","MarcRecord","subfieldValues","expectedMatches","expectedNonMatches","match","formatOptions","matches","matchStatus","nonMatches","conversionFailures","length","status","stopReason","to","eql","formattedMatchResult","formatRecordResults","formattedNonMatchResult","contextFeatures","matchDetection","features","detection","strategy","type","search","detect","map","v","stringify","candidate","formatCandidate","id","newId","newRecord","toObject"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAjCA;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;AASA,MAAMA,KAAK,GAAG,oBAAkB,8CAAlB,CAAd;AACA,MAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB;AAEAC,QAAQ,CAAC,OAAD,EAAU,MAAM;AACtB,kCAAc;AACZC,IAAAA,QADY;AAEZC,IAAAA,IAAI,EAAE,CAACC,SAAD,EAAY,IAAZ,EAAkB,eAAlB,EAAmC,OAAnC,CAFM;AAGZC,IAAAA,OAAO,EAAE,KAHG;AAIZC,IAAAA,MAAM,EAAE;AACNC,MAAAA,MAAM,EAAEC,gBAAQC;AADV;AAJI,GAAd;;AASA,iBAAeP,QAAf,CAAwB;AAACQ,IAAAA,UAAD;AAAaC,IAAAA,OAAb;AAAsBC,IAAAA,OAAO,GAAG,IAAhC;AAAsCC,IAAAA,mBAAtC;AAA2DC,IAAAA,kBAA3D;AAA+EC,IAAAA;AAA/E,GAAxB,EAA0H;AAExH,QAAI,CAACH,OAAL,EAAc;AACZd,MAAAA,KAAK,CAAE,gBAAF,CAAL;AACA;AACD;;AAED,UAAMkB,MAAM,GAAG,IAAIC,sBAAJ,CAAeP,UAAU,CAAC,kBAAD,CAAzB,EAA+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lB,CAA2BC,IAAnD,CAAxB;AAEA,aAAO,EACL,GAAG7B,OADE;AAEL8B,QAAAA,MAAM,EAAE,EACN,GAAG9B,OAAO,CAAC8B;AADL,SAFH;AAKLH,QAAAA,SAAS,EAAE,EACT,GAAG3B,OAAO,CAAC+B,MADF;AAETH,UAAAA,QAAQ,EAAE5B,OAAO,CAAC2B,SAAR,CAAkBC,QAAlB,CAA2BF,QAA3B,CAAoCM,GAApC,CAAwCC,CAAC,IAAIT,eAAe,CAACS,CAAD,CAAf,EAA7C;AAFD;AALN,OAAP;AAUD;;AAED,aAASX,mBAAT,CAA6BV,OAA7B,EAAsC;AACpC,UAAIA,OAAJ,EAAa;AACXxB,QAAAA,SAAS,CAACU,IAAI,CAACoC,SAAL,CAAetB,OAAf,CAAD,CAAT;AACA,eAAOA,OAAO,CAACoB,GAAR,CAAatB,KAAD,KAAY,EAC7B,GAAGA,KAD0B;AAE7ByB,UAAAA,SAAS,EAAEC,eAAe,CAAC1B,KAAK,CAACyB,SAAP;AAFG,SAAZ,CAAZ,CAAP;AAID;;AACD,aAAO,EAAP;AACD,KAtDuH,CAwDxH;;;AACA,aAASC,eAAT,CAAyB;AAACC,MAAAA,EAAD;AAAKhC,MAAAA;AAAL,KAAzB,EAAuC;AACrC,YAAMiC,KAAK,GAAGD,EAAd;AACA,YAAME,SAAS,GAAGlC,MAAlB;AACA,aAAO;AACLgC,QAAAA,EAAE,EAAEC,KADC;AAELjC,QAAAA,MAAM,EAAEkC,SAAS,CAACC,QAAV;AAFH,OAAP;AAID;AAGF;AAEF,CA/EO,CAAR","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 {expect} from 'chai';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen-http-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport createMatchInterface, {matchDetection} from '.';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:index:test');\nconst debugData = debug.extend('data');\n\ndescribe('INDEX', () => {\n generateTests({\n callback,\n path: [__dirname, '..', 'test-fixtures', 'index'],\n recurse: false,\n fixura: {\n reader: READERS.JSON\n }\n });\n\n async function callback({getFixture, options, enabled = true, expectedMatchStatus, expectedStopReason, expectedFailures}) {\n\n if (!enabled) {\n debug(`Disabled test!`);\n return;\n }\n\n const record = new MarcRecord(getFixture('inputRecord.json'), {subfieldValues: false});\n const expectedMatches = getFixture('expectedMatches.json');\n const expectedNonMatches = getFixture('expectedNonMatches.json') || [];\n\n\n const match = createMatchInterface(formatOptions());\n const {matches, matchStatus, nonMatches, conversionFailures} = await match(record);\n debugData(`Matches: ${matches.length}, Status: ${matchStatus.status}/${matchStatus.stopReason}, NonMatches: ${nonMatches ? nonMatches.length : 'not returned'}, ConversionFailures: ${conversionFailures ? conversionFailures.length : 'not returned'}`);\n\n expect(matchStatus.status).to.eql(expectedMatchStatus);\n expect(matchStatus.stopReason).to.eql(expectedStopReason);\n\n const formattedMatchResult = formatRecordResults(matches);\n expect(formattedMatchResult).to.eql(expectedMatches);\n\n const formattedNonMatchResult = formatRecordResults(nonMatches);\n expect(formattedNonMatchResult).to.eql(expectedNonMatches);\n\n // eslint-disable-next-line functional/no-conditional-statement\n if (expectedFailures) {\n expect(conversionFailures).to.eql(expectedFailures);\n }\n\n function formatOptions() {\n const contextFeatures = matchDetection.features[options.detection.strategy.type];\n\n return {\n ...options,\n search: {\n ...options.search\n },\n detection: {\n ...options.detect,\n strategy: options.detection.strategy.features.map(v => contextFeatures[v]())\n }\n };\n }\n\n function formatRecordResults(matches) {\n if (matches) {\n debugData(JSON.stringify(matches));\n return matches.map((match) => ({\n ...match,\n candidate: formatCandidate(match.candidate)\n }));\n }\n return [];\n }\n\n // Format candidate to remove validationOptions from record\n function formatCandidate({id, record}) {\n const newId = id;\n const newRecord = record;\n return {\n id: newId,\n record: newRecord.toObject()\n };\n }\n\n\n }\n\n});\n"],"file":"index.spec.js"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/match-detection/features/bib/authors.js"],"names":["nameTreshold","name","extract","record","get","map","subfields","filter","code","value","includes","toObj","reduce","acc","v","replace","toLowerCase","id","compare","a","b","maxAuthors","length","matchingIds","findMatchingIds","matchingNames","findMatchingNames","idPoints","namePoints","totalPoints","findMatches","distance","maxLength","getMaxLength","percentage","key","cb","valuesA","o","valuesB","allValues","concat","occurrance","otherValue"],"mappings":";;;;;;;AA4BA;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eAIe,CAAC;AAACA,EAAAA,YAAY,GAAG;AAAhB,IAAsB,EAAvB,MAA+B;AAC5CC,EAAAA,IAAI,EAAE,SADsC;AAE5CC,EAAAA,OAAO,EAAEC,MAAM,IAAIA,MAAM,CAACC,GAAP,CAAW,oBAAX,EAChBC,GADgB,CACZ,CAAC;AAACC,IAAAA;AAAD,GAAD,KAAiB;AACpB,WAAOA,SAAS,CACbC,MADI,CACG,CAAC;AAACC,MAAAA,IAAD;AAAOC,MAAAA;AAAP,KAAD,KAAmBD,IAAI,IAAIC,KAD9B,EAEJF,MAFI,CAEG,CAAC;AAACC,MAAAA;AAAD,KAAD,KAAY,CAAC,GAAD,EAAM,GAAN,EAAWE,QAAX,CAAoBF,IAApB,CAFf,EAGJH,GAHI,CAGAM,KAHA,EAIJC,MAJI,CAIG,CAACC,GAAD,EAAMC,CAAN,MAAa,EAAC,GAAGD,GAAJ;AAAS,SAAGC;AAAZ,KAAb,CAJH,EAIiC,EAJjC,CAAP;;AAMA,aAASH,KAAT,CAAe;AAACH,MAAAA,IAAD;AAAOC,MAAAA;AAAP,KAAf,EAA8B;AAC5B,UAAID,IAAI,KAAK,GAAb,EAAkB;AAChB,eAAO;AAACP,UAAAA,IAAI,EAAEQ,KAAK,CAACM,OAAN,CAAc,2BAAd,EAA2C,EAA3C,EAA+CC,WAA/C;
|
|
1
|
+
{"version":3,"sources":["../../../../src/match-detection/features/bib/authors.js"],"names":["nameTreshold","name","extract","record","get","map","subfields","filter","code","value","includes","toObj","reduce","acc","v","replace","toLowerCase","id","compare","a","b","maxAuthors","length","matchingIds","findMatchingIds","matchingNames","findMatchingNames","idPoints","namePoints","totalPoints","findMatches","distance","maxLength","getMaxLength","percentage","key","cb","valuesA","o","valuesB","allValues","concat","occurrance","otherValue"],"mappings":";;;;;;;AA4BA;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;eAIe,CAAC;AAACA,EAAAA,YAAY,GAAG;AAAhB,IAAsB,EAAvB,MAA+B;AAC5CC,EAAAA,IAAI,EAAE,SADsC;AAE5CC,EAAAA,OAAO,EAAEC,MAAM,IAAIA,MAAM,CAACC,GAAP,CAAW,oBAAX,EAChBC,GADgB,CACZ,CAAC;AAACC,IAAAA;AAAD,GAAD,KAAiB;AACpB,WAAOA,SAAS,CACbC,MADI,CACG,CAAC;AAACC,MAAAA,IAAD;AAAOC,MAAAA;AAAP,KAAD,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IAAIP,EAAE,CAAC3B,KAAD,EAAQkC,UAAR,CAAjC,EAAsDrB,MAAzE;AACA,eAAOoB,UAAU,IAAI,CAAd,GAAkB7B,GAAG,GAAG,CAAxB,GAA4BA,GAAnC;AACD,OAHM,EAGJ,CAHI,CAAP;AAID;AACF;AAlE2C,CAA/B,C","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 {LevenshteinDistance as leven} from 'natural';\n\nexport default ({nameTreshold = 10} = {}) => ({\n name: 'Authors',\n extract: record => record.get(/^(?<def>100|700)$/u)\n .map(({subfields}) => {\n return subfields\n .filter(({code, value}) => code && value)\n .filter(({code}) => ['a', '0'].includes(code))\n .map(toObj)\n .reduce((acc, v) => ({...acc, ...v}), {});\n\n function toObj({code, value}) {\n if (code === 'a') {\n return {name: value ? value.replace(/[^\\p{Letter}\\p{Number}]/gu, '').toLowerCase() : ''};\n }\n\n return {id: value};\n }\n }),\n compare: (a, b) => {\n const maxAuthors = a.length > b.length ? a.length : b.length;\n const matchingIds = findMatchingIds();\n\n if (maxAuthors >= 3 && matchingIds >= 3) {\n return 0.3;\n }\n\n const matchingNames = findMatchingNames();\n const idPoints = matchingIds / maxAuthors * 0.3;\n const namePoints = matchingNames / maxAuthors * 0.2;\n const totalPoints = idPoints + namePoints;\n\n return totalPoints <= 0.2 ? totalPoints : 0.2;\n\n function findMatchingIds() {\n return findMatches('id', (a, b) => a === b);\n }\n\n function findMatchingNames() {\n return findMatches('name', (a, b) => {\n const distance = leven(a, b);\n\n if (distance === 0) {\n return true;\n }\n\n const maxLength = getMaxLength();\n const percentage = distance / maxLength * 100;\n\n return percentage <= nameTreshold;\n\n function getMaxLength() {\n return a.length > b.length ? a.length : b.length;\n }\n });\n }\n\n function findMatches(key, cb) {\n const valuesA = a.filter(o => o[key]).map(o => o[key]);\n const valuesB = b.filter(o => o[key]).map(o => o[key]);\n const allValues = valuesA.concat(valuesB);\n\n return allValues.reduce((acc, value) => {\n const occurrance = allValues.filter(otherValue => cb(value, otherValue)).length;\n return occurrance >= 2 ? acc + 1 : acc;\n }, 0);\n }\n }\n});\n"],"file":"authors.js"}
|
|
@@ -54,12 +54,13 @@ var _default = ({
|
|
|
54
54
|
if (field) {
|
|
55
55
|
return field.subfields.filter(({
|
|
56
56
|
code
|
|
57
|
-
}) => subfieldCodes.includes(code)).map(({
|
|
57
|
+
}) => subfieldCodes.includes(code)) // .map(({code, value}) => ({code, value: value.replace(/-/ug, '')}));
|
|
58
|
+
.map(({
|
|
58
59
|
code,
|
|
59
60
|
value
|
|
60
61
|
}) => ({
|
|
61
62
|
code,
|
|
62
|
-
value: value.replace(/-/ug, '')
|
|
63
|
+
value: value ? value.replace(/-/ug, '') : ''
|
|
63
64
|
}));
|
|
64
65
|
}
|
|
65
66
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../src/match-detection/features/bib/standard-identifier-factory.js"],"names":["debug","debugData","extend","pattern","subfieldCodes","extract","compare","record","field","get","subfields","filter","code","includes","map","value","replace","a","b","length","bothHaveValidIdentifiers","maxValues","matchingValues","getValueCount","aValues","bValues","validOnly","getIdentifiers","aValue","some","bValue","values"],"mappings":";;;;;;;AA4BA;;;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA,MAAMA,KAAK,GAAG,oBAAkB,iFAAlB,CAAd;AACA,MAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB;;eAEe,CAAC;AAACC,EAAAA,OAAD;AAAUC,EAAAA;AAAV,CAAD,KAA8B;AAC3C,SAAO;AAACC,IAAAA,OAAD;AAAUC,IAAAA;AAAV,GAAP;;AAEA,WAASD,OAAT,CAAiBE,MAAjB,EAAyB;AACvB,UAAM,CAACC,KAAD,IAAUD,MAAM,CAACE,GAAP,CAAWN,OAAX,CAAhB;;AAEA,QAAIK,KAAJ,EAAW;AACT,aAAOA,KAAK,CAACE,SAAN,CACJC,MADI,CACG,CAAC;AAACC,QAAAA;AAAD,OAAD,KAAYR,aAAa,CAACS,QAAd,CAAuBD,IAAvB,CADf,
|
|
1
|
+
{"version":3,"sources":["../../../../src/match-detection/features/bib/standard-identifier-factory.js"],"names":["debug","debugData","extend","pattern","subfieldCodes","extract","compare","record","field","get","subfields","filter","code","includes","map","value","replace","a","b","length","bothHaveValidIdentifiers","maxValues","matchingValues","getValueCount","aValues","bValues","validOnly","getIdentifiers","aValue","some","bValue","values"],"mappings":";;;;;;;AA4BA;;;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA,MAAMA,KAAK,GAAG,oBAAkB,iFAAlB,CAAd;AACA,MAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB;;eAEe,CAAC;AAACC,EAAAA,OAAD;AAAUC,EAAAA;AAAV,CAAD,KAA8B;AAC3C,SAAO;AAACC,IAAAA,OAAD;AAAUC,IAAAA;AAAV,GAAP;;AAEA,WAASD,OA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AAYA,IAAI,KAAK,GAA9B,CAAhB;AACA,aAAOY,OAAO,CAACL,MAAR,GAAiB,CAAjB,IAAsBM,OAAO,CAACN,MAAR,GAAiB,CAA9C;AACD;;AAED,aAASI,aAAT,CAAuBG,SAAS,GAAG,KAAnC,EAA0C;AACxC,YAAMF,OAAO,GAAGG,cAAc,CAACV,CAAD,CAA9B;AACA,YAAMQ,OAAO,GAAGE,cAAc,CAACT,CAAD,CAA9B;AAEA,aAAO;AACLG,QAAAA,SAAS,EAAEG,OAAO,CAACL,MAAR,GAAiBM,OAAO,CAACN,MAAzB,GAAkCK,OAAO,CAACL,MAA1C,GAAmDM,OAAO,CAACN,MADjE;AAELG,QAAAA,cAAc,EAAEE,OAAO,CAACb,MAAR,CAAeiB,MAAM,IAAIH,OAAO,CAACI,IAAR,CAAaC,MAAM,IAAIF,MAAM,KAAKE,MAAlC,CAAzB,EAAoEX;AAF/E,OAAP;;AAKA,eAASQ,cAAT,CAAwBI,MAAxB,EAAgC;AAC9B,YAAIL,SAAJ,EAAe;AACb,iBAAOK,MAAM,CACVpB,MADI,CACG,CAAC;AAACC,YAAAA;AAAD,WAAD,KAAYA,IAAI,KAAK,GADxB,EAEJE,GAFI,CAEA,CAAC;AAACC,YAAAA;AAAD,WAAD,KAAaA,KAFb,CAAP;AAGD;;AAED,eAAOgB,MAAM,CAACjB,GAAP,CAAW,CAAC;AAACC,UAAAA;AAAD,SAAD,KAAaA,KAAxB,CAAP;AACD;AACF;AACF;AACF,C","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 createDebugLogger from 'debug';\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: value.replace(/-/ug, '')}));\n .map(({code, value}) => ({code, value: value ? value.replace(/-/ug, '') : ''}));\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"],"file":"standard-identifier-factory.js"}
|
|
@@ -46,7 +46,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
46
46
|
* for the JavaScript code in this file.
|
|
47
47
|
*
|
|
48
48
|
*/
|
|
49
|
-
// eslint-disable-next-line max-statements
|
|
50
49
|
var _default = ({
|
|
51
50
|
strategy,
|
|
52
51
|
treshold = 0.9
|
|
@@ -58,26 +57,43 @@ var _default = ({
|
|
|
58
57
|
debugData(`Treshold: ${JSON.stringify(treshold)}`);
|
|
59
58
|
debugData(`ReturnStrategy: ${JSON.stringify(returnStrategy)}`);
|
|
60
59
|
const featuresA = extractFeatures(recordA);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
60
|
+
debug(`We got an array of records: ${Array.isArray(recordB)}`);
|
|
61
|
+
const recordsB = Array.isArray(recordB) ? recordB : [recordB];
|
|
62
|
+
const detectionResults = recordsB.map(record => actualDetection(featuresA, record));
|
|
63
|
+
return Array.isArray(recordB) ? detectionResults : detectionResults[0];
|
|
64
|
+
|
|
65
|
+
function actualDetection(featuresA, record) {
|
|
66
|
+
const featuresB = extractFeatures(record);
|
|
67
|
+
debugData(`Features (a): ${JSON.stringify(featuresA)}`);
|
|
68
|
+
debugData(`Features (b): ${JSON.stringify(featuresB)}`);
|
|
69
|
+
const featurePairs = generateFeaturePairs(featuresA, featuresB);
|
|
70
|
+
const similarityVector = generateSimilarityVector(featurePairs);
|
|
71
|
+
|
|
72
|
+
if (similarityVector.some(v => v >= minProbabilityQuantifier)) {
|
|
73
|
+
const probability = calculateprobability(similarityVector);
|
|
74
|
+
debug(`probability: ${probability} (Treshold: ${treshold})`);
|
|
75
|
+
return returnResult({
|
|
76
|
+
match: probability >= treshold,
|
|
77
|
+
probability
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);
|
|
70
82
|
return returnResult({
|
|
71
|
-
match:
|
|
72
|
-
probability
|
|
83
|
+
match: false,
|
|
84
|
+
probability: 0.0
|
|
73
85
|
});
|
|
74
86
|
}
|
|
75
87
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
88
|
+
function extractFeatures(record) {
|
|
89
|
+
return strategy.reduce((acc, {
|
|
90
|
+
name,
|
|
91
|
+
extract
|
|
92
|
+
}) => acc.concat({
|
|
93
|
+
name,
|
|
94
|
+
value: extract(record)
|
|
95
|
+
}), []);
|
|
96
|
+
}
|
|
81
97
|
|
|
82
98
|
function returnResult(result) {
|
|
83
99
|
if (returnStrategy) {
|
|
@@ -100,22 +116,12 @@ var _default = ({
|
|
|
100
116
|
return strategyNames || [];
|
|
101
117
|
}
|
|
102
118
|
|
|
103
|
-
function calculateprobability() {
|
|
119
|
+
function calculateprobability(similarityVector) {
|
|
104
120
|
const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);
|
|
105
121
|
return probability > 1.0 ? 1.0 : probability;
|
|
106
122
|
}
|
|
107
123
|
|
|
108
|
-
function
|
|
109
|
-
return strategy.reduce((acc, {
|
|
110
|
-
name,
|
|
111
|
-
extract
|
|
112
|
-
}) => acc.concat({
|
|
113
|
-
name,
|
|
114
|
-
value: extract(record)
|
|
115
|
-
}), []);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
function generateSimilarityVector() {
|
|
124
|
+
function generateSimilarityVector(featurePairs) {
|
|
119
125
|
const compared = featurePairs.map(({
|
|
120
126
|
name,
|
|
121
127
|
a,
|
|
@@ -138,7 +144,7 @@ var _default = ({
|
|
|
138
144
|
}) => points);
|
|
139
145
|
}
|
|
140
146
|
|
|
141
|
-
function generateFeaturePairs() {
|
|
147
|
+
function generateFeaturePairs(featuresA, featuresB) {
|
|
142
148
|
const pairs = generatePairs();
|
|
143
149
|
const missingFeatures = findMissing();
|
|
144
150
|
debug(`Not comparing the following features because one, or both records are missing features: ${JSON.stringify(missingFeatures)}`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/match-detection/index.js"],"names":["strategy","treshold","returnStrategy","recordA","recordB","minProbabilityQuantifier","debug","debugData","extend","JSON","stringify","featuresA","extractFeatures","featuresB","featurePairs","generateFeaturePairs","similarityVector","generateSimilarityVector","some","v","probability","calculateprobability","returnResult","match","result","resultWithStrategy","formatStrategy","strategyNames","map","element","name","reduce","acc","record","extract","concat","value","compared","a","b","compare","find","featureName","points","pairs","generatePairs","missingFeatures","findMissing","index","filter","length"],"mappings":";;;;;;;AA6BA;;AACA;;;;;;;;;;AA9BA;;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;AAOA;eACe,CAAC;AAACA,EAAAA,QAAD;AAAWC,EAAAA,QAAQ,GAAG;AAAtB,CAAD,EAA6BC,cAAc,GAAG,KAA9C,KAAwD,CAACC,OAAD,EAAUC,OAAV,KAAsB;AAC3F,QAAMC,wBAAwB,GAAG,GAAjC;AAEA,QAAMC,KAAK,GAAG,oBAAkB,mDAAlB,CAAd;AACA,QAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB;AAEAD,EAAAA,SAAS,CAAE,aAAYE,IAAI,CAACC,SAAL,CAAeV,QAAf,CAAyB,EAAvC,CAAT;AACAO,EAAAA,SAAS,CAAE,aAAYE,IAAI,CAACC,SAAL,CAAeT,QAAf,CAAyB,EAAvC,CAAT;AACAM,EAAAA,SAAS,CAAE,mBAAkBE,IAAI,CAACC,SAAL,CAAeR,cAAf,CAA+B,EAAnD,CAAT;AAEA,QAAMS,SAAS,GAAGC,eAAe,CAACT,OAAD,CAAjC;AACA,QAAMU,SAAS,GAAGD,eAAe,CAACR,OAAD,CAAjC;AAEAG,EAAAA,SAAS,CAAE,iBAAgBE,IAAI,CAACC,SAAL,CAAeC,SAAf,CAA0B,EAA5C,CAAT;AACAJ,EAAAA,SAAS,CAAE,iBAAgBE,IAAI,CAACC,SAA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GAAGC,WAAW,EAAnC;AAEAzC,IAAAA,KAAK,CAAE,2FAA0FG,IAAI,CAACC,SAAL,CAAeoC,eAAf,CAAgC,EAA5H,CAAL;AACA,WAAOF,KAAP;;AAEA,aAASC,aAAT,GAAyB;AACvB,aAAOlC,SAAS,CACboB,MADI,CACG,CAACC,GAAD,EAAM;AAACF,QAAAA,IAAD;AAAOM,QAAAA;AAAP,OAAN,EAAqBY,KAArB,KAA+BhB,GAAG,CAACG,MAAJ,CAAW;AAChDL,QAAAA,IADgD;AAEhDQ,QAAAA,CAAC,EAAEF,KAF6C;AAGhDG,QAAAA,CAAC,EAAE1B,SAAS,CAACmC,KAAD,CAAT,CAAiBZ;AAH4B,OAAX,CADlC,EAKD,EALC,EAMJa,MANI,CAMG,CAAC;AAACX,QAAAA,CAAD;AAAIC,QAAAA;AAAJ,OAAD,KAAY;AAClB,YAAID,CAAC,CAACY,MAAF,KAAa,CAAb,IAAkBX,CAAC,CAACW,MAAF,KAAa,CAAnC,EAAsC;AACpC,iBAAO,KAAP;AACD;;AAED,eAAO,IAAP;AACD,OAZI,CAAP;AAaD;;AAED,aAASH,WAAT,GAAuB;AACrB,aAAOpC,SAAS,CACbiB,GADI,CACA,CAAC;AAACE,QAAAA;AAAD,OAAD,KAAYA,IADZ,EAEJmB,MAFI,CAEG9B,CAAC,IAAIyB,KAAK,CAAC1B,IAAN,CAAW,CAAC;AAACY,QAAAA;AAAD,OAAD,KAAYA,IAAI,KAAKX,CAAhC,MAAuC,KAF/C,CAAP;AAGD;AACF;AACF,C","sourcesContent":["/* eslint-disable no-console */\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 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 * as features from './features';\n\nexport {features};\n\n// eslint-disable-next-line max-statements\nexport default ({strategy, treshold = 0.9}, returnStrategy = false) => (recordA, recordB) => {\n const minProbabilityQuantifier = 0.5;\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection');\n const debugData = debug.extend('data');\n\n debugData(`Strategy: ${JSON.stringify(strategy)}`);\n debugData(`Treshold: ${JSON.stringify(treshold)}`);\n debugData(`ReturnStrategy: ${JSON.stringify(returnStrategy)}`);\n\n const featuresA = extractFeatures(recordA);\n const featuresB = extractFeatures(recordB);\n\n debugData(`Features (a): ${JSON.stringify(featuresA)}`);\n debugData(`Features (b): ${JSON.stringify(featuresB)}`);\n\n const featurePairs = generateFeaturePairs();\n const similarityVector = generateSimilarityVector();\n\n if (similarityVector.some(v => v >= minProbabilityQuantifier)) {\n const probability = calculateprobability();\n debug(`probability: ${probability} (Treshold: ${treshold})`);\n return returnResult({match: probability >= treshold, probability});\n }\n\n debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);\n return returnResult({match: false, probability: 0.0});\n\n function returnResult(result) {\n if (returnStrategy) {\n debug(`Returning detection strategy with the result`);\n const resultWithStrategy = {match: result.match, probability: result.probability, strategy: formatStrategy(strategy), treshold};\n debugData(`${JSON.stringify(resultWithStrategy)}`);\n return resultWithStrategy;\n }\n return result;\n }\n\n function formatStrategy(strategy) {\n const strategyNames = strategy.map(element => element.name);\n return strategyNames || [];\n }\n\n function calculateprobability() {\n const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);\n return probability > 1.0 ? 1.0 : probability;\n }\n\n function extractFeatures(record) {\n return strategy.reduce((acc, {name, extract}) => acc.concat({name, value: extract(record)}), []);\n }\n\n function generateSimilarityVector() {\n const compared = featurePairs.map(({name, a, b}) => {\n const {compare} = strategy.find(({name: featureName}) => name === featureName);\n const points = compare(a, b);\n return {name, points};\n });\n\n debugData(`Points: ${JSON.stringify(compared)}`);\n return compared.map(({points}) => points);\n }\n\n function generateFeaturePairs() {\n const pairs = generatePairs();\n const missingFeatures = findMissing();\n\n debug(`Not comparing the following features because one, or both records are missing features: ${JSON.stringify(missingFeatures)}`);\n return pairs;\n\n function generatePairs() {\n return featuresA\n .reduce((acc, {name, value}, index) => acc.concat({\n name,\n a: value,\n b: featuresB[index].value\n }), [])\n .filter(({a, b}) => {\n if (a.length === 0 || b.length === 0) {\n return false;\n }\n\n return true;\n });\n }\n\n function findMissing() {\n return featuresA\n .map(({name}) => name)\n .filter(v => pairs.some(({name}) => name === v) === false);\n }\n }\n};\n"],"file":"index.js"}
|
|
1
|
+
{"version":3,"sources":["../../src/match-detection/index.js"],"names":["strategy","treshold","returnStrategy","recordA","recordB","minProbabilityQuantifier","debug","debugData","extend","JSON","stringify","featuresA","extractFeatures","Array","isArray","recordsB","detectionResults","map","record","actualDetection","featuresB","featurePairs","generateFeaturePairs","similarityVector","generateSimilarityVector","some","v","probability","calculateprobability","returnResult","match","reduce","acc","name","extract","concat","value","result","resultWithStrategy","formatStrategy","strategyNames","element","compared","a","b","compare","find","featureName","points","pairs","generatePairs","missingFeatures","findMissing","index","filter","length"],"mappings":";;;;;;;AA6BA;;AACA;;;;;;;;;;AA9BA;;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;eAOe,CAAC;AAACA,EAAAA,QAAD;AAAWC,EAAAA,QAAQ,GAAG;AAAtB,CAAD,EAA6BC,cAAc,GAAG,KAA9C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,KAAK,GAAGC,aAAa,EAA3B;AACA,UAAMC,eAAe,GAAGC,WAAW,EAAnC;AAEA9C,IAAAA,KAAK,CAAE,2FAA0FG,IAAI,CAACC,SAAL,CAAeyC,eAAf,CAAgC,EAA5H,CAAL;AACA,WAAOF,KAAP;;AAEA,aAASC,aAAT,GAAyB;AACvB,aAAOvC,SAAS,CACboB,MADI,CACG,CAACC,GAAD,EAAM;AAACC,QAAAA,IAAD;AAAOG,QAAAA;AAAP,OAAN,EAAqBiB,KAArB,KAA+BrB,GAAG,CAACG,MAAJ,CAAW;AAChDF,QAAAA,IADgD;AAEhDU,QAAAA,CAAC,EAAEP,KAF6C;AAGhDQ,QAAAA,CAAC,EAAExB,SAAS,CAACiC,KAAD,CAAT,CAAiBjB;AAH4B,OAAX,CADlC,EAKD,EALC,EAMJkB,MANI,CAMG,CAAC;AAACX,QAAAA,CAAD;AAAIC,QAAAA;AAAJ,OAAD,KAAY;AAClB,YAAID,CAAC,CAACY,MAAF,KAAa,CAAb,IAAkBX,CAAC,CAACW,MAAF,KAAa,CAAnC,EAAsC;AACpC,iBAAO,KAAP;AACD;;AAED,eAAO,IAAP;AACD,OAZI,CAAP;AAaD;;AAED,aAASH,WAAT,GAAuB;AACrB,aAAOzC,SAAS,CACbM,GADI,CACA,CAAC;AAACgB,QAAAA;AAAD,OAAD,KAAYA,IADZ,EAEJqB,MAFI,CAEG5B,CAAC,IAAIuB,KAAK,CAACxB,IAAN,CAAW,CAAC;AAACQ,QAAAA;AAAD,OAAD,KAAYA,IAAI,KAAKP,CAAhC,MAAuC,KAF/C,CAAP;AAGD;AACF;AAEF,C","sourcesContent":["/* eslint-disable no-console */\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 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 * as features from './features';\n\nexport {features};\n\nexport default ({strategy, treshold = 0.9}, returnStrategy = false) => (recordA, recordB) => {\n const minProbabilityQuantifier = 0.5;\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection');\n const debugData = debug.extend('data');\n\n debugData(`Strategy: ${JSON.stringify(strategy)}`);\n debugData(`Treshold: ${JSON.stringify(treshold)}`);\n debugData(`ReturnStrategy: ${JSON.stringify(returnStrategy)}`);\n\n const featuresA = extractFeatures(recordA);\n\n debug(`We got an array of records: ${Array.isArray(recordB)}`);\n const recordsB = Array.isArray(recordB) ? recordB : [recordB];\n const detectionResults = recordsB.map(record => actualDetection(featuresA, record));\n\n return Array.isArray(recordB) ? detectionResults : detectionResults[0];\n\n function actualDetection(featuresA, record) {\n\n const featuresB = extractFeatures(record);\n\n debugData(`Features (a): ${JSON.stringify(featuresA)}`);\n debugData(`Features (b): ${JSON.stringify(featuresB)}`);\n\n const featurePairs = generateFeaturePairs(featuresA, featuresB);\n const similarityVector = generateSimilarityVector(featurePairs);\n\n if (similarityVector.some(v => v >= minProbabilityQuantifier)) {\n const probability = calculateprobability(similarityVector);\n debug(`probability: ${probability} (Treshold: ${treshold})`);\n return returnResult({match: probability >= treshold, probability});\n }\n\n debugData(`No feature yielded minimum probability amount of points (${minProbabilityQuantifier})`);\n return returnResult({match: false, probability: 0.0});\n }\n\n function extractFeatures(record) {\n return strategy.reduce((acc, {name, extract}) => acc.concat({name, value: extract(record)}), []);\n }\n\n function returnResult(result) {\n if (returnStrategy) {\n debug(`Returning detection strategy with the result`);\n const resultWithStrategy = {match: result.match, probability: result.probability, strategy: formatStrategy(strategy), treshold};\n debugData(`${JSON.stringify(resultWithStrategy)}`);\n return resultWithStrategy;\n }\n return result;\n }\n\n function formatStrategy(strategy) {\n const strategyNames = strategy.map(element => element.name);\n return strategyNames || [];\n }\n\n function calculateprobability(similarityVector) {\n const probability = similarityVector.reduce((acc, v) => acc + v, 0.0);\n return probability > 1.0 ? 1.0 : probability;\n }\n\n function generateSimilarityVector(featurePairs) {\n const compared = featurePairs.map(({name, a, b}) => {\n const {compare} = strategy.find(({name: featureName}) => name === featureName);\n const points = compare(a, b);\n return {name, points};\n });\n\n debugData(`Points: ${JSON.stringify(compared)}`);\n return compared.map(({points}) => points);\n }\n\n function generateFeaturePairs(featuresA, featuresB) {\n const pairs = generatePairs();\n const missingFeatures = findMissing();\n\n debug(`Not comparing the following features because one, or both records are missing features: ${JSON.stringify(missingFeatures)}`);\n return pairs;\n\n function generatePairs() {\n return featuresA\n .reduce((acc, {name, value}, index) => acc.concat({\n name,\n a: value,\n b: featuresB[index].value\n }), [])\n .filter(({a, b}) => {\n if (a.length === 0 || b.length === 0) {\n return false;\n }\n\n return true;\n });\n }\n\n function findMissing() {\n return featuresA\n .map(({name}) => name)\n .filter(v => pairs.some(({name}) => name === v) === false);\n }\n }\n\n};\n"],"file":"index.js"}
|
|
@@ -12,6 +12,10 @@ var features = _interopRequireWildcard(require("./features"));
|
|
|
12
12
|
|
|
13
13
|
var _ = _interopRequireDefault(require("."));
|
|
14
14
|
|
|
15
|
+
var _util = require("util");
|
|
16
|
+
|
|
17
|
+
var _debug = _interopRequireDefault(require("debug"));
|
|
18
|
+
|
|
15
19
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
16
20
|
|
|
17
21
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -45,6 +49,8 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
45
49
|
* for the JavaScript code in this file.
|
|
46
50
|
*
|
|
47
51
|
*/
|
|
52
|
+
const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:test');
|
|
53
|
+
const debugData = debug.extend('data');
|
|
48
54
|
describe('match-detection', () => {
|
|
49
55
|
(0, _fixugen.default)({
|
|
50
56
|
path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],
|
|
@@ -57,16 +63,28 @@ describe('match-detection', () => {
|
|
|
57
63
|
getFixture,
|
|
58
64
|
options,
|
|
59
65
|
expectedResults,
|
|
66
|
+
array,
|
|
60
67
|
enabled = true
|
|
61
68
|
}) => {
|
|
62
69
|
if (!enabled) {
|
|
70
|
+
debug(`*** DISABLED TEST! ***`);
|
|
63
71
|
return;
|
|
64
72
|
}
|
|
65
73
|
|
|
66
74
|
const detect = (0, _.default)(formatOptions());
|
|
67
|
-
const recordA = new _marcRecord.MarcRecord(getFixture('recordA.json')
|
|
68
|
-
|
|
75
|
+
const recordA = new _marcRecord.MarcRecord(getFixture('recordA.json'), {
|
|
76
|
+
subfieldValues: false
|
|
77
|
+
});
|
|
78
|
+
debugData((0, _util.inspect)(recordA));
|
|
79
|
+
debug(`Our recordB is an array of records: ${array}`);
|
|
80
|
+
const recordB = array ? getFixture('recordB.json').map(recordJson => new _marcRecord.MarcRecord(recordJson, {
|
|
81
|
+
subfieldValues: false
|
|
82
|
+
})) : new _marcRecord.MarcRecord(getFixture('recordB.json'), {
|
|
83
|
+
subfieldValues: false
|
|
84
|
+
});
|
|
85
|
+
debugData((0, _util.inspect)(recordB));
|
|
69
86
|
const results = detect(recordA, recordB);
|
|
87
|
+
debugData(`${JSON.stringify(results)}`);
|
|
70
88
|
(0, _chai.expect)(results).to.eql(expectedResults);
|
|
71
89
|
|
|
72
90
|
function formatOptions() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/match-detection/index.spec.js"],"names":["describe","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","callback","getFixture","options","expectedResults","enabled","detect","formatOptions","recordA","MarcRecord","recordB","results","to","eql","contextFeatures","features","strategy","type","
|
|
1
|
+
{"version":3,"sources":["../../src/match-detection/index.spec.js"],"names":["debug","debugData","extend","describe","path","__dirname","useMetadataFile","recurse","fixura","reader","READERS","JSON","callback","getFixture","options","expectedResults","array","enabled","detect","formatOptions","recordA","MarcRecord","subfieldValues","recordB","map","recordJson","results","stringify","to","eql","contextFeatures","features","strategy","type","v"],"mappings":";;AA4BA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;AACA;;;;;;;;AAnCA;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;AAWA,MAAMA,KAAK,GAAG,oBAAkB,wDAAlB,CAAd;AACA,MAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB;AAEAC,QAAQ,CAAC,iBAAD,EAAoB,MAAM;AAChC,wBAAc;AACZC,IAAAA,IAAI,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,SAAL,CAAeD,OAAf,CAAwB,EAA5B,CAAT;AAEA,wBAAOA,OAAP,EAAgBE,EAAhB,CAAmBC,GAAnB,CAAuBd,eAAvB;;AAEA,eAASI,aAAT,GAAyB;AACvB,cAAMW,eAAe,GAAGC,QAAQ,CAACjB,OAAO,CAACkB,QAAR,CAAiBC,IAAlB,CAAhC;AAEA,eAAO,EACL,GAAGnB,OADE;AAELkB,UAAAA,QAAQ,EAAElB,OAAO,CAACkB,QAAR,CAAiBD,QAAjB,CAA0BP,GAA1B,CAA8BU,CAAC,IAAIJ,eAAe,CAACI,CAAD,CAAf,EAAnC;AAFL,SAAP;AAID;AACF;AArCW,GAAd;AAuCD,CAxCO,CAAR","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 generateTests from '@natlibfi/fixugen';\nimport {READERS} from '@natlibfi/fixura';\nimport {expect} from 'chai';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport * as features from './features';\nimport createDetectionInterface from '.';\nimport {inspect} from 'util';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:test');\nconst debugData = debug.extend('data');\n\ndescribe('match-detection', () => {\n generateTests({\n path: [__dirname, '..', '..', 'test-fixtures', 'match-detection', 'index'],\n useMetadataFile: true,\n recurse: false,\n fixura: {\n reader: READERS.JSON\n },\n callback: ({getFixture, options, expectedResults, array, enabled = true}) => {\n\n if (!enabled) {\n debug(`*** DISABLED TEST! ***`);\n return;\n }\n\n const detect = createDetectionInterface(formatOptions());\n const recordA = new MarcRecord(getFixture('recordA.json'), {subfieldValues: false});\n debugData(inspect(recordA));\n\n debug(`Our recordB is an array of records: ${array}`);\n const recordB = array\n ? getFixture('recordB.json').map(recordJson => new MarcRecord(recordJson, {subfieldValues: false}))\n : new MarcRecord(getFixture('recordB.json'), {subfieldValues: false});\n debugData(inspect(recordB));\n\n const results = detect(recordA, recordB);\n debugData(`${JSON.stringify(results)}`);\n\n expect(results).to.eql(expectedResults);\n\n function formatOptions() {\n const contextFeatures = features[options.strategy.type];\n\n return {\n ...options,\n strategy: options.strategy.features.map(v => contextFeatures[v]())\n };\n }\n }\n });\n});\n"],"file":"index.spec.js"}
|
package/dist/matching-utils.js
CHANGED
|
@@ -64,7 +64,7 @@ function getMelindaIdsF035(record) {
|
|
|
64
64
|
const melindaIdRegExp = /^(?<prefix>\(FI-MELINDA\)|FCC)(?<id>\d{9})$/u;
|
|
65
65
|
return subfields.filter(sub => ['a', 'z'].includes(sub.code)).filter(sub => melindaIdRegExp.test(sub.value)).map(({
|
|
66
66
|
value
|
|
67
|
-
}) => value.replace(melindaIdRegExp, '$<id>'));
|
|
67
|
+
}) => value ? value.replace(melindaIdRegExp, '$<id>') : '');
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
70
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/matching-utils.js"],"names":["debug","debugData","extend","getMelindaIdsF035","record","f035s","getFields","length","allF035MelindaIds","concat","map","toMelindaIds","f035MelindaIds","Set","JSON","stringify","subfields","melindaIdRegExp","filter","sub","includes","code","test","value","replace","validateSidFieldSubfieldCounts","field","countC","countSubfields","countB","subfieldCode","getSubfieldValues"],"mappings":";;;;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,WAAOD,SAAS,CACbE,MADI,CACGC,GAAG,IAAI,CAAC,GAAD,EAAM,GAAN,EAAWC,QAAX,CAAoBD,GAAG,CAACE,IAAxB,CADV,EAEJH,MAFI,CAEGC,GAAG,IAAIF,eAAe,CAACK,IAAhB,CAAqBH,GAAG,CAACI,KAAzB,CAFV,EAGJb,GAHI,CAGA,CAAC;AAACa,MAAAA;AAAD,KAAD,KAAaA,KAAK,CAACC,OAAN,CAAcP,eAAd,EAA+B,OAA/B,
|
|
1
|
+
{"version":3,"sources":["../src/matching-utils.js"],"names":["debug","debugData","extend","getMelindaIdsF035","record","f035s","getFields","length","allF035MelindaIds","concat","map","toMelindaIds","f035MelindaIds","Set","JSON","stringify","subfields","melindaIdRegExp","filter","sub","includes","code","test","value","replace","validateSidFieldSubfieldCounts","field","countC","countSubfields","countB","subfieldCode","getSubfieldValues"],"mappings":";;;;;;;;;AA4BA;;;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA,MAAMA,KAAK,GAAG,oBAAkB,yCAAlB,CAAd;AACA,MAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB,C,CAEA;;AACO,SAASC,iBAAT,CAA2BC,MAA3B,EAAmC;AAExC,QAAMJ,KAAK,GAAG,oBAAkB,8CAAlB,CAAd;AACA,QAAMC,SAAS,GAAGD,KAAK,CAACE,MAAN,CAAa,MAAb,CAAlB;AAEA,QAAMG,KAAK,GAAGD,MAAM,CAACE,SAAP,CAAiB,KAAjB,CAAd;;AAEA,MAAID,KAAK,CAACE,MAAN,GAAe,CAAnB,EAAsB;AACpBP,IAAAA,KAAK,CAAE,iBAAF,CAAL;AACA,WAAO,EAAP;AACD;;AAED,QAAMQ,iBAAiB,GAAG,GAAGC,MAAH,CAAU,GAAGJ,KAAK,CAACK,GAAN,CAAUC,YAA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AAM,KAAK,CAAX,IAAgBE,MAAM,KAAK,CAAE,EAAvF,CAAL;AAEA,SAAOF,MAAM,KAAK,CAAX,IAAgBE,MAAM,KAAK,CAAlC;AACD;;AAED,SAASD,cAAT,CAAwBF,KAAxB,EAA+BI,YAA/B,EAA6C;AAC3C;AACA,SAAOJ,KAAK,CAACV,SAAN,CAAgBE,MAAhB,CAAuB,CAAC;AAACG,IAAAA;AAAD,GAAD,KAAYA,IAAI,KAAKS,YAA5C,EAA0DvB,MAAjE;AACD;;AAEM,SAASwB,iBAAT,CAA2BL,KAA3B,EAAkCI,YAAlC,EAAgD;AACrD7B,EAAAA,SAAS,CAAE,oBAAmB6B,YAAa,SAAQhB,IAAI,CAACC,SAAL,CAAeW,KAAf,CAAsB,EAAhE,CAAT;AACA,SAAOA,KAAK,CAACV,SAAN,CAAgBE,MAAhB,CAAuB,CAAC;AAACG,IAAAA;AAAD,GAAD,KAAYA,IAAI,KAAKS,YAA5C,EAA0DpB,GAA1D,CAA8D,CAAC;AAACa,IAAAA;AAAD,GAAD,KAAaA,KAA3E,CAAP;AACD","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 createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');\nconst debugData = debug.extend('data');\n\n// eslint-disable-next-line max-statements\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 => melindaIdRegExp.test(sub.value))\n .map(({value}) => value ? 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.filter(({code}) => code === subfieldCode).map(({value}) => value);\n}\n\n"],"file":"matching-utils.js"}
|
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": "2.
|
|
17
|
+
"version": "2.2.0-alpha.3",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14"
|
|
@@ -37,31 +37,32 @@
|
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"@natlibfi/marc-record": "^7.0.0",
|
|
39
39
|
"@natlibfi/marc-record-serializers": "^8.1.0",
|
|
40
|
-
"@natlibfi/
|
|
41
|
-
"
|
|
42
|
-
"
|
|
40
|
+
"@natlibfi/melinda-commons": "^12.0.3",
|
|
41
|
+
"@natlibfi/sru-client": "^5.0.1",
|
|
42
|
+
"debug": "^4.3.4",
|
|
43
|
+
"moment": "^2.29.2",
|
|
43
44
|
"natural": "^5.1.13",
|
|
44
45
|
"uuid": "^8.3.2",
|
|
45
|
-
"winston": "^3.
|
|
46
|
+
"winston": "^3.7.2"
|
|
46
47
|
},
|
|
47
48
|
"devDependencies": {
|
|
48
|
-
"@babel/cli": "^7.
|
|
49
|
-
"@babel/core": "^7.
|
|
50
|
-
"@babel/eslint-parser": "^7.
|
|
51
|
-
"@babel/node": "^7.16.
|
|
52
|
-
"@babel/preset-env": "^7.16.
|
|
53
|
-
"@babel/register": "^7.
|
|
49
|
+
"@babel/cli": "^7.17.6",
|
|
50
|
+
"@babel/core": "^7.17.9",
|
|
51
|
+
"@babel/eslint-parser": "^7.17.0",
|
|
52
|
+
"@babel/node": "^7.16.8",
|
|
53
|
+
"@babel/preset-env": "^7.16.11",
|
|
54
|
+
"@babel/register": "^7.17.7",
|
|
54
55
|
"@natlibfi/eslint-config-melinda-backend": "^2.0.0",
|
|
55
56
|
"@natlibfi/fixugen": "^1.0.2",
|
|
56
|
-
"@natlibfi/fixugen-http-client": "^
|
|
57
|
+
"@natlibfi/fixugen-http-client": "^2.0.1",
|
|
57
58
|
"@natlibfi/fixura": "^2.2.1",
|
|
58
59
|
"babel-plugin-istanbul": "^6.1.1",
|
|
59
60
|
"babel-plugin-rewire": "^1.2.0",
|
|
60
|
-
"chai": "^4.3.
|
|
61
|
+
"chai": "^4.3.6",
|
|
61
62
|
"chai-as-promised": "^7.1.1",
|
|
62
63
|
"cross-env": "^7.0.3",
|
|
63
|
-
"eslint": "^8.
|
|
64
|
-
"mocha": "^9.
|
|
64
|
+
"eslint": "^8.13.0",
|
|
65
|
+
"mocha": "^9.2.2",
|
|
65
66
|
"nodemon": "^2.0.15",
|
|
66
67
|
"nyc": "^15.1.0"
|
|
67
68
|
},
|
|
@@ -31,6 +31,7 @@ import createClient, {SruSearchError} from '@natlibfi/sru-client';
|
|
|
31
31
|
import {MarcRecord} from '@natlibfi/marc-record';
|
|
32
32
|
import {MARCXML} from '@natlibfi/marc-record-serializers';
|
|
33
33
|
import generateQueryList from './query-list';
|
|
34
|
+
import {Error as MatchingError} from '@natlibfi/melinda-commons';
|
|
34
35
|
|
|
35
36
|
export {searchTypes} from './query-list';
|
|
36
37
|
|
|
@@ -65,6 +66,9 @@ export default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest =
|
|
|
65
66
|
|
|
66
67
|
debug(`Searching matches for ${inputRecordId}`);
|
|
67
68
|
debug(`Generated queryList ${JSON.stringify(queryList)}`);
|
|
69
|
+
|
|
70
|
+
// if generateQueryList errored we should throw 422
|
|
71
|
+
|
|
68
72
|
if (queryList.length === 0) { // eslint-disable-line functional/no-conditional-statement
|
|
69
73
|
throw new CandidateSearchError(`Generated query list contains no queries`);
|
|
70
74
|
}
|
|
@@ -72,40 +76,39 @@ export default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest =
|
|
|
72
76
|
// state.totalRecords : amount of candidate records available to the current query (undefined, if there was no queries left)
|
|
73
77
|
// state.query : current query (undefined if there was no queries left)
|
|
74
78
|
// state.searchCounter : sequence for current search for current query (undefined, if there we no queries left)
|
|
75
|
-
// state.queryCandidateCounter: amount of
|
|
79
|
+
// state.queryCandidateCounter: amount of candidates (records+failures) retrieved from SRU for matching for current query, including the current record+failure set (undefined if there were no queries left)
|
|
76
80
|
// state.queriesLeft : amount of queries left
|
|
77
81
|
// state.queryCounter : sequence for current query
|
|
78
82
|
// state.maxedQueries : queries that resulted in more than serverMaxResults hits
|
|
79
83
|
|
|
80
84
|
|
|
81
|
-
// eslint-disable-next-line max-statements
|
|
82
85
|
return async ({queryOffset = 0, resultSetOffset = 1, totalRecords = 0, searchCounter = 0, queryCandidateCounter = 0, queryCounter = 0, maxedQueries = []}) => {
|
|
83
86
|
const query = queryList[queryOffset];
|
|
84
87
|
|
|
85
88
|
if (query) {
|
|
86
|
-
const {records, nextOffset, total} = await retrieveRecords();
|
|
89
|
+
const {records, failures, nextOffset, total} = await retrieveRecords();
|
|
87
90
|
|
|
88
91
|
// If resultSetOffset === 1 this is the first search for the current query
|
|
89
92
|
debugData(`ResultSetOffset: ${resultSetOffset}`);
|
|
90
93
|
const newTotalRecords = resultSetOffset === 1 ? total : totalRecords;
|
|
91
94
|
const newQueryCounter = resultSetOffset === 1 ? queryCounter + 1 : queryCounter;
|
|
92
95
|
const newSearchCounter = resultSetOffset === 1 ? 1 : searchCounter + 1;
|
|
93
|
-
const newQueryCandidateCounter = resultSetOffset === 1 ? records.length : queryCandidateCounter + records.length;
|
|
96
|
+
const newQueryCandidateCounter = resultSetOffset === 1 ? records.length + failures.length : queryCandidateCounter + records.length + failures.length;
|
|
94
97
|
|
|
95
98
|
const maxedQuery = resultSetOffset === 1 ? checkMaxedQuery(query, total, serverMaxResult) : undefined;
|
|
96
99
|
const newMaxedQueries = maxedQuery ? maxedQueries.concat(maxedQuery) : maxedQueries;
|
|
97
100
|
|
|
98
101
|
if (typeof nextOffset === 'number') {
|
|
99
102
|
debug(`Next search will be for query ${queryOffset} ${query}, starting from record ${nextOffset}`);
|
|
100
|
-
return {records, queryOffset, resultSetOffset: nextOffset, queriesLeft: queryList.length - (queryOffset + 1), totalRecords: newTotalRecords, query, searchCounter: newSearchCounter, queryCandidateCounter: newQueryCandidateCounter, queryCounter: newQueryCounter, maxedQueries: newMaxedQueries};
|
|
103
|
+
return {records, failures, queryOffset, resultSetOffset: nextOffset, queriesLeft: queryList.length - (queryOffset + 1), totalRecords: newTotalRecords, query, searchCounter: newSearchCounter, queryCandidateCounter: newQueryCandidateCounter, queryCounter: newQueryCounter, maxedQueries: newMaxedQueries};
|
|
101
104
|
}
|
|
102
105
|
debug(`Query ${queryOffset} ${query} done.`);
|
|
103
106
|
debug(`There are (${queryList.length - (queryOffset + 1)} queries left)`);
|
|
104
|
-
return {records, queryOffset: queryOffset + 1, queriesLeft: queryList.length - (queryOffset + 1), totalRecords: newTotalRecords, query, searchCounter: newSearchCounter, queryCandidateCounter: newQueryCandidateCounter, queryCounter: newQueryCounter, maxedQueries: newMaxedQueries};
|
|
107
|
+
return {records, failures, queryOffset: queryOffset + 1, queriesLeft: queryList.length - (queryOffset + 1), totalRecords: newTotalRecords, query, searchCounter: newSearchCounter, queryCandidateCounter: newQueryCandidateCounter, queryCounter: newQueryCounter, maxedQueries: newMaxedQueries};
|
|
105
108
|
}
|
|
106
109
|
|
|
107
110
|
debug(`All ${queryList.length} queries done, there's no query for ${queryOffset}`);
|
|
108
|
-
return {records: [], queriesLeft: 0, queryCounter, maxedQueries};
|
|
111
|
+
return {records: [], failures: [], queriesLeft: 0, queryCounter, maxedQueries};
|
|
109
112
|
|
|
110
113
|
function retrieveRecords() {
|
|
111
114
|
return new Promise((resolve, reject) => {
|
|
@@ -131,27 +134,39 @@ export default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest =
|
|
|
131
134
|
})
|
|
132
135
|
.on('end', async nextOffset => {
|
|
133
136
|
try {
|
|
134
|
-
const
|
|
135
|
-
|
|
137
|
+
const recordPromises = await Promise.allSettled(promises);
|
|
138
|
+
debug(`All recordPromises: ${JSON.stringify(recordPromises)}`);
|
|
139
|
+
const filtered = recordPromises.filter(r => r.status === 'fulfilled').map(r => r.value);
|
|
140
|
+
const failures = recordPromises.filter(r => r.status === 'rejected').map(r => ({status: r.reason.status, payload: r.reason.payload}));
|
|
141
|
+
|
|
142
|
+
debug(`Found ${JSON.stringify(recordPromises)} records`);
|
|
143
|
+
debug(`Found ${filtered.length} convertable candidates`);
|
|
144
|
+
debug(`Found ${failures.length} NON-convertable candidates`);
|
|
145
|
+
debug(`Converted: ${JSON.stringify(filtered)}.`);
|
|
146
|
+
debug(`Not converted: ${JSON.stringify(failures)}.`);
|
|
136
147
|
|
|
137
|
-
debug(`Found ${filtered.length} candidates`);
|
|
138
148
|
|
|
139
|
-
resolve({nextOffset, records: filtered, total: totalRecords});
|
|
149
|
+
resolve({nextOffset, records: filtered, failures, total: totalRecords});
|
|
140
150
|
} catch (err) {
|
|
151
|
+
debug(`Error caught on END`);
|
|
141
152
|
reject(err);
|
|
142
153
|
}
|
|
143
154
|
})
|
|
144
|
-
.on('record',
|
|
155
|
+
.on('record', foundRecordXML => {
|
|
145
156
|
promises.push(handleRecord()); // eslint-disable-line functional/immutable-data
|
|
146
157
|
|
|
147
158
|
async function handleRecord() {
|
|
148
159
|
try {
|
|
149
|
-
const foundRecordMarc = await MARCXML.from(
|
|
160
|
+
const foundRecordMarc = await MARCXML.from(foundRecordXML, {subfieldValues: false});
|
|
150
161
|
const foundRecordId = getRecordId(foundRecordMarc);
|
|
151
162
|
|
|
152
163
|
return {record: foundRecordMarc, id: foundRecordId};
|
|
153
164
|
} catch (err) {
|
|
154
|
-
|
|
165
|
+
// What should this do?
|
|
166
|
+
const idFromXML = getRecordIdFromXML(foundRecordXML);
|
|
167
|
+
debugData(`Failed converting record: ${err.message}, id: ${idFromXML}, data: ${foundRecordXML}`);
|
|
168
|
+
//return {message: `Failed converting record: ${err.message}`, id: idFromXML, data: foundRecordXML};
|
|
169
|
+
throw new MatchingError(422, {message: `Failed converting record: ${err.message}`, id: idFromXML || '000000000', data: foundRecordXML});
|
|
155
170
|
}
|
|
156
171
|
}
|
|
157
172
|
});
|
|
@@ -172,4 +187,11 @@ export default ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest =
|
|
|
172
187
|
const [field] = record.get(/^001$/u);
|
|
173
188
|
return field ? field.value : '';
|
|
174
189
|
}
|
|
190
|
+
|
|
191
|
+
function getRecordIdFromXML(recordXML) {
|
|
192
|
+
//<controlfield tag=\"001\">015376846</controlfield
|
|
193
|
+
debug(`Cannot yet find possible database record id from recordXML (length ${recordXML.length})`);
|
|
194
|
+
return undefined;
|
|
195
|
+
}
|
|
196
|
+
|
|
175
197
|
};
|