@internetarchive/collection-browser 2.8.1-alpha-webdev7002.0 → 2.8.1-alpha-webdev7386.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/index.d.ts +1 -4
- package/dist/index.js +1 -3
- package/dist/index.js.map +1 -1
- package/dist/src/collection-browser.js +7 -1
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/collection-facets/smart-facets/heuristics/{browser-language/browser-language-heuristic.d.ts → browser-language-heuristic.d.ts} +1 -1
- package/dist/src/collection-facets/smart-facets/heuristics/browser-language-heuristic.js.map +1 -0
- package/dist/src/collection-facets/smart-facets/heuristics/{query-keywords/query-keywords-heuristic.d.ts → query-keywords-heuristic.d.ts} +2 -1
- package/dist/src/collection-facets/smart-facets/heuristics/{query-keywords/query-keywords-map.js → query-keywords-heuristic.js} +17 -7
- package/dist/src/collection-facets/smart-facets/heuristics/query-keywords-heuristic.js.map +1 -0
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata-heuristic.d.ts +5 -0
- package/dist/src/collection-facets/smart-facets/heuristics/{wikidata/wikidata-entity-map.js → wikidata-heuristic.js} +49 -9
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata-heuristic.js.map +1 -0
- package/dist/src/collection-facets/smart-facets/models.d.ts +0 -4
- package/dist/src/collection-facets/smart-facets/models.js.map +1 -1
- package/dist/src/collection-facets/smart-facets/smart-facet-heuristics.d.ts +2 -2
- package/dist/src/collection-facets/smart-facets/smart-facet-heuristics.js +7 -9
- package/dist/src/collection-facets/smart-facets/smart-facet-heuristics.js.map +1 -1
- package/index.ts +1 -15
- package/package.json +1 -1
- package/src/collection-browser.ts +6 -3
- package/src/collection-facets/smart-facets/heuristics/{browser-language/browser-language-heuristic.ts → browser-language-heuristic.ts} +1 -1
- package/src/collection-facets/smart-facets/heuristics/query-keywords-heuristic.ts +55 -0
- package/src/collection-facets/smart-facets/heuristics/wikidata-heuristic.ts +191 -0
- package/src/collection-facets/smart-facets/models.ts +0 -4
- package/src/collection-facets/smart-facets/smart-facet-heuristics.ts +8 -13
- package/dist/src/collection-facets/smart-facets/heuristics/browser-language/browser-language-heuristic.js.map +0 -1
- package/dist/src/collection-facets/smart-facets/heuristics/index.d.ts +0 -3
- package/dist/src/collection-facets/smart-facets/heuristics/index.js +0 -4
- package/dist/src/collection-facets/smart-facets/heuristics/index.js.map +0 -1
- package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.js +0 -14
- package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.js.map +0 -1
- package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.d.ts +0 -6
- package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.js.map +0 -1
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.d.ts +0 -9
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.js.map +0 -1
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.d.ts +0 -21
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.js +0 -75
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.js.map +0 -1
- package/src/collection-facets/smart-facets/heuristics/index.ts +0 -3
- package/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.ts +0 -17
- package/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.ts +0 -36
- package/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.ts +0 -134
- package/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.ts +0 -89
- /package/dist/src/collection-facets/smart-facets/heuristics/{browser-language/browser-language-heuristic.js → browser-language-heuristic.js} +0 -0
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query-keywords-heuristic.js","sourceRoot":"","sources":["../../../../../../src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,gFAAgF;AAChF,MAAM,OAAO,sBAAsB;IACjC,KAAK,CAAC,oBAAoB,CAAC,KAAa;QACtC,MAAM,eAAe,GAAiB,EAAE,CAAC;QAEzC,KAAK,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,CAAC,EAAE,CAAC;YAC/D,IAAI,KAAK,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;gBAC5B,eAAe,CAAC,IAAI,CAAC,GAAG,MAAM,CAAC,CAAC;YAClC,CAAC;QACH,CAAC;QAED,OAAO,eAAe,CAAC;IACzB,CAAC;CACF","sourcesContent":["import type { SmartQueryHeuristic, SmartFacet } from '../../models';\nimport { QUERY_KEYWORDS } from './query-keywords-map';\n\n// If the query contains X keyword but Y facet isn't selected, recommend facet Y\nexport class QueryKeywordsHeuristic implements SmartQueryHeuristic {\n async getRecommendedFacets(query: string): Promise<SmartFacet[]> {\n const recommendations: SmartFacet[] = [];\n\n for (const [keyword, facets] of Object.entries(QUERY_KEYWORDS)) {\n if (query.includes(keyword)) {\n recommendations.push(...facets);\n }\n }\n\n return recommendations;\n }\n}\n"]}
|
package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"query-keywords-map.js","sourceRoot":"","sources":["../../../../../../src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,CAAC,MAAM,cAAc,GAA8B;IACvD,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACpE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE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KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACrE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACvE,YAAY,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IAC5E,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;CACvE,CAAC","sourcesContent":["import type { KeywordFacetMap } from '../../models';\n\n/**\n * Map from keywords found in the search query to an array of\n * likely-relevant \"smart facets\" for those keywords.\n */\nexport const QUERY_KEYWORDS: Readonly<KeywordFacetMap> = {\n text: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],\n book: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],\n pdf: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],\n epub: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],\n audio: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],\n song: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],\n music: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],\n listen: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],\n podcast: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],\n radio: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],\n stream: [\n { facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] },\n { facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] },\n ],\n video: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],\n movie: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],\n film: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],\n image: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],\n photo: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],\n picture: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],\n software: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],\n app: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],\n program: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],\n game: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],\n etree: [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],\n concert: [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],\n 'live music': [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],\n dataset: [{ facets: [{ facetType: 'mediatype', bucketKey: 'data' }] }],\n};\n"]}
|
package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.d.ts
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { KeywordFacetMap } from '../../models';
|
|
2
|
-
/**
|
|
3
|
-
* Map from Wikidata description keywords for a given entity to a
|
|
4
|
-
* set of likely-relevant "smart facets" for that query.
|
|
5
|
-
*
|
|
6
|
-
* The placeholder string "__QUERY" should be substituted for the actual
|
|
7
|
-
* queried entity when generating facet values.
|
|
8
|
-
*/
|
|
9
|
-
export declare const WIKIDATA_ENTITIES: Readonly<KeywordFacetMap>;
|
package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wikidata-entity-map.js","sourceRoot":"","sources":["../../../../../../src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,MAAM,CA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E,SAAS,EAAE,OAAO,EAAE;gBAC9C,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE;aAC/C;SACF;KACF;IACD,QAAQ,EAAE;QACR;YACE,KAAK,EAAE,kBAAkB;YACzB,MAAM,EAAE;gBACN,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE;gBAC9C,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE;aAC/C;SACF;KACF;IACD,QAAQ,EAAE;QACR;YACE,KAAK,EAAE,kBAAkB;YACzB,MAAM,EAAE;gBACN,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE;gBAC9C,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE;aAC/C;SACF;KACF;IACD,OAAO,EAAE;QACP;YACE,KAAK,EAAE,kBAAkB;YACzB,MAAM,EAAE;gBACN,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE;gBAC9C,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE;aAC/C;SACF;KACF;CACF,CAAC","sourcesContent":["import type { KeywordFacetMap } from '../../models';\n\n/**\n * Map from Wikidata description keywords for a given entity to a\n * set of likely-relevant \"smart facets\" for that query.\n *\n * The placeholder string \"__QUERY\" should be substituted for the actual\n * queried entity when generating facet values.\n */\nexport const WIKIDATA_ENTITIES: Readonly<KeywordFacetMap> = {\n 'written work': [\n { facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] },\n ],\n literature: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],\n book: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],\n novel: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],\n filmmaker: [\n {\n label: 'Films by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'movies' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n author: [\n {\n label: 'Writing by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'texts' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n writer: [\n {\n label: 'Writing by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'texts' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n poet: [\n {\n label: 'Writing by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'texts' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n photographer: [\n {\n label: 'Images by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'image' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n painter: [\n {\n label: 'Images by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'image' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n 'visual artist': [\n {\n label: 'Images by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'image' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n 'graphic artist': [\n {\n label: 'Images by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'image' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n singer: [\n {\n label: 'Music by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'audio' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n songwriter: [\n {\n label: 'Music by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'audio' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n musician: [\n {\n label: 'Music by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'audio' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n composer: [\n {\n label: 'Music by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'audio' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n pianist: [\n {\n label: 'Music by __QUERY',\n facets: [\n { facetType: 'mediatype', bucketKey: 'audio' },\n { facetType: 'creator', bucketKey: '__QUERY' },\n ],\n },\n ],\n};\n"]}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import type { SmartQueryHeuristic, SmartFacet } from '../../models';
|
|
2
|
-
export declare class WikidataHeuristic implements SmartQueryHeuristic {
|
|
3
|
-
private readonly WIKIDATA_BASE_URL;
|
|
4
|
-
private readonly WIKIDATA_DEFAULT_ARGS;
|
|
5
|
-
/**
|
|
6
|
-
* Returns the full URL for a Wikidata search for the given query
|
|
7
|
-
* @param query The query to search for
|
|
8
|
-
*/
|
|
9
|
-
private getWikidataURL;
|
|
10
|
-
/**
|
|
11
|
-
* Replaces query placeholders with an actual query string, within a collection of smart facets
|
|
12
|
-
* @param smartFacets The array of smart facets
|
|
13
|
-
* @param query The query string to replace placeholders with
|
|
14
|
-
* @returns A new array of smart facets with all query placeholders replaced
|
|
15
|
-
*/
|
|
16
|
-
private replaceQueryPlaceholders;
|
|
17
|
-
/**
|
|
18
|
-
* @inheritdoc
|
|
19
|
-
*/
|
|
20
|
-
getRecommendedFacets(query: string): Promise<SmartFacet[]>;
|
|
21
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { WIKIDATA_ENTITIES } from './wikidata-entity-map';
|
|
2
|
-
// If wikidata describes the top query result as X, recommend facet Y, e.g.:
|
|
3
|
-
// X Y
|
|
4
|
-
// written work mt:texts
|
|
5
|
-
// film mt:movies
|
|
6
|
-
// author mt:texts and creator:<query>
|
|
7
|
-
// filmmaker mt:movies and creator:<query>
|
|
8
|
-
// photographer mt:image and creator:<query>
|
|
9
|
-
// visual artist mt:image and creator:<query>
|
|
10
|
-
// etc.
|
|
11
|
-
export class WikidataHeuristic {
|
|
12
|
-
constructor() {
|
|
13
|
-
this.WIKIDATA_BASE_URL = 'https://www.wikidata.org/w/api.php';
|
|
14
|
-
this.WIKIDATA_DEFAULT_ARGS = '?action=wbsearchentities&format=json&language=en&uselang=en&origin=*&type=item&limit=5';
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* Returns the full URL for a Wikidata search for the given query
|
|
18
|
-
* @param query The query to search for
|
|
19
|
-
*/
|
|
20
|
-
getWikidataURL(query) {
|
|
21
|
-
const urlQuery = encodeURIComponent(query);
|
|
22
|
-
return `${this.WIKIDATA_BASE_URL}${this.WIKIDATA_DEFAULT_ARGS}&search=${urlQuery}`;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Replaces query placeholders with an actual query string, within a collection of smart facets
|
|
26
|
-
* @param smartFacets The array of smart facets
|
|
27
|
-
* @param query The query string to replace placeholders with
|
|
28
|
-
* @returns A new array of smart facets with all query placeholders replaced
|
|
29
|
-
*/
|
|
30
|
-
replaceQueryPlaceholders(smartFacets, query) {
|
|
31
|
-
return smartFacets.map(smartFacet => {
|
|
32
|
-
var _a;
|
|
33
|
-
return ({
|
|
34
|
-
// Replace placeholders within the smart facet label
|
|
35
|
-
label: (_a = smartFacet.label) === null || _a === void 0 ? void 0 : _a.replace('__QUERY', query),
|
|
36
|
-
// Replace placeholders within the facets themselves (buckets & display text)
|
|
37
|
-
facets: smartFacet.facets.map(facet => {
|
|
38
|
-
var _a;
|
|
39
|
-
const replaced = {
|
|
40
|
-
...facet,
|
|
41
|
-
bucketKey: facet.bucketKey.replace('__QUERY', query),
|
|
42
|
-
};
|
|
43
|
-
if (facet.displayText) {
|
|
44
|
-
replaced.displayText = (_a = replaced.displayText) === null || _a === void 0 ? void 0 : _a.replace('__QUERY', query);
|
|
45
|
-
}
|
|
46
|
-
return replaced;
|
|
47
|
-
}),
|
|
48
|
-
});
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @inheritdoc
|
|
53
|
-
*/
|
|
54
|
-
async getRecommendedFacets(query) {
|
|
55
|
-
var _a;
|
|
56
|
-
const recommendations = [];
|
|
57
|
-
try {
|
|
58
|
-
const wikidataURL = this.getWikidataURL(query);
|
|
59
|
-
const wikidataResponse = await fetch(wikidataURL);
|
|
60
|
-
const searchResults = await wikidataResponse.json();
|
|
61
|
-
for (const [keyword, facets] of Object.entries(WIKIDATA_ENTITIES)) {
|
|
62
|
-
const keywordRegex = new RegExp(`\\b${keyword}\\b`);
|
|
63
|
-
if (keywordRegex.test((_a = searchResults.search[0]) === null || _a === void 0 ? void 0 : _a.description)) {
|
|
64
|
-
const entityName = searchResults.search[0].label;
|
|
65
|
-
recommendations.push(...this.replaceQueryPlaceholders(facets, entityName));
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
return recommendations;
|
|
69
|
-
}
|
|
70
|
-
catch (err) {
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
//# sourceMappingURL=wikidata-heuristic.js.map
|
package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wikidata-heuristic.js","sourceRoot":"","sources":["../../../../../../src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAE1D,4EAA4E;AAC5E,mBAAmB;AACnB,0BAA0B;AAC1B,2BAA2B;AAC3B,8CAA8C;AAC9C,+CAA+C;AAC/C,8CAA8C;AAC9C,8CAA8C;AAC9C,OAAO;AACP,MAAM,OAAO,iBAAiB;IAA9B;QACmB,sBAAiB,GAAG,oCAAoC,CAAC;QAEzD,0BAAqB,GACpC,wFAAwF,CAAC;IAwE7F,CAAC;IAtEC;;;OAGG;IACK,cAAc,CAAC,KAAa;QAClC,MAAM,QAAQ,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC;QAC3C,OAAO,GAAG,IAAI,CAAC,iBAAiB,GAAG,IAAI,CAAC,qBAAqB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IAAI,YAAY,CAAC,IAAI,CAAC,MAAA,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,0CAAE,WAAW,CAAC,EAAE,CAAC;oBAC5D,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;oBACjD,eAAe,CAAC,IAAI,CAClB,GAAG,IAAI,CAAC,wBAAwB,CAAC,MAAM,EAAE,UAAU,CAAC,CACrD,CAAC;gBACJ,CAAC;YACH,CAAC;YAED,OAAO,eAAe,CAAC;QACzB,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,EAAE,CAAC;QACZ,CAAC;IACH,CAAC;CACF","sourcesContent":["import type { SmartQueryHeuristic, SmartFacet } from '../../models';\nimport { WIKIDATA_ENTITIES } from './wikidata-entity-map';\n\n// If wikidata describes the top query result as X, recommend facet Y, e.g.:\n// X Y\n// written work mt:texts\n// film mt:movies\n// author mt:texts and creator:<query>\n// filmmaker mt:movies and creator:<query>\n// photographer mt:image and creator:<query>\n// visual artist mt:image and creator:<query>\n// etc.\nexport class WikidataHeuristic implements SmartQueryHeuristic {\n private readonly WIKIDATA_BASE_URL = 'https://www.wikidata.org/w/api.php';\n\n private readonly WIKIDATA_DEFAULT_ARGS =\n '?action=wbsearchentities&format=json&language=en&uselang=en&origin=*&type=item&limit=5';\n\n /**\n * Returns the full URL for a Wikidata search for the given query\n * @param query The query to search for\n */\n private getWikidataURL(query: string): string {\n const urlQuery = encodeURIComponent(query);\n return `${this.WIKIDATA_BASE_URL}${this.WIKIDATA_DEFAULT_ARGS}&search=${urlQuery}`;\n }\n\n /**\n * Replaces query placeholders with an actual query string, within a collection of smart facets\n * @param smartFacets The array of smart facets\n * @param query The query string to replace placeholders with\n * @returns A new array of smart facets with all query placeholders replaced\n */\n private replaceQueryPlaceholders(\n smartFacets: SmartFacet[],\n query: string,\n ): SmartFacet[] {\n return smartFacets.map(\n smartFacet =>\n ({\n // Replace placeholders within the smart facet label\n label: smartFacet.label?.replace('__QUERY', query),\n // Replace placeholders within the facets themselves (buckets & display text)\n facets: smartFacet.facets.map(facet => {\n const replaced = {\n ...facet,\n bucketKey: facet.bucketKey.replace('__QUERY', query),\n };\n\n if (facet.displayText) {\n replaced.displayText = replaced.displayText?.replace(\n '__QUERY',\n query,\n );\n }\n\n return replaced;\n }),\n }) as SmartFacet,\n );\n }\n\n /**\n * @inheritdoc\n */\n async getRecommendedFacets(query: string): Promise<SmartFacet[]> {\n const recommendations: SmartFacet[] = [];\n\n try {\n const wikidataURL = this.getWikidataURL(query);\n const wikidataResponse = await fetch(wikidataURL);\n const searchResults = await wikidataResponse.json();\n\n for (const [keyword, facets] of Object.entries(WIKIDATA_ENTITIES)) {\n const keywordRegex = new RegExp(`\\\\b${keyword}\\\\b`);\n if (keywordRegex.test(searchResults.search[0]?.description)) {\n const entityName = searchResults.search[0].label;\n recommendations.push(\n ...this.replaceQueryPlaceholders(facets, entityName),\n );\n }\n }\n\n return recommendations;\n } catch (err) {\n return [];\n }\n }\n}\n"]}
|
package/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.ts
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { SmartQueryHeuristic, SmartFacet } from '../../models';
|
|
2
|
-
import { QUERY_KEYWORDS } from './query-keywords-map';
|
|
3
|
-
|
|
4
|
-
// If the query contains X keyword but Y facet isn't selected, recommend facet Y
|
|
5
|
-
export class QueryKeywordsHeuristic implements SmartQueryHeuristic {
|
|
6
|
-
async getRecommendedFacets(query: string): Promise<SmartFacet[]> {
|
|
7
|
-
const recommendations: SmartFacet[] = [];
|
|
8
|
-
|
|
9
|
-
for (const [keyword, facets] of Object.entries(QUERY_KEYWORDS)) {
|
|
10
|
-
if (query.includes(keyword)) {
|
|
11
|
-
recommendations.push(...facets);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
return recommendations;
|
|
16
|
-
}
|
|
17
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { KeywordFacetMap } from '../../models';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Map from keywords found in the search query to an array of
|
|
5
|
-
* likely-relevant "smart facets" for those keywords.
|
|
6
|
-
*/
|
|
7
|
-
export const QUERY_KEYWORDS: Readonly<KeywordFacetMap> = {
|
|
8
|
-
text: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
9
|
-
book: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
10
|
-
pdf: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
11
|
-
epub: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
12
|
-
audio: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
13
|
-
song: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
14
|
-
music: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
15
|
-
listen: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
16
|
-
podcast: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
17
|
-
radio: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
18
|
-
stream: [
|
|
19
|
-
{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] },
|
|
20
|
-
{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] },
|
|
21
|
-
],
|
|
22
|
-
video: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
23
|
-
movie: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
24
|
-
film: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
25
|
-
image: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
26
|
-
photo: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
27
|
-
picture: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
28
|
-
software: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
29
|
-
app: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
30
|
-
program: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
31
|
-
game: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
32
|
-
etree: [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
33
|
-
concert: [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
34
|
-
'live music': [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
35
|
-
dataset: [{ facets: [{ facetType: 'mediatype', bucketKey: 'data' }] }],
|
|
36
|
-
};
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
import type { KeywordFacetMap } from '../../models';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Map from Wikidata description keywords for a given entity to a
|
|
5
|
-
* set of likely-relevant "smart facets" for that query.
|
|
6
|
-
*
|
|
7
|
-
* The placeholder string "__QUERY" should be substituted for the actual
|
|
8
|
-
* queried entity when generating facet values.
|
|
9
|
-
*/
|
|
10
|
-
export const WIKIDATA_ENTITIES: Readonly<KeywordFacetMap> = {
|
|
11
|
-
'written work': [
|
|
12
|
-
{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] },
|
|
13
|
-
],
|
|
14
|
-
literature: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
15
|
-
book: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
16
|
-
novel: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
17
|
-
filmmaker: [
|
|
18
|
-
{
|
|
19
|
-
label: 'Films by __QUERY',
|
|
20
|
-
facets: [
|
|
21
|
-
{ facetType: 'mediatype', bucketKey: 'movies' },
|
|
22
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
23
|
-
],
|
|
24
|
-
},
|
|
25
|
-
],
|
|
26
|
-
author: [
|
|
27
|
-
{
|
|
28
|
-
label: 'Writing by __QUERY',
|
|
29
|
-
facets: [
|
|
30
|
-
{ facetType: 'mediatype', bucketKey: 'texts' },
|
|
31
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
32
|
-
],
|
|
33
|
-
},
|
|
34
|
-
],
|
|
35
|
-
writer: [
|
|
36
|
-
{
|
|
37
|
-
label: 'Writing by __QUERY',
|
|
38
|
-
facets: [
|
|
39
|
-
{ facetType: 'mediatype', bucketKey: 'texts' },
|
|
40
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
41
|
-
],
|
|
42
|
-
},
|
|
43
|
-
],
|
|
44
|
-
poet: [
|
|
45
|
-
{
|
|
46
|
-
label: 'Writing by __QUERY',
|
|
47
|
-
facets: [
|
|
48
|
-
{ facetType: 'mediatype', bucketKey: 'texts' },
|
|
49
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
50
|
-
],
|
|
51
|
-
},
|
|
52
|
-
],
|
|
53
|
-
photographer: [
|
|
54
|
-
{
|
|
55
|
-
label: 'Images by __QUERY',
|
|
56
|
-
facets: [
|
|
57
|
-
{ facetType: 'mediatype', bucketKey: 'image' },
|
|
58
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
59
|
-
],
|
|
60
|
-
},
|
|
61
|
-
],
|
|
62
|
-
painter: [
|
|
63
|
-
{
|
|
64
|
-
label: 'Images by __QUERY',
|
|
65
|
-
facets: [
|
|
66
|
-
{ facetType: 'mediatype', bucketKey: 'image' },
|
|
67
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
68
|
-
],
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
'visual artist': [
|
|
72
|
-
{
|
|
73
|
-
label: 'Images by __QUERY',
|
|
74
|
-
facets: [
|
|
75
|
-
{ facetType: 'mediatype', bucketKey: 'image' },
|
|
76
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
77
|
-
],
|
|
78
|
-
},
|
|
79
|
-
],
|
|
80
|
-
'graphic artist': [
|
|
81
|
-
{
|
|
82
|
-
label: 'Images by __QUERY',
|
|
83
|
-
facets: [
|
|
84
|
-
{ facetType: 'mediatype', bucketKey: 'image' },
|
|
85
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
86
|
-
],
|
|
87
|
-
},
|
|
88
|
-
],
|
|
89
|
-
singer: [
|
|
90
|
-
{
|
|
91
|
-
label: 'Music by __QUERY',
|
|
92
|
-
facets: [
|
|
93
|
-
{ facetType: 'mediatype', bucketKey: 'audio' },
|
|
94
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
95
|
-
],
|
|
96
|
-
},
|
|
97
|
-
],
|
|
98
|
-
songwriter: [
|
|
99
|
-
{
|
|
100
|
-
label: 'Music by __QUERY',
|
|
101
|
-
facets: [
|
|
102
|
-
{ facetType: 'mediatype', bucketKey: 'audio' },
|
|
103
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
104
|
-
],
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
musician: [
|
|
108
|
-
{
|
|
109
|
-
label: 'Music by __QUERY',
|
|
110
|
-
facets: [
|
|
111
|
-
{ facetType: 'mediatype', bucketKey: 'audio' },
|
|
112
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
113
|
-
],
|
|
114
|
-
},
|
|
115
|
-
],
|
|
116
|
-
composer: [
|
|
117
|
-
{
|
|
118
|
-
label: 'Music by __QUERY',
|
|
119
|
-
facets: [
|
|
120
|
-
{ facetType: 'mediatype', bucketKey: 'audio' },
|
|
121
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
122
|
-
],
|
|
123
|
-
},
|
|
124
|
-
],
|
|
125
|
-
pianist: [
|
|
126
|
-
{
|
|
127
|
-
label: 'Music by __QUERY',
|
|
128
|
-
facets: [
|
|
129
|
-
{ facetType: 'mediatype', bucketKey: 'audio' },
|
|
130
|
-
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
131
|
-
],
|
|
132
|
-
},
|
|
133
|
-
],
|
|
134
|
-
};
|
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
import type { SmartQueryHeuristic, SmartFacet } from '../../models';
|
|
2
|
-
import { WIKIDATA_ENTITIES } from './wikidata-entity-map';
|
|
3
|
-
|
|
4
|
-
// If wikidata describes the top query result as X, recommend facet Y, e.g.:
|
|
5
|
-
// X Y
|
|
6
|
-
// written work mt:texts
|
|
7
|
-
// film mt:movies
|
|
8
|
-
// author mt:texts and creator:<query>
|
|
9
|
-
// filmmaker mt:movies and creator:<query>
|
|
10
|
-
// photographer mt:image and creator:<query>
|
|
11
|
-
// visual artist mt:image and creator:<query>
|
|
12
|
-
// etc.
|
|
13
|
-
export class WikidataHeuristic implements SmartQueryHeuristic {
|
|
14
|
-
private readonly WIKIDATA_BASE_URL = 'https://www.wikidata.org/w/api.php';
|
|
15
|
-
|
|
16
|
-
private readonly WIKIDATA_DEFAULT_ARGS =
|
|
17
|
-
'?action=wbsearchentities&format=json&language=en&uselang=en&origin=*&type=item&limit=5';
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Returns the full URL for a Wikidata search for the given query
|
|
21
|
-
* @param query The query to search for
|
|
22
|
-
*/
|
|
23
|
-
private getWikidataURL(query: string): string {
|
|
24
|
-
const urlQuery = encodeURIComponent(query);
|
|
25
|
-
return `${this.WIKIDATA_BASE_URL}${this.WIKIDATA_DEFAULT_ARGS}&search=${urlQuery}`;
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Replaces query placeholders with an actual query string, within a collection of smart facets
|
|
30
|
-
* @param smartFacets The array of smart facets
|
|
31
|
-
* @param query The query string to replace placeholders with
|
|
32
|
-
* @returns A new array of smart facets with all query placeholders replaced
|
|
33
|
-
*/
|
|
34
|
-
private replaceQueryPlaceholders(
|
|
35
|
-
smartFacets: SmartFacet[],
|
|
36
|
-
query: string,
|
|
37
|
-
): SmartFacet[] {
|
|
38
|
-
return smartFacets.map(
|
|
39
|
-
smartFacet =>
|
|
40
|
-
({
|
|
41
|
-
// Replace placeholders within the smart facet label
|
|
42
|
-
label: smartFacet.label?.replace('__QUERY', query),
|
|
43
|
-
// Replace placeholders within the facets themselves (buckets & display text)
|
|
44
|
-
facets: smartFacet.facets.map(facet => {
|
|
45
|
-
const replaced = {
|
|
46
|
-
...facet,
|
|
47
|
-
bucketKey: facet.bucketKey.replace('__QUERY', query),
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
if (facet.displayText) {
|
|
51
|
-
replaced.displayText = replaced.displayText?.replace(
|
|
52
|
-
'__QUERY',
|
|
53
|
-
query,
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return replaced;
|
|
58
|
-
}),
|
|
59
|
-
}) as SmartFacet,
|
|
60
|
-
);
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* @inheritdoc
|
|
65
|
-
*/
|
|
66
|
-
async getRecommendedFacets(query: string): Promise<SmartFacet[]> {
|
|
67
|
-
const recommendations: SmartFacet[] = [];
|
|
68
|
-
|
|
69
|
-
try {
|
|
70
|
-
const wikidataURL = this.getWikidataURL(query);
|
|
71
|
-
const wikidataResponse = await fetch(wikidataURL);
|
|
72
|
-
const searchResults = await wikidataResponse.json();
|
|
73
|
-
|
|
74
|
-
for (const [keyword, facets] of Object.entries(WIKIDATA_ENTITIES)) {
|
|
75
|
-
const keywordRegex = new RegExp(`\\b${keyword}\\b`);
|
|
76
|
-
if (keywordRegex.test(searchResults.search[0]?.description)) {
|
|
77
|
-
const entityName = searchResults.search[0].label;
|
|
78
|
-
recommendations.push(
|
|
79
|
-
...this.replaceQueryPlaceholders(facets, entityName),
|
|
80
|
-
);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
return recommendations;
|
|
85
|
-
} catch (err) {
|
|
86
|
-
return [];
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|