@natlibfi/melinda-record-matching 2.2.0-alpha.4 → 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.
- package/.github/CODEOWNERS +10 -0
- package/.github/dependabot.yml +40 -0
- package/.github/workflows/melinda-node-tests.yml +70 -0
- package/dist/candidate-search/query-list/bib.js +17 -17
- package/dist/candidate-search/query-list/bib.js.map +1 -1
- package/dist/candidate-search/query-list/index.js +1 -1
- package/dist/candidate-search/query-list/index.js.map +1 -1
- package/dist/match-detection/features/bib/authors.js +5 -2
- package/dist/match-detection/features/bib/authors.js.map +1 -1
- package/dist/match-detection/features/bib/language.js +2 -2
- package/dist/match-detection/features/bib/language.js.map +1 -1
- package/dist/match-detection/features/bib/publication-time.js +7 -3
- package/dist/match-detection/features/bib/publication-time.js.map +1 -1
- package/dist/match-detection/features/bib/record-type.js +1 -0
- package/dist/match-detection/features/bib/record-type.js.map +1 -1
- package/dist/match-detection/features/bib/standard-identifier-factory.js +6 -5
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +1 -1
- package/dist/match-detection/features/bib/title.js +8 -4
- package/dist/match-detection/features/bib/title.js.map +1 -1
- package/dist/matching-utils.js +13 -4
- package/dist/matching-utils.js.map +1 -1
- package/package.json +2 -1
- package/src/candidate-search/query-list/bib.js +19 -18
- package/src/candidate-search/query-list/index.js +1 -1
- package/src/match-detection/features/bib/authors.js +5 -2
- package/src/match-detection/features/bib/language.js +2 -2
- package/src/match-detection/features/bib/publication-time.js +8 -3
- package/src/match-detection/features/bib/record-type.js +2 -0
- package/src/match-detection/features/bib/standard-identifier-factory.js +4 -3
- package/src/match-detection/features/bib/title.js +6 -4
- package/src/matching-utils.js +13 -4
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# With this line @NatLibFi/melinda-js-lead owns any files in the /.github/
|
|
2
|
+
# directory at the root of the repository and any of its
|
|
3
|
+
# subdirectories.
|
|
4
|
+
/.github/ @NatLibFi/melinda-js-lead
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
# With this line @NatLibFi/melinda-js-lead owns any files in the /src/
|
|
8
|
+
# directory at the root of the repository and any of its
|
|
9
|
+
# subdirectories.
|
|
10
|
+
/src/ @NatLibFi/melinda-js-lead
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# NatLibFi/Melinda maintenance strategy
|
|
2
|
+
# https://docs.github.com/en/code-security/supply-chain-security/keeping-your-dependencies-updated-automatically/configuration-options-for-dependency-updates
|
|
3
|
+
|
|
4
|
+
version: 2
|
|
5
|
+
updates:
|
|
6
|
+
# Maintain dependencies for GitHub Actions
|
|
7
|
+
- package-ecosystem: "github-actions"
|
|
8
|
+
directory: "/"
|
|
9
|
+
schedule:
|
|
10
|
+
interval: "daily"
|
|
11
|
+
time: "06:30"
|
|
12
|
+
timezone: "Europe/Helsinki"
|
|
13
|
+
|
|
14
|
+
# Minor updates to npm production dependencies daily
|
|
15
|
+
- package-ecosystem: "npm"
|
|
16
|
+
directory: "/"
|
|
17
|
+
schedule:
|
|
18
|
+
interval: "daily"
|
|
19
|
+
time: "06:45"
|
|
20
|
+
timezone: "Europe/Helsinki"
|
|
21
|
+
versioning-strategy: lockfile-only
|
|
22
|
+
labels:
|
|
23
|
+
- "npm minor dependencies"
|
|
24
|
+
allow:
|
|
25
|
+
- dependency-type: "production"
|
|
26
|
+
|
|
27
|
+
# Major updates to npm dependencies weekly @tuesday
|
|
28
|
+
# Not possible yet https://github.com/dependabot/dependabot-core/issues/1778
|
|
29
|
+
# - package-ecosystem: "npm"
|
|
30
|
+
# directory: "/"
|
|
31
|
+
# schedule:
|
|
32
|
+
# interval: "weekly"
|
|
33
|
+
# day: "tuesday"
|
|
34
|
+
# time: "07:00"
|
|
35
|
+
# timezone: "Europe/Helsinki"
|
|
36
|
+
# versioning-strategy: increase-if-necessary
|
|
37
|
+
# labels:
|
|
38
|
+
# - "npm major dependencies"
|
|
39
|
+
# reviewers:
|
|
40
|
+
# - "natlibfi/melinda-js-lead"
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
# Melinda node tests
|
|
2
|
+
|
|
3
|
+
name: Melinda node tests
|
|
4
|
+
|
|
5
|
+
on: push
|
|
6
|
+
|
|
7
|
+
jobs:
|
|
8
|
+
build-node-versions:
|
|
9
|
+
name: Node version matrix
|
|
10
|
+
runs-on: ubuntu-latest
|
|
11
|
+
|
|
12
|
+
strategy:
|
|
13
|
+
matrix:
|
|
14
|
+
node-version: [14.x, 16.x, 18.x]
|
|
15
|
+
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/
|
|
16
|
+
|
|
17
|
+
steps:
|
|
18
|
+
- name: Checkout the code
|
|
19
|
+
uses: actions/checkout@v2
|
|
20
|
+
- name: Use Node.js ${{ matrix.node-version }}
|
|
21
|
+
uses: actions/setup-node@v3
|
|
22
|
+
with:
|
|
23
|
+
node-version: ${{ matrix.node-version }}
|
|
24
|
+
cache: 'npm'
|
|
25
|
+
env:
|
|
26
|
+
NPM_CONFIG_IGNORE_SCRIPTS: true
|
|
27
|
+
- run: npm audit --package-lock-only --production --audit-level=high
|
|
28
|
+
- run: npm ci
|
|
29
|
+
- run: npm test
|
|
30
|
+
- run: npm run build --if-present
|
|
31
|
+
|
|
32
|
+
njsscan:
|
|
33
|
+
name: Njsscan check
|
|
34
|
+
runs-on: ubuntu-latest
|
|
35
|
+
|
|
36
|
+
steps:
|
|
37
|
+
- name: Checkout the code
|
|
38
|
+
uses: actions/checkout@v3
|
|
39
|
+
- name: nodejsscan scan
|
|
40
|
+
id: njsscan
|
|
41
|
+
uses: ajinabraham/njsscan-action@master
|
|
42
|
+
with:
|
|
43
|
+
args: '.'
|
|
44
|
+
|
|
45
|
+
license-scan:
|
|
46
|
+
name: License compliance check
|
|
47
|
+
runs-on: ubuntu-latest
|
|
48
|
+
|
|
49
|
+
steps:
|
|
50
|
+
- uses: actions/checkout@v3
|
|
51
|
+
- uses: mikaelvesavuori/license-compliance-action@v1.0.2
|
|
52
|
+
with:
|
|
53
|
+
exclude_pattern: /^@natlibfi/
|
|
54
|
+
|
|
55
|
+
publish:
|
|
56
|
+
runs-on: ubuntu-latest
|
|
57
|
+
needs: [build-node-versions, njsscan]
|
|
58
|
+
if: contains(github.ref, 'refs/tags/')
|
|
59
|
+
|
|
60
|
+
steps:
|
|
61
|
+
- uses: actions/checkout@v2
|
|
62
|
+
# Setup .npmrc file to publish to npm
|
|
63
|
+
- uses: actions/setup-node@v3
|
|
64
|
+
with:
|
|
65
|
+
node-version: '14.x'
|
|
66
|
+
registry-url: 'https://registry.npmjs.org'
|
|
67
|
+
- run: npm ci
|
|
68
|
+
- run: npm publish
|
|
69
|
+
env:
|
|
70
|
+
NODE_AUTH_TOKEN: ${{ secrets.MELINDA_RECORD_MATCHING_NPM_TOKEN }}
|
|
@@ -23,7 +23,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
23
23
|
*
|
|
24
24
|
* Melinda record matching modules for Javascript
|
|
25
25
|
*
|
|
26
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
26
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
27
27
|
*
|
|
28
28
|
* This file is part of melinda-record-matching-js
|
|
29
29
|
*
|
|
@@ -104,7 +104,7 @@ function bibSourceIds(record) {
|
|
|
104
104
|
|
|
105
105
|
function removeSourcePrefix(subfieldValue) {
|
|
106
106
|
const sourcePrefixRegex = /^(?<sourcePrefix>\([A-Za-z0-9-]+\))(?<id>.+)$/u;
|
|
107
|
-
const normalizedValue = subfieldValue ? subfieldValue.replace(sourcePrefixRegex, '$<id>') : '';
|
|
107
|
+
const normalizedValue = (0, _matchingUtils.testStringOrNumber)(subfieldValue) ? String(subfieldValue).replace(sourcePrefixRegex, '$<id>') : '';
|
|
108
108
|
debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);
|
|
109
109
|
return normalizedValue;
|
|
110
110
|
}
|
|
@@ -112,7 +112,7 @@ function bibSourceIds(record) {
|
|
|
112
112
|
function normalizeSidSubfieldValue(subfieldValue) {
|
|
113
113
|
debugData(`Normalizing ${subfieldValue}`);
|
|
114
114
|
const normalizeAwayRegex = /[- ]/u;
|
|
115
|
-
return subfieldValue ? subfieldValue.replace(normalizeAwayRegex, '') : '';
|
|
115
|
+
return (0, _matchingUtils.testStringOrNumber)(subfieldValue) ? String(subfieldValue).replace(normalizeAwayRegex, '') : '';
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
118
|
}
|
|
@@ -142,7 +142,7 @@ function bibMelindaIds(record) {
|
|
|
142
142
|
|
|
143
143
|
function bibHostComponents(record) {
|
|
144
144
|
const id = getHostId();
|
|
145
|
-
return id ? [`melinda.partsofhost=${id}`] : [];
|
|
145
|
+
return (0, _matchingUtils.testStringOrNumber)(id) ? [`melinda.partsofhost=${id}`] : [];
|
|
146
146
|
|
|
147
147
|
function getHostId() {
|
|
148
148
|
const [field] = record.get(/^773$/u);
|
|
@@ -154,12 +154,12 @@ function bibHostComponents(record) {
|
|
|
154
154
|
code
|
|
155
155
|
}) => code === 'w') || {};
|
|
156
156
|
|
|
157
|
-
if (value && /^\(FI-MELINDA\)/u.test(value)) {
|
|
158
|
-
return value.replace(/^\(FI-MELINDA\)/u, '');
|
|
157
|
+
if ((0, _matchingUtils.testStringOrNumber)(value) && /^\(FI-MELINDA\)/u.test(String(value))) {
|
|
158
|
+
return String(value).replace(/^\(FI-MELINDA\)/u, '');
|
|
159
159
|
}
|
|
160
160
|
|
|
161
|
-
if (value && /^\(FIN01\)/u.test(value)) {
|
|
162
|
-
return value.replace(/^\(FIN01\)/u, '');
|
|
161
|
+
if ((0, _matchingUtils.testStringOrNumber)(value) && /^\(FIN01\)/u.test(String(value))) {
|
|
162
|
+
return String(value).replace(/^\(FIN01\)/u, '');
|
|
163
163
|
}
|
|
164
164
|
|
|
165
165
|
return false;
|
|
@@ -179,8 +179,8 @@ function bibTitle(record) {
|
|
|
179
179
|
const title = getTitle();
|
|
180
180
|
const booleanStartWords = ['and', 'or', 'nor', 'not'];
|
|
181
181
|
|
|
182
|
-
if (title) {
|
|
183
|
-
const formatted = title.replace(/[^\w\s\p{Alphabetic}]/gu, '') // Clean up concurrent spaces from fe. subfield changes
|
|
182
|
+
if ((0, _matchingUtils.testStringOrNumber)(title)) {
|
|
183
|
+
const formatted = String(title).replace(/[^\w\s\p{Alphabetic}]/gu, '') // Clean up concurrent spaces from fe. subfield changes
|
|
184
184
|
.replace(/ +/gu, ' ').trim().slice(0, 30).trim(); // use word search for titles starting with a boolean
|
|
185
185
|
|
|
186
186
|
const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word)); // Prevent too many matches by having a minimum length requirement
|
|
@@ -198,7 +198,7 @@ function bibTitle(record) {
|
|
|
198
198
|
code
|
|
199
199
|
}) => ['a', 'b'].includes(code)).map(({
|
|
200
200
|
value
|
|
201
|
-
}) => value) // In Melinda's index subfield separators are indexed as ' '
|
|
201
|
+
}) => (0, _matchingUtils.testStringOrNumber)(value) ? String(value) : '').filter(value => value) // In Melinda's index subfield separators are indexed as ' '
|
|
202
202
|
.join(' ');
|
|
203
203
|
}
|
|
204
204
|
|
|
@@ -233,20 +233,20 @@ function bibStandardIdentifiers(record) {
|
|
|
233
233
|
const otherIdReqExp = /^[A-Za-z0-9-:]+$/u;
|
|
234
234
|
|
|
235
235
|
if (tag === '022') {
|
|
236
|
-
return subfields.filter(sub => ['a', 'z', 'y'].includes(sub.code) &&
|
|
236
|
+
return subfields.filter(sub => ['a', 'z', 'y'].includes(sub.code) && (0, _matchingUtils.testStringOrNumber)(sub.value) && issnIsbnReqExp.test(String(sub.value))).map(({
|
|
237
237
|
value
|
|
238
|
-
}) => value);
|
|
238
|
+
}) => String(value));
|
|
239
239
|
}
|
|
240
240
|
|
|
241
241
|
if (tag === '020') {
|
|
242
|
-
return subfields.filter(sub => ['a', 'z'].includes(sub.code) &&
|
|
242
|
+
return subfields.filter(sub => ['a', 'z'].includes(sub.code) && (0, _matchingUtils.testStringOrNumber)(sub.value) && issnIsbnReqExp.test(String(sub.value))).map(({
|
|
243
243
|
value
|
|
244
|
-
}) => value);
|
|
244
|
+
}) => String(value));
|
|
245
245
|
}
|
|
246
246
|
|
|
247
|
-
return subfields.filter(sub => ['a', 'z'].includes(sub.code) &&
|
|
247
|
+
return subfields.filter(sub => ['a', 'z'].includes(sub.code) && (0, _matchingUtils.testStringOrNumber)(sub.value) && otherIdReqExp.test(String(sub.value))).map(({
|
|
248
248
|
value
|
|
249
|
-
}) => value);
|
|
249
|
+
}) => String(value));
|
|
250
250
|
}
|
|
251
251
|
}
|
|
252
252
|
//# sourceMappingURL=bib.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bib.js","names":["bibSourceIds","record","debug","createDebugLogger","debugData","extend","fSids","get","length","JSON","stringify","toSidQueries","sidStrings","getSidStrings","sidQueries","toQueries","map","toSidString","filter","nonEmptySid","field","validateSidFieldSubfieldCounts","createSidString","sfC","getSubfieldValues","sfB","cleanedSfC","removeSourcePrefix","normalizeSidSubfieldValue","cleanedSfB","concat","subfieldValue","sourcePrefixRegex","normalizedValue","replace","normalizeAwayRegex","bibMelindaIds","melindaIds","getMelindaIdsF035","bibHostComponents","id","getHostId","value","subfields","find","code","test","bibTitle","title","getTitle","booleanStartWords","formatted","trim","slice","useWordSearch","some","word","toLowerCase","startsWith","includes","join","bibStandardIdentifiers","fields","identifiers","toIdentifiers","uniqueIdentifiers","Set","tag","issnIsbnReqExp","otherIdReqExp","sub","undefined"],"sources":["../../../src/candidate-search/query-list/bib.js"],"sourcesContent":["\n/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\nimport createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues} from '../../matching-utils';\n\n\nexport function bibSourceIds(record) {\n\n /* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records\n SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:\n\n SID__ $c 123457 $b helka\n SID__ $c (ANDL100020)1077305 $b sata\n SID__ $c VER999999 $ FI-KV\n SID__ $c /10024/508126 $ REPO_THESEUS\n\n In melinda.sourceid -index case is kept, sourceprefixes in brackets and hyphens are normalized away:\n Note: slashes are not normalized away, but a SRU-search-string including slashes needs to be quoted\n\n 1234567helka\n 1077305sata\n VER999999FIKV\n /10024/508126REPO_THESEUS\n\n Note: All Melinda records that have a matching records in a local db do NOT have SID for that local records,\n existence of a SID field depends on how the record has been added to Melinda and how it has been handled\n afterwards. SIDs are also not reliably maintained. A record might or might not have a SID for a local db\n after the matching record is removed from the local db.\n\n */\n\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:source-ids');\n const debugData = debug.extend('data');\n //const debugInfo = debug.extend('info');\n\n debug(`Creating queries for sourceid's`);\n\n const fSids = record.get('SID');\n debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);\n\n return fSids.length > 0 ? toSidQueries(fSids) : [];\n\n function toSidQueries(fSids) {\n debug(`Creating actual queries for sourceid's`);\n\n const sidStrings = getSidStrings(fSids);\n\n if (sidStrings.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n const sidQueries = toQueries(sidStrings, 'melinda.sourceid');\n\n return sidQueries;\n\n function getSidStrings(fSids) {\n debug(`Getting Sid strings from SID fields`);\n\n // Map SID fields to valid sidStrings, filter out empty strings\n const sidStrings = fSids.map(toSidString).filter(nonEmptySid => nonEmptySid);\n return sidStrings;\n\n function toSidString(field) {\n debug(`Getting string from a field`);\n\n return validateSidFieldSubfieldCounts(field) ? createSidString(field) : '';\n\n function createSidString(field) {\n debug(`Creating string from a field`);\n const [sfC] = getSubfieldValues(field, 'c');\n const [sfB] = getSubfieldValues(field, 'b');\n\n const cleanedSfC = removeSourcePrefix(normalizeSidSubfieldValue(sfC));\n const cleanedSfB = normalizeSidSubfieldValue(sfB);\n\n debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);\n return cleanedSfC.concat(cleanedSfB);\n }\n\n function removeSourcePrefix(subfieldValue) {\n const sourcePrefixRegex = (/^(?<sourcePrefix>\\([A-Za-z0-9-]+\\))(?<id>.+)$/u);\n const normalizedValue = subfieldValue ? subfieldValue.replace(sourcePrefixRegex, '$<id>') : '';\n debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);\n return normalizedValue;\n }\n\n function normalizeSidSubfieldValue(subfieldValue) {\n debugData(`Normalizing ${subfieldValue}`);\n const normalizeAwayRegex = (/[- ]/u);\n return subfieldValue ? subfieldValue.replace(normalizeAwayRegex, '') : '';\n }\n\n }\n }\n }\n}\n\nexport function bibMelindaIds(record) {\n // Melinda's SRU-index melinda.melindaid includes f001 controlnumbers and old Melinda-IDs from f035z's for all non-deleted Melinda-records\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibMelindaIds');\n const debugData = debug.extend('data');\n debug(`Creating queries for MelindaIds`);\n\n // Note: Melinda-ID's for search queries are created just from records f035a's and f035z's\n // Both (FI-MELINDA)- and FCC-prefixed forms are found\n // f001 controlnumber is not currently included, even if record's f003 is FI-MELINDA\n const melindaIds = getMelindaIdsF035(record);\n\n debugData(`Unique identifiers (${melindaIds.length}): ${JSON.stringify(melindaIds)}`);\n\n if (melindaIds.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(melindaIds, 'melinda.melindaid');\n}\n\n\n// bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05\n// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?\nexport function bibHostComponents(record) {\n const id = getHostId();\n return id ? [`melinda.partsofhost=${id}`] : [];\n\n function getHostId() {\n const [field] = record.get(/^773$/u);\n\n if (field) {\n const {value} = field.subfields.find(({code}) => code === 'w') || {};\n\n if (value && (/^\\(FI-MELINDA\\)/u).test(value)) {\n return value.replace(/^\\(FI-MELINDA\\)/u, '');\n }\n\n if (value && (/^\\(FIN01\\)/u).test(value)) {\n return value.replace(/^\\(FIN01\\)/u, '');\n }\n\n return false;\n }\n return false;\n }\n}\n\n// SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to\n// (probably) to *headings* index TIT\n// - Aleph cannot currently handle headings searches starting with a boolean - in these cases use word search\n\n// Headings index TIT drops articles etc. from the start of the title according to the filing indicator\n// Currently filing indicator is not implemented - if the title starts with an article and the Melinda\n// record is correctly catalogued using a filing indicator -> dc.title search won't match\n\nexport function bibTitle(record) {\n const title = getTitle();\n const booleanStartWords = ['and', 'or', 'nor', 'not'];\n\n if (title) {\n const formatted = title\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for titles starting with a boolean\n const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));\n // Prevent too many matches by having a minimum length requirement\n return formatted.length >= 5 ? [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`] : [];\n }\n\n return [];\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n return field.subfields\n .filter(({code}) => ['a', 'b'].includes(code))\n .map(({value}) => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n }\n return false;\n }\n}\n\n// eslint-disable-next-line max-statements\nexport function bibStandardIdentifiers(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');\n const debugData = debug.extend('data');\n debug(`Creating queries for standard identifiers`);\n\n const fields = record.get(/^(?<def>020|022|024)$/u);\n const identifiers = [].concat(...fields.map(toIdentifiers));\n const uniqueIdentifiers = [...new Set(identifiers)];\n\n debugData(`Standard identifier fields: ${JSON.stringify(fields)}`);\n debugData(`Identifiers (${identifiers.length}): ${JSON.stringify(identifiers)}`);\n debugData(`Unique identifiers (${uniqueIdentifiers.length}): ${JSON.stringify(uniqueIdentifiers)}`);\n\n if (uniqueIdentifiers.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(uniqueIdentifiers, 'dc.identifier');\n\n function toIdentifiers({tag, subfields}) {\n const issnIsbnReqExp = (/^[A-Za-z0-9-]+$/u);\n const otherIdReqExp = (/^[A-Za-z0-9-:]+$/u);\n\n if (tag === '022') {\n return subfields\n .filter(sub => ['a', 'z', 'y'].includes(sub.code) && issnIsbnReqExp.test(sub.value) && sub.value !== undefined)\n .map(({value}) => value);\n }\n\n if (tag === '020') {\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && issnIsbnReqExp.test(sub.value) && sub.value !== undefined)\n .map(({value}) => value);\n }\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && otherIdReqExp.test(sub.value) && sub.value !== undefined)\n .map(({value}) => value);\n }\n}\n"],"mappings":";;;;;;;;;;;AA4BA;;AACA;;AACA;;;;AA7BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMO,SAASA,YAAT,CAAsBC,MAAtB,EAA8B;EAEnC;AACF;AAC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AAC;QAAC0B;MAAD,CAAD,KAAaA,KAFb,CAAP;IAGD;;IAED,IAAIyB,GAAG,KAAK,KAAZ,EAAmB;MACjB,OAAOxB,SAAS,CACbzB,MADI,CACGoD,GAAG,IAAI,CAAC,GAAD,EAAM,GAAN,EAAWX,QAAX,CAAoBW,GAAG,CAACzB,IAAxB,KAAiCuB,cAAc,CAACtB,IAAf,CAAoBwB,GAAG,CAAC5B,KAAxB,CAAjC,IAAmE4B,GAAG,CAAC5B,KAAJ,KAAc6B,SAD3F,EAEJvD,GAFI,CAEA,CAAC;QAAC0B;MAAD,CAAD,KAAaA,KAFb,CAAP;IAGD;;IAED,OAAOC,SAAS,CACbzB,MADI,CACGoD,GAAG,IAAI,CAAC,GAAD,EAAM,GAAN,EAAWX,QAAX,CAAoBW,GAAG,CAACzB,IAAxB,KAAiCwB,aAAa,CAACvB,IAAd,CAAmBwB,GAAG,CAAC5B,KAAvB,CAAjC,IAAkE4B,GAAG,CAAC5B,KAAJ,KAAc6B,SAD1F,EAEJvD,GAFI,CAEA,CAAC;MAAC0B;IAAD,CAAD,KAAaA,KAFb,CAAP;EAGD;AACF"}
|
|
1
|
+
{"version":3,"file":"bib.js","names":["bibSourceIds","record","debug","createDebugLogger","debugData","extend","fSids","get","length","JSON","stringify","toSidQueries","sidStrings","getSidStrings","sidQueries","toQueries","map","toSidString","filter","nonEmptySid","field","validateSidFieldSubfieldCounts","createSidString","sfC","getSubfieldValues","sfB","cleanedSfC","removeSourcePrefix","normalizeSidSubfieldValue","cleanedSfB","concat","subfieldValue","sourcePrefixRegex","normalizedValue","testStringOrNumber","String","replace","normalizeAwayRegex","bibMelindaIds","melindaIds","getMelindaIdsF035","bibHostComponents","id","getHostId","value","subfields","find","code","test","bibTitle","title","getTitle","booleanStartWords","formatted","trim","slice","useWordSearch","some","word","toLowerCase","startsWith","includes","join","bibStandardIdentifiers","fields","identifiers","toIdentifiers","uniqueIdentifiers","Set","tag","issnIsbnReqExp","otherIdReqExp","sub"],"sources":["../../../src/candidate-search/query-list/bib.js"],"sourcesContent":["\n/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\nimport createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils';\n\n\nexport function bibSourceIds(record) {\n\n /* Melinda's SRU-index melinda.sourceid includes source IDs from SID fields in Melinda records\n SID-fields in Melinda have sf $c with local id and sf $b with a code for the local db:\n\n SID__ $c 123457 $b helka\n SID__ $c (ANDL100020)1077305 $b sata\n SID__ $c VER999999 $ FI-KV\n SID__ $c /10024/508126 $ REPO_THESEUS\n\n In melinda.sourceid -index case is kept, sourceprefixes in brackets and hyphens are normalized away:\n Note: slashes are not normalized away, but a SRU-search-string including slashes needs to be quoted\n\n 1234567helka\n 1077305sata\n VER999999FIKV\n /10024/508126REPO_THESEUS\n\n Note: All Melinda records that have a matching records in a local db do NOT have SID for that local records,\n existence of a SID field depends on how the record has been added to Melinda and how it has been handled\n afterwards. SIDs are also not reliably maintained. A record might or might not have a SID for a local db\n after the matching record is removed from the local db.\n\n */\n\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:source-ids');\n const debugData = debug.extend('data');\n //const debugInfo = debug.extend('info');\n\n debug(`Creating queries for sourceid's`);\n\n const fSids = record.get('SID');\n debugData(`SID-fields (${fSids.length}): ${JSON.stringify(fSids)}`);\n\n return fSids.length > 0 ? toSidQueries(fSids) : [];\n\n function toSidQueries(fSids) {\n debug(`Creating actual queries for sourceid's`);\n\n const sidStrings = getSidStrings(fSids);\n\n if (sidStrings.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n const sidQueries = toQueries(sidStrings, 'melinda.sourceid');\n\n return sidQueries;\n\n function getSidStrings(fSids) {\n debug(`Getting Sid strings from SID fields`);\n\n // Map SID fields to valid sidStrings, filter out empty strings\n const sidStrings = fSids.map(toSidString).filter(nonEmptySid => nonEmptySid);\n return sidStrings;\n\n function toSidString(field) {\n debug(`Getting string from a field`);\n\n return validateSidFieldSubfieldCounts(field) ? createSidString(field) : '';\n\n function createSidString(field) {\n debug(`Creating string from a field`);\n const [sfC] = getSubfieldValues(field, 'c');\n const [sfB] = getSubfieldValues(field, 'b');\n\n const cleanedSfC = removeSourcePrefix(normalizeSidSubfieldValue(sfC));\n const cleanedSfB = normalizeSidSubfieldValue(sfB);\n\n debugData(`${JSON.stringify(sfC)} + ${JSON.stringify(sfB)}`);\n return cleanedSfC.concat(cleanedSfB);\n }\n\n function removeSourcePrefix(subfieldValue) {\n const sourcePrefixRegex = (/^(?<sourcePrefix>\\([A-Za-z0-9-]+\\))(?<id>.+)$/u);\n const normalizedValue = testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(sourcePrefixRegex, '$<id>') : '';\n debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);\n return normalizedValue;\n }\n\n function normalizeSidSubfieldValue(subfieldValue) {\n debugData(`Normalizing ${subfieldValue}`);\n const normalizeAwayRegex = (/[- ]/u);\n return testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(normalizeAwayRegex, '') : '';\n }\n\n }\n }\n }\n}\n\nexport function bibMelindaIds(record) {\n // Melinda's SRU-index melinda.melindaid includes f001 controlnumbers and old Melinda-IDs from f035z's for all non-deleted Melinda-records\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibMelindaIds');\n const debugData = debug.extend('data');\n debug(`Creating queries for MelindaIds`);\n\n // Note: Melinda-ID's for search queries are created just from records f035a's and f035z's\n // Both (FI-MELINDA)- and FCC-prefixed forms are found\n // f001 controlnumber is not currently included, even if record's f003 is FI-MELINDA\n const melindaIds = getMelindaIdsF035(record);\n\n debugData(`Unique identifiers (${melindaIds.length}): ${JSON.stringify(melindaIds)}`);\n\n if (melindaIds.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(melindaIds, 'melinda.melindaid');\n}\n\n\n// bibHostComponents returns host id from the first subfield $w of first field f773, see test-fixtures 04 and 05\n// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?\nexport function bibHostComponents(record) {\n const id = getHostId();\n return testStringOrNumber(id) ? [`melinda.partsofhost=${id}`] : [];\n\n function getHostId() {\n const [field] = record.get(/^773$/u);\n\n if (field) {\n const {value} = field.subfields.find(({code}) => code === 'w') || {};\n\n if (testStringOrNumber(value) && (/^\\(FI-MELINDA\\)/u).test(String(value))) {\n return String(value).replace(/^\\(FI-MELINDA\\)/u, '');\n }\n\n if (testStringOrNumber(value) && (/^\\(FIN01\\)/u).test(String(value))) {\n return String(value).replace(/^\\(FIN01\\)/u, '');\n }\n\n return false;\n }\n return false;\n }\n}\n\n// SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to\n// (probably) to *headings* index TIT\n// - Aleph cannot currently handle headings searches starting with a boolean - in these cases use word search\n\n// Headings index TIT drops articles etc. from the start of the title according to the filing indicator\n// Currently filing indicator is not implemented - if the title starts with an article and the Melinda\n// record is correctly catalogued using a filing indicator -> dc.title search won't match\n\nexport function bibTitle(record) {\n const title = getTitle();\n const booleanStartWords = ['and', 'or', 'nor', 'not'];\n\n if (testStringOrNumber(title)) {\n const formatted = String(title)\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '')\n // Clean up concurrent spaces from fe. subfield changes\n .replace(/ +/gu, ' ')\n .trim()\n .slice(0, 30)\n .trim();\n\n // use word search for titles starting with a boolean\n const useWordSearch = booleanStartWords.some(word => formatted.toLowerCase().startsWith(word));\n // Prevent too many matches by having a minimum length requirement\n return formatted.length >= 5 ? [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`] : [];\n }\n\n return [];\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n return field.subfields\n .filter(({code}) => ['a', 'b'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n }\n return false;\n }\n}\n\n// eslint-disable-next-line max-statements\nexport function bibStandardIdentifiers(record) {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibStandardIdentifiers');\n const debugData = debug.extend('data');\n debug(`Creating queries for standard identifiers`);\n\n const fields = record.get(/^(?<def>020|022|024)$/u);\n const identifiers = [].concat(...fields.map(toIdentifiers));\n const uniqueIdentifiers = [...new Set(identifiers)];\n\n debugData(`Standard identifier fields: ${JSON.stringify(fields)}`);\n debugData(`Identifiers (${identifiers.length}): ${JSON.stringify(identifiers)}`);\n debugData(`Unique identifiers (${uniqueIdentifiers.length}): ${JSON.stringify(uniqueIdentifiers)}`);\n\n if (uniqueIdentifiers.length < 1) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n\n return toQueries(uniqueIdentifiers, 'dc.identifier');\n\n function toIdentifiers({tag, subfields}) {\n const issnIsbnReqExp = (/^[A-Za-z0-9-]+$/u);\n const otherIdReqExp = (/^[A-Za-z0-9-:]+$/u);\n\n if (tag === '022') {\n return subfields\n .filter(sub => ['a', 'z', 'y'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n if (tag === '020') {\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n\n return subfields\n .filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value)))\n .map(({value}) => String(value));\n }\n}\n"],"mappings":";;;;;;;;;;;AA4BA;;AACA;;AACA;;;;AA7BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAMO,SAASA,YAAT,CAAsBC,MAAtB,EAA8B;EAEnC;AACF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EAQE,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAkB,qEAAlB,CAAd;EACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB,CA3BmC,CA4BnC;;EAEAH,KAAK,CAAE,iCAAF,CAAL;EAEA,MAAMI,KAAK,GAAGL,MAAM,CAACM,GAAP,CAAW,KAAX,CAAd;EACAH,SAAS,CAAE,eAAcE,KAAK,CAACE,MAAO,MAAKC,IAAI,CAACC,SAAL,CAAeJ,KAAf,CAAsB,EAAxD,CAAT;EAEA,OAAOA,KAAK,CAACE,MAAN,GAAe,CAAf,GAAmBG,YAAY,CAACL,KAAD,CAA/B,GAAyC,EAAhD;;EAEA,SAASK,YAAT,CAAsBL,KAAtB,EAA6B;IAC3BJ,KAAK,CAAE,wCAAF,CAAL;IAEA,MAAMU,UAAU,GAAGC,aAAa,CAACP,KAAD,CAAhC;;IAEA,IAAIM,UAAU,CAACJ,MAAX,GAAoB,CAAxB,EAA2B;MACzBN,KAAK,CAAE,2CAAF,CAAL;MACA,OAAO,EAAP;IACD;;IAED,MAAMY,UAAU,GAAG,IAAAC,+BAAA,EAAUH,UAAV,E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GAAG,CAAC5B,KAAL,CAA1B,CAD5E,EAEJ5B,GAFI,CAEA,CAAC;QAAC4B;MAAD,CAAD,KAAaT,MAAM,CAACS,KAAD,CAFnB,CAAP;IAGD;;IAED,OAAOC,SAAS,CACb3B,MADI,CACGsD,GAAG,IAAI,CAAC,GAAD,EAAM,GAAN,EAAWX,QAAX,CAAoBW,GAAG,CAACzB,IAAxB,KAAiC,IAAAb,iCAAA,EAAmBsC,GAAG,CAAC5B,KAAvB,CAAjC,IAAkE2B,aAAa,CAACvB,IAAd,CAAmBb,MAAM,CAACqC,GAAG,CAAC5B,KAAL,CAAzB,CAD5E,EAEJ5B,GAFI,CAEA,CAAC;MAAC4B;IAAD,CAAD,KAAaT,MAAM,CAACS,KAAD,CAFnB,CAAP;EAGD;AACF"}
|
|
@@ -17,7 +17,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
|
17
17
|
*
|
|
18
18
|
* Melinda record matching modules for Javascript
|
|
19
19
|
*
|
|
20
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
20
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
21
21
|
*
|
|
22
22
|
* This file is part of melinda-record-matching-js
|
|
23
23
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["searchTypes","bib","standardIdentifiers","hostComponents","title","melindaId","sourceIds","record","searchSpec","extractors","map","generateQueryExtractor","cb","flat","type","Error"],"sources":["../../../src/candidate-search/query-list/index.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport * as bib from './bib';\n\nexport const searchTypes = {\n bib: {\n standardIdentifiers: 'bibStandardIdentifiers',\n hostComponents: 'bibHostComponents',\n title: 'bibTitle',\n melindaId: 'bibMelindaIds',\n sourceIds: 'bibSourceIds'\n }\n};\n\nexport default (record, searchSpec) => {\n const extractors = {...bib};\n\n return searchSpec\n .map(generateQueryExtractor)\n .map(cb => cb(record))\n .flat();\n\n function generateQueryExtractor(type) {\n if (extractors[type]) {\n return extractors[type];\n }\n\n throw new Error(`Unknown search type: ${type}`);\n }\n};\n"],"mappings":";;;;;;;AA4BA;;;;;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIO,MAAMA,WAAW,GAAG;EACzBC,GAAG,EAAE;IACHC,mBAAmB,EAAE,wBADlB;IAEHC,cAAc,EAAE,mBAFb;IAGHC,KAAK,EAAE,UAHJ;IAIHC,SAAS,EAAE,eAJR;IAKHC,SAAS,EAAE;EALR;AADoB,CAApB;;;eAUQ,CAACC,MAAD,EAASC,UAAT,KAAwB;EACrC,MAAMC,UAAU,GAAG,EAAC,GAAGR;EAAJ,CAAnB;EAEA,OAAOO,UAAU,CACdE,GADI,CACAC,sBADA,EAEJD,GAFI,CAEAE,EAAE,IAAIA,EAAE,CAACL,MAAD,CAFR,EAGJM,IAHI,EAAP;;EAKA,SAASF,sBAAT,CAAgCG,IAAhC,EAAsC;IACpC,IAAIL,UAAU,CAACK,IAAD,CAAd,EAAsB;MACpB,OAAOL,UAAU,CAACK,IAAD,CAAjB;IACD;;IAED,MAAM,IAAIC,KAAJ,CAAW,wBAAuBD,IAAK,EAAvC,CAAN;EACD;AACF,C"}
|
|
1
|
+
{"version":3,"file":"index.js","names":["searchTypes","bib","standardIdentifiers","hostComponents","title","melindaId","sourceIds","record","searchSpec","extractors","map","generateQueryExtractor","cb","flat","type","Error"],"sources":["../../../src/candidate-search/query-list/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 * as bib from './bib';\n\nexport const searchTypes = {\n bib: {\n standardIdentifiers: 'bibStandardIdentifiers',\n hostComponents: 'bibHostComponents',\n title: 'bibTitle',\n melindaId: 'bibMelindaIds',\n sourceIds: 'bibSourceIds'\n }\n};\n\nexport default (record, searchSpec) => {\n const extractors = {...bib};\n\n return searchSpec\n .map(generateQueryExtractor)\n .map(cb => cb(record))\n .flat();\n\n function generateQueryExtractor(type) {\n if (extractors[type]) {\n return extractors[type];\n }\n\n throw new Error(`Unknown search type: ${type}`);\n }\n};\n"],"mappings":";;;;;;;AA4BA;;;;;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIO,MAAMA,WAAW,GAAG;EACzBC,GAAG,EAAE;IACHC,mBAAmB,EAAE,wBADlB;IAEHC,cAAc,EAAE,mBAFb;IAGHC,KAAK,EAAE,UAHJ;IAIHC,SAAS,EAAE,eAJR;IAKHC,SAAS,EAAE;EALR;AADoB,CAApB;;;eAUQ,CAACC,MAAD,EAASC,UAAT,KAAwB;EACrC,MAAMC,UAAU,GAAG,EAAC,GAAGR;EAAJ,CAAnB;EAEA,OAAOO,UAAU,CACdE,GADI,CACAC,sBADA,EAEJD,GAFI,CAEAE,EAAE,IAAIA,EAAE,CAACL,MAAD,CAFR,EAGJM,IAHI,EAAP;;EAKA,SAASF,sBAAT,CAAgCG,IAAhC,EAAsC;IACpC,IAAIL,UAAU,CAACK,IAAD,CAAd,EAAsB;MACpB,OAAOL,UAAU,CAACK,IAAD,CAAjB;IACD;;IAED,MAAM,IAAIC,KAAJ,CAAW,wBAAuBD,IAAK,EAAvC,CAAN;EACD;AACF,C"}
|
|
@@ -7,13 +7,15 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _natural = require("natural");
|
|
9
9
|
|
|
10
|
+
var _matchingUtils = require("../../../matching-utils");
|
|
11
|
+
|
|
10
12
|
/**
|
|
11
13
|
*
|
|
12
14
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
13
15
|
*
|
|
14
16
|
* Melinda record matching modules for Javascript
|
|
15
17
|
*
|
|
16
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
18
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
17
19
|
*
|
|
18
20
|
* This file is part of melinda-record-matching-js
|
|
19
21
|
*
|
|
@@ -34,6 +36,7 @@ var _natural = require("natural");
|
|
|
34
36
|
* for the JavaScript code in this file.
|
|
35
37
|
*
|
|
36
38
|
*/
|
|
39
|
+
// We should extract also organisational authors (110/710)
|
|
37
40
|
var _default = ({
|
|
38
41
|
nameTreshold = 10
|
|
39
42
|
} = {}) => ({
|
|
@@ -56,7 +59,7 @@ var _default = ({
|
|
|
56
59
|
}) {
|
|
57
60
|
if (code === 'a') {
|
|
58
61
|
return {
|
|
59
|
-
name: value ? value.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase() : ''
|
|
62
|
+
name: (0, _matchingUtils.testStringOrNumber)(value) ? String(value).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase() : ''
|
|
60
63
|
};
|
|
61
64
|
}
|
|
62
65
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"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","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 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"],"mappings":";;;;;;;AA4BA;;
|
|
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;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAKA;eAEe,CAAC;EAACA,YAAY,GAAG;AAAhB,IAAsB,EAAvB,MAA+B;EAC5CC,IAAI,EAAE,SADsC;EAE5CC,OAAO,EAAEC,MAAM,IAAIA,MAAM,CAACC,GAAP,CAAW,oBAAX,EAChBC,GADgB,CACZ,CAAC;IAACC;EAAD,CAAD,KAAiB;IACpB,OAAOA,SAAS,CACbC,MADI,CACG,CAAC;MAACC,IAAD;MAAOC;IAAP,CAAD,KAAmBD,IAAI,IAAIC,KAD9B,EAEJF,MAFI,CAEG,CAAC;MAACC;IAAD,CAAD,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;MAAS,GAAGC;IAAZ,CAAb,CAJH,EAIiC,EAJjC,CAAP;;IAMA,SAASH,KAAT,CAAe;MA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ching modules for Javascript
|
|
19
19
|
*
|
|
20
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
20
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
21
21
|
*
|
|
22
22
|
* This file is part of melinda-record-matching-js
|
|
23
23
|
*
|
|
@@ -99,7 +99,7 @@ var _default = () => ({
|
|
|
99
99
|
return 0;
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
debugData(`There
|
|
102
|
+
debugData(`There are languages to compare`);
|
|
103
103
|
|
|
104
104
|
if (a[0] === b[0]) {
|
|
105
105
|
return 0.1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"language.js","names":["debug","createDebugLogger","debugData","extend","name","extract","record","value008","get008Value","values041","get041Values","JSON","stringify","length","correspondingValue","find","v","value","get","undefined","code","slice","filter","ind2","map","subfields","flat","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/language.js"],"sourcesContent":["/* 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';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:language');\nconst debugData = debug.extend('data');\n\nexport default () => ({\n name: 'Language',\n extract: record => {\n const value008 = get008Value();\n const values041 = get041Values();\n debugData(`008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);\n\n if (value008 && values041.length > 0) {\n debugData(`There's both 008 and 041, searching for value in both`);\n const correspondingValue = values041.find(v => v === value008);\n debugData(`Corresponding value: ${correspondingValue}`);\n return correspondingValue ? [correspondingValue] : [];\n }\n\n if (!value008 && values041.length < 1) {\n debugData(`No actual values found`);\n return [];\n }\n\n return value008 ? [value008] : [values041[0]];\n\n function get008Value() {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n debugData(`008 value: ${value}`);\n\n if (!value) {\n return undefined;\n }\n\n const code = value.slice(35, 38);\n debugData(`008 code: ${code}`);\n return code === '|||' || code === ' ' || code === '^^^' ? undefined : code;\n }\n\n // Main language for the resource: in the first f041 $a or f041 $d\n // Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes\n\n function get041Values() {\n return record.get(/^041$/u)\n .filter(({ind2}) => ind2 === ' ')\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'a' || code === 'd')\n .map(({value}) => value);\n }\n },\n compare: (a, b) => {\n debugData(`Comparing ${JSON.stringify(a[0])} and ${JSON.stringify(b[0])}`);\n\n if (a.length === 0 || b.length === 0) {\n debugData(`No language to compare`);\n return 0;\n }\n\n debugData(`There
|
|
1
|
+
{"version":3,"file":"language.js","names":["debug","createDebugLogger","debugData","extend","name","extract","record","value008","get008Value","values041","get041Values","JSON","stringify","length","correspondingValue","find","v","value","get","undefined","code","slice","filter","ind2","map","subfields","flat","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/language.js"],"sourcesContent":["/* eslint-disable max-statements */\n/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:language');\nconst debugData = debug.extend('data');\n\nexport default () => ({\n name: 'Language',\n extract: record => {\n const value008 = get008Value();\n const values041 = get041Values();\n debugData(`008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);\n\n if (value008 && values041.length > 0) {\n debugData(`There's both 008 and 041, searching for value in both`);\n const correspondingValue = values041.find(v => v === value008);\n debugData(`Corresponding value: ${correspondingValue}`);\n return correspondingValue ? [correspondingValue] : [];\n }\n\n if (!value008 && values041.length < 1) {\n debugData(`No actual values found`);\n return [];\n }\n\n return value008 ? [value008] : [values041[0]];\n\n function get008Value() {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n debugData(`008 value: ${value}`);\n\n if (!value) {\n return undefined;\n }\n\n const code = value.slice(35, 38);\n debugData(`008 code: ${code}`);\n return code === '|||' || code === ' ' || code === '^^^' ? undefined : code;\n }\n\n // Main language for the resource: in the first f041 $a or f041 $d\n // Uses only f041s that have 2nd ind ' ', which means that the codes used are MARC 21 language codes\n\n function get041Values() {\n return record.get(/^041$/u)\n .filter(({ind2}) => ind2 === ' ')\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'a' || code === 'd')\n .map(({value}) => value);\n }\n },\n compare: (a, b) => {\n debugData(`Comparing ${JSON.stringify(a[0])} and ${JSON.stringify(b[0])}`);\n\n if (a.length === 0 || b.length === 0) {\n debugData(`No language to compare`);\n return 0;\n }\n\n debugData(`There are languages to compare`);\n\n if (a[0] === b[0]) {\n return 0.1;\n }\n\n return a[0] === 'und' || b[0] === 'und' ? 0.0 : -1.0;\n }\n});\n"],"mappings":";;;;;;;AA6BA;;;;AA7BA;;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;AAIA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAkB,qEAAlB,CAAd;AACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB;;eAEe,OAAO;EACpBC,IAAI,EAAE,UADc;EAEpBC,OAAO,EAAEC,MAAM,IAAI;IACjB,MAAMC,QAAQ,GAAGC,WAAW,EAA5B;IACA,MAAMC,SAAS,GAAGC,YAAY,EAA9B;IACAR,SAAS,CAAE,QAAOS,IAAI,CAACC,SAAL,CAAeL,QAAf,CAAyB,UAASI,IAAI,CAACC,SAAL,CAAeH,SAAf,CAA0B,EAArE,CAAT;;IAEA,IAAIF,QAAQ,IAAIE,SAAS,CAACI,MAAV,GAAmB,CAAnC,EAAsC;MACpCX,SAAS,CAAE,uDAAF,CAAT;MACA,MAAMY,kBAAkB,GAAGL,SAAS,CAACM,IAAV,CAAeC,CAAC,IAAIA,CAAC,KAAKT,QAA1B,CAA3B;MACAL,SAAS,CAAE,wBAAuBY,kBAAmB,EAA5C,CAAT;MACA,OAAOA,kBAAkB,GAAG,CAACA,kBAAD,CAAH,GAA0B,EAAnD;IACD;;IAED,IAAI,CAACP,QAAD,IAAaE,SAAS,CAACI,MAAV,GAAmB,CAApC,EAAuC;MACrCX,SAAS,CAAE,wBAAF,CAAT;MACA,OAAO,EAAP;IACD;;IAED,OAAOK,QAAQ,GAAG,CAACA,QAAD,CAAH,GAAgB,CAACE,SAAS,CAAC,CAAD,CAAV,CAA/B;;IAEA,SAASD,WAAT,GAAuB;MA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D;;IAEDA,SAAS,CAAE,gCAAF,CAAT;;IAEA,IAAI0B,CAAC,CAAC,CAAD,CAAD,KAASC,CAAC,CAAC,CAAD,CAAd,EAAmB;MACjB,OAAO,GAAP;IACD;;IAED,OAAOD,CAAC,CAAC,CAAD,CAAD,KAAS,KAAT,IAAkBC,CAAC,CAAC,CAAD,CAAD,KAAS,KAA3B,GAAmC,GAAnC,GAAyC,CAAC,GAAjD;EACD;AA7DmB,CAAP,C"}
|
|
@@ -5,13 +5,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.default = void 0;
|
|
7
7
|
|
|
8
|
+
var _matchingUtils = require("../../../matching-utils");
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
*
|
|
10
12
|
* @licstart The following is the entire license notice for the JavaScript code in this file.
|
|
11
13
|
*
|
|
12
14
|
* Melinda record matching modules for Javascript
|
|
13
15
|
*
|
|
14
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
16
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
15
17
|
*
|
|
16
18
|
* This file is part of melinda-record-matching-js
|
|
17
19
|
*
|
|
@@ -32,13 +34,15 @@ exports.default = void 0;
|
|
|
32
34
|
* for the JavaScript code in this file.
|
|
33
35
|
*
|
|
34
36
|
*/
|
|
37
|
+
// We should also get copyright time and copyright/publication times from 26x
|
|
38
|
+
// We could also enable matching of records which have consequent publication years
|
|
35
39
|
var _default = () => ({
|
|
36
40
|
name: 'Publication time',
|
|
37
41
|
extract: record => {
|
|
38
42
|
var _record$get, _record$get$;
|
|
39
43
|
|
|
40
|
-
const value = ((_record$get = record.get(/^008$/u)) === null || _record$get === void 0 ? void 0 : (_record$get$ = _record$get[0]) === null || _record$get$ === void 0 ? void 0 : _record$get$.value) ||
|
|
41
|
-
return value ? [value.slice(7, 11)] : [];
|
|
44
|
+
const value = ((_record$get = record.get(/^008$/u)) === null || _record$get === void 0 ? void 0 : (_record$get$ = _record$get[0]) === null || _record$get$ === void 0 ? void 0 : _record$get$.value) || undefined;
|
|
45
|
+
return (0, _matchingUtils.testStringOrNumber)(value) ? [String(value).slice(7, 11)] : [];
|
|
42
46
|
},
|
|
43
47
|
compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0
|
|
44
48
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"publication-time.js","names":["name","extract","record","value","get","slice","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/publication-time.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 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: 'Publication time',\n extract: record => {\n const value = record.get(/^008$/u)?.[0]?.value ||
|
|
1
|
+
{"version":3,"file":"publication-time.js","names":["name","extract","record","value","get","undefined","testStringOrNumber","String","slice","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/publication-time.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport {testStringOrNumber} from '../../../matching-utils';\n\n// We should also get copyright time and copyright/publication times from 26x\n// We could also enable matching of records which have consequent publication years\n\nexport default () => ({\n name: 'Publication time',\n extract: record => {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];\n },\n compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0\n});\n"],"mappings":";;;;;;;AA4BA;;AA5BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAIA;AACA;eAEe,OAAO;EACpBA,IAAI,EAAE,kBADc;EAEpBC,OAAO,EAAEC,MAAM,IAAI;IAAA;;IACjB,MAAMC,KAAK,GAAG,gBAAAD,MAAM,CAACE,GAAP,CAAW,QAAX,6EAAuB,CAAvB,+DAA2BD,KAA3B,KAAoCE,SAAlD;IACA,OAAO,IAAAC,iCAAA,EAAmBH,KAAnB,IAA4B,CAACI,MAAM,CAACJ,KAAD,CAAN,CAAcK,KAAd,CAAoB,CAApB,EAAuB,EAAvB,CAAD,CAA5B,GAA2D,EAAlE;EACD,CALmB;EAMpBC,OAAO,EAAE,CAACC,CAAD,EAAIC,CAAJ,KAAUD,CAAC,CAAC,CAAD,CAAD,KAASC,CAAC,CAAC,CAAD,CAAV,GAAgB,GAAhB,GAAsB,CAAC;AANtB,CAAP,C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"record-type.js","names":["name","extract","r","leader","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/record-type.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: 'Record type',\n extract: r => r.leader[6] ? [r.leader[6]] : [],\n compare: (a, b) => a[0] === b[0] ? 0.1 : -0.5\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,aADc;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"}
|
|
1
|
+
{"version":3,"file":"record-type.js","names":["name","extract","r","leader","compare","a","b"],"sources":["../../../../src/match-detection/features/bib/record-type.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\n// we could handle the case of books/notes\n\nexport default () => ({\n name: 'Record type',\n extract: r => r.leader[6] ? [r.leader[6]] : [],\n compare: (a, b) => a[0] === b[0] ? 0.1 : -0.5\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;AAEA;eAEe,OAAO;EACpBA,IAAI,EAAE,aADc;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"}
|
|
@@ -7,6 +7,8 @@ exports.default = void 0;
|
|
|
7
7
|
|
|
8
8
|
var _debug = _interopRequireDefault(require("debug"));
|
|
9
9
|
|
|
10
|
+
var _matchingUtils = require("../../../matching-utils");
|
|
11
|
+
|
|
10
12
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
11
13
|
|
|
12
14
|
/**
|
|
@@ -15,7 +17,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
15
17
|
*
|
|
16
18
|
* Melinda record matching modules for Javascript
|
|
17
19
|
*
|
|
18
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
20
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
19
21
|
*
|
|
20
22
|
* This file is part of melinda-record-matching-js
|
|
21
23
|
*
|
|
@@ -54,14 +56,13 @@ var _default = ({
|
|
|
54
56
|
if (field) {
|
|
55
57
|
return field.subfields.filter(({
|
|
56
58
|
code
|
|
57
|
-
}) => subfieldCodes.includes(code))
|
|
58
|
-
.map(({
|
|
59
|
+
}) => subfieldCodes.includes(code)).map(({
|
|
59
60
|
code,
|
|
60
61
|
value
|
|
61
62
|
}) => ({
|
|
62
63
|
code,
|
|
63
|
-
value: value ? value.replace(/-/ug, '') : ''
|
|
64
|
-
}));
|
|
64
|
+
value: (0, _matchingUtils.testStringOrNumber)(value) ? String(value).replace(/-/ug, '') : ''
|
|
65
|
+
})).filter(value => value);
|
|
65
66
|
}
|
|
66
67
|
|
|
67
68
|
return [];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standard-identifier-factory.js","names":["debug","createDebugLogger","debugData","extend","pattern","subfieldCodes","extract","compare","record","field","get","subfields","filter","code","includes","map","value","replace","a","b","length","bothHaveValidIdentifiers","maxValues","matchingValues","getValueCount","aValues","bValues","validOnly","getIdentifiers","aValue","some","bValue","values"],"sources":["../../../../src/match-detection/features/bib/standard-identifier-factory.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 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
|
|
1
|
+
{"version":3,"file":"standard-identifier-factory.js","names":["debug","createDebugLogger","debugData","extend","pattern","subfieldCodes","extract","compare","record","field","get","subfields","filter","code","includes","map","value","testStringOrNumber","String","replace","a","b","length","bothHaveValidIdentifiers","maxValues","matchingValues","getValueCount","aValues","bValues","validOnly","getIdentifiers","aValue","some","bValue","values"],"sources":["../../../../src/match-detection/features/bib/standard-identifier-factory.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\nimport {testStringOrNumber} from '../../../matching-utils';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');\nconst debugData = debug.extend('data');\n\nexport default ({pattern, subfieldCodes}) => {\n return {extract, compare};\n\n function extract(record) {\n const [field] = record.get(pattern);\n\n if (field) {\n return field.subfields\n .filter(({code}) => subfieldCodes.includes(code))\n .map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value).replace(/-/ug, '') : ''}))\n .filter(value => value);\n }\n\n return [];\n }\n\n function compare(a, b) {\n if (a.length === 0 || b.length === 0) {\n debugData(`No standardidentifiers to compare`);\n return 0;\n }\n\n if (bothHaveValidIdentifiers()) {\n const {maxValues, matchingValues} = getValueCount(true);\n return matchingValues / maxValues * 0.75;\n }\n\n const {maxValues, matchingValues} = getValueCount();\n return matchingValues / maxValues * 0.2;\n\n function bothHaveValidIdentifiers() {\n const aValues = a.filter(({code}) => code === 'a');\n const bValues = a.filter(({code}) => code === 'a');\n return aValues.length > 0 && bValues.length > 0;\n }\n\n function getValueCount(validOnly = false) {\n const aValues = getIdentifiers(a);\n const bValues = getIdentifiers(b);\n\n return {\n maxValues: aValues.length > bValues.length ? aValues.length : bValues.length,\n matchingValues: aValues.filter(aValue => bValues.some(bValue => aValue === bValue)).length\n };\n\n function getIdentifiers(values) {\n if (validOnly) {\n return values\n .filter(({code}) => code === 'a')\n .map(({value}) => value);\n }\n\n return values.map(({value}) => value);\n }\n }\n }\n};\n"],"mappings":";;;;;;;AA4BA;;AACA;;;;AA7BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAC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
var _natural = require("natural");
|
|
11
11
|
|
|
12
|
+
var _matchingUtils = require("../../../matching-utils");
|
|
13
|
+
|
|
12
14
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
13
15
|
|
|
14
16
|
/**
|
|
@@ -17,7 +19,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
19
|
*
|
|
18
20
|
* Melinda record matching modules for Javascript
|
|
19
21
|
*
|
|
20
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
22
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
21
23
|
*
|
|
22
24
|
* This file is part of melinda-record-matching-js
|
|
23
25
|
*
|
|
@@ -45,8 +47,8 @@ var _default = ({
|
|
|
45
47
|
extract: record => {
|
|
46
48
|
const title = getTitle();
|
|
47
49
|
|
|
48
|
-
if (title) {
|
|
49
|
-
return [title.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
|
|
50
|
+
if ((0, _matchingUtils.testStringOrNumber)(title)) {
|
|
51
|
+
return [String(title).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
|
|
50
52
|
}
|
|
51
53
|
|
|
52
54
|
return [];
|
|
@@ -59,8 +61,10 @@ var _default = ({
|
|
|
59
61
|
code
|
|
60
62
|
}) => ['a', 'b'].includes(code)).map(({
|
|
61
63
|
value
|
|
62
|
-
}) => value).join('');
|
|
64
|
+
}) => (0, _matchingUtils.testStringOrNumber)(value) ? String(value) : '').join('');
|
|
63
65
|
}
|
|
66
|
+
|
|
67
|
+
return false;
|
|
64
68
|
}
|
|
65
69
|
},
|
|
66
70
|
compare: (a, b) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"title.js","names":["treshold","name","extract","record","title","getTitle","replace","toLowerCase","field","get","subfields","filter","code","includes","map","value","join","compare","a","b","debug","createDebugLogger","distance","leven","maxLength","getMaxLength","percentage","length"],"sources":["../../../../src/match-detection/features/bib/title.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\nimport {LevenshteinDistance as leven} from 'natural';\n\nexport default ({treshold = 10} = {}) => ({\n name: 'Title',\n extract: record => {\n const title = getTitle();\n\n if (title) {\n return [title.replace(/[^\\p{Letter}\\p{Number}]/gu, '').toLowerCase()];\n }\n\n return [];\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n return field.subfields\n .filter(({code}) => ['a', 'b'].includes(code))\n .map(({value}) => value)\n .join('');\n }\n }\n },\n compare: (a, b) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/title');\n const distance = leven(a[0], b[0]);\n\n if (distance === 0) {\n return 0.5;\n }\n\n const maxLength = getMaxLength();\n const percentage = distance / maxLength * 100;\n\n debug(`'${a}' vs '${b}': Max length = ${maxLength}, distance = ${distance}, percentage = ${percentage}`);\n\n if (percentage <= treshold) {\n return 0.3;\n }\n\n return -0.5;\n\n function getMaxLength() {\n return a[0].length > b[0].length ? a[0].length : b[0].length;\n }\n\n }\n});\n"],"mappings":";;;;;;;AA4BA;;AACA;;;;
|
|
1
|
+
{"version":3,"file":"title.js","names":["treshold","name","extract","record","title","getTitle","testStringOrNumber","String","replace","toLowerCase","field","get","subfields","filter","code","includes","map","value","join","compare","a","b","debug","createDebugLogger","distance","leven","maxLength","getMaxLength","percentage","length"],"sources":["../../../../src/match-detection/features/bib/title.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 {LevenshteinDistance as leven} from 'natural';\nimport {testStringOrNumber} from '../../../matching-utils';\n\nexport default ({treshold = 10} = {}) => ({\n name: 'Title',\n extract: record => {\n const title = getTitle();\n\n if (testStringOrNumber(title)) {\n return [String(title).replace(/[^\\p{Letter}\\p{Number}]/gu, '').toLowerCase()];\n }\n\n return [];\n\n function getTitle() {\n const [field] = record.get(/^245$/u);\n\n if (field) {\n return field.subfields\n .filter(({code}) => ['a', 'b'].includes(code))\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .join('');\n }\n return false;\n }\n },\n compare: (a, b) => {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/title');\n const distance = leven(a[0], b[0]);\n\n if (distance === 0) {\n return 0.5;\n }\n\n const maxLength = getMaxLength();\n const percentage = distance / maxLength * 100;\n\n debug(`'${a}' vs '${b}': Max length = ${maxLength}, distance = ${distance}, percentage = ${percentage}`);\n\n if (percentage <= treshold) {\n return 0.3;\n }\n\n return -0.5;\n\n function getMaxLength() {\n return a[0].length > b[0].length ? a[0].length : b[0].length;\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;eAMe,CAAC;EAACA,QAAQ,GAAG;AAAZ,IAAkB,EAAnB,MAA2B;EACxCC,IAAI,EAAE,OADkC;EAExCC,OAAO,EAAEC,MAAM,IAAI;IACjB,MAAMC,KAAK,GAAGC,QAAQ,EAAtB;;IAEA,IAAI,IAAAC,iCAAA,EAAmBF,KAAnB,CAAJ,EAA+B;MAC7B,OAAO,CAACG,MAAM,CAACH,KAAD,CAAN,CAAcI,OAAd,CAAsB,2BAAtB,EAAmD,EAAnD,EAAuDC,WAAvD,EAAD,CAAP;IACD;;IAED,OAAO,EAAP;;IAEA,SAASJ,QAAT,GAAoB;MAClB,MAAM,CAACK,KAAD,IAAUP,MAAM,CAACQ,GAAP,CAAW,QAAX,CAAhB;;MAEA,IAAID,KAAJ,EAAW;QACT,OAAOA,KAAK,CAACE,SAAN,CACJC,MADI,CACG,CAAC;UAACC;QAAD,CAAD,KAAY,CAAC,GAAD,EAAM,GAAN,EAAWC,QAAX,CAAoBD,IAApB,CADf,EAEJE,GAFI,CAEA,CAAC;UAACC;QAAD,CAAD,KAAa,IAAAX,iCAAA,EAAmBW,KAAnB,IAA4BV,MAAM,CAACU,KAAD,CAAlC,GAA4C,EAFzD,EAGJC,IAHI,CAGC,EAHD,CAAP;MAID;;MACD,OAAO,KAAP;IACD;EACF,CAtBuC;EAuBxCC,OAAO,EAAE,CAACC,CAAD,EAAIC,CAAJ,KAAU;IACjB,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAkB,sEAAlB,CAAd;IACA,MAAMC,QAAQ,GAAG,IAAAC,4BAAA,EAAML,CAAC,CAAC,CAAD,CAAP,EAAYC,CAAC,CAAC,CAAD,CAAb,CAAjB;;IAEA,IAAIG,QAAQ,KAAK,CAAjB,EAAoB;MAClB,OAAO,GAAP;IACD;;IAED,MAAME,SAAS,GAAGC,YAAY,EAA9B;IACA,MAAMC,UAAU,GAAGJ,QAAQ,GAAGE,SAAX,GAAuB,GAA1C;IAEAJ,KAAK,CAAE,IAAGF,CAAE,SAAQC,CAAE,mBAAkBK,SAAU,gBAAeF,QAAS,kBAAiBI,UAAW,EAAjG,CAAL;;IAEA,IAAIA,UAAU,IAAI5B,QAAlB,EAA4B;MAC1B,OAAO,GAAP;IACD;;IAED,OAAO,CAAC,GAAR;;IAEA,SAAS2B,YAAT,GAAwB;MACtB,OAAOP,CAAC,CAAC,CAAD,CAAD,CAAKS,MAAL,GAAcR,CAAC,CAAC,CAAD,CAAD,CAAKQ,MAAnB,GAA4BT,CAAC,CAAC,CAAD,CAAD,CAAKS,MAAjC,GAA0CR,CAAC,CAAC,CAAD,CAAD,CAAKQ,MAAtD;IACD;EAEF;AA9CuC,CAA3B,C"}
|
package/dist/matching-utils.js
CHANGED
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.getMelindaIdsF035 = getMelindaIdsF035;
|
|
7
7
|
exports.getSubfieldValues = getSubfieldValues;
|
|
8
|
+
exports.testStringOrNumber = testStringOrNumber;
|
|
8
9
|
exports.validateSidFieldSubfieldCounts = validateSidFieldSubfieldCounts;
|
|
9
10
|
|
|
10
11
|
var _debug = _interopRequireDefault(require("debug"));
|
|
@@ -17,7 +18,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
|
|
|
17
18
|
*
|
|
18
19
|
* Melinda record matching modules for Javascript
|
|
19
20
|
*
|
|
20
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
21
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
21
22
|
*
|
|
22
23
|
* This file is part of melinda-record-matching-js
|
|
23
24
|
*
|
|
@@ -62,9 +63,9 @@ function getMelindaIdsF035(record) {
|
|
|
62
63
|
subfields
|
|
63
64
|
}) {
|
|
64
65
|
const melindaIdRegExp = /^(?<prefix>\(FI-MELINDA\)|FCC)(?<id>\d{9})$/u;
|
|
65
|
-
return subfields.filter(sub => ['a', 'z'].includes(sub.code)).filter(sub => melindaIdRegExp.test(sub.value)).map(({
|
|
66
|
+
return subfields.filter(sub => ['a', 'z'].includes(sub.code)).filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value))).map(({
|
|
66
67
|
value
|
|
67
|
-
}) => value ? value.replace(melindaIdRegExp, '$<id>') : '');
|
|
68
|
+
}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');
|
|
68
69
|
}
|
|
69
70
|
}
|
|
70
71
|
|
|
@@ -90,6 +91,14 @@ function getSubfieldValues(field, subfieldCode) {
|
|
|
90
91
|
code
|
|
91
92
|
}) => code === subfieldCode).map(({
|
|
92
93
|
value
|
|
93
|
-
}) => value);
|
|
94
|
+
}) => testStringOrNumber(value) ? String(value) : '').filter(value => value);
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function testStringOrNumber(value) {
|
|
98
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
99
|
+
return true;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
return false;
|
|
94
103
|
}
|
|
95
104
|
//# sourceMappingURL=matching-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"matching-utils.js","names":["debug","createDebugLogger","debugData","extend","getMelindaIdsF035","record","f035s","getFields","length","allF035MelindaIds","concat","map","toMelindaIds","f035MelindaIds","Set","JSON","stringify","subfields","melindaIdRegExp","filter","sub","includes","code","
|
|
1
|
+
{"version":3,"file":"matching-utils.js","names":["debug","createDebugLogger","debugData","extend","getMelindaIdsF035","record","f035s","getFields","length","allF035MelindaIds","concat","map","toMelindaIds","f035MelindaIds","Set","JSON","stringify","subfields","melindaIdRegExp","filter","sub","includes","code","testStringOrNumber","value","test","String","replace","validateSidFieldSubfieldCounts","field","countC","countSubfields","countB","subfieldCode","getSubfieldValues"],"sources":["../src/matching-utils.js"],"sourcesContent":["/**\n*\n* @licstart The following is the entire license notice for the JavaScript code in this file.\n*\n* Melinda record matching modules for Javascript\n*\n* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)\n*\n* This file is part of melinda-record-matching-js\n*\n* melinda-record-matching-js program is free software: you can redistribute it and/or modify\n* it under the terms of the GNU Lesser General Public License as\n* published by the Free Software Foundation, either version 3 of the\n* License, or (at your option) any later version.\n*\n* melinda-record-matching-js is distributed in the hope that it will be useful,\n* but WITHOUT ANY WARRANTY; without even the implied warranty of\n* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n* GNU Lesser General Public License for more details.\n*\n* You should have received a copy of the GNU Affero General Public License\n* along with this program. If not, see <http://www.gnu.org/licenses/>.\n*\n* @licend The above is the entire license notice\n* for the JavaScript code in this file.\n*\n*/\n\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:utils');\nconst debugData = debug.extend('data');\n\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 => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))\n .map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');\n\n }\n}\n\nexport function validateSidFieldSubfieldCounts(field) {\n // Valid SID-fields have just one $c and one $b\n debugData(`Validating SID field ${JSON.stringify(field)}`);\n const countC = countSubfields(field, 'c');\n const countB = countSubfields(field, 'b');\n debug(`Found ${countC} sf $cs and ${countB} sf $bs. IsValid: ${countC === 1 && countB === 1}`);\n\n return countC === 1 && countB === 1;\n}\n\nfunction countSubfields(field, subfieldCode) {\n // debug(`Counting subfields ${subfieldCode}`);\n return field.subfields.filter(({code}) => code === subfieldCode).length;\n}\n\nexport function getSubfieldValues(field, subfieldCode) {\n debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);\n return field.subfields\n .filter(({code}) => code === subfieldCode)\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value);\n}\n\nexport function testStringOrNumber(value) {\n if (typeof value === 'string' || typeof value === 'number') {\n return true;\n }\n return false;\n}\n"],"mappings":";;;;;;;;;;AA4BA;;;;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,IAAAC,cAAA,EAAkB,yCAAlB,CAAd;AACA,MAAMC,SAAS,GAAGF,KAAK,CAACG,MAAN,CAAa,MAAb,CAAlB,C,CAEA;;AACO,SAASC,iBAAT,CAA2BC,MAA3B,EAAmC;EAExC,MAAML,KAAK,GAAG,IAAAC,cAAA,EAAkB,8CAAlB,CAAd;EACA,MAAMC,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AA4D;IAC1D,OAAO,IAAP;EACD;;EACD,OAAO,KAAP;AACD"}
|
package/package.json
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"url": "git@github.com:natlibfi/melinda-record-matching-js.git"
|
|
15
15
|
},
|
|
16
16
|
"license": "LGPL-3.0+",
|
|
17
|
-
"version": "2.2.
|
|
17
|
+
"version": "2.2.1-alpha.2",
|
|
18
18
|
"main": "./dist/index.js",
|
|
19
19
|
"engines": {
|
|
20
20
|
"node": ">=14"
|
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
"access": "public"
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
+
"prepare": "npm run build",
|
|
26
27
|
"start": "node dist/index.js",
|
|
27
28
|
"cli": "node dist/cli.js",
|
|
28
29
|
"lint": "eslint src",
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Melinda record matching modules for Javascript
|
|
7
7
|
*
|
|
8
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
8
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
9
9
|
*
|
|
10
10
|
* This file is part of melinda-record-matching-js
|
|
11
11
|
*
|
|
@@ -28,7 +28,7 @@
|
|
|
28
28
|
*/
|
|
29
29
|
import createDebugLogger from 'debug';
|
|
30
30
|
import {toQueries} from '../candidate-search-utils';
|
|
31
|
-
import {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues} from '../../matching-utils';
|
|
31
|
+
import {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils';
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
export function bibSourceIds(record) {
|
|
@@ -108,7 +108,7 @@ export function bibSourceIds(record) {
|
|
|
108
108
|
|
|
109
109
|
function removeSourcePrefix(subfieldValue) {
|
|
110
110
|
const sourcePrefixRegex = (/^(?<sourcePrefix>\([A-Za-z0-9-]+\))(?<id>.+)$/u);
|
|
111
|
-
const normalizedValue = subfieldValue ? subfieldValue.replace(sourcePrefixRegex, '$<id>') : '';
|
|
111
|
+
const normalizedValue = testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(sourcePrefixRegex, '$<id>') : '';
|
|
112
112
|
debugData(`Normalized ${subfieldValue} to ${normalizedValue}`);
|
|
113
113
|
return normalizedValue;
|
|
114
114
|
}
|
|
@@ -116,7 +116,7 @@ export function bibSourceIds(record) {
|
|
|
116
116
|
function normalizeSidSubfieldValue(subfieldValue) {
|
|
117
117
|
debugData(`Normalizing ${subfieldValue}`);
|
|
118
118
|
const normalizeAwayRegex = (/[- ]/u);
|
|
119
|
-
return subfieldValue ? subfieldValue.replace(normalizeAwayRegex, '') : '';
|
|
119
|
+
return testStringOrNumber(subfieldValue) ? String(subfieldValue).replace(normalizeAwayRegex, '') : '';
|
|
120
120
|
}
|
|
121
121
|
|
|
122
122
|
}
|
|
@@ -151,7 +151,7 @@ export function bibMelindaIds(record) {
|
|
|
151
151
|
// bibHostComponents should search all 773 $ws for possible host id, but what should it do in case of multiple host ids?
|
|
152
152
|
export function bibHostComponents(record) {
|
|
153
153
|
const id = getHostId();
|
|
154
|
-
return id ? [`melinda.partsofhost=${id}`] : [];
|
|
154
|
+
return testStringOrNumber(id) ? [`melinda.partsofhost=${id}`] : [];
|
|
155
155
|
|
|
156
156
|
function getHostId() {
|
|
157
157
|
const [field] = record.get(/^773$/u);
|
|
@@ -159,12 +159,12 @@ export function bibHostComponents(record) {
|
|
|
159
159
|
if (field) {
|
|
160
160
|
const {value} = field.subfields.find(({code}) => code === 'w') || {};
|
|
161
161
|
|
|
162
|
-
if (value && (/^\(FI-MELINDA\)/u).test(value)) {
|
|
163
|
-
return value.replace(/^\(FI-MELINDA\)/u, '');
|
|
162
|
+
if (testStringOrNumber(value) && (/^\(FI-MELINDA\)/u).test(String(value))) {
|
|
163
|
+
return String(value).replace(/^\(FI-MELINDA\)/u, '');
|
|
164
164
|
}
|
|
165
165
|
|
|
166
|
-
if (value && (/^\(FIN01\)/u).test(value)) {
|
|
167
|
-
return value.replace(/^\(FIN01\)/u, '');
|
|
166
|
+
if (testStringOrNumber(value) && (/^\(FIN01\)/u).test(String(value))) {
|
|
167
|
+
return String(value).replace(/^\(FIN01\)/u, '');
|
|
168
168
|
}
|
|
169
169
|
|
|
170
170
|
return false;
|
|
@@ -185,8 +185,8 @@ export function bibTitle(record) {
|
|
|
185
185
|
const title = getTitle();
|
|
186
186
|
const booleanStartWords = ['and', 'or', 'nor', 'not'];
|
|
187
187
|
|
|
188
|
-
if (title) {
|
|
189
|
-
const formatted = title
|
|
188
|
+
if (testStringOrNumber(title)) {
|
|
189
|
+
const formatted = String(title)
|
|
190
190
|
.replace(/[^\w\s\p{Alphabetic}]/gu, '')
|
|
191
191
|
// Clean up concurrent spaces from fe. subfield changes
|
|
192
192
|
.replace(/ +/gu, ' ')
|
|
@@ -208,7 +208,8 @@ export function bibTitle(record) {
|
|
|
208
208
|
if (field) {
|
|
209
209
|
return field.subfields
|
|
210
210
|
.filter(({code}) => ['a', 'b'].includes(code))
|
|
211
|
-
.map(({value}) => value)
|
|
211
|
+
.map(({value}) => testStringOrNumber(value) ? String(value) : '')
|
|
212
|
+
.filter(value => value)
|
|
212
213
|
// In Melinda's index subfield separators are indexed as ' '
|
|
213
214
|
.join(' ');
|
|
214
215
|
}
|
|
@@ -244,18 +245,18 @@ export function bibStandardIdentifiers(record) {
|
|
|
244
245
|
|
|
245
246
|
if (tag === '022') {
|
|
246
247
|
return subfields
|
|
247
|
-
.filter(sub => ['a', 'z', 'y'].includes(sub.code) &&
|
|
248
|
-
.map(({value}) => value);
|
|
248
|
+
.filter(sub => ['a', 'z', 'y'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))
|
|
249
|
+
.map(({value}) => String(value));
|
|
249
250
|
}
|
|
250
251
|
|
|
251
252
|
if (tag === '020') {
|
|
252
253
|
return subfields
|
|
253
|
-
.filter(sub => ['a', 'z'].includes(sub.code) &&
|
|
254
|
-
.map(({value}) => value);
|
|
254
|
+
.filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && issnIsbnReqExp.test(String(sub.value)))
|
|
255
|
+
.map(({value}) => String(value));
|
|
255
256
|
}
|
|
256
257
|
|
|
257
258
|
return subfields
|
|
258
|
-
.filter(sub => ['a', 'z'].includes(sub.code) &&
|
|
259
|
-
.map(({value}) => value);
|
|
259
|
+
.filter(sub => ['a', 'z'].includes(sub.code) && testStringOrNumber(sub.value) && otherIdReqExp.test(String(sub.value)))
|
|
260
|
+
.map(({value}) => String(value));
|
|
260
261
|
}
|
|
261
262
|
}
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -27,6 +27,9 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import {LevenshteinDistance as leven} from 'natural';
|
|
30
|
+
import {testStringOrNumber} from '../../../matching-utils';
|
|
31
|
+
|
|
32
|
+
// We should extract also organisational authors (110/710)
|
|
30
33
|
|
|
31
34
|
export default ({nameTreshold = 10} = {}) => ({
|
|
32
35
|
name: 'Authors',
|
|
@@ -40,7 +43,7 @@ export default ({nameTreshold = 10} = {}) => ({
|
|
|
40
43
|
|
|
41
44
|
function toObj({code, value}) {
|
|
42
45
|
if (code === 'a') {
|
|
43
|
-
return {name: value ? value.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase() : ''};
|
|
46
|
+
return {name: testStringOrNumber(value) ? String(value).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase() : ''};
|
|
44
47
|
}
|
|
45
48
|
|
|
46
49
|
return {id: value};
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Melinda record matching modules for Javascript
|
|
7
7
|
*
|
|
8
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
8
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
9
9
|
*
|
|
10
10
|
* This file is part of melinda-record-matching-js
|
|
11
11
|
*
|
|
@@ -86,7 +86,7 @@ export default () => ({
|
|
|
86
86
|
return 0;
|
|
87
87
|
}
|
|
88
88
|
|
|
89
|
-
debugData(`There
|
|
89
|
+
debugData(`There are languages to compare`);
|
|
90
90
|
|
|
91
91
|
if (a[0] === b[0]) {
|
|
92
92
|
return 0.1;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -26,11 +26,16 @@
|
|
|
26
26
|
*
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
|
+
import {testStringOrNumber} from '../../../matching-utils';
|
|
30
|
+
|
|
31
|
+
// We should also get copyright time and copyright/publication times from 26x
|
|
32
|
+
// We could also enable matching of records which have consequent publication years
|
|
33
|
+
|
|
29
34
|
export default () => ({
|
|
30
35
|
name: 'Publication time',
|
|
31
36
|
extract: record => {
|
|
32
|
-
const value = record.get(/^008$/u)?.[0]?.value ||
|
|
33
|
-
return value ? [value.slice(7, 11)] : [];
|
|
37
|
+
const value = record.get(/^008$/u)?.[0]?.value || undefined;
|
|
38
|
+
return testStringOrNumber(value) ? [String(value).slice(7, 11)] : [];
|
|
34
39
|
},
|
|
35
40
|
compare: (a, b) => a[0] === b[0] ? 0.1 : -1.0
|
|
36
41
|
});
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -27,6 +27,7 @@
|
|
|
27
27
|
*/
|
|
28
28
|
|
|
29
29
|
import createDebugLogger from 'debug';
|
|
30
|
+
import {testStringOrNumber} from '../../../matching-utils';
|
|
30
31
|
|
|
31
32
|
const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers');
|
|
32
33
|
const debugData = debug.extend('data');
|
|
@@ -40,8 +41,8 @@ export default ({pattern, subfieldCodes}) => {
|
|
|
40
41
|
if (field) {
|
|
41
42
|
return field.subfields
|
|
42
43
|
.filter(({code}) => subfieldCodes.includes(code))
|
|
43
|
-
|
|
44
|
-
.
|
|
44
|
+
.map(({code, value}) => ({code, value: testStringOrNumber(value) ? String(value).replace(/-/ug, '') : ''}))
|
|
45
|
+
.filter(value => value);
|
|
45
46
|
}
|
|
46
47
|
|
|
47
48
|
return [];
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -28,14 +28,15 @@
|
|
|
28
28
|
|
|
29
29
|
import createDebugLogger from 'debug';
|
|
30
30
|
import {LevenshteinDistance as leven} from 'natural';
|
|
31
|
+
import {testStringOrNumber} from '../../../matching-utils';
|
|
31
32
|
|
|
32
33
|
export default ({treshold = 10} = {}) => ({
|
|
33
34
|
name: 'Title',
|
|
34
35
|
extract: record => {
|
|
35
36
|
const title = getTitle();
|
|
36
37
|
|
|
37
|
-
if (title) {
|
|
38
|
-
return [title.replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
|
|
38
|
+
if (testStringOrNumber(title)) {
|
|
39
|
+
return [String(title).replace(/[^\p{Letter}\p{Number}]/gu, '').toLowerCase()];
|
|
39
40
|
}
|
|
40
41
|
|
|
41
42
|
return [];
|
|
@@ -46,9 +47,10 @@ export default ({treshold = 10} = {}) => ({
|
|
|
46
47
|
if (field) {
|
|
47
48
|
return field.subfields
|
|
48
49
|
.filter(({code}) => ['a', 'b'].includes(code))
|
|
49
|
-
.map(({value}) => value)
|
|
50
|
+
.map(({value}) => testStringOrNumber(value) ? String(value) : '')
|
|
50
51
|
.join('');
|
|
51
52
|
}
|
|
53
|
+
return false;
|
|
52
54
|
}
|
|
53
55
|
},
|
|
54
56
|
compare: (a, b) => {
|
package/src/matching-utils.js
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*
|
|
5
5
|
* Melinda record matching modules for Javascript
|
|
6
6
|
*
|
|
7
|
-
* Copyright (C) 2020 University Of Helsinki (The National Library Of Finland)
|
|
7
|
+
* Copyright (C) 2020-2022 University Of Helsinki (The National Library Of Finland)
|
|
8
8
|
*
|
|
9
9
|
* This file is part of melinda-record-matching-js
|
|
10
10
|
*
|
|
@@ -58,8 +58,8 @@ export function getMelindaIdsF035(record) {
|
|
|
58
58
|
|
|
59
59
|
return subfields
|
|
60
60
|
.filter(sub => ['a', 'z'].includes(sub.code))
|
|
61
|
-
.filter(sub => melindaIdRegExp.test(sub.value))
|
|
62
|
-
.map(({value}) => value ? value.replace(melindaIdRegExp, '$<id>') : '');
|
|
61
|
+
.filter(sub => testStringOrNumber(sub.value) && melindaIdRegExp.test(String(sub.value)))
|
|
62
|
+
.map(({value}) => testStringOrNumber(value) ? String(value).replace(melindaIdRegExp, '$<id>') : '');
|
|
63
63
|
|
|
64
64
|
}
|
|
65
65
|
}
|
|
@@ -81,6 +81,15 @@ function countSubfields(field, subfieldCode) {
|
|
|
81
81
|
|
|
82
82
|
export function getSubfieldValues(field, subfieldCode) {
|
|
83
83
|
debugData(`Get subfield(s) $${subfieldCode} from ${JSON.stringify(field)}`);
|
|
84
|
-
return field.subfields
|
|
84
|
+
return field.subfields
|
|
85
|
+
.filter(({code}) => code === subfieldCode)
|
|
86
|
+
.map(({value}) => testStringOrNumber(value) ? String(value) : '')
|
|
87
|
+
.filter(value => value);
|
|
85
88
|
}
|
|
86
89
|
|
|
90
|
+
export function testStringOrNumber(value) {
|
|
91
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
92
|
+
return true;
|
|
93
|
+
}
|
|
94
|
+
return false;
|
|
95
|
+
}
|