Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Functionality updates #112

Merged
merged 6 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 65 additions & 66 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"url": "[email protected]:natlibfi/melinda-marc-record-merge-reducers-js.git"
},
"license": "LGPL-3.0+",
"version": "2.0.19",
"version": "2.0.20-alpha.4",
"main": "./dist/index.js",
"engines": {
"node": ">=18"
Expand All @@ -39,9 +39,8 @@
"@natlibfi/marc-record": "^8.0.0",
"@natlibfi/marc-record-merge": "^7.0.0",
"@natlibfi/marc-record-validate": "^8.0.3",
"@natlibfi/marc-record-validators-melinda": "^10.15.0",
"@natlibfi/marc-record-validators-melinda": "^10.15.1",
"@natlibfi/melinda-commons": "^13.0.7",
"clone": "^2.1.2",
"debug": "^4.3.4",
"isbn3": "^1.1.43",
"normalize-diacritics": "^4.0.3"
Expand All @@ -59,7 +58,7 @@
"babel-plugin-rewire": "^1.2.0",
"chai": "^4.3.10",
"cross-env": "^7.0.3",
"eslint": "^8.52.0",
"eslint": "^8.53.0",
"mocha": "^10.2.0",
"nodemon": "^3.0.1",
"nyc": "^15.1.0"
Expand Down
55 changes: 51 additions & 4 deletions src/reducers/counterpartField.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,55 @@ function differentPublisherSubfields(field1, field2) {
}
*/


export function splitToNameAndQualifier(name) {
const nameOnly = name.replace(/(?: \([^)]+\)| abp?|, kustannusosakeyhtiö| oyj?| ry)$/ugi, '');
if (nameOnly === name) {
return [getBestName(name).toLowerCase(), undefined];
}

const bestName = getBestName(nameOnly);
return [bestName.toLowerCase(), name.substring(nameOnly.length)]; // NB! qualifier retains initial space in " (whatever)"

function getBestName(name) {
const NAME = name.toUpperCase();

if (NAME === 'WSOY') {
return 'Werner Söderström osakeyhtiö';
}
if (NAME === 'NTAMO') {
return 'ntamo';
}
return name;
}
}

function corporateNamesAgree(value1, value2, tag, subfieldCode) {
if (subfieldCode !== 'a' || !['110', '610', '710', '810'].includes(tag)) {
return false;
}
const [name1, qualifier1] = splitToNameAndQualifier(value1);
const [name2, qualifier2] = splitToNameAndQualifier(value2);

nvdebug(`CN1: '${name1}', '${qualifier1}'`, debugDev);
nvdebug(`CN2: '${name2}', '${qualifier2}'`, debugDev);

if (name1.toUpperCase() !== name2.toUpperCase()) {
return false;
}

// If both values have qualifiers, they must be equal!
// Note this will reject ", kustannusosakeyhtiö" vs "(yhtiö)" pair
// Also qualifer pair "(foo)" and "(bar)" will result in a failure.
if (qualifier1 !== undefined && qualifier2 !== undefined && qualifier1 !== qualifier2) {
// Should we support "Yhtiö ab" equals "Yhtiö oy"? If so, this is the place. Pretty marginal though
return false;
}
return true;
}

function pairableValue(tag, subfieldCode, value1, value2) {
if (partsAgree(value1, value2, tag, subfieldCode)) {
if (partsAgree(value1, value2, tag, subfieldCode) || corporateNamesAgree(value1, value2, tag, subfieldCode)) {
// Pure baseness: here we assume that base's value1 is better than source's value2.
return value1;
}
Expand All @@ -52,8 +99,8 @@ function counterpartExtraNormalize(tag, subfieldCode, value) {
// Remove trailing punctuation:
value = value.replace(/(\S)(?:,|\.|\?|!|\. -| *:| *;| =| \/)$/u, '$1');
// Remove brackets:
value = value.replace(/^\(([^()]+)\)$/u, '$1'); // Remove starting-'(' and ending-')'
value = value.replace(/^\[([^[\]]+)\]$/u, '$1'); // Remove starting-'[' and ending-']'
value = value.replace(/^\(([^()]+)\)$/u, '$1'); // Remove initial '(' and final ')' if both exist.
value = value.replace(/^\[([^[\]]+)\]$/u, '$1'); // Remove initial '[' and final ']' if both exist.
// Mainly for field 260$c:
value = removeCopyright(value);

Expand Down Expand Up @@ -523,7 +570,7 @@ export function getCounterpart(baseRecord, sourceRecord, field, config) {

nvdebug(`Compare incoming '${fieldToString(field)}' with (up to) ${counterpartCands.length} existing field(s)`, debugDev);

const normalizedField = cloneAndNormalizeFieldForComparison(field);
const normalizedField = cloneAndNormalizeFieldForComparison(field); // mainly strip punctuation here

nvdebug(`Norm to: '${fieldToString(normalizedField)}'`, debugDev);

Expand Down
Loading