@natlibfi/melinda-record-matching 5.0.5 → 5.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/candidate-search/index.js.map +2 -2
- package/dist/candidate-search/index.test.js +1 -4
- package/dist/candidate-search/index.test.js.map +2 -2
- package/dist/candidate-search/query-list/auth.js +21 -0
- package/dist/candidate-search/query-list/auth.js.map +7 -0
- package/dist/candidate-search/query-list/auth.test.js +31 -0
- package/dist/candidate-search/query-list/auth.test.js.map +7 -0
- package/dist/candidate-search/query-list/bib.js +1 -1
- package/dist/candidate-search/query-list/bib.js.map +2 -2
- package/dist/candidate-search/query-list/bib.test.js +1 -4
- package/dist/candidate-search/query-list/bib.test.js.map +2 -2
- package/dist/candidate-search/query-list/component.js +1 -1
- package/dist/candidate-search/query-list/component.js.map +2 -2
- package/dist/candidate-search/query-list/index.js +8 -1
- package/dist/candidate-search/query-list/index.js.map +2 -2
- package/dist/cli.js +11 -1
- package/dist/cli.js.map +2 -2
- package/dist/index.js.map +2 -2
- package/dist/index.test.js.map +2 -2
- package/dist/match-detection/features/auth/index.js +2 -0
- package/dist/match-detection/features/auth/index.js.map +7 -0
- package/dist/match-detection/features/auth/index.test.js +37 -0
- package/dist/match-detection/features/auth/index.test.js.map +7 -0
- package/dist/match-detection/features/auth/yso.js +43 -0
- package/dist/match-detection/features/auth/yso.js.map +7 -0
- package/dist/match-detection/features/bib/index.test.js +1 -4
- package/dist/match-detection/features/bib/index.test.js.map +2 -2
- package/dist/match-detection/features/bib/isbn.js +0 -1
- package/dist/match-detection/features/bib/isbn.js.map +2 -2
- package/dist/match-detection/features/bib/issn.js +0 -1
- package/dist/match-detection/features/bib/issn.js.map +2 -2
- package/dist/match-detection/features/bib/language.js +0 -1
- package/dist/match-detection/features/bib/language.js.map +2 -2
- package/dist/match-detection/features/bib/media-type.js.map +2 -2
- package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js +0 -1
- package/dist/match-detection/features/bib/publication-time-allow-cons-years-multi.js.map +2 -2
- package/dist/match-detection/features/bib/standard-identifier-factory.js.map +2 -2
- package/dist/match-detection/features/index.js +2 -1
- package/dist/match-detection/features/index.js.map +2 -2
- package/dist/match-detection/index.test.js +1 -5
- package/dist/match-detection/index.test.js.map +2 -2
- package/package.json +6 -3
- package/src/candidate-search/index.js +0 -2
- package/src/candidate-search/index.test.js +1 -6
- package/src/candidate-search/query-list/auth.js +25 -0
- package/src/candidate-search/query-list/auth.test.js +34 -0
- package/src/candidate-search/query-list/bib.js +1 -2
- package/src/candidate-search/query-list/bib.test.js +1 -5
- package/src/candidate-search/query-list/component.js +4 -4
- package/src/candidate-search/query-list/index.js +7 -1
- package/src/cli.js +13 -1
- package/src/index.js +0 -1
- package/src/index.test.js +0 -1
- package/src/match-detection/features/auth/index.js +1 -0
- package/src/match-detection/features/auth/index.test.js +47 -0
- package/src/match-detection/features/auth/yso.js +53 -0
- package/src/match-detection/features/bib/index.test.js +1 -6
- package/src/match-detection/features/bib/isbn.js +0 -1
- package/src/match-detection/features/bib/issn.js +0 -1
- package/src/match-detection/features/bib/language.js +0 -2
- package/src/match-detection/features/bib/media-type.js +0 -3
- package/src/match-detection/features/bib/publication-time-allow-cons-years-multi.js +0 -1
- package/src/match-detection/features/bib/standard-identifier-factory.js +0 -2
- package/src/match-detection/features/index.js +3 -1
- package/src/match-detection/index.test.js +1 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/candidate-search/index.js"],
|
|
4
|
-
"sourcesContent": ["import createDebugLogger from 'debug';\nimport createClient, {SruSearchError} from '@natlibfi/sru-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\n\nimport generateQueryList from './query-list/index.js';\nimport chooseQueries from './choose-queries.js';\n\nexport {searchTypes} from './query-list/index.js';\n\nexport class CandidateSearchError extends Error { }\n\n// serverMaxResults : maximum size of total search result available from the server, defaults to Aleph's 20000\n\nexport default async ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest = 50, serverMaxResult = 20000}) => {\n MarcRecord.setValidationOptions({subfieldValues: false});\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search');\n const debugData = debug.extend('data');\n\n debugData(`SearchSpec: ${JSON.stringify(searchSpec)}`);\n debugData(`Url: ${url}`);\n debugData(`MaxRecordsPerRequest ${maxRecordsPerRequest}`);\n debugData(`ServerMaxResult: ${serverMaxResult}`);\n debugData(`MaxCandidates: ${maxCandidates}`);\n\n // Do not retrieve more candidates than defined in maxCandidates\n const adjustedMaxRecordsPerRequest = maxRecordsPerRequest >= maxCandidates ? maxCandidates : maxRecordsPerRequest;\n\n const client = createClient({\n url,\n maxRecordsPerRequest: adjustedMaxRecordsPerRequest,\n version: '2.0',\n retrieveAll: false,\n metadataFormat: 'marcJson'\n });\n\n const inputRecordId = getRecordId(record);\n const queryListResult = await generateQueryList(record, searchSpec, client);\n const queryList = queryListResult[0]?.queryList ? queryListResult[0].queryList : queryListResult;\n const queryListType = queryListResult[0]?.queryListType ? queryListResult[0].queryListType : undefined;\n\n // if generateQueryList errored we should throw 422\n if (queryList.length === 0) {\n debug(`Empty list`);\n throw new CandidateSearchError(`Generated query list contains no queries`);\n }\n if (queryListType && queryListType !== 'alternates') {\n debug(`Unknown queryListType`);\n throw new CandidateSearchError(`Generated query list has invalid type`);\n }\n\n debug(`Searching matches for ${inputRecordId}`);\n const chosenQueryList = await filterQueryList({queryList, queryListType});\n debug(`Chosen queries: ${JSON.stringify(chosenQueryList)}`);\n\n async function filterQueryList({queryList, queryListType, maxCandidates}) {\n debug(`Generated queryList (type: ${queryListType}) ${JSON.stringify(queryList)}`);\n\n if (queryListType === 'alternates' && queryList.length > 1) {\n const queryListResult = await chooseQueries({url, queryList, queryListType, maxCandidates});\n debug(`queryListResult: ${JSON.stringify(queryListResult)}`);\n return queryListResult.map(elem => elem.query);\n }\n return queryList;\n }\n // state.totalRecords : amount of candidate records available to the current query (undefined, if there was no queries left)\n // state.query : current query (undefined if there was no queries left)\n // state.searchCounter : sequence for current search for current query (undefined, if there we no queries left)\n // state.queryCandidateCounter: amount of candidates (records+failures) retrieved from SRU for matching for current query, including the current record+failure set (undefined if there were no queries left)\n // state.queriesLeft : amount of queries left\n // state.queryCounter : sequence for current query\n // state.maxedQueries : queries that resulted in more than serverMaxResults hits\n\n return {search};\n\n
|
|
5
|
-
"mappings": "AAAA,OAAO,uBAAuB;AAC9B,OAAO,gBAAe,sBAAqB;AAC3C,SAAQ,kBAAiB;AAEzB,OAAO,uBAAuB;AAC9B,OAAO,mBAAmB;AAE1B,SAAQ,mBAAkB;AAEnB,aAAM,6BAA6B,MAAM;AAAE;AAIlD,eAAe,OAAO,EAAC,QAAQ,YAAY,KAAK,eAAe,uBAAuB,IAAI,kBAAkB,IAAK,MAAM;AACrH,aAAW,qBAAqB,EAAC,gBAAgB,MAAK,CAAC;AAEvD,QAAM,QAAQ,kBAAkB,oDAAoD;AACpF,QAAM,YAAY,MAAM,OAAO,MAAM;AAErC,YAAU,eAAe,KAAK,UAAU,UAAU,CAAC,EAAE;AACrD,YAAU,QAAQ,GAAG,EAAE;AACvB,YAAU,wBAAwB,oBAAoB,EAAE;AACxD,YAAU,oBAAoB,eAAe,EAAE;AAC/C,YAAU,kBAAkB,aAAa,EAAE;AAG3C,QAAM,+BAA+B,wBAAwB,gBAAgB,gBAAgB;AAE7F,QAAM,SAAS,aAAa;AAAA,IAC1B;AAAA,IACA,sBAAsB;AAAA,IACtB,SAAS;AAAA,IACT,aAAa;AAAA,IACb,gBAAgB;AAAA,EAClB,CAAC;AAED,QAAM,gBAAgB,YAAY,MAAM;AACxC,QAAM,kBAAkB,MAAM,kBAAkB,QAAQ,YAAY,MAAM;AAC1E,QAAM,YAAY,gBAAgB,CAAC,GAAG,YAAY,gBAAgB,CAAC,EAAE,YAAY;AACjF,QAAM,gBAAgB,gBAAgB,CAAC,GAAG,gBAAgB,gBAAgB,CAAC,EAAE,gBAAgB;AAG7F,MAAI,UAAU,WAAW,GAAG;AAC1B,UAAM,YAAY;AAClB,UAAM,IAAI,qBAAqB,0CAA0C;AAAA,EAC3E;AACA,MAAI,iBAAiB,kBAAkB,cAAc;AACnD,UAAM,uBAAuB;AAC7B,UAAM,IAAI,qBAAqB,uCAAuC;AAAA,EACxE;AAEA,QAAM,yBAAyB,aAAa,EAAE;AAC9C,QAAM,kBAAkB,MAAM,gBAAgB,EAAC,WAAW,cAAa,CAAC;AACxE,QAAM,mBAAmB,KAAK,UAAU,eAAe,CAAC,EAAE;AAE1D,iBAAe,gBAAgB,EAAC,WAAAA,YAAW,eAAAC,gBAAe,eAAAC,eAAa,GAAG;AACxE,UAAM,8BAA8BD,cAAa,KAAK,KAAK,UAAUD,UAAS,CAAC,EAAE;AAEjF,QAAIC,mBAAkB,gBAAgBD,WAAU,SAAS,GAAG;AAC1D,YAAMG,mBAAkB,MAAM,cAAc,EAAC,KAAK,WAAAH,YAAW,eAAAC,gBAAe,eAAAC,eAAa,CAAC;AAC1F,YAAM,oBAAoB,KAAK,UAAUC,gBAAe,CAAC,EAAE;AAC3D,aAAOA,iBAAgB,IAAI,UAAQ,KAAK,KAAK;AAAA,IAC/C;AACA,WAAOH;AAAA,EACT;AASA,SAAO,EAAC,OAAM;
|
|
4
|
+
"sourcesContent": ["import createDebugLogger from 'debug';\nimport createClient, {SruSearchError} from '@natlibfi/sru-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\n\nimport generateQueryList from './query-list/index.js';\nimport chooseQueries from './choose-queries.js';\n\nexport {searchTypes} from './query-list/index.js';\n\nexport class CandidateSearchError extends Error { }\n\n// serverMaxResults : maximum size of total search result available from the server, defaults to Aleph's 20000\n\nexport default async ({record, searchSpec, url, maxCandidates, maxRecordsPerRequest = 50, serverMaxResult = 20000}) => {\n MarcRecord.setValidationOptions({subfieldValues: false});\n\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search');\n const debugData = debug.extend('data');\n\n debugData(`SearchSpec: ${JSON.stringify(searchSpec)}`);\n debugData(`Url: ${url}`);\n debugData(`MaxRecordsPerRequest ${maxRecordsPerRequest}`);\n debugData(`ServerMaxResult: ${serverMaxResult}`);\n debugData(`MaxCandidates: ${maxCandidates}`);\n\n // Do not retrieve more candidates than defined in maxCandidates\n const adjustedMaxRecordsPerRequest = maxRecordsPerRequest >= maxCandidates ? maxCandidates : maxRecordsPerRequest;\n\n const client = createClient({\n url,\n maxRecordsPerRequest: adjustedMaxRecordsPerRequest,\n version: '2.0',\n retrieveAll: false,\n metadataFormat: 'marcJson'\n });\n\n const inputRecordId = getRecordId(record);\n const queryListResult = await generateQueryList(record, searchSpec, client);\n const queryList = queryListResult[0]?.queryList ? queryListResult[0].queryList : queryListResult;\n const queryListType = queryListResult[0]?.queryListType ? queryListResult[0].queryListType : undefined;\n\n // if generateQueryList errored we should throw 422\n if (queryList.length === 0) {\n debug(`Empty list`);\n throw new CandidateSearchError(`Generated query list contains no queries`);\n }\n if (queryListType && queryListType !== 'alternates') {\n debug(`Unknown queryListType`);\n throw new CandidateSearchError(`Generated query list has invalid type`);\n }\n\n debug(`Searching matches for ${inputRecordId}`);\n const chosenQueryList = await filterQueryList({queryList, queryListType});\n debug(`Chosen queries: ${JSON.stringify(chosenQueryList)}`);\n\n async function filterQueryList({queryList, queryListType, maxCandidates}) {\n debug(`Generated queryList (type: ${queryListType}) ${JSON.stringify(queryList)}`);\n\n if (queryListType === 'alternates' && queryList.length > 1) {\n const queryListResult = await chooseQueries({url, queryList, queryListType, maxCandidates});\n debug(`queryListResult: ${JSON.stringify(queryListResult)}`);\n return queryListResult.map(elem => elem.query);\n }\n return queryList;\n }\n // state.totalRecords : amount of candidate records available to the current query (undefined, if there was no queries left)\n // state.query : current query (undefined if there was no queries left)\n // state.searchCounter : sequence for current search for current query (undefined, if there we no queries left)\n // state.queryCandidateCounter: amount of candidates (records+failures) retrieved from SRU for matching for current query, including the current record+failure set (undefined if there were no queries left)\n // state.queriesLeft : amount of queries left\n // state.queryCounter : sequence for current query\n // state.maxedQueries : queries that resulted in more than serverMaxResults hits\n\n return {search};\n\n async function search({queryOffset = 0, resultSetOffset = 1, totalRecords = 0, searchCounter = 0, queryCandidateCounter = 0, queryCounter = 0, maxedQueries = []}) {\n const query = chosenQueryList[queryOffset];\n debug(`Running query ${JSON.stringify(query)} (${queryOffset})`);\n\n if (query) {\n const {records, nextOffset, total} = await retrieveRecords(client, query, resultSetOffset);\n\n // If resultSetOffset === 1 this is the first search for the current query\n debugData(`ResultSetOffset: ${resultSetOffset}`);\n const newTotalRecords = resultSetOffset === 1 ? total : totalRecords;\n const newQueryCounter = resultSetOffset === 1 ? queryCounter + 1 : queryCounter;\n const newSearchCounter = resultSetOffset === 1 ? 1 : searchCounter + 1;\n const newQueryCandidateCounter = resultSetOffset === 1 ? records.length : queryCandidateCounter + records.length;\n\n const maxedQuery = resultSetOffset === 1 ? checkMaxedQuery(query, total, serverMaxResult) : undefined;\n const newMaxedQueries = maxedQuery ? maxedQueries.concat(maxedQuery) : maxedQueries;\n\n if (typeof nextOffset === 'number') {\n debug(`Next search will be for query ${queryOffset} ${query}, starting from record ${nextOffset}`);\n return {records, queryOffset, resultSetOffset: nextOffset, queriesLeft: queryList.length - (queryOffset + 1), totalRecords: newTotalRecords, query, searchCounter: newSearchCounter, queryCandidateCounter: newQueryCandidateCounter, queryCounter: newQueryCounter, maxedQueries: newMaxedQueries};\n }\n debug(`Query ${queryOffset} ${query} done.`);\n debug(`There are (${queryList.length - (queryOffset + 1)} queries left)`);\n return {records, queryOffset: queryOffset + 1, queriesLeft: queryList.length - (queryOffset + 1), totalRecords: newTotalRecords, query, searchCounter: newSearchCounter, queryCandidateCounter: newQueryCandidateCounter, queryCounter: newQueryCounter, maxedQueries: newMaxedQueries};\n }\n\n debug(`All ${queryList.length} queries done, there's no query for ${queryOffset}`);\n return {records: [], queriesLeft: 0, queryCounter, maxedQueries};\n }\n\n function checkMaxedQuery(query, total, serverMaxResult) {\n if (total >= serverMaxResult) {\n debug(`WARNING: Query ${query} resulted in ${total} hits which meets the serverMaxResult (${serverMaxResult}) `);\n return query;\n }\n }\n\n function getRecordId(record) {\n const [f001] = record.get(/^001$/u);\n const [f003] = record.get(/^003$/u);\n if (f001 && f003) {\n return `${f003.value}-${f001.value}`;\n }\n return f001 ? f001.value : '';\n }\n\n};\n\nexport function retrieveRecords(client, query, resultSetOffset) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:retrieveRecords');\n const debugData = debug.extend('data');\n\n return new Promise((resolve, reject) => {\n const records = [];\n let totalRecords = 0;\n\n debug(`Searching for candidates with query: ${query} (Offset ${resultSetOffset})`);\n\n client.searchRetrieve(query, {startRecord: resultSetOffset})\n .on('error', err => {\n if (err instanceof SruSearchError) {\n debug(`SRU SruSearchError for query: ${query}: ${err}`);\n reject(new CandidateSearchError(`SRU SruSearchError for query: ${query}: ${err}`));\n }\n\n debug(`SRU error for query: ${query}: ${err}`);\n reject(new CandidateSearchError(`SRU error for query: ${query}: ${err}`));\n })\n .on('total', total => {\n debug(`Got total: ${total}`);\n totalRecords += total;\n })\n .on('end', nextOffset => {\n try {\n debug(`Found ${records.length} records`);\n\n resolve({nextOffset, records, total: totalRecords});\n } catch (err) {\n debug(`Error caught on END`);\n reject(err);\n }\n })\n .on('record', record => {\n // MarcRecord Error handling\n try {\n const marcRecord = new MarcRecord(record);\n const [field] = marcRecord.get(/^001$/u);\n debug(field);\n const id = field.value ? field.value : '';\n records.push({record: marcRecord, id});\n } catch (error) {\n debug(`Sru => record error: ${error}`);\n debug(`Sru => record: ${record}`);\n }\n });\n });\n}\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,uBAAuB;AAC9B,OAAO,gBAAe,sBAAqB;AAC3C,SAAQ,kBAAiB;AAEzB,OAAO,uBAAuB;AAC9B,OAAO,mBAAmB;AAE1B,SAAQ,mBAAkB;AAEnB,aAAM,6BAA6B,MAAM;AAAE;AAIlD,eAAe,OAAO,EAAC,QAAQ,YA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,eAAO,IAAI,qBAAqB,iCAAiC,KAAK,KAAK,GAAG,EAAE,CAAC;AAAA,MACnF;AAEA,YAAM,wBAAwB,KAAK,KAAK,GAAG,EAAE;AAC7C,aAAO,IAAI,qBAAqB,wBAAwB,KAAK,KAAK,GAAG,EAAE,CAAC;AAAA,IAC1E,CAAC,EACA,GAAG,SAAS,WAAS;AACpB,YAAM,cAAc,KAAK,EAAE;AAC3B,sBAAgB;AAAA,IAClB,CAAC,EACA,GAAG,OAAO,gBAAc;AACvB,UAAI;AACF,cAAM,SAAS,QAAQ,MAAM,UAAU;AAEvC,gBAAQ,EAAC,YAAY,SAAS,OAAO,aAAY,CAAC;AAAA,MACpD,SAAS,KAAK;AACZ,cAAM,qBAAqB;AAC3B,eAAO,GAAG;AAAA,MACZ;AAAA,IACF,CAAC,EACA,GAAG,UAAU,YAAU;AAEtB,UAAI;AACF,cAAM,aAAa,IAAI,WAAW,MAAM;AACxC,cAAM,CAAC,KAAK,IAAI,WAAW,IAAI,QAAQ;AACvC,cAAM,KAAK;AACX,cAAM,KAAK,MAAM,QAAQ,MAAM,QAAQ;AACvC,gBAAQ,KAAK,EAAC,QAAQ,YAAY,GAAE,CAAC;AAAA,MACvC,SAAS,OAAO;AACd,cAAM,wBAAwB,KAAK,EAAE;AACrC,cAAM,kBAAkB,MAAM,EAAE;AAAA,MAClC;AAAA,IACF,CAAC;AAAA,EACL,CAAC;AACH;",
|
|
6
6
|
"names": ["queryList", "queryListType", "maxCandidates", "queryListResult", "serverMaxResult", "record"]
|
|
7
7
|
}
|
|
@@ -16,11 +16,8 @@ describe("candidate-search", () => {
|
|
|
16
16
|
reader: READERS.JSON
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
-
async function callback({ getFixture, factoryOptions, searchOptions, expectedFactoryError = false, expectedSearchError = false
|
|
19
|
+
async function callback({ getFixture, factoryOptions, searchOptions, expectedFactoryError = false, expectedSearchError = false }) {
|
|
20
20
|
const url = "http://foo.bar";
|
|
21
|
-
if (!enabled) {
|
|
22
|
-
return;
|
|
23
|
-
}
|
|
24
21
|
if (expectedFactoryError) {
|
|
25
22
|
debug(`We're expecting an error`);
|
|
26
23
|
if (expectedFactoryError.isCandidateSearchError) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/candidate-search/index.test.js"],
|
|
4
|
-
"sourcesContent": ["import assert from 'node:assert';\nimport {describe} from 'node:test';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen-http-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as MatchingError} from '@natlibfi/melinda-commons';\nimport createSearchInterface, {CandidateSearchError} from './index.js';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:test');\n\ndescribe('candidate-search', () => {\n generateTests({\n callback,\n path: [import.meta.dirname, '..', '..', 'test-fixtures', 'candidate-search', 'index'],\n recurse: false,\n fixura: {\n reader: READERS.JSON\n }\n });\n\n
|
|
5
|
-
"mappings": "AAAA,OAAO,YAAY;AACnB,SAAQ,gBAAe;AACvB,SAAQ,eAAc;AACtB,OAAO,mBAAmB;AAC1B,SAAQ,kBAAiB;AACzB,SAAQ,SAAS,qBAAoB;AACrC,OAAO,yBAAwB,4BAA2B;AAC1D,OAAO,uBAAuB;AAE9B,MAAM,QAAQ,kBAAkB,yDAAyD;AAEzF,SAAS,oBAAoB,MAAM;AACjC,gBAAc;AAAA,IACZ;AAAA,IACA,MAAM,CAAC,YAAY,SAAS,MAAM,MAAM,iBAAiB,oBAAoB,OAAO;AAAA,IACpF,SAAS;AAAA,IACT,QAAQ;AAAA,MACN,QAAQ,QAAQ;AAAA,IAClB;AAAA,EACF,CAAC;
|
|
4
|
+
"sourcesContent": ["import assert from 'node:assert';\nimport {describe} from 'node:test';\nimport {READERS} from '@natlibfi/fixura';\nimport generateTests from '@natlibfi/fixugen-http-client';\nimport {MarcRecord} from '@natlibfi/marc-record';\nimport {Error as MatchingError} from '@natlibfi/melinda-commons';\nimport createSearchInterface, {CandidateSearchError} from './index.js';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:test');\n\ndescribe('candidate-search', () => {\n generateTests({\n callback,\n path: [import.meta.dirname, '..', '..', 'test-fixtures', 'candidate-search', 'index'],\n recurse: false,\n fixura: {\n reader: READERS.JSON\n }\n });\n\n async function callback({getFixture, factoryOptions, searchOptions, expectedFactoryError = false, expectedSearchError = false}) {\n const url = 'http://foo.bar';\n\n if (expectedFactoryError) {\n debug(`We're expecting an error`);\n if (expectedFactoryError.isCandidateSearchError) {\n try {\n const result = await createSearchInterface({...formatFactoryOptions(), url});\n debug(result);\n } catch (err) {\n assert.equal(err instanceof CandidateSearchError, true);\n assert.match(err.message, new RegExp(expectedFactoryError.message));\n } finally {\n return;\n }\n }\n\n try {\n const result = await createSearchInterface({...formatFactoryOptions(), url});\n debug(result);\n } catch (err) {\n assert.equal(err instanceof Error, true);\n assert.match(err.message, new RegExp(expectedFactoryError.message));\n } finally {\n return;\n }\n }\n\n const {search} = await createSearchInterface({...formatFactoryOptions(), url});\n await iterate({searchOptions, expectedSearchError});\n\n function formatFactoryOptions() {\n debug(`Using factoryOptions: ${JSON.stringify(factoryOptions)}`);\n return {\n ...factoryOptions,\n maxRecordsPerRequest: factoryOptions.maxRecordsPerRequest || 1,\n maxServerResults: factoryOptions.maxServerResults || undefined,\n record: new MarcRecord(factoryOptions.record, {subfieldValues: false})\n };\n }\n\n async function iterate({searchOptions, expectedSearchError, expectedErrorStatus, count = 1}) {\n const expectedResults = getFixture(`expectedResults${count}.json`);\n\n if (expectedSearchError) {\n try {\n await search(searchOptions);\n throw new Error('Expected an error');\n } catch (err) {\n debug(`Got an error: ${err}`);\n assert(err instanceof Error);\n const errorMessage = err instanceof MatchingError ? err.payload.message : err.message;\n const errorStatus = err instanceof MatchingError ? err.status : undefined;\n debug(`errorMessage: ${errorMessage}, errorStatus: ${errorStatus}`);\n assert.match(errorMessage, new RegExp(expectedSearchError, 'u'));\n\n if (expectedErrorStatus) {\n assert.equal(errorStatus, expectedErrorStatus);\n return;\n }\n return;\n }\n }\n\n if (!expectedSearchError) {\n const results = await search(searchOptions);\n assert.deepStrictEqual(formatResults(results), expectedResults);\n }\n\n function formatResults(results) {\n debug(results);\n return {\n ...results,\n records: results.records.map(({record, id}) => ({id, record: record.toObject()}))\n };\n }\n }\n }\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,YAAY;AACnB,SAAQ,gBAAe;AACvB,SAAQ,eAAc;AACtB,OAAO,mBAAmB;AAC1B,SAAQ,kBAAiB;AACzB,SAAQ,SAAS,qBAAoB;AACrC,OAAO,yBAAwB,4BAA2B;AAC1D,OAAO,uBAAuB;AAE9B,MAAM,QAAQ,kBAAkB,yDAAyD;AAEzF,SAAS,oBAAoB,MAAM;AACjC,gBAAc;AAAA,IACZ;AAAA,IACA,MAAM,CAAC,YAAY,SAAS,MAAM,MAAM,iBAAiB,oBAAoB,OAAO;AAAA,IACpF,SAAS;AAAA,IACT,QAAQ;AAAA,MACN,QAAQ,QAAQ;AAAA,IAClB;AAAA,EACF,CAAC;AAED,iBAAe,SAAS,EAAC,YAAY,gBAAgB,eAAe,uBAAuB,OAAO,sBAAsB,MAAK,GAAG;AAC9H,UAAM,MAAM;AAEZ,QAAI,sBAAsB;AACxB,YAAM,0BAA0B;AAChC,UAAI,qBAAqB,wBAAwB;AAC/C,YAAI;AACF,gBAAM,SAAS,MAAM,sBAAsB,EAAC,GAAG,qBAAqB,GAAG,IAAG,CAAC;AAC3E,gBAAM,MAAM;AAAA,QACd,SAAS,KAAK;AACZ,iBAAO,MAAM,eAAe,sBAAsB,IAAI;AACtD,iBAAO,MAAM,IAAI,SAAS,IAAI,OAAO,qBAAqB,OAAO,CAAC;AAAA,QACpE,UAAE;AACA;AAAA,QACF;AAAA,MACF;AAEA,UAAI;AACF,cAAM,SAAS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ACF;AACA;AAAA,QACF;AAAA,MACF;AAEA,UAAI,CAACA,sBAAqB;AACxB,cAAM,UAAU,MAAM,OAAOD,cAAa;AAC1C,eAAO,gBAAgB,cAAc,OAAO,GAAG,eAAe;AAAA,MAChE;AAEA,eAAS,cAAc,SAAS;AAC9B,cAAM,OAAO;AACb,eAAO;AAAA,UACL,GAAG;AAAA,UACH,SAAS,QAAQ,QAAQ,IAAI,CAAC,EAAC,QAAQ,GAAE,OAAO,EAAC,IAAI,QAAQ,OAAO,SAAS,EAAC,EAAE;AAAA,QAClF;AAAA,MACF;AAAA,IACF;AAAA,EACF;AACF,CAAC;",
|
|
6
6
|
"names": ["searchOptions", "expectedSearchError"]
|
|
7
7
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import createDebugLogger from "debug";
|
|
2
|
+
import { toQueries } from "../candidate-search-utils.js";
|
|
3
|
+
const debug = createDebugLogger("@natlibfi/melinda-record-matching:candidate-search:query-list:auth");
|
|
4
|
+
export function authURX(record) {
|
|
5
|
+
const a = recordGetAuthURX(record);
|
|
6
|
+
if (a.length === 0) {
|
|
7
|
+
debug(`No identifiers found, no queries created.`);
|
|
8
|
+
return [];
|
|
9
|
+
}
|
|
10
|
+
return toQueries(a, "melinda.urx");
|
|
11
|
+
}
|
|
12
|
+
export function recordGetAuthURX(record) {
|
|
13
|
+
const f024s = record.get(/024/u).filter((f) => f.subfields.some((sf) => sf.code === "2" && ["uri", "urn"].includes(sf.value)));
|
|
14
|
+
if (f024s.length > 0) {
|
|
15
|
+
debug(`${f024s.length} id(s) found`);
|
|
16
|
+
const values = f024s.map((f) => f.subfields).flat().filter((sf) => sf.code === "a").map((sf) => sf.value);
|
|
17
|
+
return values;
|
|
18
|
+
}
|
|
19
|
+
return [];
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=auth.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/candidate-search/query-list/auth.js"],
|
|
4
|
+
"sourcesContent": ["import createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils.js';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query-list:auth');\n\nexport function authURX(record) {\n const a = recordGetAuthURX(record);\n\n if (a.length === 0) {\n debug(`No identifiers found, no queries created.`);\n return [];\n }\n return toQueries(a, 'melinda.urx');\n}\n\nexport function recordGetAuthURX(record) {\n const f024s = record.get(/024/u).filter(f => f.subfields.some(sf => sf.code === '2' && ['uri', 'urn'].includes(sf.value))); // f024 is repeatable\n if (f024s.length > 0) {\n debug(`${f024s.length} id(s) found`);\n // NB! f024$a is a non-repeatable subfield, but we are not checking that here\n const values = f024s.map(f => f.subfields).flat().filter(sf => sf.code === 'a').map(sf => sf.value);\n return values;\n }\n return [];\n}"],
|
|
5
|
+
"mappings": "AAAA,OAAO,uBAAuB;AAC9B,SAAQ,iBAAgB;AAExB,MAAM,QAAQ,kBAAkB,oEAAoE;AAE7F,gBAAS,QAAQ,QAAQ;AAC5B,QAAM,IAAI,iBAAiB,MAAM;AAEjC,MAAI,EAAE,WAAW,GAAG;AAChB,UAAM,2CAA2C;AACjD,WAAO,CAAC;AAAA,EACZ;AACA,SAAO,UAAU,GAAG,aAAa;AACrC;AAEO,gBAAS,iBAAiB,QAAQ;AACrC,QAAM,QAAQ,OAAO,IAAI,MAAM,EAAE,OAAO,OAAK,EAAE,UAAU,KAAK,QAAM,GAAG,SAAS,OAAO,CAAC,OAAO,KAAK,EAAE,SAAS,GAAG,KAAK,CAAC,CAAC;AACzH,MAAI,MAAM,SAAS,GAAG;AAClB,UAAM,GAAG,MAAM,MAAM,cAAc;AAEnC,UAAM,SAAS,MAAM,IAAI,OAAK,EAAE,SAAS,EAAE,KAAK,EAAE,OAAO,QAAM,GAAG,SAAS,GAAG,EAAE,IAAI,QAAM,GAAG,KAAK;AAClG,WAAO;AAAA,EACX;AACA,SAAO,CAAC;AACZ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
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 generators from "./auth.js";
|
|
8
|
+
const debug = createDebugLogger("@natlibfi/melinda-record-matching:candidate-search:query-list:auth-test");
|
|
9
|
+
const debugData = debug.extend("data");
|
|
10
|
+
describe("candidate-search/query-list/auth/", () => {
|
|
11
|
+
generateTests({
|
|
12
|
+
path: [import.meta.dirname, "..", "..", "..", "test-fixtures", "candidate-search", "query-list", "auth"],
|
|
13
|
+
useMetadataFile: true,
|
|
14
|
+
fixura: {
|
|
15
|
+
reader: READERS.JSON
|
|
16
|
+
},
|
|
17
|
+
callback: ({ type, inputRecord, expectedQuery, expectedQueryListType }) => {
|
|
18
|
+
const generate = generators[type];
|
|
19
|
+
const record = new MarcRecord(inputRecord, { subfieldValues: false });
|
|
20
|
+
const result = generate(record);
|
|
21
|
+
debugData(`Result: ${JSON.stringify(result)}`);
|
|
22
|
+
if (result.queryListType) {
|
|
23
|
+
assert.deepStrictEqual(result.queryList, expectedQuery);
|
|
24
|
+
assert.equal(result.queryListType, expectedQueryListType);
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
assert.deepStrictEqual(result, expectedQuery);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
});
|
|
31
|
+
//# sourceMappingURL=auth.test.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/candidate-search/query-list/auth.test.js"],
|
|
4
|
+
"sourcesContent": ["import 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 generators from './auth.js';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query-list:auth-test');\nconst debugData = debug.extend('data');\n\ndescribe('candidate-search/query-list/auth/', () => {\n generateTests({\n path: [import.meta.dirname, '..', '..', '..', 'test-fixtures', 'candidate-search', 'query-list', 'auth'],\n useMetadataFile: true,\n fixura: {\n reader: READERS.JSON\n },\n callback: ({type, inputRecord, expectedQuery, expectedQueryListType}) => {\n const generate = generators[type];\n const record = new MarcRecord(inputRecord, {subfieldValues: false});\n\n const result = generate(record);\n debugData(`Result: ${JSON.stringify(result)}`);\n\n if (result.queryListType) {\n assert.deepStrictEqual(result.queryList, expectedQuery);\n assert.equal(result.queryListType, expectedQueryListType);\n return;\n }\n assert.deepStrictEqual(result, expectedQuery);\n }\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,YAAY;AACnB,SAAQ,gBAAe;AACvB,OAAO,uBAAuB;AAC9B,OAAO,mBAAmB;AAC1B,SAAQ,eAAc;AACtB,SAAQ,kBAAiB;AACzB,YAAY,gBAAgB;AAE5B,MAAM,QAAQ,kBAAkB,yEAAyE;AACzG,MAAM,YAAY,MAAM,OAAO,MAAM;AAErC,SAAS,qCAAqC,MAAM;AAClD,gBAAc;AAAA,IACZ,MAAM,CAAC,YAAY,SAAS,MAAM,MAAM,MAAM,iBAAiB,oBAAoB,cAAc,MAAM;AAAA,IACvG,iBAAiB;AAAA,IACjB,QAAQ;AAAA,MACN,QAAQ,QAAQ;AAAA,IAClB;AAAA,IACA,UAAU,CAAC,EAAC,MAAM,aAAa,eAAe,sBAAqB,MAAM;AACvE,YAAM,WAAW,WAAW,IAAI;AAChC,YAAM,SAAS,IAAI,WAAW,aAAa,EAAC,gBAAgB,MAAK,CAAC;AAElE,YAAM,SAAS,SAAS,MAAM;AAC9B,gBAAU,WAAW,KAAK,UAAU,MAAM,CAAC,EAAE;AAE7C,UAAI,OAAO,eAAe;AACxB,eAAO,gBAAgB,OAAO,WAAW,aAAa;AACtD,eAAO,MAAM,OAAO,eAAe,qBAAqB;AACxD;AAAA,MACF;AACA,aAAO,gBAAgB,QAAQ,aAAa;AAAA,IAC9C;AAAA,EACF,CAAC;AACH,CAAC;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -196,7 +196,7 @@ export function bibAuthors(record) {
|
|
|
196
196
|
}
|
|
197
197
|
return [];
|
|
198
198
|
function getAuthor(record2) {
|
|
199
|
-
const [field] = record2.get(/^(100
|
|
199
|
+
const [field] = record2.get(/^(?:100|110|111|700|710|711)$/u);
|
|
200
200
|
if (field) {
|
|
201
201
|
const authorString = field.subfields.filter(({ code }) => ["a"].includes(code)).map(({ value }) => testStringOrNumber(value) ? String(value) : "").filter((value) => value).join(" ");
|
|
202
202
|
return authorString;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/candidate-search/query-list/bib.js"],
|
|
4
|
-
"sourcesContent": ["import createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils.js';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils.js';\nimport {extractHostMelindaIdsFromField, extractPublicationYearFrom773, getHostMelindaFields} from './component.js';\nimport {fieldToString} from '@natlibfi/marc-record-validators-melinda';\nimport {getTitle} from '../../match-detection/features/bib/title.js';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query');\n\nconst IS_OK_ALONE_THRESHOLD = 5;\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 debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents');\n const debugData = debug.extend('data');\n debug(`Creating queries for hostIds`);\n const f773s = getHostMelindaFields(record);\n if (f773s.length !== 1) { // This needs some thinking...\n return [];\n }\n\n const [id] = extractHostMelindaIdsFromField(f773s[0]);\n debug(`Found id: ${JSON.stringify(id)}`);\n\n // NB! record.isCR() does not work if LDR/07=a, so we get year from 773$g!\n const year = extractPublicationYearFrom773(f773s[0]);\n debug(`${fieldToString(f773s[0])} => ${year ? year : 'N/A'}`);\n if (year) {\n return [`dc.date=${year} AND melinda.partsofhost=${id}`];\n }\n\n return [`melinda.partsofhost=${id}`];\n\n}\n\n\n\n\n// SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to (probably) to *headings* index TIT\n// - Aleph cannot currently handle headings searches starting with a boolean - in these cases use word search\n\nexport function bibTitle(record) {\n // We get author/publisher only when formatted title is shorter than 5 chars\n return bibTitleAuthorPublisher({record, onlyTitleLength: 5});\n}\n\nexport function bibTitleAuthor(record) {\n debug('bibTitleAuthor');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100});\n}\n\nexport function bibTitleAuthorYear(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true});\n}\n\nexport function bibTitleAuthorYearAlternates(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n const origQueryList = bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true, alternates: true, alternateQueries: []});\n debug(`${JSON.stringify(origQueryList)}`);\n return {queryList: Array.from(origQueryList).reverse(), queryListType: 'alternates'};\n}\n\nfunction getTitleForQuery(record) {\n const title = getTitle(record, ['a']);\n if (title) {\n const nWords = title.split(' ');\n // If lone $a is deemed too short, fetch $b as well:\n // (NV: I've seen pairs with 245$a-only vs 245$a$b, so I'd like to use $a only if it is long enough)\n\n if (nWords < 3 || title.length < 12) {\n const [f245] = record.get('245');\n // If punctuation is ' =' I think that f245$a is good enough despite shortness. Trying to balance between two bad situations...\n // \"Suo (= short title) siell\u00E4, vetel\u00E4 (= missing $b name in another language) t\u00E4\u00E4ll\u00E4...\"\n if (f245 && f245.subfields.find(sf => sf.code === 'a' && sf.value.match(/ =$/u)) && title.length >= IS_OK_ALONE_THRESHOLD) {\n return title;\n }\n return getTitle(record, ['a', 'b']); // Try to get a longer title\n }\n }\n return title;\n}\n\nfunction dcTitle(record, onlyTitleLength, alternates = false) {\n const title = getTitleForQuery(record);\n if (!testStringOrNumber(title)) {\n return [];\n }\n\n const formatted = getFormattedTitle(title);\n\n // use word search for titles starting with a boolean\n const useWordSearch = checkUseWordSearch(formatted);\n // Prevent too many matches / SRU crashing by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= onlyTitleLength && !alternates) {\n return [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`, formatted, true];\n }\n\n const queryIsOkAlone = !useWordSearch && formatted.length >= IS_OK_ALONE_THRESHOLD;\n\n // use word search without ending * also in combination searches to avoid SRU-server crashes [MRA-189]\n return [`dc.title=\"${useWordSearch || !queryIsOkAlone ? '' : '^'}${formatted}${queryIsOkAlone ? '*' : ''}\"`, formatted, queryIsOkAlone];\n\n function getFormattedTitle(title) {\n const formatted = String(title)\n .replace(/[\\-+ !\"(){}\\[\\]<>;:.?/@*%=^_`~]/gu, ' ')\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '') // Apparently matches to/works with non-aplhabetic scripts such as Chinese as well\n .replace(/ +/gu, ' ') // Clean up concurrent spaces from eg. subfield changes\n .trim()\n .replace(/^(.{30}\\S*) .*$/, \"$1\")\n .trim();\n\n return formatted;\n }\n}\n\nexport function bibTitleAuthorPublisher({record, onlyTitleLength, addYear = false, alternates = false, alternateQueries = []}) {\n debug(`bibTitleAuthorPublisher, onlyTitleLength: ${onlyTitleLength}, addYear: ${addYear}, alternates: ${alternates}`);\n const [query, formatted, queryIsOkAlone] = dcTitle(record, onlyTitleLength, alternates);\n if (query === undefined) {\n return [];\n }\n\n debug(`query: ${query}`);\n\n // Prevent too many matches / SRU crashing by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= onlyTitleLength && !alternates) {\n return [query];\n }\n\n const newAlternateQueries = alternates ? [...alternateQueries, query] : alternateQueries;\n\n return addAuthorsToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries: newAlternateQueries});\n\n function addAuthorsToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n debug('addAuthorsToSearch');\n const [authorQuery] = bibAuthors(record);\n if (authorQuery !== undefined) {\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${authorQuery} AND ${query}`] : alternateQueries;\n return addYearToSearch({query: `${authorQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [`${authorQuery} AND ${query}`];\n }\n return addPublisherToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries});\n //return [];\n }\n\n function addPublisherToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n const [publisherQuery] = bibPublishers(record);\n if (publisherQuery !== undefined) {\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${publisherQuery} AND ${query}`] : alternateQueries;\n return addYearToSearch({query: `${publisherQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [`${publisherQuery} AND ${query}`];\n }\n if (queryIsOkAlone && !addYear) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return addYearToSearch({query, queryIsOkAlone, alternates, alternateQueries});\n }\n\n function addYearToSearch({query, queryIsOkAlone = false, alternates = false, alternateQueries = []}) {\n const [yearQuery] = bibYear(record);\n if (yearQuery !== undefined) {\n const yearAndOtherQueries = `${yearQuery} AND ${query}`;\n return alternates ? [...alternateQueries, yearAndOtherQueries] : [yearAndOtherQueries];\n }\n if (queryIsOkAlone) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return [];\n }\n\n}\n\nexport function bibAuthors(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibAuthors');\n const debugData = debug.extend('data');\n debug(`Creating query for the first author`);\n //debugData(record);\n\n const author = getAuthor(record);\n\n if (testStringOrNumber(author)) {\n const formatted = String(author)\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 authors starting with a boolean\n const useWordSearch = checkUseWordSearch(formatted);\n // Prevent too many matches by having a minimum length\n debugData(`Author string: ${formatted}`);\n if (formatted.length >= 5) {\n return [`dc.author=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n return [];\n }\n\n return [];\n\n function getAuthor(record) {\n //debugData(record);\n // eslint-disable-next-line prefer-named-capture-group\n const [field] = record.get(/^(100)|(110)|(111)|(700)|(710)|(711)$/u);\n //debugData(field);\n\n if (field) {\n const authorString = field.subfields\n .filter(({code}) => ['a'].includes(code)) // We might use different subfield code sets for X00, X10 and X11?\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return authorString;\n }\n return false;\n }\n}\n\nexport function bibPublishers(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibPublishers');\n const debugData = debug.extend('data');\n debug(`Creating query for the first publisher`);\n //debugData(record);\n\n const publisher = getPublisher(record);\n if (testStringOrNumber(publisher)) {\n const formatted = String(publisher)\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 debugData(`Publisher string: '${formatted}'`);\n if (formatted.length === 0) {\n return [];\n }\n // use non-wildcard word search from dc.publisher\n return [`dc.publisher=\"${formatted}\"`];\n }\n\n return [];\n\n function getPublisher(record) {\n //debugData(record);\n const [field] = record.get(/^26[04]$/u).filter(f => f.subfields.some(sf => sf.code === 'b')); // Filter removes copyright-only fields\n //debugData(field);\n\n if (field) {\n const publisherString = field.subfields\n .filter(({code}) => ['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 .trim();\n return publisherString;\n }\n return false;\n }\n}\n\nexport function bibYear(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibYear');\n const debugData = debug.extend('data');\n debug(`Creating query for the publishing year`);\n\n const year = getYear(record);\n if (year) {\n return [`dc.date=\"${year}\"`];\n }\n return [];\n\n function getYear(record) {\n const [f008] = record.get(/^008$/u);\n if (!f008 || !f008.value || f008.value.length < 11) {\n debug('f008 missing/crappy');\n return false;\n }\n\n debugData(`f008: ${JSON.stringify(f008)}`);\n const {value} = f008;\n if (value === '||||' || value === ' ') { // Meaningless values\n return false;\n }\n return value.slice(7, 11);\n }\n}\n\nexport function checkUseWordSearch(formatted) {\n const lowercased = formatted.toLowerCase();\n // Note: add a space to startWords to catch just actual boolean words\n const booleanStartWords = ['and ', 'or ', 'nor ', 'not '];\n return booleanStartWords.some(word => lowercased.startsWith(word));\n}\n\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 // DEVELOP: should we query also f015 and f028?\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"],
|
|
5
|
-
"mappings": "AAAA,OAAO,uBAAuB;AAC9B,SAAQ,iBAAgB;AACxB,SAAQ,mBAAmB,gCAAgC,mBAAmB,0BAAyB;AACvG,SAAQ,gCAAgC,+BAA+B,4BAA2B;AAClG,SAAQ,qBAAoB;AAC5B,SAAQ,gBAAe;AAEvB,MAAM,QAAQ,kBAAkB,0DAA0D;AAE1F,MAAM,wBAAwB;AAEvB,gBAAS,aAAa,QAAQ;AA0BnC,QAAMA,SAAQ,kBAAkB,qEAAqE;AACrG,QAAM,YAAYA,OAAM,OAAO,MAAM;AAGrC,EAAAA,OAAM,iCAAiC;AAEvC,QAAM,QAAQ,OAAO,IAAI,KAAK;AAC9B,YAAU,eAAe,MAAM,MAAM,MAAM,KAAK,UAAU,KAAK,CAAC,EAAE;AAElE,SAAO,MAAM,SAAS,IAAI,aAAa,KAAK,IAAI,CAAC;AAEjD,WAAS,aAAaC,QAAO;AAC3B,IAAAD,OAAM,wCAAwC;AAE9C,UAAM,aAAa,cAAcC,MAAK;AAEtC,QAAI,WAAW,SAAS,GAAG;AACzB,MAAAD,OAAM,2CAA2C;AACjD,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,aAAa,UAAU,YAAY,kBAAkB;AAE3D,WAAO;AAEP,aAAS,cAAcC,QAAO;AAC5B,MAAAD,OAAM,qCAAqC;AAG3C,YAAME,cAAaD,OAAM,IAAI,WAAW,EAAE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;AAG3C,QAAM,SAAS,UAAU,MAAM;AAE/B,MAAI,mBAAmB,MAAM,GAAG;AAC9B,UAAM,YAAY,OAAO,MAAM,EAC5B,QAAQ,2BAA2B,EAAE,EAErC,QAAQ,QAAQ,GAAG,EACnB,KAAK,EACL,MAAM,GAAG,EAAE,EACX,KAAK;AAGR,UAAM,gBAAgB,mBAAmB,SAAS;AAElD,cAAU,kBAAkB,SAAS,EAAE;AACvC,QAAI,UAAU,UAAU,GAAG;AACzB,aAAO,CAAC,cAAc,gBAAgB,KAAK,GAAG,GAAG,SAAS,IAAI;AAAA,IAChE;AACA,WAAO,CAAC;AAAA,EACV;AAEA,SAAO,CAAC;AAER,WAAS,UAAUY,SAAQ;
|
|
4
|
+
"sourcesContent": ["import createDebugLogger from 'debug';\nimport {toQueries} from '../candidate-search-utils.js';\nimport {getMelindaIdsF035, validateSidFieldSubfieldCounts, getSubfieldValues, testStringOrNumber} from '../../matching-utils.js';\nimport {extractHostMelindaIdsFromField, extractPublicationYearFrom773, getHostMelindaFields} from './component.js';\nimport {fieldToString} from '@natlibfi/marc-record-validators-melinda';\nimport {getTitle} from '../../match-detection/features/bib/title.js';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query');\n\nconst IS_OK_ALONE_THRESHOLD = 5;\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 debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents');\n const debugData = debug.extend('data');\n debug(`Creating queries for hostIds`);\n const f773s = getHostMelindaFields(record);\n if (f773s.length !== 1) { // This needs some thinking...\n return [];\n }\n\n const [id] = extractHostMelindaIdsFromField(f773s[0]);\n debug(`Found id: ${JSON.stringify(id)}`);\n\n // NB! record.isCR() does not work if LDR/07=a, so we get year from 773$g!\n const year = extractPublicationYearFrom773(f773s[0]);\n debug(`${fieldToString(f773s[0])} => ${year ? year : 'N/A'}`);\n if (year) {\n return [`dc.date=${year} AND melinda.partsofhost=${id}`];\n }\n\n return [`melinda.partsofhost=${id}`];\n\n}\n\n\n\n\n// SRU search dc.title with a search phrase starting with ^ maps currently in Melinda to (probably) to *headings* index TIT\n// - Aleph cannot currently handle headings searches starting with a boolean - in these cases use word search\n\nexport function bibTitle(record) {\n // We get author/publisher only when formatted title is shorter than 5 chars\n return bibTitleAuthorPublisher({record, onlyTitleLength: 5});\n}\n\nexport function bibTitleAuthor(record) {\n debug('bibTitleAuthor');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100});\n}\n\nexport function bibTitleAuthorYear(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n\n return bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true});\n}\n\nexport function bibTitleAuthorYearAlternates(record) {\n debug('bibTitleAuthorYearAlternates');\n // We use onlyTitleLength that is longer than our formatted length to\n // get an author or an publisher always\n const origQueryList = bibTitleAuthorPublisher({record, onlyTitleLength: 100, addYear: true, alternates: true, alternateQueries: []});\n debug(`${JSON.stringify(origQueryList)}`);\n return {queryList: Array.from(origQueryList).reverse(), queryListType: 'alternates'};\n}\n\nfunction getTitleForQuery(record) {\n const title = getTitle(record, ['a']);\n if (title) {\n const nWords = title.split(' ');\n // If lone $a is deemed too short, fetch $b as well:\n // (NV: I've seen pairs with 245$a-only vs 245$a$b, so I'd like to use $a only if it is long enough)\n\n if (nWords < 3 || title.length < 12) {\n const [f245] = record.get('245');\n // If punctuation is ' =' I think that f245$a is good enough despite shortness. Trying to balance between two bad situations...\n // \"Suo (= short title) siell\u00E4, vetel\u00E4 (= missing $b name in another language) t\u00E4\u00E4ll\u00E4...\"\n if (f245 && f245.subfields.find(sf => sf.code === 'a' && sf.value.match(/ =$/u)) && title.length >= IS_OK_ALONE_THRESHOLD) {\n return title;\n }\n return getTitle(record, ['a', 'b']); // Try to get a longer title\n }\n }\n return title;\n}\n\nfunction dcTitle(record, onlyTitleLength, alternates = false) {\n const title = getTitleForQuery(record);\n if (!testStringOrNumber(title)) {\n return [];\n }\n\n const formatted = getFormattedTitle(title);\n\n // use word search for titles starting with a boolean\n const useWordSearch = checkUseWordSearch(formatted);\n // Prevent too many matches / SRU crashing by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= onlyTitleLength && !alternates) {\n return [`dc.title=\"${useWordSearch ? '' : '^'}${formatted}*\"`, formatted, true];\n }\n\n const queryIsOkAlone = !useWordSearch && formatted.length >= IS_OK_ALONE_THRESHOLD;\n\n // use word search without ending * also in combination searches to avoid SRU-server crashes [MRA-189]\n return [`dc.title=\"${useWordSearch || !queryIsOkAlone ? '' : '^'}${formatted}${queryIsOkAlone ? '*' : ''}\"`, formatted, queryIsOkAlone];\n\n function getFormattedTitle(title) {\n const formatted = String(title)\n .replace(/[\\-+ !\"(){}\\[\\]<>;:.?/@*%=^_`~]/gu, ' ')\n .replace(/[^\\w\\s\\p{Alphabetic}]/gu, '') // Apparently matches to/works with non-aplhabetic scripts such as Chinese as well\n .replace(/ +/gu, ' ') // Clean up concurrent spaces from eg. subfield changes\n .trim()\n .replace(/^(.{30}\\S*) .*$/, \"$1\")\n .trim();\n\n return formatted;\n }\n}\n\nexport function bibTitleAuthorPublisher({record, onlyTitleLength, addYear = false, alternates = false, alternateQueries = []}) {\n debug(`bibTitleAuthorPublisher, onlyTitleLength: ${onlyTitleLength}, addYear: ${addYear}, alternates: ${alternates}`);\n const [query, formatted, queryIsOkAlone] = dcTitle(record, onlyTitleLength, alternates);\n if (query === undefined) {\n return [];\n }\n\n debug(`query: ${query}`);\n\n // Prevent too many matches / SRU crashing by having a minimum length\n // Note that currently this fails matching if there are no matches from previous matchers\n if (formatted.length >= onlyTitleLength && !alternates) {\n return [query];\n }\n\n const newAlternateQueries = alternates ? [...alternateQueries, query] : alternateQueries;\n\n return addAuthorsToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries: newAlternateQueries});\n\n function addAuthorsToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n debug('addAuthorsToSearch');\n const [authorQuery] = bibAuthors(record);\n if (authorQuery !== undefined) {\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${authorQuery} AND ${query}`] : alternateQueries;\n return addYearToSearch({query: `${authorQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [`${authorQuery} AND ${query}`];\n }\n return addPublisherToSearch({query, queryIsOkAlone, addYear, alternates, alternateQueries});\n //return [];\n }\n\n function addPublisherToSearch({query, queryIsOkAlone = false, addYear = false, alternates = false, alternateQueries = []}) {\n const [publisherQuery] = bibPublishers(record);\n if (publisherQuery !== undefined) {\n if (addYear) {\n const newAlternateQueries = alternates ? [...alternateQueries, `${publisherQuery} AND ${query}`] : alternateQueries;\n return addYearToSearch({query: `${publisherQuery} AND ${query}`, queryIsOkAlone: true, alternates, alternateQueries: newAlternateQueries});\n }\n return alternates ? alternateQueries : [`${publisherQuery} AND ${query}`];\n }\n if (queryIsOkAlone && !addYear) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return addYearToSearch({query, queryIsOkAlone, alternates, alternateQueries});\n }\n\n function addYearToSearch({query, queryIsOkAlone = false, alternates = false, alternateQueries = []}) {\n const [yearQuery] = bibYear(record);\n if (yearQuery !== undefined) {\n const yearAndOtherQueries = `${yearQuery} AND ${query}`;\n return alternates ? [...alternateQueries, yearAndOtherQueries] : [yearAndOtherQueries];\n }\n if (queryIsOkAlone) {\n return alternates ? alternateQueries : [`${query}`];\n }\n return [];\n }\n\n}\n\nexport function bibAuthors(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibAuthors');\n const debugData = debug.extend('data');\n debug(`Creating query for the first author`);\n //debugData(record);\n\n const author = getAuthor(record);\n\n if (testStringOrNumber(author)) {\n const formatted = String(author)\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 authors starting with a boolean\n const useWordSearch = checkUseWordSearch(formatted);\n // Prevent too many matches by having a minimum length\n debugData(`Author string: ${formatted}`);\n if (formatted.length >= 5) {\n return [`dc.author=\"${useWordSearch ? '' : '^'}${formatted}*\"`];\n }\n return [];\n }\n\n return [];\n\n function getAuthor(record) {\n //debugData(record);\n const [field] = record.get(/^(?:100|110|111|700|710|711)$/u);\n //debugData(field);\n\n if (field) {\n const authorString = field.subfields\n .filter(({code}) => ['a'].includes(code)) // We might use different subfield code sets for X00, X10 and X11?\n .map(({value}) => testStringOrNumber(value) ? String(value) : '')\n .filter(value => value)\n // In Melinda's index subfield separators are indexed as ' '\n .join(' ');\n return authorString;\n }\n return false;\n }\n}\n\nexport function bibPublishers(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibPublishers');\n const debugData = debug.extend('data');\n debug(`Creating query for the first publisher`);\n //debugData(record);\n\n const publisher = getPublisher(record);\n if (testStringOrNumber(publisher)) {\n const formatted = String(publisher)\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 debugData(`Publisher string: '${formatted}'`);\n if (formatted.length === 0) {\n return [];\n }\n // use non-wildcard word search from dc.publisher\n return [`dc.publisher=\"${formatted}\"`];\n }\n\n return [];\n\n function getPublisher(record) {\n //debugData(record);\n const [field] = record.get(/^26[04]$/u).filter(f => f.subfields.some(sf => sf.code === 'b')); // Filter removes copyright-only fields\n //debugData(field);\n\n if (field) {\n const publisherString = field.subfields\n .filter(({code}) => ['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 .trim();\n return publisherString;\n }\n return false;\n }\n}\n\nexport function bibYear(record) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibYear');\n const debugData = debug.extend('data');\n debug(`Creating query for the publishing year`);\n\n const year = getYear(record);\n if (year) {\n return [`dc.date=\"${year}\"`];\n }\n return [];\n\n function getYear(record) {\n const [f008] = record.get(/^008$/u);\n if (!f008 || !f008.value || f008.value.length < 11) {\n debug('f008 missing/crappy');\n return false;\n }\n\n debugData(`f008: ${JSON.stringify(f008)}`);\n const {value} = f008;\n if (value === '||||' || value === ' ') { // Meaningless values\n return false;\n }\n return value.slice(7, 11);\n }\n}\n\nexport function checkUseWordSearch(formatted) {\n const lowercased = formatted.toLowerCase();\n // Note: add a space to startWords to catch just actual boolean words\n const booleanStartWords = ['and ', 'or ', 'nor ', 'not '];\n return booleanStartWords.some(word => lowercased.startsWith(word));\n}\n\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 // DEVELOP: should we query also f015 and f028?\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"],
|
|
5
|
+
"mappings": "AAAA,OAAO,uBAAuB;AAC9B,SAAQ,iBAAgB;AACxB,SAAQ,mBAAmB,gCAAgC,mBAAmB,0BAAyB;AACvG,SAAQ,gCAAgC,+BAA+B,4BAA2B;AAClG,SAAQ,qBAAoB;AAC5B,SAAQ,gBAAe;AAEvB,MAAM,QAAQ,kBAAkB,0DAA0D;AAE1F,MAAM,wBAAwB;AAEvB,gBAAS,aAAa,QAAQ;AA0BnC,QAAMA,SAAQ,kBAAkB,qEAAqE;AACrG,QAAM,YAAYA,OAAM,OAAO,MAAM;AAGrC,EAAAA,OAAM,iCAAiC;AAEvC,QAAM,QAAQ,OAAO,IAAI,KAAK;AAC9B,YAAU,eAAe,MAAM,MAAM,MAAM,KAAK,UAAU,KAAK,CAAC,EAAE;AAElE,SAAO,MAAM,SAAS,IAAI,aAAa,KAAK,IAAI,CAAC;AAEjD,WAAS,aAAaC,QAAO;AAC3B,IAAAD,OAAM,wCAAwC;AAE9C,UAAM,aAAa,cAAcC,MAAK;AAEtC,QAAI,WAAW,SAAS,GAAG;AACzB,MAAAD,OAAM,2CAA2C;AACjD,aAAO,CAAC;AAAA,IACV;AAEA,UAAM,aAAa,UAAU,YAAY,kBAAkB;AAE3D,WAAO;AAEP,aAAS,cAAcC,QAAO;AAC5B,MAAAD,OAAM,qCAAqC;AAG3C,YAAME,cAAaD,OAAM,IAAI,WAAW,EAAE,OAAO,iBAAe,WAAW;AAC3E,aAAOC;AAEP,eAAS,YAAY,OAAO;AAC1B,QAAAF,OAAM,6BAA6B;AAEnC,eAAO,+BAA+B,KAAK,IAAI,gBAAgB,KAAK,IAAI;AAExE,iBAAS,gBAAgBG,QAAO;AAC9B,UAAAH,OAAM,8BAA8B;AACpC,gBAAM,CAAC,GAAG,IAAI,kBAAkBG,Q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": ["debug", "fSids", "sidStrings", "field", "title", "formatted", "query", "queryIsOkAlone", "addYear", "alternates", "alternateQueries", "newAlternateQueries", "record"]
|
|
7
7
|
}
|
|
@@ -14,12 +14,9 @@ describe("candidate-search/query-list/bib/", () => {
|
|
|
14
14
|
fixura: {
|
|
15
15
|
reader: READERS.JSON
|
|
16
16
|
},
|
|
17
|
-
callback: ({ type, inputRecord, expectedQuery, expectedQueryListType
|
|
17
|
+
callback: ({ type, inputRecord, expectedQuery, expectedQueryListType }) => {
|
|
18
18
|
const generate = generators[type];
|
|
19
19
|
const record = new MarcRecord(inputRecord, { subfieldValues: false });
|
|
20
|
-
if (!enabled) {
|
|
21
|
-
return;
|
|
22
|
-
}
|
|
23
20
|
const result = generate(record);
|
|
24
21
|
debugData(`Result: ${JSON.stringify(result)}`);
|
|
25
22
|
if (result.queryListType) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/candidate-search/query-list/bib.test.js"],
|
|
4
|
-
"sourcesContent": ["import 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 generators from './bib.js';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents:test');\nconst debugData = debug.extend('data');\n\ndescribe('candidate-search/query-list/bib/', () => {\n generateTests({\n path: [import.meta.dirname, '..', '..', '..', 'test-fixtures', 'candidate-search', 'query-list', 'bib'],\n useMetadataFile: true,\n fixura: {\n reader: READERS.JSON\n },\n callback: ({type, inputRecord, expectedQuery, expectedQueryListType
|
|
5
|
-
"mappings": "AAAA,OAAO,YAAY;AACnB,SAAQ,gBAAe;AACvB,OAAO,uBAAuB;AAC9B,OAAO,mBAAmB;AAC1B,SAAQ,eAAc;AACtB,SAAQ,kBAAiB;AACzB,YAAY,gBAAgB;AAE5B,MAAM,QAAQ,kBAAkB,iFAAiF;AACjH,MAAM,YAAY,MAAM,OAAO,MAAM;AAErC,SAAS,oCAAoC,MAAM;AACjD,gBAAc;AAAA,IACZ,MAAM,CAAC,YAAY,SAAS,MAAM,MAAM,MAAM,iBAAiB,oBAAoB,cAAc,KAAK;AAAA,IACtG,iBAAiB;AAAA,IACjB,QAAQ;AAAA,MACN,QAAQ,QAAQ;AAAA,IAClB;AAAA,IACA,UAAU,CAAC,EAAC,MAAM,aAAa,eAAe,
|
|
4
|
+
"sourcesContent": ["import 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 generators from './bib.js';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:bibHostComponents:test');\nconst debugData = debug.extend('data');\n\ndescribe('candidate-search/query-list/bib/', () => {\n generateTests({\n path: [import.meta.dirname, '..', '..', '..', 'test-fixtures', 'candidate-search', 'query-list', 'bib'],\n useMetadataFile: true,\n fixura: {\n reader: READERS.JSON\n },\n callback: ({type, inputRecord, expectedQuery, expectedQueryListType}) => {\n const generate = generators[type];\n const record = new MarcRecord(inputRecord, {subfieldValues: false});\n\n const result = generate(record);\n debugData(`Result: ${JSON.stringify(result)}`);\n\n if (result.queryListType) {\n assert.deepStrictEqual(result.queryList, expectedQuery);\n assert.equal(result.queryListType, expectedQueryListType);\n return;\n }\n assert.deepStrictEqual(result, expectedQuery);\n }\n });\n});\n"],
|
|
5
|
+
"mappings": "AAAA,OAAO,YAAY;AACnB,SAAQ,gBAAe;AACvB,OAAO,uBAAuB;AAC9B,OAAO,mBAAmB;AAC1B,SAAQ,eAAc;AACtB,SAAQ,kBAAiB;AACzB,YAAY,gBAAgB;AAE5B,MAAM,QAAQ,kBAAkB,iFAAiF;AACjH,MAAM,YAAY,MAAM,OAAO,MAAM;AAErC,SAAS,oCAAoC,MAAM;AACjD,gBAAc;AAAA,IACZ,MAAM,CAAC,YAAY,SAAS,MAAM,MAAM,MAAM,iBAAiB,oBAAoB,cAAc,KAAK;AAAA,IACtG,iBAAiB;AAAA,IACjB,QAAQ;AAAA,MACN,QAAQ,QAAQ;AAAA,IAClB;AAAA,IACA,UAAU,CAAC,EAAC,MAAM,aAAa,eAAe,sBAAqB,MAAM;AACvE,YAAM,WAAW,WAAW,IAAI;AAChC,YAAM,SAAS,IAAI,WAAW,aAAa,EAAC,gBAAgB,MAAK,CAAC;AAElE,YAAM,SAAS,SAAS,MAAM;AAC9B,gBAAU,WAAW,KAAK,UAAU,MAAM,CAAC,EAAE;AAE7C,UAAI,OAAO,eAAe;AACxB,eAAO,gBAAgB,OAAO,WAAW,aAAa;AACtD,eAAO,MAAM,OAAO,eAAe,qBAAqB;AACxD;AAAA,MACF;AACA,aAAO,gBAAgB,QAAQ,aAAa;AAAA,IAC9C;AAAA,EACF,CAAC;AACH,CAAC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -33,7 +33,7 @@ export function parse773g(field) {
|
|
|
33
33
|
if (value2.match(/^[0-9]+(?:-[0-9]+)?(?:, [0-9]+(?:-[0-9]+)?)*$/u)) {
|
|
34
34
|
return value2;
|
|
35
35
|
}
|
|
36
|
-
const numberPartOnly = value2.replace(/^.*(?:p\.|raidat|raita
|
|
36
|
+
const numberPartOnly = value2.replace(/^.*(?:p\.|raidat|raita|\bs\.|Seite|sivut?|pages?) /ui, "");
|
|
37
37
|
if (numberPartOnly !== value2) {
|
|
38
38
|
return gToPages(numberPartOnly);
|
|
39
39
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/candidate-search/query-list/component.js"],
|
|
4
|
-
"sourcesContent": ["import createDebugLogger from 'debug';\nimport {promisify} from 'util';\nimport {toQueries} from '../candidate-search-utils.js';\nimport {getSubfieldValues, stringAfter, stringBefore, testStringOrNumber, toMelindaIds} from '../../matching-utils.js';\nimport {fieldToString, uniqArray} from '@natlibfi/marc-record-validators-melinda/dist/utils.js';\n\nconst setTimeoutPromise = promisify(setTimeout)
|
|
5
|
-
"mappings": "AAAA,OAAO,uBAAuB;AAC9B,SAAQ,iBAAgB;AACxB,SAAQ,iBAAgB;AACxB,SAAQ,mBAAmB,aAAa,cAAc,oBAAoB,oBAAmB;AAC7F,SAAQ,eAAe,iBAAgB;AAEvC,MAAM,oBAAoB,UAAU,UAAU;AAE9C,MAAM,QAAQ,kBAAkB,oEAAoE;AACpG,MAAM,YAAY,MAAM,OAAO,MAAM;AAI9B,gBAAS,UAAU,OAAO;AAC/B,QAAM,IAAI,OAAO,WAAW,KAAK,QAAM,GAAG,SAAS,GAAG;AAEtD,MAAI,CAAC,GAAG;AACN,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,QAAQ,eAAe,EAAE,KAAK;AAEpC,SAAO;AAAA;AAAA,IAEL,MAAM,QAAQ,KAAK,KAAK;AAAA,IACxB,QAAQ,UAAU,KAAK,KAAK;AAAA,IAC5B,OAAO,SAAS,KAAK,KAAK;AAAA;AAAA,EAC5B;AAEA,WAAS,eAAeA,QAAO;AAC7B,WAAOA,OAAM,QAAQ,iBAAiB,EAAE;AAAA,EAC1C;AAEA,WAAS,UAAUA,QAAO;AAExB,UAAM,WAAWA,OAAM,QAAQ,6EAA6E,IAAI;AAChH,QAAI,aAAaA,QAAO;AACtB,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT;AAEA,WAAS,SAASA,QAAO;AACvB,QAAIA,OAAM,MAAM,gDAAgD,GAAG;AACjE,aAAOA;AAAA,IACT;AACA,UAAM,iBAAiBA,OAAM,QAAQ,
|
|
4
|
+
"sourcesContent": ["import createDebugLogger from 'debug';\nimport {promisify} from 'util';\nimport {toQueries} from '../candidate-search-utils.js';\nimport {getSubfieldValues, stringAfter, stringBefore, testStringOrNumber, toMelindaIds} from '../../matching-utils.js';\nimport {fieldToString, uniqArray} from '@natlibfi/marc-record-validators-melinda/dist/utils.js';\n\nconst setTimeoutPromise = promisify(setTimeout);\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:component');\nconst debugData = debug.extend('data');\n\n\n\nexport function parse773g(field) {\n const g = field?.subfields?.find(sf => sf.code === 'g'); // NB! returns the first $g\n\n if (!g) {\n return {};\n }\n\n const value = normalizeValue(g.value);\n\n return {\n // NB! We are not currently interested in volume (vuosikerta)\n year: gToYear(value) || null,\n number: gToNumber(value) || null,\n pages: gToPages(value) || null // Might also be eg. Raita 5. However, returns only the number part\n }\n\n function normalizeValue(value) {\n return value.replace(/(?:\\. -|\\.)$/u, '');\n }\n\n function gToNumber(value) {\n // Allow up to 3-digit numbers\n const extract1 = value.replace(/^.*: ([1-9][0-9]?[0-9]), (?:p\\.|page|pp\\.|s\\.|Seite|sida|sidor|sivu).*$/ui, '$1');\n if (extract1 !== value) {\n return extract1;\n }\n return undefined;\n }\n\n function gToPages(value) {\n if (value.match(/^[0-9]+(?:-[0-9]+)?(?:, [0-9]+(?:-[0-9]+)?)*$/u)) {\n return value;\n }\n const numberPartOnly = value.replace(/^.*(?:p\\.|raidat|raita|\\bs\\.|Seite|sivut?|pages?) /ui, '');\n if (numberPartOnly !== value) {\n return gToPages(numberPartOnly);\n }\n return undefined;\n }\n\n\n function gToYear(value) {\n debug(`EXTRACT YEAR FROM '${value}`);\n // extract year from within parentheses: $g vsk (yyyy) AND $g (YYYY)\n if (value.match(/^[1-9][0-9]?[0-9]? ?\\((?:20[012][0-9]|19[0-9][0-9])\\)/u) || value.match(/^\\((?:20[012][0-9]|19[0-9][0-9])\\)/u) ) {\n return stringBefore(stringAfter(value, '('), ')');\n }\n // If volume is missing, the year often seems to come without them parentheses:\n if (value.match(/^(?:20[012][0-9]|19[0-9][0-9]) :/u)) {\n return stringBefore(value, ' ');\n }\n // Seen in SB $g (vsk)year joulukuu\n if (value.match(/^\\([1-9][0-9]?\\) ?(?:20[012][0-9]|19[0-9][0-9])[^0-9]/)) {\n return value.replace(/^\\([0-9]+\\) ?/u, '').replace(/[^0-9].*$/u, '');\n }\n // Some magazines use DD.MM.YYYY\n if (value.match(/^[^0-9]*(?:[1-9]|[12][0-9]|30|31)\\.(?:1[012]|[1-9])\\. ?(?:20[012][0-9]|19[0-9][0-9])[^0-9]/u)) {\n return value.replace(/^[^0-9]*[0-9]+\\.[0-9]+\\. ?/u, '').replace(/[^0-9].*$/u, '');\n }\n\n return undefined;\n }\n}\n\nexport function extractPublicationYearFrom773(field) {\n const data = parse773g(field);\n debug(`Extracted year ${data.year} from f773$g ${fieldToString(field)}`);\n return data.year;\n}\n\nfunction isMelindaSubfieldW(subfield) {\n if (subfield.code !== 'w') {\n return false;\n }\n return (/^\\((?:FI-MELINDA|FIN01)\\)0[0-9]{8}$/ui).test(subfield.value);\n}\n\nfunction removeMelindaPrefixFromValue(value) {\n return value.replace(/^(?:\\(FI-MELINDA\\)|\\(FIN01\\))/, '');\n}\n\nexport function getHostMelindaFields(record) {\n return record.get(/^773$/u).filter(f => f.subfields.some(sf => isMelindaSubfieldW(sf)));\n}\n\nexport function extractHostMelindaIdsFromField(field) {\n return field.subfields.filter(sf => isMelindaSubfieldW(sf)).map(sf => removeMelindaPrefixFromValue(sf.value));\n}\n\nexport function getHostMelindaIds(record) {\n return uniqArray(getHostMelindaFields(record).map(f => extractHostMelindaIdsFromField(f)).flat());\n}\n\nexport function hostIdMelinda(record) { // old function with replaced code\n debug(`Creating query for the Melinda Id host`);\n const ids = getHostMelindaIds(record);\n if (ids.length === 0) {\n debug(`No valid Melinda Id host found`);\n return [];\n }\n return toQueries(getHostMelindaIds(record), 'melinda.partsofhost');\n}\n\nexport async function hostIdOtherSource(record, client) {\n const debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:query:hostIdOtherSource');\n const debugData = debug.extend('data');\n debug(`Creating query for the Other source Id host`);\n\n const ids = getHostIds(record);\n const otherSources = getOtherSources(record);\n if (ids.length > 0 && otherSources.length > 0) {\n const otherSourceIds = ids.map(id => otherSources.map(source => `${id}${source}`)).flat();\n const melindaHostQueries = await handleSruCalls(otherSourceIds);\n debug(JSON.stringify(melindaHostQueries));\n\n return melindaHostQueries;\n }\n\n debug(`No valid other source hosts found`);\n return [];\n\n\n function getHostIds(record) {\n const f773s = record.get(/^773$/u)\n .filter(f773 => f773.subfields.some(sub => sub.code === 'w' && !(/\\(FI-MELINDA\\).*/ui).test(sub.value)));\n if (f773s.length === 0) {\n return false;\n }\n\n // Multi 773 handling\n const subfieldWs = f773s\n .map(f773 => {\n debugData(`f773: ${JSON.stringify(f773)}`);\n return getSubfieldValues(f773, 'w').flat();\n }).flat();\n\n // Multi $w handling\n // $w (prefix)<id> handling\n // $w <id> & $w (prefix)<id> Match\n const ids = subfieldWs.map(value => `${value}`.replace(/\\(FI-.*\\)/ui, '')) // remove prefixes\n .filter(value => testStringOrNumber(value)) // drop invalid values\n .filter((value, index, array) => array.indexOf(value) === index); // unique values\n\n return ids;\n }\n\n function getOtherSources(record) {\n const fSids = record.get('SID');\n return fSids.map(field => getSubfieldValues(field, 'b'));\n }\n\n async function handleSruCalls(otherSourceIds, ids = []) {\n const [otherSourceId, ...rest] = otherSourceIds;\n\n if (otherSourceId === undefined) {\n debug(`host ids: ${ids}`);\n const validIds = ids.filter(id => id);\n return toQueries(validIds, 'melinda.partsofhost');\n }\n\n const otherSourceHostQuery = await toQueries([otherSourceId], 'melinda.sourceid');\n const id = await new Promise((resolve, reject) => {\n debug(`Searching for hosts with query: ${otherSourceHostQuery}`);\n let recordId;\n\n client.searchRetrieve(otherSourceHostQuery)\n .on('error', err => {\n debug(`SRU error for query: ${otherSourceHostQuery}: ${err}`);\n reject(err);\n })\n .on('end', async () => {\n try {\n debug(`Searching for hosts: done`);\n await setTimeoutPromise(10);\n resolve(recordId);\n } catch (err) {\n debug(`Error caught on END`);\n reject(err);\n }\n })\n .on('record', record => {\n const [field] = record.get(/^001$/u);\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ug", "debugData", "record", "ids", "id"]
|
|
7
7
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as bib from "./bib.js";
|
|
2
2
|
import * as component from "./component.js";
|
|
3
|
+
import * as auth from "./auth.js";
|
|
3
4
|
import createDebugLogger from "debug";
|
|
4
5
|
const debug = createDebugLogger("@natlibfi/melinda-record-matching:candidate-search:index");
|
|
5
6
|
const debugData = debug.extend("data");
|
|
@@ -26,10 +27,16 @@ export const searchTypes = {
|
|
|
26
27
|
// 773 $w !(FI-MELINDA)
|
|
27
28
|
hostIsbn: "hostIsbn"
|
|
28
29
|
// 773 $z
|
|
30
|
+
},
|
|
31
|
+
auth: {
|
|
32
|
+
//catalogingRules: 'authCatalogingRules', // 008/10 and 040$f
|
|
33
|
+
//term: 'authTermComparison' // 1XX
|
|
34
|
+
authURX: "authURX"
|
|
35
|
+
// 024$a
|
|
29
36
|
}
|
|
30
37
|
};
|
|
31
38
|
export default async (record, searchSpec, client) => {
|
|
32
|
-
const extractors = { ...bib, ...component };
|
|
39
|
+
const extractors = { ...auth, ...bib, ...component };
|
|
33
40
|
debugData(`extractors: ${JSON.stringify(extractors)}`);
|
|
34
41
|
debugData(`searchSpec: ${JSON.stringify(searchSpec)}`);
|
|
35
42
|
const qExtractors = searchSpec.map(generateQueryExtractor);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/candidate-search/query-list/index.js"],
|
|
4
|
-
"sourcesContent": ["import * as bib from './bib.js';\nimport * as component from './component.js';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:index');\nconst debugData = debug.extend('data');\n\nexport const searchTypes = {\n bib: {\n standardIdentifiers: 'bibStandardIdentifiers',\n hostComponents: 'bibHostComponents',\n title: 'bibTitle', // title ( + first author + first publisher if needed)\n titleAuthor: 'bibTitleAuthor', // title + first author (or first publisher if no author)\n titleAuthorYear: 'bibTitleAuthorYear', // title + first author (or first publisher if no author), publishing year\n titleAuthorYearAlternates: 'bibTitleAuthorYearAlternates', // title + first author (or first publisher if no author), publishing year\n melindaId: 'bibMelindaIds',\n sourceIds: 'bibSourceIds'\n //DEVELOP: bibContent: 'bibContent'\n },\n component: {\n hostIdMelinda: 'hostIdMelinda', // 773 $w (FI-MELINDA)\n hostIdOtherSource: 'hostIdOtherSource', // 773 $w !(FI-MELINDA)\n hostIsbn: 'hostIsbn' // 773 $z\n }\n};\n\nexport default async (record, searchSpec, client) => {\n const extractors = {...bib, ...component};\n debugData(`extractors: ${JSON.stringify(extractors)}`);\n debugData(`searchSpec: ${JSON.stringify(searchSpec)}`);\n\n const qExtractors = searchSpec.map(generateQueryExtractor);\n const results = await handleQextractors(qExtractors);\n return results;\n\n async function handleQextractors(qExtractors, results = []) {\n const [qExtractor, ...rest] = qExtractors;\n\n if (qExtractor === undefined) {\n return results.flat();\n }\n\n const result = await qExtractor(record, client);\n return handleQextractors(rest, [...results, result]);\n }\n\n function generateQueryExtractor(type) {\n if (extractors[type]) {\n //debugData(`${JSON.stringify(extractors[type])}`);\n return extractors[type];\n }\n\n throw new Error(`Unknown search type: ${type}`);\n }\n};\n"],
|
|
5
|
-
"mappings": "AAAA,YAAY,SAAS;AACrB,YAAY,eAAe;AAC3B,OAAO,uBAAuB;AAE9B,MAAM,QAAQ,kBAAkB,0DAA0D;AAC1F,MAAM,YAAY,MAAM,OAAO,MAAM;AAE9B,aAAM,cAAc;AAAA,EACzB,KAAK;AAAA,IACH,qBAAqB;AAAA,IACrB,gBAAgB;AAAA,IAChB,OAAO;AAAA;AAAA,IACP,aAAa;AAAA;AAAA,IACb,iBAAiB;AAAA;AAAA,IACjB,2BAA2B;AAAA;AAAA,IAC3B,WAAW;AAAA,IACX,WAAW;AAAA;AAAA,EAEb;AAAA,EACA,WAAW;AAAA,IACT,eAAe;AAAA;AAAA,IACf,mBAAmB;AAAA;AAAA,IACnB,UAAU;AAAA;AAAA,EACZ;AACF;AAEA,eAAe,OAAO,QAAQ,YAAY,WAAW;AACnD,QAAM,aAAa,EAAC,GAAG,KAAK,GAAG,UAAS;
|
|
4
|
+
"sourcesContent": ["import * as bib from './bib.js';\nimport * as component from './component.js';\nimport * as auth from './auth.js';\nimport createDebugLogger from 'debug';\n\nconst debug = createDebugLogger('@natlibfi/melinda-record-matching:candidate-search:index');\nconst debugData = debug.extend('data');\n\nexport const searchTypes = {\n bib: {\n standardIdentifiers: 'bibStandardIdentifiers',\n hostComponents: 'bibHostComponents',\n title: 'bibTitle', // title ( + first author + first publisher if needed)\n titleAuthor: 'bibTitleAuthor', // title + first author (or first publisher if no author)\n titleAuthorYear: 'bibTitleAuthorYear', // title + first author (or first publisher if no author), publishing year\n titleAuthorYearAlternates: 'bibTitleAuthorYearAlternates', // title + first author (or first publisher if no author), publishing year\n melindaId: 'bibMelindaIds',\n sourceIds: 'bibSourceIds'\n //DEVELOP: bibContent: 'bibContent'\n },\n component: {\n hostIdMelinda: 'hostIdMelinda', // 773 $w (FI-MELINDA)\n hostIdOtherSource: 'hostIdOtherSource', // 773 $w !(FI-MELINDA)\n hostIsbn: 'hostIsbn' // 773 $z\n },\n auth: {\n //catalogingRules: 'authCatalogingRules', // 008/10 and 040$f\n //term: 'authTermComparison' // 1XX\n authURX: 'authURX' // 024$a\n }\n};\n\nexport default async (record, searchSpec, client) => {\n const extractors = {...auth, ...bib, ...component};\n debugData(`extractors: ${JSON.stringify(extractors)}`);\n debugData(`searchSpec: ${JSON.stringify(searchSpec)}`);\n\n const qExtractors = searchSpec.map(generateQueryExtractor);\n const results = await handleQextractors(qExtractors);\n return results;\n\n async function handleQextractors(qExtractors, results = []) {\n const [qExtractor, ...rest] = qExtractors;\n\n if (qExtractor === undefined) {\n return results.flat();\n }\n\n const result = await qExtractor(record, client);\n return handleQextractors(rest, [...results, result]);\n }\n\n function generateQueryExtractor(type) {\n if (extractors[type]) {\n //debugData(`${JSON.stringify(extractors[type])}`);\n return extractors[type];\n }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AO,WAAW,IAAI;AAAA,IACxB;AAEA,UAAM,IAAI,MAAM,wBAAwB,IAAI,EAAE;AAAA,EAChD;AACF;",
|
|
6
6
|
"names": ["qExtractors", "results"]
|
|
7
7
|
}
|
package/dist/cli.js
CHANGED
|
@@ -24,7 +24,7 @@ async function cli() {
|
|
|
24
24
|
if (args2.sruUrl === void 0) {
|
|
25
25
|
throw new Error("Setup sru url");
|
|
26
26
|
}
|
|
27
|
-
if (!["IDS", "STANDARD_IDS", "COMPONENT", "CONTENT", "CONTENTALT"].includes(args2.searchType)) {
|
|
27
|
+
if (!["IDS", "STANDARD_IDS", "COMPONENT", "CONTENT", "CONTENTALT", "YSO"].includes(args2.searchType)) {
|
|
28
28
|
throw new Error("Invalid search type");
|
|
29
29
|
}
|
|
30
30
|
return true;
|
|
@@ -106,6 +106,11 @@ async function cli() {
|
|
|
106
106
|
// Host data
|
|
107
107
|
];
|
|
108
108
|
}
|
|
109
|
+
if (["YSO"]) {
|
|
110
|
+
return [
|
|
111
|
+
matchDetection.features.auth.yso()
|
|
112
|
+
];
|
|
113
|
+
}
|
|
109
114
|
throw new Error("Unsupported match validation package");
|
|
110
115
|
}
|
|
111
116
|
function generateSearchSpec(searchType2) {
|
|
@@ -140,6 +145,11 @@ async function cli() {
|
|
|
140
145
|
candidateSearch.searchTypes.bib.titleAuthorYearAlternates
|
|
141
146
|
];
|
|
142
147
|
}
|
|
148
|
+
if (searchType2 === "YSO") {
|
|
149
|
+
return [
|
|
150
|
+
candidateSearch.searchTypes.auth.authURX
|
|
151
|
+
];
|
|
152
|
+
}
|
|
143
153
|
throw new Error("Unsupported match validation package");
|
|
144
154
|
}
|
|
145
155
|
}
|