@natlibfi/melinda-record-matching 5.0.0-alpha.1 → 5.0.0-alpha.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/workflows/{melinda-node-tests.yml → melinda-node-tests-and-publish.yml} +22 -12
- package/dist/candidate-search/candidate-search-utils.js +18 -0
- package/dist/candidate-search/candidate-search-utils.js.map +7 -0
- package/dist/candidate-search/choose-queries.js +75 -0
- package/dist/candidate-search/choose-queries.js.map +7 -0
- package/dist/candidate-search/index.js +118 -0
- package/dist/candidate-search/index.js.map +7 -0
- package/dist/candidate-search/index.test.js +92 -0
- package/dist/candidate-search/index.test.js.map +7 -0
- package/dist/candidate-search/query-list/bib.js +260 -0
- package/dist/candidate-search/query-list/bib.js.map +7 -0
- package/dist/candidate-search/query-list/bib.test.js +34 -0
- package/dist/candidate-search/query-list/bib.test.js.map +7 -0
- package/dist/candidate-search/query-list/component.js +87 -0
- package/dist/candidate-search/query-list/component.js.map +7 -0
- package/dist/candidate-search/query-list/index.js +53 -0
- package/dist/candidate-search/query-list/index.js.map +7 -0
- package/dist/cli.js +138 -0
- package/dist/cli.js.map +7 -0
- package/dist/index.js +204 -0
- package/dist/index.js.map +7 -0
- package/dist/index.test.js +69 -0
- package/dist/index.test.js.map +7 -0
- package/dist/match-detection/features/bib/all-source-ids.js +48 -0
- package/dist/match-detection/features/bib/all-source-ids.js.map +7 -0
- package/dist/match-detection/features/bib/authors.js +57 -0
- package/dist/match-detection/features/bib/authors.js.map +7 -0
- package/dist/match-detection/features/bib/bibliographic-level.js +6 -0
- package/dist/match-detection/features/bib/bibliographic-level.js.map +7 -0
- package/dist/match-detection/features/bib/host-component.js +6 -0
- package/dist/match-detection/features/bib/host-component.js.map +7 -0
- package/dist/match-detection/features/bib/index.js +17 -0
- package/dist/match-detection/features/bib/index.js.map +7 -0
- package/dist/match-detection/features/bib/index.test.js +40 -0
- package/dist/match-detection/features/bib/index.test.js.map +7 -0
- package/dist/match-detection/features/bib/isbn.js +21 -0
- package/dist/match-detection/features/bib/isbn.js.map +7 -0
- package/dist/match-detection/features/bib/issn.js +6 -0
- package/dist/match-detection/features/bib/issn.js.map +7 -0
- package/dist/match-detection/features/bib/language.js +80 -0
- package/dist/match-detection/features/bib/language.js.map +7 -0
- package/dist/match-detection/features/bib/media-type.js +31 -0
- package/dist/match-detection/features/bib/media-type.js.map +7 -0
- package/dist/match-detection/features/bib/melinda-id.js +6 -0
- package/dist/match-detection/features/bib/melinda-id.js.map +7 -0
- package/dist/match-detection/features/bib/melinda-identifier-factory.js +38 -0
- package/dist/match-detection/features/bib/melinda-identifier-factory.js.map +7 -0
- package/dist/match-detection/features/bib/other-standard-identifier.js +6 -0
- package/dist/match-detection/features/bib/other-standard-identifier.js.map +7 -0
- package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js +116 -0
- package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js.map +7 -0
- package/dist/match-detection/features/bib/publication-time-allow-cons-years.js +28 -0
- package/dist/match-detection/features/bib/publication-time-allow-cons-years.js.map +7 -0
- package/dist/match-detection/features/bib/publication-time.js +10 -0
- package/dist/match-detection/features/bib/publication-time.js.map +7 -0
- package/dist/match-detection/features/bib/record-type.js +6 -0
- package/dist/match-detection/features/bib/record-type.js.map +7 -0
- package/dist/match-detection/features/bib/standard-identifier-factory.js +99 -0
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +7 -0
- package/dist/match-detection/features/bib/title-version-original.js +37 -0
- package/dist/match-detection/features/bib/title-version-original.js.map +7 -0
- package/dist/match-detection/features/bib/title.js +46 -0
- package/dist/match-detection/features/bib/title.js.map +7 -0
- package/dist/match-detection/features/index.js +3 -0
- package/dist/match-detection/features/index.js.map +7 -0
- package/dist/match-detection/index.js +86 -0
- package/dist/match-detection/index.js.map +7 -0
- package/dist/match-detection/index.test.js +44 -0
- package/dist/match-detection/index.test.js.map +7 -0
- package/dist/matching-utils.js +79 -0
- package/dist/matching-utils.js.map +7 -0
- package/package.json +12 -12
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import naturalPkg from "natural";
|
|
2
|
+
const { LevenshteinDistance: leven } = naturalPkg;
|
|
3
|
+
import { testStringOrNumber } from "../../../matching-utils.js";
|
|
4
|
+
export default ({ nameTreshold = 10 } = {}) => ({
|
|
5
|
+
name: "Authors",
|
|
6
|
+
extract: ({ record }) => {
|
|
7
|
+
const authors = record.get(/^(?<def>100|700)$/u).map(({ subfields }) => {
|
|
8
|
+
return subfields.filter(({ code, value }) => code && value).filter(({ code }) => ["a", "0"].includes(code)).map(toObj).reduce((acc, v) => ({ ...acc, ...v }), {});
|
|
9
|
+
function toObj({ code, value }) {
|
|
10
|
+
if (code === "a") {
|
|
11
|
+
return { name: testStringOrNumber(value) ? String(value).replace(/[^\p{Letter}\p{Number}]/gu, "").toLowerCase() : "" };
|
|
12
|
+
}
|
|
13
|
+
return { id: value };
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
return authors;
|
|
17
|
+
},
|
|
18
|
+
compare: (a, b) => {
|
|
19
|
+
const maxAuthors = a.length > b.length ? a.length : b.length;
|
|
20
|
+
const matchingIds = findMatchingIds();
|
|
21
|
+
if (maxAuthors >= 3 && matchingIds >= 3) {
|
|
22
|
+
return 0.3;
|
|
23
|
+
}
|
|
24
|
+
const matchingNames = findMatchingNames();
|
|
25
|
+
const idPoints = matchingIds / maxAuthors * 0.3;
|
|
26
|
+
const namePoints = matchingNames / maxAuthors * 0.2;
|
|
27
|
+
const totalPoints = idPoints + namePoints;
|
|
28
|
+
return totalPoints <= 0.2 ? totalPoints : 0.2;
|
|
29
|
+
function findMatchingIds() {
|
|
30
|
+
return findMatches("id", (a2, b2) => a2 === b2);
|
|
31
|
+
}
|
|
32
|
+
function findMatchingNames() {
|
|
33
|
+
return findMatches("name", (a2, b2) => {
|
|
34
|
+
const distance = leven(a2, b2);
|
|
35
|
+
if (distance === 0) {
|
|
36
|
+
return true;
|
|
37
|
+
}
|
|
38
|
+
const maxLength = getMaxLength();
|
|
39
|
+
const percentage = distance / maxLength * 100;
|
|
40
|
+
return percentage <= nameTreshold;
|
|
41
|
+
function getMaxLength() {
|
|
42
|
+
return a2.length > b2.length ? a2.length : b2.length;
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function findMatches(key, cb) {
|
|
47
|
+
const valuesA = a.filter((o) => o[key]).map((o) => o[key]);
|
|
48
|
+
const valuesB = b.filter((o) => o[key]).map((o) => o[key]);
|
|
49
|
+
const allValues = valuesA.concat(valuesB);
|
|
50
|
+
return allValues.reduce((acc, value) => {
|
|
51
|
+
const occurrance = allValues.filter((otherValue) => cb(value, otherValue)).length;
|
|
52
|
+
return occurrance >= 2 ? acc + 1 : acc;
|
|
53
|
+
}, 0);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
//# sourceMappingURL=authors.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/match-detection/features/bib/authors.js"],
|
|
4
|
+
"sourcesContent": ["\n\nimport naturalPkg from 'natural';\nconst {LevenshteinDistance: leven} = naturalPkg;\nimport {testStringOrNumber} from '../../../matching-utils.js';\n\n// We should extract also organisational authors (110/710)\n\nexport default ({nameTreshold = 10} = {}) => ({\n name: 'Authors',\n extract: ({record}) => {\n //const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n const authors = 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 return authors;\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"],
|
|
5
|
+
"mappings": "AAEA,OAAO,gBAAgB;AACvB,MAAM,EAAC,qBAAqB,MAAK,IAAI;AACrC,SAAQ,0BAAyB;AAIjC,eAAe,CAAC,EAAC,eAAe,GAAE,IAAI,CAAC,OAAO;AAAA,EAC5C,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,OAAM,MAAM;AAErB,UAAM,UAAU,OAAO,IAAI,oBAAoB,EAC5C,IAAI,CAAC,EAAC,UAAS,MAAM;AACpB,aAAO,UACJ,OAAO,CAAC,EAAC,MAAM,MAAK,MAAM,QAAQ,KAAK,EACvC,OAAO,CAAC,EAAC,KAAI,MAAM,CAAC,KAAK,GAAG,EAAE,SAAS,IAAI,CAAC,EAC5C,IAAI,KAAK,EACT,OAAO,CAAC,KAAK,OAAO,EAAC,GAAG,KAAK,GAAG,EAAC,IAAI,CAAC,CAAC;AAE1C,eAAS,MAAM,EAAC,MAAM,MAAK,GAAG;AAC5B,YAAI,SAAS,KAAK;AAChB,iBAAO,EAAC,MAAM,mBAAmB,KAAK,IAAI,OAAO,KAAK,EAAE,QAAQ,6BAA6B,EAAE,EAAE,YAAY,IAAI,GAAE;AAAA,QACrH;AAEA,eAAO,EAAC,IAAI,MAAK;AAAA,MACnB;AAAA,IACF,CAAC;AACH,WAAO;AAAA,EACT;AAAA,EACA,SAAS,CAAC,GAAG,MAAM;AACjB,UAAM,aAAa,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE;AACtD,UAAM,cAAc,gBAAgB;AAEpC,QAAI,cAAc,KAAK,eAAe,GAAG;AACvC,aAAO;AAAA,IACT;AAEA,UAAM,gBAAgB,kBAAkB;AACxC,UAAM,WAAW,cAAc,aAAa;AAC5C,UAAM,aAAa,gBAAgB,aAAa;AAChD,UAAM,cAAc,WAAW;AAE/B,WAAO,eAAe,MAAM,cAAc;AAE1C,aAAS,kBAAkB;AACzB,aAAO,YAAY,MAAM,CAACA,IAAGC,OAAMD,OAAMC,EAAC;AAAA,IAC5C;AAEA,aAAS,oBAAoB;AAC3B,aAAO,YAAY,QAAQ,CAACD,IAAGC,OAAM;AACnC,cAAM,WAAW,MAAMD,IAAGC,EAAC;AAE3B,YAAI,aAAa,GAAG;AAClB,iBAAO;AAAA,QACT;AAEA,cAAM,YAAY,aAAa;AAC/B,cAAM,aAAa,WAAW,YAAY;AAE1C,eAAO,cAAc;AAErB,iBAAS,eAAe;AACtB,iBAAOD,GAAE,SAASC,GAAE,SAASD,GAAE,SAASC,GAAE;AAAA,QAC5C;AAAA,MACF,CAAC;AAAA,IACH;AAEA,aAAS,YAAY,KAAK,IAAI;AAC5B,YAAM,UAAU,EAAE,OAAO,OAAK,EAAE,GAAG,CAAC,EAAE,IAAI,OAAK,EAAE,GAAG,CAAC;AACrD,YAAM,UAAU,EAAE,OAAO,OAAK,EAAE,GAAG,CAAC,EAAE,IAAI,OAAK,EAAE,GAAG,CAAC;AACrD,YAAM,YAAY,QAAQ,OAAO,OAAO;AAExC,aAAO,UAAU,OAAO,CAAC,KAAK,UAAU;AACtC,cAAM,aAAa,UAAU,OAAO,gBAAc,GAAG,OAAO,UAAU,CAAC,EAAE;AACzE,eAAO,cAAc,IAAI,MAAM,IAAI;AAAA,MACrC,GAAG,CAAC;AAAA,IACN;AAAA,EACF;AACF;",
|
|
6
|
+
"names": ["a", "b"]
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/match-detection/features/bib/bibliographic-level.js"],
|
|
4
|
+
"sourcesContent": ["\nexport default () => ({\n name: 'Bibliographic level',\n extract: ({record}) => record.leader[7] ? [record.leader[7]] : [],\n compare: (a, b) => a[0] === b[0] ? 0.1 : -0.2\n});\n"],
|
|
5
|
+
"mappings": "AACA,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,OAAM,MAAM,OAAO,OAAO,CAAC,IAAI,CAAC,OAAO,OAAO,CAAC,CAAC,IAAI,CAAC;AAAA,EAChE,SAAS,CAAC,GAAG,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,MAAM;AAC3C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/match-detection/features/bib/host-component.js"],
|
|
4
|
+
"sourcesContent": ["\nexport default () => ({\n name: 'Host/Component record',\n extract: ({record}) => record.get(/^773$/u).length > 0 ? ['component'] : ['host'],\n compare: (a, b) => a[0] === b[0] ? 0.0 : -1.0\n});\n"],
|
|
5
|
+
"mappings": "AACA,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,OAAM,MAAM,OAAO,IAAI,QAAQ,EAAE,SAAS,IAAI,CAAC,WAAW,IAAI,CAAC,MAAM;AAAA,EAChF,SAAS,CAAC,GAAG,MAAM,EAAE,CAAC,MAAM,EAAE,CAAC,IAAI,IAAM;AAC3C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export { default as hostComponent } from "./host-component.js";
|
|
2
|
+
export { default as isbn } from "./isbn.js";
|
|
3
|
+
export { default as issn } from "./issn.js";
|
|
4
|
+
export { default as otherStandardIdentifier } from "./other-standard-identifier.js";
|
|
5
|
+
export { default as title } from "./title.js";
|
|
6
|
+
export { default as titleVersionOriginal } from "./title-version-original.js";
|
|
7
|
+
export { default as authors } from "./authors.js";
|
|
8
|
+
export { default as recordType } from "./record-type.js";
|
|
9
|
+
export { default as publicationTime } from "./publication-time.js";
|
|
10
|
+
export { default as publicationTimeAllowConsYears } from "./publication-time-allow-cons-years.js";
|
|
11
|
+
export { default as publicationTimeAllowConsYearsMulti } from "./publication-time-allow-cons-years-multi.js";
|
|
12
|
+
export { default as language } from "./language.js";
|
|
13
|
+
export { default as bibliographicLevel } from "./bibliographic-level.js";
|
|
14
|
+
export { default as melindaId } from "./melinda-id.js";
|
|
15
|
+
export { default as allSourceIds } from "./all-source-ids.js";
|
|
16
|
+
export { default as mediaType } from "./media-type.js";
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/match-detection/features/bib/index.js"],
|
|
4
|
+
"sourcesContent": ["\nexport {default as hostComponent} from './host-component.js';\nexport {default as isbn} from './isbn.js';\nexport {default as issn} from './issn.js';\nexport {default as otherStandardIdentifier} from './other-standard-identifier.js';\nexport {default as title} from './title.js';\nexport {default as titleVersionOriginal} from './title-version-original.js';\nexport {default as authors} from './authors.js';\nexport {default as recordType} from './record-type.js';\nexport {default as publicationTime} from './publication-time.js';\nexport {default as publicationTimeAllowConsYears} from './publication-time-allow-cons-years.js';\nexport {default as publicationTimeAllowConsYearsMulti} from './publication-time-allow-cons-years-multi.js';\nexport {default as language} from './language.js';\nexport {default as bibliographicLevel} from './bibliographic-level.js';\nexport {default as melindaId} from './melinda-id.js';\nexport {default as allSourceIds} from './all-source-ids.js';\nexport {default as mediaType} from './media-type.js';\n"],
|
|
5
|
+
"mappings": "AACA,SAAQ,WAAW,qBAAoB;AACvC,SAAQ,WAAW,YAAW;AAC9B,SAAQ,WAAW,YAAW;AAC9B,SAAQ,WAAW,+BAA8B;AACjD,SAAQ,WAAW,aAAY;AAC/B,SAAQ,WAAW,4BAA2B;AAC9C,SAAQ,WAAW,eAAc;AACjC,SAAQ,WAAW,kBAAiB;AACpC,SAAQ,WAAW,uBAAsB;AACzC,SAAQ,WAAW,qCAAoC;AACvD,SAAQ,WAAW,0CAAyC;AAC5D,SAAQ,WAAW,gBAAe;AAClC,SAAQ,WAAW,0BAAyB;AAC5C,SAAQ,WAAW,iBAAgB;AACnC,SAAQ,WAAW,oBAAmB;AACtC,SAAQ,WAAW,iBAAgB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import assert from "node:assert";
|
|
2
|
+
import { describe } from "node:test";
|
|
3
|
+
import createDebugLogger from "debug";
|
|
4
|
+
import generateTests from "@natlibfi/fixugen";
|
|
5
|
+
import { READERS } from "@natlibfi/fixura";
|
|
6
|
+
import { MarcRecord } from "@natlibfi/marc-record";
|
|
7
|
+
import * as features from "./index.js";
|
|
8
|
+
const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features/bib:test");
|
|
9
|
+
const debugData = debug.extend("data");
|
|
10
|
+
describe("match-detection/features/bib/", () => {
|
|
11
|
+
generateTests({
|
|
12
|
+
path: [import.meta.dirname, "..", "..", "..", "..", "test-fixtures", "match-detection", "features", "bib"],
|
|
13
|
+
useMetadataFile: true,
|
|
14
|
+
fixura: {
|
|
15
|
+
reader: READERS.JSON
|
|
16
|
+
},
|
|
17
|
+
callback: ({ enabled = true, feature, options, type, ...expectations }) => {
|
|
18
|
+
if (!enabled) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
debug(`Testing: ${feature} ${type}`);
|
|
22
|
+
if (type === "extract") {
|
|
23
|
+
const { expectedFeatures, inputRecord } = expectations;
|
|
24
|
+
const record = new MarcRecord(inputRecord, { subfieldValues: false });
|
|
25
|
+
debugData(`Record: ${record}`);
|
|
26
|
+
const { extract } = features[feature](options);
|
|
27
|
+
assert.deepStrictEqual(extract({ record }), expectedFeatures);
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
if (type === "compare") {
|
|
31
|
+
const { featuresA, featuresB, expectedPoints } = expectations;
|
|
32
|
+
const { compare } = features[feature](options);
|
|
33
|
+
assert.equal(compare(featuresA, featuresB), expectedPoints);
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
throw new Error(`Invalid type ${type}`);
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
//# sourceMappingURL=index.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/match-detection/features/bib/index.test.js"],
|
|
4
|
+
"sourcesContent": ["\nimport assert from 'node:assert';\nimport {describe} from 'node:test';\nimport createDebugLogger from 'debug';\nimport generateTests from '@natlibfi/fixugen';\nimport {READERS} from '@natlibfi/fixura';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport * as features from './index.js';\n\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib:test');\nconst debugData = debug.extend('data');\n\n\ndescribe('match-detection/features/bib/', () => {\n generateTests({\n path: [import.meta.dirname, '..', '..', '..', '..', 'test-fixtures', 'match-detection', 'features', 'bib'],\n useMetadataFile: true,\n fixura: {\n reader: READERS.JSON\n },\n\n callback: ({enabled = true, feature, options, type, ...expectations}) => {\n\n if (!enabled) {\n return;\n }\n\n debug(`Testing: ${feature} ${type}`);\n\n if (type === 'extract') {\n const {expectedFeatures, inputRecord} = expectations;\n const record = new MarcRecord(inputRecord, {subfieldValues: false});\n debugData(`Record: ${record}`);\n const {extract} = features[feature](options);\n\n assert.deepStrictEqual(extract({record}), expectedFeatures);\n return;\n }\n\n if (type === 'compare') {\n const {featuresA, featuresB, expectedPoints} = expectations;\n const {compare} = features[feature](options);\n\n assert.equal(compare(featuresA, featuresB), expectedPoints);\n return;\n }\n\n throw new Error(`Invalid type ${type}`);\n }\n });\n});\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,YAAY;AACnB,SAAQ,gBAAe;AACvB,OAAO,uBAAuB;AAC9B,OAAO,mBAAmB;AAC1B,SAAQ,eAAc;AACtB,SAAQ,kBAAiB;AACzB,YAAY,cAAc;AAG1B,MAAM,QAAQ,kBAAkB,qEAAqE;AACrG,MAAM,YAAY,MAAM,OAAO,MAAM;AAGrC,SAAS,iCAAiC,MAAM;AAC9C,gBAAc;AAAA,IACZ,MAAM,CAAC,YAAY,SAAS,MAAM,MAAM,MAAM,MAAM,iBAAiB,mBAAmB,YAAY,KAAK;AAAA,IACzG,iBAAiB;AAAA,IACjB,QAAQ;AAAA,MACN,QAAQ,QAAQ;AAAA,IAClB;AAAA,IAEA,UAAU,CAAC,EAAC,UAAU,MAAM,SAAS,SAAS,MAAM,GAAG,aAAY,MAAM;AAEvE,UAAI,CAAC,SAAS;AACZ;AAAA,MACF;AAEA,YAAM,YAAY,OAAO,IAAI,IAAI,EAAE;AAEnC,UAAI,SAAS,WAAW;AACtB,cAAM,EAAC,kBAAkB,YAAW,IAAI;AACxC,cAAM,SAAS,IAAI,WAAW,aAAa,EAAC,gBAAgB,MAAK,CAAC;AAClE,kBAAU,WAAW,MAAM,EAAE;AAC7B,cAAM,EAAC,QAAO,IAAI,SAAS,OAAO,EAAE,OAAO;AAE3C,eAAO,gBAAgB,QAAQ,EAAC,OAAM,CAAC,GAAG,gBAAgB;AAC1D;AAAA,MACF;AAEA,UAAI,SAAS,WAAW;AACtB,cAAM,EAAC,WAAW,WAAW,eAAc,IAAI;AAC/C,cAAM,EAAC,QAAO,IAAI,SAAS,OAAO,EAAE,OAAO;AAE3C,eAAO,MAAM,QAAQ,WAAW,SAAS,GAAG,cAAc;AAC1D;AAAA,MACF;AAEA,YAAM,IAAI,MAAM,gBAAgB,IAAI,EAAE;AAAA,IACxC;AAAA,EACF,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import createDebugLogger from "debug";
|
|
2
|
+
import { parse as isbnParse } from "isbn3";
|
|
3
|
+
import createInterface from "./standard-identifier-factory.js";
|
|
4
|
+
const debug = createDebugLogger(`@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers:ISBN`);
|
|
5
|
+
const debugData = debug.extend("data");
|
|
6
|
+
export default () => {
|
|
7
|
+
const IDENTIFIER_NAME = "ISBN";
|
|
8
|
+
function validatorAndNormalizer(string) {
|
|
9
|
+
const isbnParseResult = isbnParse(string);
|
|
10
|
+
debugData(`isbnParseResult: ${JSON.stringify(isbnParseResult)}`);
|
|
11
|
+
if (isbnParseResult === null) {
|
|
12
|
+
debug(`Not parseable ISBN, just removing hyphens`);
|
|
13
|
+
return { valid: false, value: string.replace(/-/ug, "") };
|
|
14
|
+
}
|
|
15
|
+
debug(`Parseable ISBN, normalizing to ISBN-13`);
|
|
16
|
+
return { valid: true, value: isbnParseResult.isbn13 };
|
|
17
|
+
}
|
|
18
|
+
const { extract, compare } = createInterface({ identifier: IDENTIFIER_NAME, pattern: /^020$/u, subfieldCodes: ["a", "z"], validIdentifierSubfieldCodes: ["a"], invalidIdentifierSubfieldCodes: ["z"], validatorAndNormalizer });
|
|
19
|
+
return { extract, compare, name: IDENTIFIER_NAME };
|
|
20
|
+
};
|
|
21
|
+
//# sourceMappingURL=isbn.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/match-detection/features/bib/isbn.js"],
|
|
4
|
+
"sourcesContent": ["\nimport createDebugLogger from 'debug';\nimport {parse as isbnParse} from 'isbn3';\nimport createInterface from './standard-identifier-factory.js';\n\nconst debug = createDebugLogger(`@natlibfi/melinda-record-matching:match-detection:features:standard-identifiers:ISBN`);\nconst debugData = debug.extend('data');\n\nexport default () => {\n const IDENTIFIER_NAME = 'ISBN';\n\n function validatorAndNormalizer(string) {\n const isbnParseResult = isbnParse(string);\n debugData(`isbnParseResult: ${JSON.stringify(isbnParseResult)}`);\n if (isbnParseResult === null) {\n debug(`Not parseable ISBN, just removing hyphens`);\n return {valid: false, value: string.replace(/-/ug, '')};\n }\n debug(`Parseable ISBN, normalizing to ISBN-13`);\n return {valid: true, value: isbnParseResult.isbn13};\n }\n\n const {extract, compare} = createInterface({identifier: IDENTIFIER_NAME, pattern: /^020$/u, subfieldCodes: ['a', 'z'], validIdentifierSubfieldCodes: ['a'], invalidIdentifierSubfieldCodes: ['z'], validatorAndNormalizer});\n return {extract, compare, name: IDENTIFIER_NAME};\n};\n\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,uBAAuB;AAC9B,SAAQ,SAAS,iBAAgB;AACjC,OAAO,qBAAqB;AAE5B,MAAM,QAAQ,kBAAkB,sFAAsF;AACtH,MAAM,YAAY,MAAM,OAAO,MAAM;AAErC,eAAe,MAAM;AACnB,QAAM,kBAAkB;AAExB,WAAS,uBAAuB,QAAQ;AACtC,UAAM,kBAAkB,UAAU,MAAM;AACxC,cAAU,oBAAoB,KAAK,UAAU,eAAe,CAAC,EAAE;AAC/D,QAAI,oBAAoB,MAAM;AAC5B,YAAM,2CAA2C;AACjD,aAAO,EAAC,OAAO,OAAO,OAAO,OAAO,QAAQ,OAAO,EAAE,EAAC;AAAA,IACxD;AACA,UAAM,wCAAwC;AAC9C,WAAO,EAAC,OAAO,MAAM,OAAO,gBAAgB,OAAM;AAAA,EACpD;AAEA,QAAM,EAAC,SAAS,QAAO,IAAI,gBAAgB,EAAC,YAAY,iBAAiB,SAAS,UAAU,eAAe,CAAC,KAAK,GAAG,GAAG,8BAA8B,CAAC,GAAG,GAAG,gCAAgC,CAAC,GAAG,GAAG,uBAAsB,CAAC;AAC1N,SAAO,EAAC,SAAS,SAAS,MAAM,gBAAe;AACjD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import createInterface from "./standard-identifier-factory.js";
|
|
2
|
+
export default () => {
|
|
3
|
+
const { extract, compare } = createInterface({ pattern: /^022$/u, subfieldCodes: ["a", "z", "y"] });
|
|
4
|
+
return { extract, compare, name: "ISSN" };
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=issn.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/match-detection/features/bib/issn.js"],
|
|
4
|
+
"sourcesContent": ["\nimport createInterface from './standard-identifier-factory.js';\n\nexport default () => {\n const {extract, compare} = createInterface({pattern: /^022$/u, subfieldCodes: ['a', 'z', 'y']});\n return {extract, compare, name: 'ISSN'};\n};\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,qBAAqB;AAE5B,eAAe,MAAM;AACnB,QAAM,EAAC,SAAS,QAAO,IAAI,gBAAgB,EAAC,SAAS,UAAU,eAAe,CAAC,KAAK,KAAK,GAAG,EAAC,CAAC;AAC9F,SAAO,EAAC,SAAS,SAAS,MAAM,OAAM;AACxC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import createDebugLogger from "debug";
|
|
2
|
+
import { getMatchCounts } from "../../../matching-utils.js";
|
|
3
|
+
const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features:language");
|
|
4
|
+
const debugData = debug.extend("data");
|
|
5
|
+
export default () => ({
|
|
6
|
+
name: "Language",
|
|
7
|
+
extract: ({ record, recordExternal }) => {
|
|
8
|
+
const label = recordExternal && recordExternal.label ? recordExternal.label : "record";
|
|
9
|
+
const value008 = get008Value();
|
|
10
|
+
const values041 = get041Values();
|
|
11
|
+
debugData(`${label}: 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);
|
|
12
|
+
if (!value008 && values041.length < 1) {
|
|
13
|
+
debugData(`${label}: No actual values found`);
|
|
14
|
+
return [];
|
|
15
|
+
}
|
|
16
|
+
const allValues = value008 === void 0 ? values041 : values041.concat(value008);
|
|
17
|
+
const uniqueSortedValues = [...new Set(allValues)].sort();
|
|
18
|
+
return uniqueSortedValues;
|
|
19
|
+
function get008Value() {
|
|
20
|
+
const value = record.get(/^008$/u)?.[0]?.value || void 0;
|
|
21
|
+
debugData(`${label}: 008 value: ${value}`);
|
|
22
|
+
if (!value) {
|
|
23
|
+
return void 0;
|
|
24
|
+
}
|
|
25
|
+
const code = value.slice(35, 38);
|
|
26
|
+
debugData(`${label}: 008 code: ${code}`);
|
|
27
|
+
return isLangCodeForALanguage(code) ? code : void 0;
|
|
28
|
+
}
|
|
29
|
+
function get041Values() {
|
|
30
|
+
return record.get(/^041$/u).filter(({ ind2 }) => ind2 === " ").map(({ subfields }) => subfields).flat().filter(({ code }) => code === "a" || code === "d").filter(({ value }) => value && isLangCodeForALanguage(value)).map(({ value }) => value);
|
|
31
|
+
}
|
|
32
|
+
function isLangCodeForALanguage(code) {
|
|
33
|
+
if (code.length !== 3) {
|
|
34
|
+
debugData(`Code ${code} is not correct length (3) for a language code.`);
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
if (code === "|||" || code === " " || code === "^^^" || code === "mul" || code === "zxx") {
|
|
38
|
+
debugData(`Code ${code} is not code for a spesific language.`);
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
const langCodePattern = /^[a-z][a-z][a-z]$/ui;
|
|
42
|
+
if (!langCodePattern.test(code)) {
|
|
43
|
+
debugData(`Code ${code} is not valid as a language code`);
|
|
44
|
+
return false;
|
|
45
|
+
}
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
// eslint-disable-next-line max-statements
|
|
50
|
+
compare: (a, b) => {
|
|
51
|
+
debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);
|
|
52
|
+
if (a.length === 0 || b.length === 0) {
|
|
53
|
+
debugData(`No language to compare`);
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
if (a.length === b.length && a.every((element, index) => element === b[index])) {
|
|
57
|
+
debugData(`All languages match`);
|
|
58
|
+
return 0.1;
|
|
59
|
+
}
|
|
60
|
+
const { matchingValues, possibleMatchValues, maxValues } = getMatchCounts(a, b);
|
|
61
|
+
if (matchingValues < 1) {
|
|
62
|
+
debug(`Both have languages, but none of these match.`);
|
|
63
|
+
return -1;
|
|
64
|
+
}
|
|
65
|
+
debug(`Both have languages, ${matchingValues}/${possibleMatchValues} valid languages match.`);
|
|
66
|
+
debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);
|
|
67
|
+
const missingCount = maxValues - possibleMatchValues;
|
|
68
|
+
const misMatchCount = possibleMatchValues - matchingValues;
|
|
69
|
+
debug(` missing: ${missingCount}`);
|
|
70
|
+
debug(` mismatches: ${misMatchCount}`);
|
|
71
|
+
const penaltyForMissing = 0.02 * (maxValues - possibleMatchValues);
|
|
72
|
+
const penaltyForMisMatch = 0.05 * (possibleMatchValues - matchingValues);
|
|
73
|
+
debug(` points: penaltyForMissing: ${penaltyForMissing}`);
|
|
74
|
+
debug(` points: penaltyForMisMatch: ${penaltyForMisMatch}`);
|
|
75
|
+
const points = Number(Number(0.1 - penaltyForMisMatch - penaltyForMissing).toFixed(2));
|
|
76
|
+
debug(`Total points: ${points}`);
|
|
77
|
+
return points;
|
|
78
|
+
}
|
|
79
|
+
});
|
|
80
|
+
//# sourceMappingURL=language.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/match-detection/features/bib/language.js"],
|
|
4
|
+
"sourcesContent": ["\nimport createDebugLogger from 'debug';\nimport {getMatchCounts} from '../../../matching-utils.js';\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, recordExternal}) => {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n\n const value008 = get008Value();\n const values041 = get041Values();\n debugData(`${label}: 008: ${JSON.stringify(value008)}, 041: ${JSON.stringify(values041)}`);\n\n if (!value008 && values041.length < 1) {\n debugData(`${label}: No actual values found`);\n return [];\n }\n\n const allValues = value008 === undefined ? values041 : values041.concat(value008);\n const uniqueSortedValues = [...new Set(allValues)].sort();\n\n return uniqueSortedValues;\n\n function get008Value() {\n const value = record.get(/^008$/u)?.[0]?.value || undefined;\n debugData(`${label}: 008 value: ${value}`);\n\n if (!value) {\n return undefined;\n }\n\n const code = value.slice(35, 38);\n debugData(`${label}: 008 code: ${code}`);\n return isLangCodeForALanguage(code) ? code : undefined;\n }\n\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 .filter(({value}) => value && isLangCodeForALanguage(value))\n .map(({value}) => value);\n }\n\n // Check if a string is a possible, validly formed language code for a single language\n // Currently accept also codes in capitals\n function isLangCodeForALanguage(code) {\n if (code.length !== 3) {\n debugData(`Code ${code} is not correct length (3) for a language code.`);\n return false;\n }\n if (code === '|||' || code === ' ' || code === '^^^' || code === 'mul' || code === 'zxx') {\n debugData(`Code ${code} is not code for a spesific language.`);\n return false;\n }\n const langCodePattern = /^[a-z][a-z][a-z]$/ui;\n if (!langCodePattern.test(code)) {\n debugData(`Code ${code} is not valid as a language code`);\n return false;\n }\n return true;\n }\n\n },\n // eslint-disable-next-line max-statements\n compare: (a, b) => {\n debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);\n\n if (a.length === 0 || b.length === 0) {\n debugData(`No language to compare`);\n return 0;\n }\n\n if (a.length === b.length && a.every((element, index) => element === b[index])) {\n debugData(`All languages match`);\n return 0.1;\n }\n\n const {matchingValues, possibleMatchValues, maxValues} = getMatchCounts(a, b);\n\n if (matchingValues < 1) {\n debug(`Both have languages, but none of these match.`);\n return -1.0;\n }\n debug(`Both have languages, ${matchingValues}/${possibleMatchValues} valid languages match.`);\n // ignore non-matches if there is mismatching amount of values\n debug(`Possible matches: ${possibleMatchValues}/${maxValues}`);\n //we give some kind of penalty for mismatching amount of values instead of simple divide?\n const missingCount = maxValues - possibleMatchValues;\n const misMatchCount = possibleMatchValues - matchingValues;\n debug(`\\t missing: ${missingCount}`);\n debug(`\\t mismatches: ${misMatchCount}`);\n\n const penaltyForMissing = 0.02 * (maxValues - possibleMatchValues);\n const penaltyForMisMatch = 0.05 * (possibleMatchValues - matchingValues);\n debug(`\\t points: penaltyForMissing: ${penaltyForMissing}`);\n debug(`\\t points: penaltyForMisMatch: ${penaltyForMisMatch}`);\n\n const points = Number(Number(0.1 - penaltyForMisMatch - penaltyForMissing).toFixed(2));\n debug(`Total points: ${points}`);\n\n return points;\n }\n});\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import createDebugLogger from "debug";
|
|
2
|
+
const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features:media-type");
|
|
3
|
+
const debugData = debug.extend("data");
|
|
4
|
+
export default () => ({
|
|
5
|
+
name: "Media type",
|
|
6
|
+
extract: ({ record, recordExternal }) => {
|
|
7
|
+
const label = recordExternal && recordExternal.label ? recordExternal.label : "record";
|
|
8
|
+
debugData(`Record (${label}): ${JSON.stringify(record)}`);
|
|
9
|
+
debugData(`RecordExternal: ${JSON.stringify(recordExternal)}`);
|
|
10
|
+
const values337 = get337Values();
|
|
11
|
+
debug(`${label}: 337 $b values: ${JSON.stringify(values337)}`);
|
|
12
|
+
return values337;
|
|
13
|
+
function get337Values() {
|
|
14
|
+
return record.get(/^337$/u).filter((f) => f.subfields.some((subfield) => subfield.code === "2" && subfield.value === "rdamedia")).map(({ subfields }) => subfields).flat().filter(({ code }) => code === "b").map(({ value }) => value);
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
compare: (a, b) => {
|
|
18
|
+
debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);
|
|
19
|
+
if (a.every((elem) => b.includes(elem))) {
|
|
20
|
+
debug(`All mediaTypes from A are in B`);
|
|
21
|
+
return 1;
|
|
22
|
+
}
|
|
23
|
+
if (b.every((elem) => a.includes(elem))) {
|
|
24
|
+
debug(`All mediaTypes from B are in A`);
|
|
25
|
+
return 1;
|
|
26
|
+
}
|
|
27
|
+
debug(`Mismatch in mediaTypes between A and B`);
|
|
28
|
+
return -1;
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=media-type.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/match-detection/features/bib/media-type.js"],
|
|
4
|
+
"sourcesContent": ["/* eslint-disable max-statements */\n\n\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features:media-type');\nconst debugData = debug.extend('data');\n\nexport default () => ({\n name: 'Media type',\n extract: ({record, recordExternal}) => {\n const label = recordExternal && recordExternal.label ? recordExternal.label : 'record';\n debugData(`Record (${label}): ${JSON.stringify(record)}`);\n debugData(`RecordExternal: ${JSON.stringify(recordExternal)}`);\n const values337 = get337Values();\n debug(`${label}: 337 $b values: ${JSON.stringify(values337)}`);\n\n return values337;\n\n function get337Values() {\n return record.get(/^337$/u)\n .filter(f => f.subfields.some((subfield) => subfield.code === '2' && subfield.value === 'rdamedia'))\n .map(({subfields}) => subfields)\n .flat()\n .filter(({code}) => code === 'b')\n .map(({value}) => value);\n }\n },\n compare: (a, b) => {\n debugData(`Comparing ${JSON.stringify(a)} and ${JSON.stringify(b)}`);\n\n // Should we give extra good points if all mediaTypes match?\n // Should we give partial points for partially matching mediaTypes?\n // Should we check whether recordType is 'mixedMaterials'\n // Should we okay typical cases of not totally matching mediaTypes? What would these be?\n\n if (a.every(elem => b.includes(elem))) {\n debug(`All mediaTypes from A are in B`);\n return 1;\n }\n\n if (b.every(elem => a.includes(elem))) {\n debug(`All mediaTypes from B are in A`);\n return 1;\n }\n\n debug(`Mismatch in mediaTypes between A and B`);\n return -1;\n\n }\n});\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,uBAAuB;AAE9B,MAAM,QAAQ,kBAAkB,uEAAuE;AACvG,MAAM,YAAY,MAAM,OAAO,MAAM;AAErC,eAAe,OAAO;AAAA,EACpB,MAAM;AAAA,EACN,SAAS,CAAC,EAAC,QAAQ,eAAc,MAAM;AACrC,UAAM,QAAQ,kBAAkB,eAAe,QAAQ,eAAe,QAAQ;AAC9E,cAAU,WAAW,KAAK,MAAM,KAAK,UAAU,MAAM,CAAC,EAAE;AACxD,cAAU,mBAAmB,KAAK,UAAU,cAAc,CAAC,EAAE;AAC7D,UAAM,YAAY,aAAa;AAC/B,UAAM,GAAG,KAAK,oBAAoB,KAAK,UAAU,SAAS,CAAC,EAAE;AAE7D,WAAO;AAEP,aAAS,eAAe;AACtB,aAAO,OAAO,IAAI,QAAQ,EACvB,OAAO,OAAK,EAAE,UAAU,KAAK,CAAC,aAAa,SAAS,SAAS,OAAO,SAAS,UAAU,UAAU,CAAC,EAClG,IAAI,CAAC,EAAC,UAAS,MAAM,SAAS,EAC9B,KAAK,EACL,OAAO,CAAC,EAAC,KAAI,MAAM,SAAS,GAAG,EAC/B,IAAI,CAAC,EAAC,MAAK,MAAM,KAAK;AAAA,IAC3B;AAAA,EACF;AAAA,EACA,SAAS,CAAC,GAAG,MAAM;AACjB,cAAU,aAAa,KAAK,UAAU,CAAC,CAAC,QAAQ,KAAK,UAAU,CAAC,CAAC,EAAE;AAOnE,QAAI,EAAE,MAAM,UAAQ,EAAE,SAAS,IAAI,CAAC,GAAG;AACrC,YAAM,gCAAgC;AACtC,aAAO;AAAA,IACT;AAEA,QAAI,EAAE,MAAM,UAAQ,EAAE,SAAS,IAAI,CAAC,GAAG;AACrC,YAAM,gCAAgC;AACtC,aAAO;AAAA,IACT;AAEA,UAAM,wCAAwC;AAC9C,WAAO;AAAA,EAET;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/match-detection/features/bib/melinda-id.js"],
|
|
4
|
+
"sourcesContent": ["\nimport createInterface from './melinda-identifier-factory.js';\n\nexport default () => {\n const {extract, compare} = createInterface();\n return {extract, compare, name: 'melinda-id'};\n};\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,qBAAqB;AAE5B,eAAe,MAAM;AACnB,QAAM,EAAC,SAAS,QAAO,IAAI,gBAAgB;AAC3C,SAAO,EAAC,SAAS,SAAS,MAAM,aAAY;AAC9C;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import createDebugLogger from "debug";
|
|
2
|
+
import { getMelindaIdsF035 } from "../../../matching-utils.js";
|
|
3
|
+
export default () => {
|
|
4
|
+
const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features/bib/melinda-id");
|
|
5
|
+
const debugData = debug.extend("data");
|
|
6
|
+
return { extract, compare };
|
|
7
|
+
function extract({ record, recordExternal }) {
|
|
8
|
+
const isMelindaRecord = record.get("003").some((f003) => f003.value === "FI-MELINDA");
|
|
9
|
+
const [f001] = record.get("001").map((field) => field.value);
|
|
10
|
+
const f035MelindaIds = getMelindaIdsF035(record);
|
|
11
|
+
if (isMelindaRecord === void 0 && f001 === void 0 && f035MelindaIds.length < 1) {
|
|
12
|
+
debug(`${recordExternal.label} No Melinda-IDs found`);
|
|
13
|
+
return {};
|
|
14
|
+
}
|
|
15
|
+
return { isMelindaRecord, f001, f035MelindaIds };
|
|
16
|
+
}
|
|
17
|
+
function compare(a, b) {
|
|
18
|
+
if (a.isMelindaRecord && b.isMelindaRecord && a.f001 === b.f001) {
|
|
19
|
+
debugData(`Melinda record's A f001 ${a.f001} matches Melinda record's B f001 ${a.f001}`);
|
|
20
|
+
return 1;
|
|
21
|
+
}
|
|
22
|
+
if (a.isMelindaRecord && typeof b.f035MelindaIds !== "undefined" && b.f035MelindaIds.some((id) => id === a.f001)) {
|
|
23
|
+
debugData(`Melinda record's A f001 ${a.f001} matches record B f035 ${JSON.stringify(b.f035MelindaIds)}`);
|
|
24
|
+
return 1;
|
|
25
|
+
}
|
|
26
|
+
if (b.isMelindaRecord && typeof a.f035MelindaIds !== "undefined" && a.f035MelindaIds.some((id) => id === b.f001)) {
|
|
27
|
+
debugData(`Melinda record's B f001 ${b.f001} matches record A f035 ${JSON.stringify(a.f035MelindaIds)}`);
|
|
28
|
+
return 1;
|
|
29
|
+
}
|
|
30
|
+
if (typeof a.f035MelindaIds !== "undefined" && typeof b.f035MelindaIds !== "undefined" && a.f035MelindaIds.some((idA) => b.f035MelindaIds.some((idB) => idB === idA))) {
|
|
31
|
+
debugData(`Record A f035 ${JSON.stringify(a.f035MelindaIds)} matches record B f035 ${JSON.stringify(b.f035MelindaIds)}`);
|
|
32
|
+
return 1;
|
|
33
|
+
}
|
|
34
|
+
debug(`No matching Melinda-IDs.`);
|
|
35
|
+
return 0;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=melinda-identifier-factory.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/match-detection/features/bib/melinda-identifier-factory.js"],
|
|
4
|
+
"sourcesContent": ["\nimport createDebugLogger from 'debug';\nimport {getMelindaIdsF035} from '../../../matching-utils.js';\n\n// 003+001 FI-MELINDA <melinda-id>\n// 035 $a (FI-MELINDA)<melinda-id>\n// 035 $z (FI-MELINDA)<melinda-id>\n// 035 $a FCC<melinda-id>\n// 035 $z FCC<melinda-id>\n// melinda-id = 001234567\n\nexport default () => {\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:match-detection:features/bib/melinda-id');\n const debugData = debug.extend('data');\n\n return {extract, compare};\n\n function extract({record, recordExternal}) {\n\n const isMelindaRecord = record.get('003').some(f003 => f003.value === 'FI-MELINDA');\n const [f001] = record.get('001').map(field => field.value);\n const f035MelindaIds = getMelindaIdsF035(record);\n\n if (\n isMelindaRecord === undefined &&\n f001 === undefined &&\n f035MelindaIds.length < 1) {\n\n debug(`${recordExternal.label} No Melinda-IDs found`);\n return {};\n }\n\n return {isMelindaRecord, f001, f035MelindaIds};\n\n }\n\n function compare(a, b) {\n\n if (a.isMelindaRecord && b.isMelindaRecord &&\n a.f001 === b.f001) {\n debugData(`Melinda record's A f001 ${a.f001} matches Melinda record's B f001 ${a.f001}`);\n return 1;\n }\n\n if (a.isMelindaRecord && typeof b.f035MelindaIds !== 'undefined' &&\n b.f035MelindaIds.some(id => id === a.f001)) {\n debugData(`Melinda record's A f001 ${a.f001} matches record B f035 ${JSON.stringify(b.f035MelindaIds)}`);\n return 1;\n }\n\n if (b.isMelindaRecord && typeof a.f035MelindaIds !== 'undefined' &&\n a.f035MelindaIds.some(id => id === b.f001)) {\n debugData(`Melinda record's B f001 ${b.f001} matches record A f035 ${JSON.stringify(a.f035MelindaIds)}`);\n return 1;\n }\n\n if (typeof a.f035MelindaIds !== 'undefined' && typeof b.f035MelindaIds !== 'undefined' &&\n a.f035MelindaIds.some(idA => b.f035MelindaIds.some(idB => idB === idA))) {\n debugData(`Record A f035 ${JSON.stringify(a.f035MelindaIds)} matches record B f035 ${JSON.stringify(b.f035MelindaIds)}`);\n return 1;\n }\n debug(`No matching Melinda-IDs.`);\n return 0;\n }\n};\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,uBAAuB;AAC9B,SAAQ,yBAAwB;AAShC,eAAe,MAAM;AAEnB,QAAM,QAAQ,kBAAkB,2EAA2E;AAC3G,QAAM,YAAY,MAAM,OAAO,MAAM;AAErC,SAAO,EAAC,SAAS,QAAO;AAExB,WAAS,QAAQ,EAAC,QAAQ,eAAc,GAAG;AAEzC,UAAM,kBAAkB,OAAO,IAAI,KAAK,EAAE,KAAK,UAAQ,KAAK,UAAU,YAAY;AAClF,UAAM,CAAC,IAAI,IAAI,OAAO,IAAI,KAAK,EAAE,IAAI,WAAS,MAAM,KAAK;AACzD,UAAM,iBAAiB,kBAAkB,MAAM;AAE/C,QACE,oBAAoB,UACpB,SAAS,UACT,eAAe,SAAS,GAAG;AAE3B,YAAM,GAAG,eAAe,KAAK,uBAAuB;AACpD,aAAO,CAAC;AAAA,IACV;AAEA,WAAO,EAAC,iBAAiB,MAAM,eAAc;AAAA,EAE/C;AAEA,WAAS,QAAQ,GAAG,GAAG;AAErB,QAAI,EAAE,mBAAmB,EAAE,mBACzB,EAAE,SAAS,EAAE,MAAM;AACnB,gBAAU,2BAA2B,EAAE,IAAI,oCAAoC,EAAE,IAAI,EAAE;AACvF,aAAO;AAAA,IACT;AAEA,QAAI,EAAE,mBAAmB,OAAO,EAAE,mBAAmB,eACnD,EAAE,eAAe,KAAK,QAAM,OAAO,EAAE,IAAI,GAAG;AAC5C,gBAAU,2BAA2B,EAAE,IAAI,0BAA0B,KAAK,UAAU,EAAE,cAAc,CAAC,EAAE;AACvG,aAAO;AAAA,IACT;AAEA,QAAI,EAAE,mBAAmB,OAAO,EAAE,mBAAmB,eACnD,EAAE,eAAe,KAAK,QAAM,OAAO,EAAE,IAAI,GAAG;AAC5C,gBAAU,2BAA2B,EAAE,IAAI,0BAA0B,KAAK,UAAU,EAAE,cAAc,CAAC,EAAE;AACvG,aAAO;AAAA,IACT;AAEA,QAAI,OAAO,EAAE,mBAAmB,eAAe,OAAO,EAAE,mBAAmB,eACzE,EAAE,eAAe,KAAK,SAAO,EAAE,eAAe,KAAK,SAAO,QAAQ,GAAG,CAAC,GAAG;AACzE,gBAAU,iBAAiB,KAAK,UAAU,EAAE,cAAc,CAAC,0BAA0B,KAAK,UAAU,EAAE,cAAc,CAAC,EAAE;AACvH,aAAO;AAAA,IACT;AACA,UAAM,0BAA0B;AAChC,WAAO;AAAA,EACT;AACF;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import createInterface from "./standard-identifier-factory.js";
|
|
2
|
+
export default () => {
|
|
3
|
+
const { extract, compare } = createInterface({ pattern: /^024$/u, subfieldCodes: ["a", "z"] });
|
|
4
|
+
return { extract, compare, name: "Other standard identifier" };
|
|
5
|
+
};
|
|
6
|
+
//# sourceMappingURL=other-standard-identifier.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../../src/match-detection/features/bib/other-standard-identifier.js"],
|
|
4
|
+
"sourcesContent": ["\nimport createInterface from './standard-identifier-factory.js';\n\n// DEVELOP: we should compare indicators and sf2 for f024\n\nexport default () => {\n const {extract, compare} = createInterface({pattern: /^024$/u, subfieldCodes: ['a', 'z']});\n return {extract, compare, name: 'Other standard identifier'};\n};\n"],
|
|
5
|
+
"mappings": "AACA,OAAO,qBAAqB;AAI5B,eAAe,MAAM;AACnB,QAAM,EAAC,SAAS,QAAO,IAAI,gBAAgB,EAAC,SAAS,UAAU,eAAe,CAAC,KAAK,GAAG,EAAC,CAAC;AACzF,SAAO,EAAC,SAAS,SAAS,MAAM,4BAA2B;AAC7D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import createDebugLogger from "debug";
|
|
2
|
+
import { testStringOrNumber } from "../../../matching-utils.js";
|
|
3
|
+
export default () => ({
|
|
4
|
+
name: "Publication time, allow consequent years, years from multiple sources",
|
|
5
|
+
extract: ({ record, recordExternal }) => {
|
|
6
|
+
const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi");
|
|
7
|
+
const label = recordExternal && recordExternal.label ? recordExternal.label : "record";
|
|
8
|
+
const f008Values = extractF008Values(record);
|
|
9
|
+
debug(`${label}: f008: ${JSON.stringify(f008Values)}`);
|
|
10
|
+
const f26xValues = extractF26xValues(record);
|
|
11
|
+
debug(`${label}: f26x: ${JSON.stringify(f26xValues)}`);
|
|
12
|
+
const f500Values = extractF500Years(record);
|
|
13
|
+
debug(`${label}: f500: ${JSON.stringify(f500Values)}`);
|
|
14
|
+
const normalYears = [...new Set(f26xValues.normalYears.concat(f008Values.f008Date1).filter((value) => value && value !== " " && value !== "||||"))].sort();
|
|
15
|
+
const copyrightYears = [...new Set(f26xValues.copyrightYears)].sort();
|
|
16
|
+
const reprintYears = [...new Set(f500Values)].sort();
|
|
17
|
+
const combined = { normalYears, copyrightYears, reprintYears };
|
|
18
|
+
debug(`Combined: ${JSON.stringify(combined)}`);
|
|
19
|
+
return combined;
|
|
20
|
+
function extractF008Values(record2) {
|
|
21
|
+
const value = record2.get(/^008$/u)?.[0]?.value || void 0;
|
|
22
|
+
if (value && testStringOrNumber(value)) {
|
|
23
|
+
const f008Date1 = extractF008Date1(value);
|
|
24
|
+
const f008Date2 = extractF008Date2(value);
|
|
25
|
+
const f008YearType = extractF008YearType(value);
|
|
26
|
+
return { f008Date1, f008Date2, f008YearType };
|
|
27
|
+
}
|
|
28
|
+
return { f008Date1: void 0, f008Date2: void 0, f008YearType: void 0 };
|
|
29
|
+
function extractF008Date1(value2) {
|
|
30
|
+
return String(value2).slice(7, 11);
|
|
31
|
+
}
|
|
32
|
+
function extractF008Date2(value2) {
|
|
33
|
+
return String(value2).slice(11, 15);
|
|
34
|
+
}
|
|
35
|
+
function extractF008YearType(value2) {
|
|
36
|
+
return String(value2).slice(6, 7);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function extractF26xValues(record2) {
|
|
40
|
+
const copyrightRegex = /^(?<copyrightPrefix>cop|cop.|c|©|p|℗)/u;
|
|
41
|
+
const pubNormalSubFieldValues = extractPubNormalSubfieldValues(record2, copyrightRegex);
|
|
42
|
+
debug(`Normal years: ${JSON.stringify(pubNormalSubFieldValues)}`);
|
|
43
|
+
const pubF264CopySubFieldValues = extractPubF264CopySubfieldValues(record2);
|
|
44
|
+
debug(`F264 copyright years: ${JSON.stringify(pubF264CopySubFieldValues)}`);
|
|
45
|
+
const pubF260CopySubFieldValues = extractPubF260CopySubfieldValues(record2, copyrightRegex);
|
|
46
|
+
debug(`F260 copyright years: ${JSON.stringify(pubF260CopySubFieldValues)}`);
|
|
47
|
+
return { normalYears: pubNormalSubFieldValues, copyrightYears: [...pubF260CopySubFieldValues, ...pubF264CopySubFieldValues] };
|
|
48
|
+
function extractPubNormalSubfieldValues(record3, copyrightRegex2) {
|
|
49
|
+
return record3.get(/^26[04]$/u).filter((field) => !(field.tag === "264" && field.ind2 === "4")).map(({ subfields }) => subfields).flat().filter(({ code }) => code && code === "c").filter(({ value }) => value && !copyrightRegex2.test(value)).map(({ value }) => value).map((value) => removeNonAlphaNumeric(value));
|
|
50
|
+
}
|
|
51
|
+
function extractPubF264CopySubfieldValues(record3, copyrightRegex2) {
|
|
52
|
+
return record3.get(/^264$/u).filter((field) => field.ind2 === "4").map(({ subfields }) => subfields).flat().filter(({ code }) => code && code === "c").filter(({ value }) => value).map(({ value }) => value).map((value) => value.replace(copyrightRegex2, "")).map((value) => removeNonAlphaNumeric(value));
|
|
53
|
+
}
|
|
54
|
+
function extractPubF260CopySubfieldValues(record3, copyrightRegex2) {
|
|
55
|
+
return record3.get(/^260$/u).map(({ subfields }) => subfields).flat().filter(({ code }) => code && code === "c").filter(({ value }) => value && copyrightRegex2.test(value)).map(({ value }) => value).map((value) => value.replace(copyrightRegex2, "")).map((value) => removeNonAlphaNumeric(value));
|
|
56
|
+
}
|
|
57
|
+
function removeNonAlphaNumeric(value) {
|
|
58
|
+
debug(`Cleaning: ${JSON.stringify(value)}`);
|
|
59
|
+
const nonAlphaNumericRegex = /[^A-Za-z0-9]/ug;
|
|
60
|
+
return value ? value.replace(nonAlphaNumericRegex, "") : value;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
function extractF500Years(record2) {
|
|
64
|
+
const reprintRegex = /(?<reprint>Lisäpainokset:|Lisäpainos:)/u;
|
|
65
|
+
const reprintFieldContents = record2.get(/^500$/u).map(({ subfields }) => subfields).flat().filter(({ code }) => code === "a").map(({ value }) => value);
|
|
66
|
+
debug(`f500 reprint field contents: ${JSON.stringify(reprintFieldContents)}`);
|
|
67
|
+
const filteredF500 = reprintFieldContents.filter((content) => content && content.match(reprintRegex));
|
|
68
|
+
debug(`f500 reprint field contents (filtered): ${JSON.stringify(filteredF500)}`);
|
|
69
|
+
const reprintYears2 = extractReprintYears(filteredF500);
|
|
70
|
+
return reprintYears2;
|
|
71
|
+
}
|
|
72
|
+
function extractReprintYears(contents) {
|
|
73
|
+
const yearRegex = /[0-9][0-9][0-9][0-9]/gu;
|
|
74
|
+
const years = contents.map((content) => content.match(yearRegex)).flat();
|
|
75
|
+
debug(`${JSON.stringify(years)}`);
|
|
76
|
+
const uniqYears = [...new Set(years)].sort();
|
|
77
|
+
debug(`${JSON.stringify(uniqYears)}`);
|
|
78
|
+
return uniqYears;
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
// eslint-disable-next-line max-statements
|
|
82
|
+
compare: (a, b) => {
|
|
83
|
+
const debug = createDebugLogger("@natlibfi/melinda-record-matching:match-detection:features/bib/publication-time-allow-cons-years-multi");
|
|
84
|
+
debug(`Comparing ${JSON.stringify(a)} to ${JSON.stringify(b)}`);
|
|
85
|
+
const [firstA] = a.normalYears ? a.normalYears : a;
|
|
86
|
+
const [firstB] = b.normalYears ? b.normalYears : b;
|
|
87
|
+
debug(`Comparing ${JSON.stringify(firstA)} to ${JSON.stringify(firstB)}`);
|
|
88
|
+
if (firstA === firstB) {
|
|
89
|
+
return 0.1;
|
|
90
|
+
}
|
|
91
|
+
if (!testStringOrNumber(firstA) || !testStringOrNumber(firstB)) {
|
|
92
|
+
return 0;
|
|
93
|
+
}
|
|
94
|
+
const firstANumber = parseInt(firstA, 10);
|
|
95
|
+
const firstBNumber = parseInt(firstB, 10);
|
|
96
|
+
if (!(isNaN(firstANumber) || isNaN(firstBNumber)) && (firstANumber + 1 === firstBNumber || firstANumber - 1 === firstBNumber)) {
|
|
97
|
+
return 0.1;
|
|
98
|
+
}
|
|
99
|
+
const bNormalInANormal = a.normalYears.filter((aValue) => b.normalYears.some((bValue) => aValue === bValue));
|
|
100
|
+
const aNormalInBNormal = b.normalYears.filter((bValue) => a.normalYears.some((aValue) => bValue === aValue));
|
|
101
|
+
debug(`BNorm in ANorm: ${JSON.stringify(bNormalInANormal)}`);
|
|
102
|
+
debug(`ANorm in BNorm: ${JSON.stringify(aNormalInBNormal)}`);
|
|
103
|
+
if (bNormalInANormal > 0 || aNormalInBNormal > 0) {
|
|
104
|
+
return 0;
|
|
105
|
+
}
|
|
106
|
+
const bNormalInAReprint = a.reprintYears.filter((aValue) => b.normalYears.some((bValue) => aValue === bValue));
|
|
107
|
+
const aNormalInBReprint = b.reprintYears.filter((bValue) => a.normalYears.some((aValue) => bValue === aValue));
|
|
108
|
+
debug(`BNorm in AReprint: ${JSON.stringify(bNormalInAReprint)}`);
|
|
109
|
+
debug(`ANorm in BReprint: ${JSON.stringify(aNormalInBReprint)}`);
|
|
110
|
+
if (bNormalInAReprint > 0 || aNormalInBReprint > 0) {
|
|
111
|
+
return 0;
|
|
112
|
+
}
|
|
113
|
+
return -1;
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=publication-time-allow-cons-years-multi.js.map
|