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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (66) hide show
  1. package/dist/candidate-search/candidate-search-utils.js +58 -0
  2. package/dist/candidate-search/candidate-search-utils.js.map +1 -0
  3. package/dist/candidate-search/index.js +273 -0
  4. package/dist/candidate-search/index.js.map +1 -0
  5. package/dist/candidate-search/index.spec.js +161 -0
  6. package/dist/candidate-search/index.spec.js.map +1 -0
  7. package/dist/candidate-search/query-list/bib.js +252 -0
  8. package/dist/candidate-search/query-list/bib.js.map +1 -0
  9. package/dist/candidate-search/query-list/bib.spec.js +72 -0
  10. package/dist/candidate-search/query-list/bib.spec.js.map +1 -0
  11. package/dist/candidate-search/query-list/index.js +67 -0
  12. package/dist/candidate-search/query-list/index.js.map +1 -0
  13. package/dist/index.js +578 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/index.spec.js +133 -0
  16. package/dist/index.spec.js.map +1 -0
  17. package/dist/match-detection/features/bib/all-source-ids.js +122 -0
  18. package/dist/match-detection/features/bib/all-source-ids.js.map +1 -0
  19. package/dist/match-detection/features/bib/authors.js +120 -0
  20. package/dist/match-detection/features/bib/authors.js.map +1 -0
  21. package/dist/match-detection/features/bib/bibliographic-level.js +42 -0
  22. package/dist/match-detection/features/bib/bibliographic-level.js.map +1 -0
  23. package/dist/match-detection/features/bib/host-component.js +42 -0
  24. package/dist/match-detection/features/bib/host-component.js.map +1 -0
  25. package/dist/match-detection/features/bib/index.js +104 -0
  26. package/dist/match-detection/features/bib/index.js.map +1 -0
  27. package/dist/match-detection/features/bib/index.spec.js +97 -0
  28. package/dist/match-detection/features/bib/index.spec.js.map +1 -0
  29. package/dist/match-detection/features/bib/isbn.js +55 -0
  30. package/dist/match-detection/features/bib/isbn.js.map +1 -0
  31. package/dist/match-detection/features/bib/issn.js +55 -0
  32. package/dist/match-detection/features/bib/issn.js.map +1 -0
  33. package/dist/match-detection/features/bib/language.js +113 -0
  34. package/dist/match-detection/features/bib/language.js.map +1 -0
  35. package/dist/match-detection/features/bib/melinda-id.js +52 -0
  36. package/dist/match-detection/features/bib/melinda-id.js.map +1 -0
  37. package/dist/match-detection/features/bib/melinda-identifier-factory.js +100 -0
  38. package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +1 -0
  39. package/dist/match-detection/features/bib/other-standard-identifier.js +55 -0
  40. package/dist/match-detection/features/bib/other-standard-identifier.js.map +1 -0
  41. package/dist/match-detection/features/bib/publication-time.js +51 -0
  42. package/dist/match-detection/features/bib/publication-time.js.map +1 -0
  43. package/dist/match-detection/features/bib/record-type.js +43 -0
  44. package/dist/match-detection/features/bib/record-type.js.map +1 -0
  45. package/dist/match-detection/features/bib/standard-identifier-factory.js +127 -0
  46. package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -0
  47. package/dist/match-detection/features/bib/title.js +95 -0
  48. package/dist/match-detection/features/bib/title.js.map +1 -0
  49. package/dist/match-detection/features/index.js +15 -0
  50. package/dist/match-detection/features/index.js.map +1 -0
  51. package/dist/match-detection/index.js +184 -0
  52. package/dist/match-detection/index.js.map +1 -0
  53. package/dist/match-detection/index.spec.js +99 -0
  54. package/dist/match-detection/index.spec.js.map +1 -0
  55. package/dist/matching-utils.js +104 -0
  56. package/dist/matching-utils.js.map +1 -0
  57. package/package.json +2 -1
  58. package/src/candidate-search/query-list/bib.js +19 -18
  59. package/src/candidate-search/query-list/index.js +1 -1
  60. package/src/match-detection/features/bib/authors.js +5 -2
  61. package/src/match-detection/features/bib/language.js +2 -2
  62. package/src/match-detection/features/bib/publication-time.js +8 -3
  63. package/src/match-detection/features/bib/record-type.js +2 -0
  64. package/src/match-detection/features/bib/standard-identifier-factory.js +4 -3
  65. package/src/match-detection/features/bib/title.js +6 -4
  66. package/src/matching-utils.js +13 -4
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["detection","detectionOptions","search","searchOptions","maxMatches","maxCandidates","returnStrategy","returnQuery","returnNonMatches","returnFailures","debug","createDebugLogger","debugData","extend","JSON","stringify","detect","createDetectionInterface","record","createSearchInterface","iterate","initialState","matches","candidateCount","nonMatches","duplicateCount","nonMatchCount","conversionFailures","matchErrors","records","failures","state","length","recordSetSize","failureSetSize","newCandidateCount","newConversionFailures","concat","handleRecordSet","queriesLeft","searchCounter","query","returnResult","stopReason","matchResult","iterateRecords","newDuplicateCount","newNonMatchCount","newMatches","newNonMatches","newMatchErrors","handleMatchResult","maxMatchesFound","maxCandidatesRetrieved","addQuery","map","match","matchQuery","conversionFailureCount","matchErrorCount","checkCounts","matchStatus","getMatchState","matchesResult","result","matchCount","chosenNonMatchCount","totalHandled","conversionFailuresCount","resultSetOffset","totalRecords","queryCandidateCounter","maxedQueries","searchesLeft","nonRetrieved","maxedQueriesStopReason","undefined","conversionFailuresStopReason","matchErrorsStopReason","newStopReason","status","recordMatches","recordNonMatches","recordCount","recordDuplicateCount","recordNonMatchCount","recordMatchErrors","candidate","newRecordCount","candidateNotInMatches","candidateRecord","id","candidateId","detectionResult","handleDetectionResult","error","matchError","payload","message","newRecordMatchErrors","slice","strategy","treshold","probability","strategyResult","newMatch","handleRecordMatch","newRecordNonMatchCount","isMatch","newRecordMatches","newRecordNonMatches","newCandidateId","find"],"sources":["../src/index.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-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 createSearchInterface, * as candidateSearch from './candidate-search';\nimport createDetectionInterface, * as matchDetection from './match-detection';\n//import inspect from 'util';\n\nexport {candidateSearch, matchDetection};\n\nexport default ({detection: detectionOptions, search: searchOptions, maxMatches = 1, maxCandidates = 25, returnStrategy = false, returnQuery = false, returnNonMatches = false, returnFailures = false}) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:index');\n const debugData = debug.extend('data');\n\n debugData(`DetectionOptions: ${JSON.stringify(detectionOptions)}`);\n debugData(`SearchOptions: ${JSON.stringify(searchOptions)}`);\n debugData(`MaxMatches: ${JSON.stringify(maxMatches)}`);\n debugData(`MaxCandidates: ${JSON.stringify(maxCandidates)}`);\n debugData(`ReturnStrategy: ${JSON.stringify(returnStrategy)}`);\n debugData(`ReturnQuery: ${JSON.stringify(returnQuery)}`);\n debugData(`ReturnNonMatches: ${JSON.stringify(returnNonMatches)}`);\n debugData(`ReturnFailures: ${JSON.stringify(returnFailures)}`);\n\n\n const detect = createDetectionInterface(detectionOptions, returnStrategy);\n\n return record => {\n const search = createSearchInterface({...searchOptions, record, maxCandidates});\n return iterate({});\n\n // candidateCount : amount of candidate records retrived from SRU for matching, NOT including current record set\n // matches : candidates that have been detected as matches by current matcher job\n // nonMatches : candidates that have been detected as non-matches by current matcher job (only if returnNonMatches is 'true')\n // duplicateCount : amount of candidate records that were retrieved from the SRU but not handled further because they were already found in the matches/nonMatches\n\n // state.totalRecords : amount of candidate records available to the current query (undefined, if there was no queries left)\n // state.query : current query (undefined if there was no queries left)\n // state.searchCounter : sequence for current search for current query (undefined, if there we no queries left)\n // state.queryCandidateCounter: amount of candidate records retrieved from SRU for matching for current query, including the current record set (undefined if there were no queries left)\n // state.queriesLeft : amount of queries left\n // state.queryCounter : sequence for current query\n // state.maxedQueries : queries that resulted in more than serverMaxResults hits\n\n async function iterate({initialState = {}, matches = [], candidateCount = 0, nonMatches = [], duplicateCount = 0, nonMatchCount = 0, conversionFailures = [], matchErrors = []}) {\n debugData(`Starting next matcher iteration.`);\n const {records, failures, ...state} = await search(initialState);\n\n debugData(`Current state: ${JSON.stringify(state)}, matches: ${matches.length}, candidateCount: ${candidateCount}, nonMatches: ${nonMatches.length}, nonMatchCount: ${nonMatchCount}, conversionFailures: ${conversionFailures}, matchErrors: ${matchErrors.length}`);\n const recordSetSize = records.length;\n const failureSetSize = failures.length;\n const newCandidateCount = candidateCount + recordSetSize + failureSetSize;\n\n const newConversionFailures = conversionFailures.concat(failures);\n debugData(`Failures: ${failures.length}, ConversionFailures: ${conversionFailures.length}, NewConversionFailures: ${newConversionFailures.length}`);\n\n if (recordSetSize > 0) {\n return handleRecordSet();\n }\n\n if (state.queriesLeft > 0) {\n debug(`Empty record set ${state.searchCounter} for ${state.query}, but there are ${state.queriesLeft} queries left`);\n return iterate({initialState: state, matches, candidateCount: newCandidateCount, nonMatches, nonMatchCount, duplicateCount, conversionFailures: newConversionFailures, matchErrors});\n }\n\n debug(`No (more) candidate records to check, no more queries left, matches: ${matches.length}`);\n return returnResult({matches, state, stopReason: '', nonMatches, nonMatchCount, candidateCount: newCandidateCount, duplicateCount, conversionFailures: newConversionFailures, matchErrors});\n\n function handleRecordSet() {\n debug(`Checking record set of ${recordSetSize} candidate records for possible matches, found by ${state.searchCounter} search for ${state.query}`);\n\n const matchResult = iterateRecords({records, recordSetSize, maxMatches, matches, nonMatches, nonMatchCount});\n\n const newDuplicateCount = duplicateCount + matchResult.duplicateCount;\n const newNonMatchCount = nonMatchCount + matchResult.nonMatchCount;\n const {newMatches, newNonMatches, newMatchErrors} = handleMatchResult(matchResult, matches, nonMatches, matchErrors);\n\n if (maxMatchesFound({matches: newMatches, maxMatches})) {\n return returnResult({matches: newMatches, state, stopReason: 'maxMatches', nonMatches: newNonMatches, duplicateCount: newDuplicateCount, candidateCount: newCandidateCount, nonMatchCount: newNonMatchCount, conversionFailures: newConversionFailures, matchErrors: newMatchErrors});\n }\n\n if (maxCandidatesRetrieved(newCandidateCount, maxCandidates)) {\n return returnResult({matches: newMatches, state, stopReason: 'maxCandidates', nonMatches: newNonMatches, duplicateCount: newDuplicateCount, candidateCount: newCandidateCount, nonMatchCount: newNonMatchCount, conversionFailures: newConversionFailures, matchErrors: newMatchErrors});\n }\n\n return iterate({initialState: state, matches: newMatches, candidateCount: newCandidateCount, nonMatches: newNonMatches, duplicateCount: newDuplicateCount, nonMatchCount: newNonMatchCount, conversionFailures: newConversionFailures, matchErrors: newMatchErrors});\n }\n\n function handleMatchResult(matchResult, matches, nonMatches, matchErrors) {\n debugData(`- Amount of new matches from record set: ${matchResult.matches.length}`);\n // eslint-disable-next-line functional/no-conditional-statement\n if (returnNonMatches) {\n debugData(`- Amount of new nonMatches from record set: ${matchResult.nonMatches.length}`);\n }\n\n const newMatches = matches.concat(returnQuery ? addQuery(matchResult.matches) : matchResult.matches);\n const newNonMatches = returnNonMatches ? nonMatches.concat(returnQuery ? addQuery(matchResult.nonMatches) : matchResult.nonMatches) : [];\n const newMatchErrors = matchErrors.concat(matchResult.matchErrors);\n\n debugData(`- Total amount of matches: ${newMatches.length}`);\n // eslint-disable-next-line functional/no-conditional-statement\n if (returnNonMatches) {\n debugData(`- Total amount of nonMatches: ${newNonMatches.length}`);\n }\n\n debugData(`MatchResult: ${JSON.stringify(matchResult)}`);\n debugData(`Old matchErrors: ${JSON.stringify(matchErrors)}, matchErrors from matchResult: ${JSON.stringify(matchResult.matchErrors)}, New matchErrors: ${JSON.stringify(newMatchErrors)}`);\n\n debugData(`- Total amount of matchErrors: ${newMatchErrors.length}`);\n\n return {newMatches, newNonMatches, newMatchErrors};\n }\n\n function addQuery(matches) {\n debugData(`Adding query ${state.query} to matches`);\n return matches.map((match) => ({...match, matchQuery: state.query}));\n }\n\n function maxCandidatesRetrieved(candidateCount, maxCandidates) {\n debugData(`Total amount of candidate records retrieved: ${newCandidateCount} (max: ${maxCandidates})`);\n if (maxCandidates && candidateCount >= maxCandidates) {\n debug(`Stopped matching because maximum number of candidate records ${candidateCount} / ${maxCandidates} have been retrieved`);\n return true;\n }\n }\n }\n\n // matches : array of matching candidate records\n // nonMatches : array of nonMatching candidate records (if returnNonMatches option is true, otherwise empty array)\n // - candidate.id\n // - candidate.record\n // - probability\n // - strategy (if returnStrategy option is true)\n // - treshold (if returnStrategy option is true)\n // - matchQuery (if returnQuery option is true)\n // failures: array of conversionFailures from candidate-search and matchErrors from matchDetection in error format {status, payload: {message, id}} if returnFailures is true\n\n // we could have here also returnRecords/returnMatchRecords/returnNonMatchRecord options that could be turned false for not to return actual record data\n\n // matchStatus.status: boolean, true if matcher retrieved and handled all found candidate records, false if it did not\n // matchStatus.stopReason: string ('maxMatches','maxCandidates','maxedQueries','conversionFailures', empty string/undefined), reason for stopping retrieving or handling the candidate records\n // - only one stopReason is returned (if there would be several possible stopReasons, stopReason is picked in the above order)\n // - currently stopReason can be non-empty also in cases where status is true, if matcher hit the stop reason when handling the last available candidate record\n\n function returnResult({matches, state, stopReason, nonMatches, duplicateCount, candidateCount, nonMatchCount, conversionFailures, matchErrors}) {\n const conversionFailureCount = conversionFailures.length;\n const matchErrorCount = matchErrors.length;\n checkCounts({matches, nonMatches, candidateCount, duplicateCount, nonMatchCount, conversionFailureCount, matchErrorCount});\n const matchStatus = getMatchState(state, stopReason, conversionFailureCount, matchErrorCount);\n // add nonMatches to result only if returnNonMatches is 'true', otherwise nonMatches have not been gathered\n const matchesResult = returnNonMatches ? {matches, matchStatus, nonMatches} : {matches, matchStatus};\n const failures = [...conversionFailures, ...matchErrors];\n const result = returnFailures ? {...matchesResult, conversionFailures: failures} : matchesResult;\n debugData(`ReturnFailures ${returnFailures}`);\n debugData(`${JSON.stringify(result)}`);\n return result;\n\n // note that in cases where the matching has been stopped because of maxMatches checkCounts won't (in most cases) match\n\n function checkCounts({matches, nonMatches, candidateCount, duplicateCount, nonMatchCount, conversionFailureCount, matchErrorCount}) {\n const matchCount = matches.length;\n debugData(`Return nonMatches: ${returnNonMatches}`);\n const chosenNonMatchCount = returnNonMatches ? nonMatches.length : nonMatchCount;\n const totalHandled = matchCount + chosenNonMatchCount + duplicateCount;\n debug(`candidateCount: ${candidateCount}, matches: ${matchCount}, nonMatches: ${chosenNonMatchCount}, duplicateCount: ${duplicateCount}, conversionFailureCount: ${conversionFailureCount}, matchErrorCount: ${matchErrorCount}`);\n debug(`We got result for ${totalHandled} / ${candidateCount} retrieved candidates`);\n if (totalHandled !== candidateCount) {\n debug(`WARNING: Missing results for ${candidateCount - totalHandled} candidates`);\n return;\n }\n return;\n }\n\n // eslint-disable-next-line max-statements\n function getMatchState(state, stopReason, conversionFailuresCount, matchErrorCount) {\n debugData(`${JSON.stringify(state)}`);\n debug(`We had ${conversionFailuresCount} retrieved candidates that could not be converted.`);\n debug(`We had ${matchErrorCount} retrieved candidates that errored in matchDetection.`);\n debug(`Queries left ${state.queriesLeft}, Searches for current query left: ${state.resultSetOffset && state.resultSetOffset <= state.totalRecords}, non-retrieved records: ${state.totalRecords - state.queryCandidateCounter}, maxedQueries (${state.maxedQueries.length}): ${state.maxedQueries}`);\n\n debugData(`StopReason: <${stopReason}>`);\n\n const searchesLeft = state.resultSetOffset && state.resultSetOffset <= state.totalRecords;\n const nonRetrieved = searchesLeft ? state.totalRecords - state.queryCandidateCounter : 0;\n debugData(`nonRetrieved: ${nonRetrieved}`);\n\n // matchStatus.stopReason: string ('maxMatches','maxCandidates','maxedQueries','conversionFailures', empty string/undefined), reason for stopping retrieving or handling the candidate records\n // 'maxMatches' and 'maxCandidates' are in stopReason, 'maxedQueries', 'conversionFailures' and 'matchErrors' are created here\n\n if (state.queriesLeft > 0 || nonRetrieved > 0 || state.maxedQueries.length > 0 || conversionFailureCount > 0 || matchErrorCount > 0) {\n const maxedQueriesStopReason = state.maxedQueries.length > 0 ? 'maxedQueries' : undefined;\n const conversionFailuresStopReason = conversionFailureCount > 0 ? 'conversionFailures' : undefined;\n const matchErrorsStopReason = matchErrorCount > 0 ? 'matchErrors' : undefined;\n const newStopReason = stopReason === '' || stopReason === undefined ? maxedQueriesStopReason || conversionFailuresStopReason || matchErrorsStopReason : stopReason;\n debugData(`MaxedQueriesStopReason: <${maxedQueriesStopReason}>`);\n debugData(`ConversionFailureStopReason <${conversionFailuresStopReason}>`);\n debugData(`MatchErrorsStopReason <${matchErrorsStopReason}>`);\n debugData(`NewStopReason: <${newStopReason}>`);\n debug(`Match status: false`);\n return {status: false, stopReason: newStopReason};\n }\n\n debug(`Match status: true`);\n return {status: true, stopReason};\n }\n }\n\n // NOTES:\n // - we could optimize by creating the featureSet for the incoming record once and using it for all database/candidateRecords\n // - if creating the featureSet for the incoming record fails we have an unprocessable entity\n // - if creating the featureSet for a candidate record fails we could skip that candidate - but list the case as a detectionFailure, same as conversionFailures\n\n // eslint-disable-next-line max-statements\n function iterateRecords({records, recordSetSize, maxMatches, matches = [], nonMatches = [], recordMatches = [], recordNonMatches = [], recordCount = 0, recordDuplicateCount = 0, recordNonMatchCount = 0, recordMatchErrors = []}) {\n\n // recordSetSize : total amount of records in the current record set\n // recordCount : amount of records from the current record set that have been handled\n // maxMatches : setting for maximum amount found by current matcher job before the matcher job is stopped\n // recordDuplicateCount : amount of records from the current record set that are already included in matches/nonMatches results\n // recordNonMatchCount: amount of records from the current record set that are nonMatches (only is returnNonMatches setting is false)\n\n // records : non-handled records in the current record set\n // matches : found matches in the current matcher job\n // recordMatches : found matches in the current record set\n // recordNonMatches : found nonMatches in the current record set (only if returnNonMatches setting is true)\n // recordMatchErrors: errored matchDetection in the current record set\n\n const [candidate] = records;\n const newRecordCount = candidate ? recordCount + 1 : recordCount;\n\n // The matcher uses same matchDetection strategy for candidates from all candidate-searches -> matchDetection result for the same candidate is always same\n // Exceptions would happen if the candidate would have been updated in the database between candidate searches\n // Note that if returnNonMatches is false, matcher won't remember candidates that didn't match, so they will be matched again everytime they are retrieved by\n // different candidate search queries. Same candidate search query won't have duplicate records.\n\n /* We could optimize and detect all retrieved candidates at once\n const candidateRecords = records.map(record => record.record);\n const recordsIsArray = Array.isArray(candidateRecords);\n debug(`records is an array: ${recordsIsArray}`);\n const result = detect(record, candidateRecords);\n debug(`${JSON.stringify(result)}`);\n */\n\n if (candidate) {\n\n // eslint-disable-next-line functional/no-conditional-statement\n if (candidateNotInMatches(matches.concat(nonMatches), candidate)) {\n const {record: candidateRecord, id: candidateId} = candidate;\n try {\n debug(`Running matchDetection for record ${candidateId} (${newRecordCount}/${recordSetSize})`);\n // we should handle errors from detection somehow - ie. cases where either record or candidateRecord errors\n const detectionResult = detect(record, candidateRecord);\n\n return handleDetectionResult(detectionResult, candidateId, candidateRecord);\n } catch (error) {\n debug(`MatchDetection errored: database record ${candidateId}: ${error}`);\n\n const matchError = {status: 422, payload: {message: `Matching errored for database record ${candidateId}. ${error.message}.`, id: candidateId}};\n const newRecordMatchErrors = recordMatchErrors.concat(matchError);\n return iterateRecords({records: records.slice(1), recordSetSize, maxMatches, matches, recordMatches, recordCount: newRecordCount, recordNonMatches, recordDuplicateCount, recordNonMatchCount, recordMatchErrors: newRecordMatchErrors});\n }\n }\n\n return iterateRecords({records: records.slice(1), recordSetSize, maxMatches, matches, recordMatches, recordCount: newRecordCount, recordNonMatches, recordDuplicateCount: recordDuplicateCount + 1, recordNonMatchCount, recordMatchErrors});\n }\n\n debug(`No more candidates, record set (${recordCount}/${recordSetSize}) done, ${recordMatches.length} matches found, ${recordDuplicateCount} candidates already handled, ${returnNonMatches ? `${recordNonMatches.length}` : `${recordNonMatchCount}`} nonMatches found.`);\n return {matches: recordMatches, nonMatches: returnNonMatches ? recordNonMatches : [], duplicateCount: recordDuplicateCount, nonMatchCount: recordNonMatchCount, matchErrors: recordMatchErrors};\n\n function handleDetectionResult(detectionResult, candidateId, candidateRecord) {\n debugData(`MatchDetection results for ${candidateId} (${newRecordCount}/${recordSetSize}): ${JSON.stringify(detectionResult)}`);\n\n if (detectionResult.match || returnNonMatches) {\n debug(`${detectionResult.match ? `Record ${candidateId} (${newRecordCount}/${recordSetSize}) is a match!` : `Record ${candidateId} (${newRecordCount}/${recordSetSize}) is NOT a match!`}`);\n debugData(`Strategy: ${JSON.stringify(detectionResult.strategy)}, Treshold: ${JSON.stringify(detectionResult.treshold)}`);\n\n const matchResult = {\n probability: detectionResult.probability,\n candidate: {\n id: candidateId,\n record: candidateRecord\n }\n };\n const strategyResult = {\n strategy: detectionResult.strategy,\n treshold: detectionResult.treshold\n };\n const newMatch = returnStrategy ? {...matchResult, ...strategyResult} : {...matchResult};\n\n debugData(`${JSON.stringify(newMatch)}`);\n\n return handleRecordMatch(detectionResult.match, newMatch);\n }\n\n const newRecordNonMatchCount = recordNonMatchCount + 1;\n debugData(`- Total nonMatches after this detection: ${newRecordNonMatchCount}`);\n\n return iterateRecords({records: records.slice(1), recordSetSize, maxMatches, matches, recordMatches, recordCount: newRecordCount, recordNonMatches, recordDuplicateCount, recordNonMatchCount: newRecordNonMatchCount, recordMatchErrors});\n }\n\n function handleRecordMatch(isMatch, newMatch) {\n const newRecordMatches = isMatch ? recordMatches.concat(newMatch) : recordMatches;\n const newRecordNonMatches = isMatch ? recordNonMatches : recordNonMatches.concat(newMatch);\n const newRecordNonMatchCount = isMatch ? recordNonMatchCount : recordNonMatchCount + 1;\n\n debugData(`- Total matches after this detection: ${matches.concat(newRecordMatches).length} (max: ${maxMatches})`);\n\n // eslint-disable-next-line functional/no-conditional-statement\n if (returnNonMatches) {\n debugData(`- Total nonMatches after this detection: ${nonMatches.concat(newRecordNonMatches).length}`);\n }\n debugData(`- Total nonMatchCount after this detection: ${recordNonMatchCount}`);\n\n if (maxMatchesFound({matches: matches.concat(newRecordMatches), maxMatches})) {\n debug(`MaxMatches (${maxMatches}) reached, handled candidates in record set: ${newRecordCount} non-handled candidates in record set ${recordSetSize - newRecordCount}`);\n return {matches: newRecordMatches, nonMatches: returnNonMatches ? newRecordNonMatches : [], duplicateCount: recordDuplicateCount, nonMatchCount: newRecordNonMatchCount, matchErrors: recordMatchErrors};\n }\n\n return iterateRecords({records: records.slice(1), recordSetSize, maxMatches, matches, recordMatches: newRecordMatches, recordCount: newRecordCount, recordNonMatches: returnNonMatches ? newRecordNonMatches : [], duplicateCount: recordDuplicateCount, recordNonMatchCount: newRecordNonMatchCount, matchErrors: recordMatchErrors});\n }\n\n function candidateNotInMatches(matches, candidate) {\n debug(`Checking that record ${candidate.id} is not already included in ${matches.length} matches/nonMatches`);\n const newCandidateId = candidate.id;\n debugData(`newCandidateId: ${newCandidateId}`);\n const result = matches.find(({candidate}) => candidate.id === newCandidateId);\n debugData(`Result: ${result}`);\n if (result) {\n debug(`${candidate.id} was already handled.`);\n return false;\n }\n debug(`${candidate.id} not found in matches/nonMatches`);\n return true;\n }\n }\n\n function maxMatchesFound({matches, maxMatches}) {\n if (maxMatches && matches.length >= maxMatches) {\n debug(`Stopping recordSet iteration: maxMatches (${maxMatches}) for matcher job found.`);\n return true;\n }\n }\n };\n};\n"],"mappings":";;;;;;;AA4BA;;AACA;;;;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;AAKA;eAIe,CAAC;EAACA,SAAS,EAAEC,gBAAZ;EAA8BC,MAAM,EAAEC,aAAtC;EAAqDC,UAAU,GAAG,CAAlE;EAAqEC,aAAa,GAAG,EAArF;EAAyFC,cAAc,GAAG,KAA1G;EAAiHC,WAAW,GAAG,KAA/H;EAAsIC,gBAAgB,GAAG,KAAzJ;EAAgKC,cAAc,GAAG;AAAjL,CAAD,KAA6L;EAC1M,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAkB,yCAAlB,CAAd;EACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB;EAEAD,SAAS,CAAE,qBAAoBE,IA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");
6
+
7
+ var _fixugenHttpClient = _interopRequireDefault(require("@natlibfi/fixugen-http-client"));
8
+
9
+ var _marcRecord = require("@natlibfi/marc-record");
10
+
11
+ var _ = _interopRequireWildcard(require("."));
12
+
13
+ var _debug = _interopRequireDefault(require("debug"));
14
+
15
+ 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
+
17
+ 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; }
18
+
19
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
20
+
21
+ /**
22
+ *
23
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
24
+ *
25
+ * Melinda record matching modules for Javascript
26
+ *
27
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
28
+ *
29
+ * This file is part of melinda-record-matching-js
30
+ *
31
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
32
+ * it under the terms of the GNU Lesser General Public License as
33
+ * published by the Free Software Foundation, either version 3 of the
34
+ * License, or (at your option) any later version.
35
+ *
36
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
37
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
38
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
39
+ * GNU Lesser General Public License for more details.
40
+ *
41
+ * You should have received a copy of the GNU Affero General Public License
42
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
43
+ *
44
+ * @licend The above is the entire license notice
45
+ * for the JavaScript code in this file.
46
+ *
47
+ */
48
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:index:test');
49
+ const debugData = debug.extend('data');
50
+ describe('INDEX', () => {
51
+ (0, _fixugenHttpClient.default)({
52
+ callback,
53
+ path: [__dirname, '..', 'test-fixtures', 'index'],
54
+ recurse: false,
55
+ fixura: {
56
+ reader: _fixura.READERS.JSON
57
+ }
58
+ });
59
+
60
+ async function callback({
61
+ getFixture,
62
+ options,
63
+ enabled = true,
64
+ expectedMatchStatus,
65
+ expectedStopReason,
66
+ expectedFailures
67
+ }) {
68
+ if (!enabled) {
69
+ debug(`Disabled test!`);
70
+ return;
71
+ }
72
+
73
+ const record = new _marcRecord.MarcRecord(getFixture('inputRecord.json'), {
74
+ subfieldValues: false
75
+ });
76
+ const expectedMatches = getFixture('expectedMatches.json');
77
+ const expectedNonMatches = getFixture('expectedNonMatches.json') || [];
78
+ const match = (0, _.default)(formatOptions());
79
+ const {
80
+ matches,
81
+ matchStatus,
82
+ nonMatches,
83
+ conversionFailures
84
+ } = await match(record);
85
+ debugData(`Matches: ${matches.length}, Status: ${matchStatus.status}/${matchStatus.stopReason}, NonMatches: ${nonMatches ? nonMatches.length : 'not returned'}, ConversionFailures: ${conversionFailures ? conversionFailures.length : 'not returned'}`);
86
+ (0, _chai.expect)(matchStatus.status).to.eql(expectedMatchStatus);
87
+ (0, _chai.expect)(matchStatus.stopReason).to.eql(expectedStopReason);
88
+ const formattedMatchResult = formatRecordResults(matches);
89
+ (0, _chai.expect)(formattedMatchResult).to.eql(expectedMatches);
90
+ const formattedNonMatchResult = formatRecordResults(nonMatches);
91
+ (0, _chai.expect)(formattedNonMatchResult).to.eql(expectedNonMatches); // eslint-disable-next-line functional/no-conditional-statement
92
+
93
+ if (expectedFailures) {
94
+ (0, _chai.expect)(conversionFailures).to.eql(expectedFailures);
95
+ }
96
+
97
+ function formatOptions() {
98
+ const contextFeatures = _.matchDetection.features[options.detection.strategy.type];
99
+ return { ...options,
100
+ search: { ...options.search
101
+ },
102
+ detection: { ...options.detect,
103
+ strategy: options.detection.strategy.features.map(v => contextFeatures[v]())
104
+ }
105
+ };
106
+ }
107
+
108
+ function formatRecordResults(matches) {
109
+ if (matches) {
110
+ debugData(JSON.stringify(matches));
111
+ return matches.map(match => ({ ...match,
112
+ candidate: formatCandidate(match.candidate)
113
+ }));
114
+ }
115
+
116
+ return [];
117
+ } // Format candidate to remove validationOptions from record
118
+
119
+
120
+ function formatCandidate({
121
+ id,
122
+ record
123
+ }) {
124
+ const newId = id;
125
+ const newRecord = record;
126
+ return {
127
+ id: newId,
128
+ record: newRecord.toObject()
129
+ };
130
+ }
131
+ }
132
+ });
133
+ //# sourceMappingURL=index.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.spec.js","names":["debug","createDebugLogger","debugData","extend","describe","generateTests","callback","path","__dirname","recurse","fixura","reader","READERS","JSON","getFixture","options","enabled","expectedMatchStatus","expectedStopReason","expectedFailures","record","MarcRecord","subfieldValues","expectedMatches","expectedNonMatches","match","createMatchInterface","formatOptions","matches","matchStatus","nonMatches","conversionFailures","length","status","stopReason","expect","to","eql","formattedMatchResult","formatRecordResults","formattedNonMatchResult","contextFeatures","matchDetection","features","detection","strategy","type","search","detect","map","v","stringify","candidate","formatCandidate","id","newId","newRecord","toObject"],"sources":["../src/index.spec.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 {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"],"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,IAAAC,cAAA,EAAkB,8CAAlB,CAAd;AACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB;AAEAC,QAAQ,CAAC,OAAD,EAAU,MAAM;EACtB,IAAAC,0BAAA,EAAc;IACZC,QADY;IAEZC,IAAI,EAAE,CAACC,SAAD,EAAY,IAAZ,EAAkB,eAAlB,EAAmC,OAAnC,CAFM;IAGZC,OAAO,EAAE,KAHG;IAIZC,MAAM,EAAE;MACNC,MAAM,EAAEC,eAAA,CAAQC;IADV;EAJI,CAAd;;EASA,eAAeP,QAAf,CAAwB;IAACQ,UAAD;IAAaC,OAAb;IAAsBC,OAAO,GAAG,IAAhC;IAAsCC,mBAAtC;IAA2DC,kBAA3D;IAA+EC;EAA/E,CAAxB,EAA0H;IAExH,IAAI,CAACH,OAAL,EAAc;MACZhB,KAAK,CAAE,g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AA9B,CAAkClB,gBAAlC;IACD;;IAED,SAASQ,aAAT,GAAyB;MACvB,MAAMc,eAAe,GAAGC,gBAAA,CAAeC,QAAf,CAAwB5B,OAAO,CAAC6B,SAAR,CAAkBC,QAAlB,CAA2BC,IAAnD,CAAxB;MAEA,OAAO,EACL,GAAG/B,OADE;QAELgC,MAAM,EAAE,EACN,GAAGhC,OAAO,CAACgC;QADL,CAFH;QAKLH,SAAS,EAAE,EACT,GAAG7B,OAAO,CAACiC,MADF;UAETH,QAAQ,EAAE9B,OAAO,CAAC6B,SAAR,CAAkBC,QAAlB,CAA2BF,QAA3B,CAAoCM,GAApC,CAAwCC,CAAC,IAAIT,eAAe,CAACS,CAAD,CAAf,EAA7C;QAFD;MALN,CAAP;IAUD;;IAED,SAASX,mBAAT,CAA6BX,OAA7B,EAAsC;MACpC,IAAIA,OAAJ,EAAa;QACX1B,SAAS,CAACW,IAAI,CAACsC,SAAL,CAAevB,OAAf,CAAD,CAAT;QACA,OAAOA,OAAO,CAACqB,GAAR,CAAaxB,KAAD,KAAY,EAC7B,GAAGA,KAD0B;UAE7B2B,SAAS,EAAEC,eAAe,CAAC5B,KAAK,CAAC2B,SAAP;QAFG,CAAZ,CAAZ,CAAP;MAID;;MACD,OAAO,EAAP;IACD,CAtDuH,CAwDxH;;;IACA,SAASC,eAAT,CAAyB;MAACC,EAAD;MAAKlC;IAAL,CAAzB,EAAuC;MACrC,MAAMmC,KAAK,GAAGD,EAAd;MACA,MAAME,SAAS,GAAGpC,MAAlB;MACA,OAAO;QACLkC,EAAE,EAAEC,KADC;QAELnC,MAAM,EAAEoC,SAAS,CAACC,QAAV;MAFH,CAAP;IAID;EAGF;AAEF,CA/EO,CAAR"}
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _debug = _interopRequireDefault(require("debug"));
9
+
10
+ var _matchingUtils = require("../../../matching-utils");
11
+
12
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
+
14
+ /* eslint-disable max-statements */
15
+
16
+ /**
17
+ *
18
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
19
+ *
20
+ * Melinda record matching modules for Javascript
21
+ *
22
+ * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
23
+ *
24
+ * This file is part of melinda-record-matching-js
25
+ *
26
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
27
+ * it under the terms of the GNU Lesser General Public License as
28
+ * published by the Free Software Foundation, either version 3 of the
29
+ * License, or (at your option) any later version.
30
+ *
31
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
32
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
33
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
34
+ * GNU Lesser General Public License for more details.
35
+ *
36
+ * You should have received a copy of the GNU Affero General Public License
37
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
38
+ *
39
+ * @licend The above is the entire license notice
40
+ * for the JavaScript code in this file.
41
+ *
42
+ */
43
+ const debug = (0, _debug.default)('@natlibfi/melinda-record-matching:match-detection:features:all-source-ids');
44
+ const debugData = debug.extend('data');
45
+ /*
46
+
47
+ SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:
48
+
49
+ SID__ $c 123457 $b helka
50
+ SID__ $c (ANDL100020)1077305 $b sata
51
+ SID__ $c VER999999 $ FI-KV
52
+
53
+ allSourceIds matching feature is formatted as [{sourceDb: "helka", sourceId: "123457"}, {sourceDb: "sata", sourceId: "(ANDL100020)1077305"}, {sourceDb: "FI-KV", sourceId: "VER999999"}]
54
+ - no normalization / prefix deletions etc. in the feature
55
+
56
+ Note: All Melinda records that have a matching records in a local db do NOT have SID for that local records,
57
+ existence of a SID field depends on how the record has been added to Melinda and how it has been handled
58
+ afterwards. SIDs are also not reliably maintained. A record might or might not have a SID for a local db
59
+ after the matching record is removed from the local db.
60
+
61
+ Records with mismatching local ids for matching local db are a strong mismatch.
62
+ Records with matching local ids for matching local db are a very good match.
63
+
64
+ */
65
+
66
+ var _default = () => ({
67
+ name: 'All source IDs',
68
+ extract: record => {
69
+ debug(`Creating match detection features for all local source id's`);
70
+ const fSids = record.get('SID');
71
+ debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);
72
+ const sidFeatures = getSidFeatures(fSids);
73
+ debugData(`SID-features (${sidFeatures.length}): ${JSON.stringify(sidFeatures)}`);
74
+ return sidFeatures;
75
+
76
+ function getSidFeatures(fSids) {
77
+ debug(`Getting Sid strings from SID fields`); // Map SID fields to sidFeatures, filter out empty strings
78
+
79
+ const sidFeatures = fSids.map(toSidFeature).filter(nonEmptySid => nonEmptySid);
80
+ return sidFeatures;
81
+
82
+ function toSidFeature(field) {
83
+ debug(`Getting feature from a field`);
84
+ return (0, _matchingUtils.validateSidFieldSubfieldCounts)(field) ? createSidFeature(field) : '';
85
+
86
+ function createSidFeature(field) {
87
+ debug(`Creating feature from a field`);
88
+ const [sfC] = (0, _matchingUtils.getSubfieldValues)(field, 'c');
89
+ const [sfB] = (0, _matchingUtils.getSubfieldValues)(field, 'b');
90
+ debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);
91
+ debugData(`sourceDb: ${sfB}, sourceId: ${sfC}`);
92
+ return {
93
+ 'sourceDb': sfB,
94
+ 'sourceId': sfC
95
+ };
96
+ }
97
+ }
98
+ }
99
+ },
100
+ compare: (a, b) => {
101
+ debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);
102
+ const matches = a.filter(sidA => b.some(sidB => sidA.sourceDb === sidB.sourceDb && sidA.sourceId === sidB.sourceId));
103
+ debugData(`Matches (${matches.length}): ${JSON.stringify(matches)}`);
104
+ const mismatches = a.filter(sidA => b.some(sidB => sidA.sourceDb === sidB.sourceDb && sidA.sourceId !== sidB.sourceId));
105
+ debugData(`Mismatches (${mismatches.length}): ${JSON.stringify(mismatches)}`); // If there's at least one mismatching source ID from matching source db
106
+
107
+ if (mismatches.length > 0) {
108
+ return -1;
109
+ } // If there's at least one matching source ID from matching source db
110
+
111
+
112
+ if (matches.length > 0) {
113
+ return 1;
114
+ } // If there are no source IDs with matching sources
115
+
116
+
117
+ return 0;
118
+ }
119
+ });
120
+
121
+ exports.default = _default;
122
+ //# sourceMappingURL=all-source-ids.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"all-source-ids.js","names":["debug","createDebugLogger","debugData","extend","name","extract","record","fSids","get","length","JSON","stringify","sidFeatures","getSidFeatures","map","toSidFeature","filter","nonEmptySid","field","validateSidFieldSubfieldCounts","createSidFeature","sfC","getSubfieldValues","sfB","compare","a","b","matches","sidA","some","sidB","sourceDb","sourceId","mismatches"],"sources":["../../../../src/match-detection/features/bib/all-source-ids.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 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 {validateSidFieldSubfieldCounts, getSubfieldValues} from '../../../matching-utils';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:all-source-ids');\nconst debugData = debug.extend('data');\n\n/*\n\nSID-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\nallSourceIds matching feature is formatted as [{sourceDb: \"helka\", sourceId: \"123457\"}, {sourceDb: \"sata\", sourceId: \"(ANDL100020)1077305\"}, {sourceDb: \"FI-KV\", sourceId: \"VER999999\"}]\n- no normalization / prefix deletions etc. in the feature\n\nNote: 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\nRecords with mismatching local ids for matching local db are a strong mismatch.\nRecords with matching local ids for matching local db are a very good match.\n\n*/\n\nexport default () => ({\n name: 'All source IDs',\n extract: record => {\n debug(`Creating match detection features for all local source id's`);\n\n const fSids = record.get('SID');\n debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);\n\n const sidFeatures = getSidFeatures(fSids);\n debugData(`SID-features (${sidFeatures.length}): ${JSON.stringify(sidFeatures)}`);\n\n return sidFeatures;\n\n function getSidFeatures(fSids) {\n debug(`Getting Sid strings from SID fields`);\n\n // Map SID fields to sidFeatures, filter out empty strings\n const sidFeatures = fSids.map(toSidFeature).filter(nonEmptySid => nonEmptySid);\n return sidFeatures;\n\n function toSidFeature(field) {\n debug(`Getting feature from a field`);\n\n return validateSidFieldSubfieldCounts(field) ? createSidFeature(field) : '';\n\n function createSidFeature(field) {\n debug(`Creating feature from a field`);\n const [sfC] = getSubfieldValues(field, 'c');\n const [sfB] = getSubfieldValues(field, 'b');\n\n debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);\n debugData(`sourceDb: ${sfB}, sourceId: ${sfC}`);\n return {'sourceDb': sfB, 'sourceId': sfC};\n }\n }\n\n }\n\n },\n compare: (a, b) => {\n\n debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);\n\n const matches = a.filter(sidA => b.some(sidB => sidA.sourceDb === sidB.sourceDb &&\n sidA.sourceId === sidB.sourceId));\n debugData(`Matches (${matches.length}): ${JSON.stringify(matches)}`);\n\n const mismatches = a.filter(sidA => b.some(sidB => sidA.sourceDb === sidB.sourceDb &&\n sidA.sourceId !== sidB.sourceId));\n debugData(`Mismatches (${mismatches.length}): ${JSON.stringify(mismatches)}`);\n\n // If there's at least one mismatching source ID from matching source db\n if (mismatches.length > 0) {\n return -1;\n }\n\n // If there's at least one matching source ID from matching source db\n if (matches.length > 0) {\n return 1;\n }\n\n // If there are no source IDs with matching sources\n return 0;\n\n }\n});\n"],"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;AAKA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAkB,2EAAlB,CAAd;AACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;eAEe,OAAO;EACpBC,IAAI,EAAE,gBADc;EAEpBC,OAAO,EAAEC,MAAM,IAAI;IACjBN,KAAK,CAAE,6DAAF,CAAL;IAEA,MAAMO,KAAK,GAAGD,MAAM,CAACE,GAAP,CAAW,KAAX,CAAd;IACAN,SAAS,CAAE,eAAcK,KAAK,CAACE,MAAO,MAAKC,IAAI,CAACC,SAAL,CAAeJ,KAAf,CAAsB,EAAxD,CAAT;IAEA,MAAMK,WAAW,GAAGC,cAAc,CAACN,KAAD,CAAlC;IACAL,SAAS,CAAE,iBAAgBU,WAAW,CAACH,MAAO,MAAKC,IAAI,CAACC,SAAL,CAAeC,WAAf,CAA4B,EAAtE,CAAT;IAEA,OAAOA,WAAP;;IAEA,SAASC,cAAT,CAAwBN,KAAxB,EAA+B;MAC7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,CAAjB,CAAhB;IAEA9B,SAAS,CAAE,YAAWyB,OAAO,CAAClB,MAAO,MAAKC,IAAI,CAACC,SAAL,CAAegB,OAAf,CAAwB,EAAzD,CAAT;IAEA,MAAMM,UAAU,GAAGR,CAAC,CAACT,MAAF,CAASY,IAAI,IAAIF,CAAC,CAACG,IAAF,CAAOC,IAAI,IAAIF,IAAI,CAACG,QAAL,KAAkBD,IAAI,CAACC,QAAvB,IACjDH,IAAI,CAACI,QAAL,KAAkBF,IAAI,CAACE,QADW,CAAjB,CAAnB;IAEA9B,SAAS,CAAE,eAAc+B,UAAU,CAACxB,MAAO,MAAKC,IAAI,CAACC,SAAL,CAAesB,UAAf,CAA2B,EAAlE,CAAT,CAViB,CAYjB;;IACA,IAAIA,UAAU,CAACxB,MAAX,GAAoB,CAAxB,EAA2B;MACzB,OAAO,CAAC,CAAR;IACD,CAfgB,CAiBjB;;;IACA,IAAIkB,OAAO,CAAClB,MAAR,GAAiB,CAArB,EAAwB;MACtB,OAAO,CAAP;IACD,CApBgB,CAsBjB;;;IACA,OAAO,CAAP;EAED;AAhEmB,CAAP,C"}
@@ -0,0 +1,120 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _natural = require("natural");
9
+
10
+ var _matchingUtils = require("../../../matching-utils");
11
+
12
+ /**
13
+ *
14
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
15
+ *
16
+ * Melinda record matching modules for Javascript
17
+ *
18
+ * Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
19
+ *
20
+ * This file is part of melinda-record-matching-js
21
+ *
22
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
23
+ * it under the terms of the GNU Lesser General Public License as
24
+ * published by the Free Software Foundation, either version 3 of the
25
+ * License, or (at your option) any later version.
26
+ *
27
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
28
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
29
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30
+ * GNU Lesser General Public License for more details.
31
+ *
32
+ * You should have received a copy of the GNU Affero General Public License
33
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
34
+ *
35
+ * @licend The above is the entire license notice
36
+ * for the JavaScript code in this file.
37
+ *
38
+ */
39
+ // We should extract also organisational authors (110/710)
40
+ var _default = ({
41
+ nameTreshold = 10
42
+ } = {}) => ({
43
+ name: 'Authors',
44
+ extract: record => record.get(/^(?<def>100|700)$/u).map(({
45
+ subfields
46
+ }) => {
47
+ return subfields.filter(({
48
+ code,
49
+ value
50
+ }) => code && value).filter(({
51
+ code
52
+ }) => ['a', '0'].includes(code)).map(toObj).reduce((acc, v) => ({ ...acc,
53
+ ...v
54
+ }), {});
55
+
56
+ function toObj({
57
+ code,
58
+ value
59
+ }) {
60
+ if (code === 'a') {
61
+ return {
62
+ name: (0, _matchingUtils.testStringOrNumber)(value) ? String(value).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase() : ''
63
+ };
64
+ }
65
+
66
+ return {
67
+ id: value
68
+ };
69
+ }
70
+ }),
71
+ compare: (a, b) => {
72
+ const maxAuthors = a.length > b.length ? a.length : b.length;
73
+ const matchingIds = findMatchingIds();
74
+
75
+ if (maxAuthors >= 3 && matchingIds >= 3) {
76
+ return 0.3;
77
+ }
78
+
79
+ const matchingNames = findMatchingNames();
80
+ const idPoints = matchingIds / maxAuthors * 0.3;
81
+ const namePoints = matchingNames / maxAuthors * 0.2;
82
+ const totalPoints = idPoints + namePoints;
83
+ return totalPoints <= 0.2 ? totalPoints : 0.2;
84
+
85
+ function findMatchingIds() {
86
+ return findMatches('id', (a, b) => a === b);
87
+ }
88
+
89
+ function findMatchingNames() {
90
+ return findMatches('name', (a, b) => {
91
+ const distance = (0, _natural.LevenshteinDistance)(a, b);
92
+
93
+ if (distance === 0) {
94
+ return true;
95
+ }
96
+
97
+ const maxLength = getMaxLength();
98
+ const percentage = distance / maxLength * 100;
99
+ return percentage <= nameTreshold;
100
+
101
+ function getMaxLength() {
102
+ return a.length > b.length ? a.length : b.length;
103
+ }
104
+ });
105
+ }
106
+
107
+ function findMatches(key, cb) {
108
+ const valuesA = a.filter(o => o[key]).map(o => o[key]);
109
+ const valuesB = b.filter(o => o[key]).map(o => o[key]);
110
+ const allValues = valuesA.concat(valuesB);
111
+ return allValues.reduce((acc, value) => {
112
+ const occurrance = allValues.filter(otherValue => cb(value, otherValue)).length;
113
+ return occurrance >= 2 ? acc + 1 : acc;
114
+ }, 0);
115
+ }
116
+ }
117
+ });
118
+
119
+ exports.default = _default;
120
+ //# sourceMappingURL=authors.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authors.js","names":["nameTreshold","name","extract","record","get","map","subfields","filter","code","value","includes","toObj","reduce","acc","v","testStringOrNumber","String","replace","toLowerCase","id","compare","a","b","maxAuthors","length","matchingIds","findMatchingIds","matchingNames","findMatchingNames","idPoints","namePoints","totalPoints","findMatches","distance","leven","maxLength","getMaxLength","percentage","key","cb","valuesA","o","valuesB","allValues","concat","occurrance","otherValue"],"sources":["../../../../src/match-detection/features/bib/authors.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 {LevenshteinDistance as leven} from 'natural';\nimport {testStringOrNumber} from '../../../matching-utils';\n\n// We should extract also organisational authors (110/710)\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: testStringOrNumber(value) ? String(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"],"mappings":";;;;;;;AA4BA;;AACA;;AA7BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA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MI,OAAO,GAAGpB,CAAC,CAACf,MAAF,CAASkC,CAAC,IAAIA,CAAC,CAACH,GAAD,CAAf,EAAsBjC,GAAtB,CAA0BoC,CAAC,IAAIA,CAAC,CAACH,GAAD,CAAhC,CAAhB;MACA,MAAMK,SAAS,GAAGH,OAAO,CAACI,MAAR,CAAeF,OAAf,CAAlB;MAEA,OAAOC,SAAS,CAAC/B,MAAV,CAAiB,CAACC,GAAD,EAAMJ,KAAN,KAAgB;QACtC,MAAMoC,UAAU,GAAGF,SAAS,CAACpC,MAAV,CAAiBuC,UAAU,IAAIP,EAAE,CAAC9B,KAAD,EAAQqC,UAAR,CAAjC,EAAsDtB,MAAzE;QACA,OAAOqB,UAAU,IAAI,CAAd,GAAkBhC,GAAG,GAAG,CAAxB,GAA4BA,GAAnC;MACD,CAHM,EAGJ,CAHI,CAAP;IAID;EACF;AAlE2C,CAA/B,C"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /**
9
+ *
10
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
11
+ *
12
+ * Melinda record matching modules for Javascript
13
+ *
14
+ * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
15
+ *
16
+ * This file is part of melinda-record-matching-js
17
+ *
18
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
19
+ * it under the terms of the GNU Lesser General Public License as
20
+ * published by the Free Software Foundation, either version 3 of the
21
+ * License, or (at your option) any later version.
22
+ *
23
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+ * GNU Lesser General Public License for more details.
27
+ *
28
+ * You should have received a copy of the GNU Affero General Public License
29
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
30
+ *
31
+ * @licend The above is the entire license notice
32
+ * for the JavaScript code in this file.
33
+ *
34
+ */
35
+ var _default = () => ({
36
+ name: 'Bibliographic level',
37
+ extract: r => r.leader[7] ? [r.leader[7]] : [],
38
+ compare: (a, b) => a[0] === b[0] ? 0.1 : -0.2
39
+ });
40
+
41
+ exports.default = _default;
42
+ //# sourceMappingURL=bibliographic-level.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bibliographic-level.js","names":["name","extract","r","leader","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/bibliographic-level.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nexport default () => ({\n name: 'Bibliographic level',\n extract: r => r.leader[7] ? [r.leader[7]] : [],\n compare: (a, b) => a[0] === b[0] ? 0.1 : -0.2\n});\n"],"mappings":";;;;;;;AAAA;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;eAEe,OAAO;EACpBA,IAAI,EAAE,qBADc;EAEpBC,OAAO,EAAEC,CAAC,IAAIA,CAAC,CAACC,MAAF,CAAS,CAAT,IAAc,CAACD,CAAC,CAACC,MAAF,CAAS,CAAT,CAAD,CAAd,GAA8B,EAFxB;EAGpBC,OAAO,EAAE,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAAC,CAAD,CAAD,KAASC,CAAC,CAAC,CAAD,CAAV,GAAgB,GAAhB,GAAsB,CAAC;AAHtB,CAAP,C"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ /**
9
+ *
10
+ * @licstart The following is the entire license notice for the JavaScript code in this file.
11
+ *
12
+ * Melinda record matching modules for Javascript
13
+ *
14
+ * Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
15
+ *
16
+ * This file is part of melinda-record-matching-js
17
+ *
18
+ * melinda-record-matching-js program is free software: you can redistribute it and/or modify
19
+ * it under the terms of the GNU Lesser General Public License as
20
+ * published by the Free Software Foundation, either version 3 of the
21
+ * License, or (at your option) any later version.
22
+ *
23
+ * melinda-record-matching-js is distributed in the hope that it will be useful,
24
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
25
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
+ * GNU Lesser General Public License for more details.
27
+ *
28
+ * You should have received a copy of the GNU Affero General Public License
29
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
30
+ *
31
+ * @licend The above is the entire license notice
32
+ * for the JavaScript code in this file.
33
+ *
34
+ */
35
+ var _default = () => ({
36
+ name: 'Host/Component record',
37
+ extract: r => r.get(/^773$/u).length > 0 ? ['component'] : ['host'],
38
+ compare: (a, b) => a[0] === b[0] ? 0.0 : -1.0
39
+ });
40
+
41
+ exports.default = _default;
42
+ //# sourceMappingURL=host-component.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"host-component.js","names":["name","extract","r","get","length","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/host-component.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nexport default () => ({\n name: 'Host/Component record',\n extract: r => r.get(/^773$/u).length > 0 ? ['component'] : ['host'],\n compare: (a, b) => a[0] === b[0] ? 0.0 : -1.0\n});\n"],"mappings":";;;;;;;AAAA;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;eAEe,OAAO;EACpBA,IAAI,EAAE,uBADc;EAEpBC,OAAO,EAAEC,CAAC,IAAIA,CAAC,CAACC,GAAF,CAAM,QAAN,EAAgBC,MAAhB,GAAyB,CAAzB,GAA6B,CAAC,WAAD,CAA7B,GAA6C,CAAC,MAAD,CAFvC;EAGpBC,OAAO,EAAE,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAAC,CAAD,CAAD,KAASC,CAAC,CAAC,CAAD,CAAV,GAAgB,GAAhB,GAAsB,CAAC;AAHtB,CAAP,C"}