@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,4 +1,4 @@
|
|
|
1
|
-
import type { SmartQueryHeuristic, SmartFacet } from '
|
|
1
|
+
import type { SmartQueryHeuristic, SmartFacet } from '../models';
|
|
2
2
|
export declare class BrowserLanguageHeuristic implements SmartQueryHeuristic {
|
|
3
3
|
getRecommendedFacets(): Promise<SmartFacet[]>;
|
|
4
4
|
private static getLanguageDisplayName;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"browser-language-heuristic.js","sourceRoot":"","sources":["../../../../../src/collection-facets/smart-facets/heuristics/browser-language-heuristic.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,wBAAwB;IACnC,KAAK,CAAC,oBAAoB;QACxB,MAAM,mBAAmB,GAAG,SAAS,CAAC,QAAQ,CAAC;QAC/C,MAAM,YAAY,GAChB,wBAAwB,CAAC,sBAAsB,CAAC,mBAAmB,CAAC,CAAC;QACvE,IAAI,CAAC,YAAY;YAAE,OAAO,EAAE,CAAC;QAE7B,OAAO;YACL;gBACE,MAAM,EAAE;oBACN;wBACE,SAAS,EAAE,UAAU;wBACrB,SAAS,EAAE,YAAY;qBACxB;iBACF;aACF;SACF,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,sBAAsB,CAAC,QAAgB;QACpD,mEAAmE;QACnE,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;IAC9E,CAAC;CACF","sourcesContent":["import type { SmartQueryHeuristic, SmartFacet } from '../models';\n\nexport class BrowserLanguageHeuristic implements SmartQueryHeuristic {\n async getRecommendedFacets(): Promise<SmartFacet[]> {\n const browserLanguageCode = navigator.language;\n const languageName =\n BrowserLanguageHeuristic.getLanguageDisplayName(browserLanguageCode);\n if (!languageName) return [];\n\n return [\n {\n facets: [\n {\n facetType: 'language',\n bucketKey: languageName,\n },\n ],\n },\n ];\n }\n\n private static getLanguageDisplayName(langCode: string): string | undefined {\n // Strip off any script/region/variant codes for greater generality\n const languageOnly = langCode.split('-')[0];\n return new Intl.DisplayNames(['en'], { type: 'language' }).of(languageOnly);\n }\n}\n"]}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { SmartQueryHeuristic, SmartFacet } from '
|
|
1
|
+
import type { SmartQueryHeuristic, SmartFacet } from '../models';
|
|
2
2
|
export declare class QueryKeywordsHeuristic implements SmartQueryHeuristic {
|
|
3
|
+
private static readonly KEYWORDS;
|
|
3
4
|
getRecommendedFacets(query: string): Promise<SmartFacet[]>;
|
|
4
5
|
}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
// If the query contains X word but Y facet isn't selected, recommend facet Y
|
|
2
|
+
export class QueryKeywordsHeuristic {
|
|
3
|
+
async getRecommendedFacets(query) {
|
|
4
|
+
const recommendations = [];
|
|
5
|
+
for (const [keyword, facets] of Object.entries(QueryKeywordsHeuristic.KEYWORDS)) {
|
|
6
|
+
if (query.includes(keyword)) {
|
|
7
|
+
recommendations.push(...facets);
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return recommendations;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
QueryKeywordsHeuristic.KEYWORDS = {
|
|
6
14
|
text: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
7
15
|
book: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
8
16
|
pdf: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
@@ -29,7 +37,9 @@ export const QUERY_KEYWORDS = {
|
|
|
29
37
|
game: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
30
38
|
etree: [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
31
39
|
concert: [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
32
|
-
'live music': [
|
|
40
|
+
'live music': [
|
|
41
|
+
{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] },
|
|
42
|
+
],
|
|
33
43
|
dataset: [{ facets: [{ facetType: 'mediatype', bucketKey: 'data' }] }],
|
|
34
44
|
};
|
|
35
|
-
//# sourceMappingURL=query-keywords-
|
|
45
|
+
//# sourceMappingURL=query-keywords-heuristic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"query-keywords-heuristic.js","sourceRoot":"","sources":["../../../../../src/collection-facets/smart-facets/heuristics/query-keywords-heuristic.ts"],"names":[],"mappings":"AAMA,6EAA6E;AAC7E,MAAM,OAAO,sBAAsB;IAkCjC,KAAK,CAAC,oBAAoB,CAAC,KAAa;QACtC,MAAM,eAAe,GAAiB,EAAE,CAAC;QAEzC,KAAK,MAAM,CAAC,OAAO,EAAE,MAAM,CAAC,IAAI,MAAM,CAAC,OAAO,CAC5C,sBAAsB,CAAC,QAAQ,CAChC,EAAE,CAAC;YACF,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;;AA7CuB,+BAAQ,GAAoB;IAClD,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,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACpE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACnE,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,E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AE;QACZ,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE;KAC7D;IACD,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,CAAC,EAAE,CAAC;CACvE,CAAC","sourcesContent":["import type {\n SmartQueryHeuristic,\n KeywordFacetMap,\n SmartFacet,\n} from '../models';\n\n// If the query contains X word but Y facet isn't selected, recommend facet Y\nexport class QueryKeywordsHeuristic implements SmartQueryHeuristic {\n private static readonly KEYWORDS: 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': [\n { facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] },\n ],\n dataset: [{ facets: [{ facetType: 'mediatype', bucketKey: 'data' }] }],\n };\n\n async getRecommendedFacets(query: string): Promise<SmartFacet[]> {\n const recommendations: SmartFacet[] = [];\n\n for (const [keyword, facets] of Object.entries(\n QueryKeywordsHeuristic.KEYWORDS,\n )) {\n if (query.includes(keyword)) {\n recommendations.push(...facets);\n }\n }\n\n return recommendations;\n }\n}\n"]}
|
|
@@ -1,11 +1,51 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
// If wikidata describes the top query result as X, recommend facet Y, e.g.:
|
|
2
|
+
// X Y
|
|
3
|
+
// written work mt:texts
|
|
4
|
+
// film mt:movies
|
|
5
|
+
// author mt:texts and creator:<query>
|
|
6
|
+
// filmmaker mt:movies and creator:<query>
|
|
7
|
+
// photographer mt:image and creator:<query>
|
|
8
|
+
// visual artist mt:image and creator:<query>
|
|
9
|
+
// etc.
|
|
10
|
+
export class WikidataHeuristic {
|
|
11
|
+
async getRecommendedFacets(query) {
|
|
12
|
+
var _a;
|
|
13
|
+
const recommendations = [];
|
|
14
|
+
try {
|
|
15
|
+
const urlQuery = encodeURIComponent(query);
|
|
16
|
+
const wikidataResponse = await fetch(`https://www.wikidata.org/w/api.php?action=wbsearchentities&search=${urlQuery}&format=json&language=en&uselang=en&origin=*&type=item&limit=5`);
|
|
17
|
+
const searchResults = await wikidataResponse.json();
|
|
18
|
+
for (const [keyword, facets] of Object.entries(WikidataHeuristic.ENTITIES)) {
|
|
19
|
+
const keywordRegex = new RegExp(`\\b${keyword}\\b`);
|
|
20
|
+
if (keywordRegex.test((_a = searchResults.search[0]) === null || _a === void 0 ? void 0 : _a.description)) {
|
|
21
|
+
const entityName = searchResults.search[0].label;
|
|
22
|
+
recommendations.push(...facets.map(sf => {
|
|
23
|
+
var _a;
|
|
24
|
+
return ({
|
|
25
|
+
label: (_a = sf.label) === null || _a === void 0 ? void 0 : _a.replace('__QUERY', entityName),
|
|
26
|
+
facets: sf.facets.map(f => {
|
|
27
|
+
var _a;
|
|
28
|
+
const replaced = {
|
|
29
|
+
...f,
|
|
30
|
+
bucketKey: f.bucketKey.replace('__QUERY', query),
|
|
31
|
+
};
|
|
32
|
+
if (f.displayText) {
|
|
33
|
+
replaced.displayText = (_a = replaced.displayText) === null || _a === void 0 ? void 0 : _a.replace('__QUERY', entityName);
|
|
34
|
+
}
|
|
35
|
+
return replaced;
|
|
36
|
+
}),
|
|
37
|
+
});
|
|
38
|
+
}));
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
return recommendations;
|
|
42
|
+
}
|
|
43
|
+
catch (_b) {
|
|
44
|
+
return [];
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
WikidataHeuristic.ENTITIES = {
|
|
9
49
|
'written work': [
|
|
10
50
|
{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] },
|
|
11
51
|
],
|
|
@@ -130,4 +170,4 @@ export const WIKIDATA_ENTITIES = {
|
|
|
130
170
|
},
|
|
131
171
|
],
|
|
132
172
|
};
|
|
133
|
-
//# sourceMappingURL=wikidata-
|
|
173
|
+
//# sourceMappingURL=wikidata-heuristic.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"wikidata-heuristic.js","sourceRoot":"","sources":["../../../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\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 static readonly ENTITIES: 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\n async getRecommendedFacets(query: string): Promise<SmartFacet[]> {\n const recommendations: SmartFacet[] = [];\n\n try {\n const urlQuery = encodeURIComponent(query);\n\n const wikidataResponse = await fetch(\n `https://www.wikidata.org/w/api.php?action=wbsearchentities&search=${urlQuery}&format=json&language=en&uselang=en&origin=*&type=item&limit=5`,\n );\n const searchResults = await wikidataResponse.json();\n\n for (const [keyword, facets] of Object.entries(\n WikidataHeuristic.ENTITIES,\n )) {\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 ...facets.map(\n sf =>\n ({\n label: sf.label?.replace('__QUERY', entityName),\n facets: sf.facets.map(f => {\n const replaced = {\n ...f,\n bucketKey: f.bucketKey.replace('__QUERY', query),\n };\n\n if (f.displayText) {\n replaced.displayText = replaced.displayText?.replace(\n '__QUERY',\n entityName,\n );\n }\n\n return replaced;\n }),\n }) as SmartFacet,\n ),\n );\n }\n }\n\n return recommendations;\n } catch {\n return [];\n }\n }\n}\n"]}
|
|
@@ -21,10 +21,6 @@ export interface SmartFacetEvent {
|
|
|
21
21
|
}
|
|
22
22
|
export type KeywordFacetMap = Record<string, SmartFacet[]>;
|
|
23
23
|
export interface SmartQueryHeuristic {
|
|
24
|
-
/**
|
|
25
|
-
* Resolves to a recommended set of facets to apply for the given query
|
|
26
|
-
* @param query The search query to recommend facets for
|
|
27
|
-
*/
|
|
28
24
|
getRecommendedFacets(query: string): Promise<SmartFacet[]>;
|
|
29
25
|
}
|
|
30
26
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/collection-facets/smart-facets/models.ts"],"names":[],"mappings":"","sourcesContent":["import type { FacetEventDetails, FacetOption } from '../../models';\n\nexport interface FacetRef {\n facetType: FacetOption;\n bucketKey: string;\n displayText?: string;\n}\n\ninterface LabeledSmartFacet {\n label: string;\n facets: FacetRef[];\n selected?: boolean;\n}\n\ninterface UnlabeledSmartFacet {\n label?: string;\n facets: [FacetRef];\n selected?: boolean;\n}\n\nexport type SmartFacet = LabeledSmartFacet | UnlabeledSmartFacet;\n\nexport interface SmartFacetEvent {\n smartFacet: SmartFacet;\n details: FacetEventDetails[];\n}\n\nexport type KeywordFacetMap = Record<string, SmartFacet[]>;\n\nexport interface SmartQueryHeuristic {\n
|
|
1
|
+
{"version":3,"file":"models.js","sourceRoot":"","sources":["../../../../src/collection-facets/smart-facets/models.ts"],"names":[],"mappings":"","sourcesContent":["import type { FacetEventDetails, FacetOption } from '../../models';\n\nexport interface FacetRef {\n facetType: FacetOption;\n bucketKey: string;\n displayText?: string;\n}\n\ninterface LabeledSmartFacet {\n label: string;\n facets: FacetRef[];\n selected?: boolean;\n}\n\ninterface UnlabeledSmartFacet {\n label?: string;\n facets: [FacetRef];\n selected?: boolean;\n}\n\nexport type SmartFacet = LabeledSmartFacet | UnlabeledSmartFacet;\n\nexport interface SmartFacetEvent {\n smartFacet: SmartFacet;\n details: FacetEventDetails[];\n}\n\nexport type KeywordFacetMap = Record<string, SmartFacet[]>;\n\nexport interface SmartQueryHeuristic {\n getRecommendedFacets(query: string): Promise<SmartFacet[]>;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { SmartFacet, SmartQueryHeuristic } from './models';
|
|
2
2
|
export declare class SmartQueryHeuristicGroup implements SmartQueryHeuristic {
|
|
3
|
-
private static readonly
|
|
4
|
-
getRecommendedFacets(query: string
|
|
3
|
+
private static readonly HEURISTICS;
|
|
4
|
+
getRecommendedFacets(query: string): Promise<SmartFacet[]>;
|
|
5
5
|
}
|
|
@@ -1,18 +1,16 @@
|
|
|
1
1
|
import { dedupe } from './dedupe';
|
|
2
|
-
import { BrowserLanguageHeuristic } from './heuristics/browser-language
|
|
3
|
-
import { QueryKeywordsHeuristic } from './heuristics/query-keywords
|
|
4
|
-
import { WikidataHeuristic } from './heuristics/wikidata
|
|
2
|
+
import { BrowserLanguageHeuristic } from './heuristics/browser-language-heuristic';
|
|
3
|
+
import { QueryKeywordsHeuristic } from './heuristics/query-keywords-heuristic';
|
|
4
|
+
import { WikidataHeuristic } from './heuristics/wikidata-heuristic';
|
|
5
5
|
export class SmartQueryHeuristicGroup {
|
|
6
|
-
async getRecommendedFacets(query
|
|
7
|
-
const promises =
|
|
6
|
+
async getRecommendedFacets(query) {
|
|
7
|
+
const promises = SmartQueryHeuristicGroup.HEURISTICS.map(HeuristicCtor => new HeuristicCtor().getRecommendedFacets(query));
|
|
8
8
|
return dedupe((await Promise.all(promises)).flat());
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
|
|
12
|
-
// prettier-ignore
|
|
13
|
-
SmartQueryHeuristicGroup.DEFAULT_HEURISTICS = [
|
|
11
|
+
SmartQueryHeuristicGroup.HEURISTICS = [
|
|
14
12
|
QueryKeywordsHeuristic,
|
|
15
13
|
WikidataHeuristic,
|
|
16
|
-
BrowserLanguageHeuristic
|
|
14
|
+
BrowserLanguageHeuristic,
|
|
17
15
|
];
|
|
18
16
|
//# sourceMappingURL=smart-facet-heuristics.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"smart-facet-heuristics.js","sourceRoot":"","sources":["../../../../src/collection-facets/smart-facets/smart-facet-heuristics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"smart-facet-heuristics.js","sourceRoot":"","sources":["../../../../src/collection-facets/smart-facets/smart-facet-heuristics.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAClC,OAAO,EAAE,wBAAwB,EAAE,MAAM,yCAAyC,CAAC;AACnF,OAAO,EAAE,sBAAsB,EAAE,MAAM,uCAAuC,CAAC;AAC/E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AAGpE,MAAM,OAAO,wBAAwB;IAOnC,KAAK,CAAC,oBAAoB,CAAC,KAAa;QACtC,MAAM,QAAQ,GAAG,wBAAwB,CAAC,UAAU,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CACvE,IAAI,aAAa,EAAE,CAAC,oBAAoB,CAAC,KAAK,CAAC,CAChD,CAAC;QAEF,OAAO,MAAM,CAAC,CAAC,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;IACtD,CAAC;;AAZuB,mCAAU,GAAG;IACnC,sBAAsB;IACtB,iBAAiB;IACjB,wBAAwB;CACzB,CAAC","sourcesContent":["import { dedupe } from './dedupe';\nimport { BrowserLanguageHeuristic } from './heuristics/browser-language-heuristic';\nimport { QueryKeywordsHeuristic } from './heuristics/query-keywords-heuristic';\nimport { WikidataHeuristic } from './heuristics/wikidata-heuristic';\nimport type { SmartFacet, SmartQueryHeuristic } from './models';\n\nexport class SmartQueryHeuristicGroup implements SmartQueryHeuristic {\n private static readonly HEURISTICS = [\n QueryKeywordsHeuristic,\n WikidataHeuristic,\n BrowserLanguageHeuristic,\n ];\n\n async getRecommendedFacets(query: string): Promise<SmartFacet[]> {\n const promises = SmartQueryHeuristicGroup.HEURISTICS.map(HeuristicCtor =>\n new HeuristicCtor().getRecommendedFacets(query),\n );\n\n return dedupe((await Promise.all(promises)).flat());\n }\n}\n"]}
|
package/index.ts
CHANGED
|
@@ -3,14 +3,7 @@ export { CollectionBrowserDataSource } from './src/data-source/collection-browse
|
|
|
3
3
|
export { CollectionBrowserDataSourceInterface } from './src/data-source/collection-browser-data-source-interface';
|
|
4
4
|
export { CollectionBrowserQueryState } from './src/data-source/collection-browser-query-state';
|
|
5
5
|
export { SortFilterBar } from './src/sort-filter-bar/sort-filter-bar';
|
|
6
|
-
export {
|
|
7
|
-
CollectionDisplayMode,
|
|
8
|
-
SortField,
|
|
9
|
-
TileModel,
|
|
10
|
-
FacetOption,
|
|
11
|
-
SelectedFacets,
|
|
12
|
-
getDefaultSelectedFacets,
|
|
13
|
-
} from './src/models';
|
|
6
|
+
export { CollectionDisplayMode, SortField, TileModel } from './src/models';
|
|
14
7
|
export { CollectionBrowserLoadingTile } from './src/tiles/collection-browser-loading-tile';
|
|
15
8
|
export { CollectionTile } from './src/tiles/grid/collection-tile';
|
|
16
9
|
export { AccountTile } from './src/tiles/grid/account-tile';
|
|
@@ -18,10 +11,3 @@ export { ItemTile } from './src/tiles/grid/item-tile';
|
|
|
18
11
|
export { TileList } from './src/tiles/list/tile-list';
|
|
19
12
|
export { TileListCompact } from './src/tiles/list/tile-list-compact';
|
|
20
13
|
export { TileDispatcher } from './src/tiles/tile-dispatcher';
|
|
21
|
-
export {
|
|
22
|
-
SmartQueryHeuristic,
|
|
23
|
-
KeywordFacetMap,
|
|
24
|
-
SmartFacet,
|
|
25
|
-
} from './src/collection-facets/smart-facets/models';
|
|
26
|
-
export * from './src/collection-facets/smart-facets/heuristics/index';
|
|
27
|
-
export { SmartQueryHeuristicGroup } from './src/collection-facets/smart-facets/smart-facet-heuristics';
|
package/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"description": "The Internet Archive Collection Browser.",
|
|
4
4
|
"license": "AGPL-3.0-only",
|
|
5
5
|
"author": "Internet Archive",
|
|
6
|
-
"version": "2.8.1-alpha-
|
|
6
|
+
"version": "2.8.1-alpha-webdev7386.0",
|
|
7
7
|
"main": "dist/index.js",
|
|
8
8
|
"module": "dist/index.js",
|
|
9
9
|
"scripts": {
|
|
@@ -815,9 +815,12 @@ export class CollectionBrowser
|
|
|
815
815
|
this.dispatchEvent(
|
|
816
816
|
new CustomEvent<{ items: string[] }>('itemRemovalRequested', {
|
|
817
817
|
detail: {
|
|
818
|
-
items: this.dataSource.checkedTileModels.map(model =>
|
|
819
|
-
|
|
820
|
-
|
|
818
|
+
items: this.dataSource.checkedTileModels.map(model => {
|
|
819
|
+
// For favorited searches, we attach a search: prefix to differentiate it from an item
|
|
820
|
+
const searchPrefix = model?.mediatype === 'search' ? 'search:' : '';
|
|
821
|
+
const identifier = model?.identifier ?? '';
|
|
822
|
+
return `${searchPrefix}${identifier}`;
|
|
823
|
+
}),
|
|
821
824
|
},
|
|
822
825
|
}),
|
|
823
826
|
);
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SmartQueryHeuristic,
|
|
3
|
+
KeywordFacetMap,
|
|
4
|
+
SmartFacet,
|
|
5
|
+
} from '../models';
|
|
6
|
+
|
|
7
|
+
// If the query contains X word but Y facet isn't selected, recommend facet Y
|
|
8
|
+
export class QueryKeywordsHeuristic implements SmartQueryHeuristic {
|
|
9
|
+
private static readonly KEYWORDS: KeywordFacetMap = {
|
|
10
|
+
text: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
11
|
+
book: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
12
|
+
pdf: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
13
|
+
epub: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
14
|
+
audio: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
15
|
+
song: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
16
|
+
music: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
17
|
+
listen: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
18
|
+
podcast: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
19
|
+
radio: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
20
|
+
stream: [
|
|
21
|
+
{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] },
|
|
22
|
+
{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] },
|
|
23
|
+
],
|
|
24
|
+
video: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
25
|
+
movie: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
26
|
+
film: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
27
|
+
image: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
28
|
+
photo: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
29
|
+
picture: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
30
|
+
software: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
31
|
+
app: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
32
|
+
program: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
33
|
+
game: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
34
|
+
etree: [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
35
|
+
concert: [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
36
|
+
'live music': [
|
|
37
|
+
{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] },
|
|
38
|
+
],
|
|
39
|
+
dataset: [{ facets: [{ facetType: 'mediatype', bucketKey: 'data' }] }],
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
async getRecommendedFacets(query: string): Promise<SmartFacet[]> {
|
|
43
|
+
const recommendations: SmartFacet[] = [];
|
|
44
|
+
|
|
45
|
+
for (const [keyword, facets] of Object.entries(
|
|
46
|
+
QueryKeywordsHeuristic.KEYWORDS,
|
|
47
|
+
)) {
|
|
48
|
+
if (query.includes(keyword)) {
|
|
49
|
+
recommendations.push(...facets);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
return recommendations;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
SmartQueryHeuristic,
|
|
3
|
+
KeywordFacetMap,
|
|
4
|
+
SmartFacet,
|
|
5
|
+
} from '../models';
|
|
6
|
+
|
|
7
|
+
// If wikidata describes the top query result as X, recommend facet Y, e.g.:
|
|
8
|
+
// X Y
|
|
9
|
+
// written work mt:texts
|
|
10
|
+
// film mt:movies
|
|
11
|
+
// author mt:texts and creator:<query>
|
|
12
|
+
// filmmaker mt:movies and creator:<query>
|
|
13
|
+
// photographer mt:image and creator:<query>
|
|
14
|
+
// visual artist mt:image and creator:<query>
|
|
15
|
+
// etc.
|
|
16
|
+
export class WikidataHeuristic implements SmartQueryHeuristic {
|
|
17
|
+
private static readonly ENTITIES: KeywordFacetMap = {
|
|
18
|
+
'written work': [
|
|
19
|
+
{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] },
|
|
20
|
+
],
|
|
21
|
+
literature: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
22
|
+
book: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
23
|
+
novel: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
24
|
+
filmmaker: [
|
|
25
|
+
{
|
|
26
|
+
label: 'Films by __QUERY',
|
|
27
|
+
facets: [
|
|
28
|
+
{ facetType: 'mediatype', bucketKey: 'movies' },
|
|
29
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
30
|
+
],
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
author: [
|
|
34
|
+
{
|
|
35
|
+
label: 'Writing by __QUERY',
|
|
36
|
+
facets: [
|
|
37
|
+
{ facetType: 'mediatype', bucketKey: 'texts' },
|
|
38
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
39
|
+
],
|
|
40
|
+
},
|
|
41
|
+
],
|
|
42
|
+
writer: [
|
|
43
|
+
{
|
|
44
|
+
label: 'Writing by __QUERY',
|
|
45
|
+
facets: [
|
|
46
|
+
{ facetType: 'mediatype', bucketKey: 'texts' },
|
|
47
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
48
|
+
],
|
|
49
|
+
},
|
|
50
|
+
],
|
|
51
|
+
poet: [
|
|
52
|
+
{
|
|
53
|
+
label: 'Writing by __QUERY',
|
|
54
|
+
facets: [
|
|
55
|
+
{ facetType: 'mediatype', bucketKey: 'texts' },
|
|
56
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
57
|
+
],
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
photographer: [
|
|
61
|
+
{
|
|
62
|
+
label: 'Images by __QUERY',
|
|
63
|
+
facets: [
|
|
64
|
+
{ facetType: 'mediatype', bucketKey: 'image' },
|
|
65
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
66
|
+
],
|
|
67
|
+
},
|
|
68
|
+
],
|
|
69
|
+
painter: [
|
|
70
|
+
{
|
|
71
|
+
label: 'Images by __QUERY',
|
|
72
|
+
facets: [
|
|
73
|
+
{ facetType: 'mediatype', bucketKey: 'image' },
|
|
74
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
75
|
+
],
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
'visual artist': [
|
|
79
|
+
{
|
|
80
|
+
label: 'Images by __QUERY',
|
|
81
|
+
facets: [
|
|
82
|
+
{ facetType: 'mediatype', bucketKey: 'image' },
|
|
83
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
84
|
+
],
|
|
85
|
+
},
|
|
86
|
+
],
|
|
87
|
+
'graphic artist': [
|
|
88
|
+
{
|
|
89
|
+
label: 'Images by __QUERY',
|
|
90
|
+
facets: [
|
|
91
|
+
{ facetType: 'mediatype', bucketKey: 'image' },
|
|
92
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
93
|
+
],
|
|
94
|
+
},
|
|
95
|
+
],
|
|
96
|
+
singer: [
|
|
97
|
+
{
|
|
98
|
+
label: 'Music by __QUERY',
|
|
99
|
+
facets: [
|
|
100
|
+
{ facetType: 'mediatype', bucketKey: 'audio' },
|
|
101
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
102
|
+
],
|
|
103
|
+
},
|
|
104
|
+
],
|
|
105
|
+
songwriter: [
|
|
106
|
+
{
|
|
107
|
+
label: 'Music by __QUERY',
|
|
108
|
+
facets: [
|
|
109
|
+
{ facetType: 'mediatype', bucketKey: 'audio' },
|
|
110
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
111
|
+
],
|
|
112
|
+
},
|
|
113
|
+
],
|
|
114
|
+
musician: [
|
|
115
|
+
{
|
|
116
|
+
label: 'Music by __QUERY',
|
|
117
|
+
facets: [
|
|
118
|
+
{ facetType: 'mediatype', bucketKey: 'audio' },
|
|
119
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
120
|
+
],
|
|
121
|
+
},
|
|
122
|
+
],
|
|
123
|
+
composer: [
|
|
124
|
+
{
|
|
125
|
+
label: 'Music by __QUERY',
|
|
126
|
+
facets: [
|
|
127
|
+
{ facetType: 'mediatype', bucketKey: 'audio' },
|
|
128
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
129
|
+
],
|
|
130
|
+
},
|
|
131
|
+
],
|
|
132
|
+
pianist: [
|
|
133
|
+
{
|
|
134
|
+
label: 'Music by __QUERY',
|
|
135
|
+
facets: [
|
|
136
|
+
{ facetType: 'mediatype', bucketKey: 'audio' },
|
|
137
|
+
{ facetType: 'creator', bucketKey: '__QUERY' },
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
async getRecommendedFacets(query: string): Promise<SmartFacet[]> {
|
|
144
|
+
const recommendations: SmartFacet[] = [];
|
|
145
|
+
|
|
146
|
+
try {
|
|
147
|
+
const urlQuery = encodeURIComponent(query);
|
|
148
|
+
|
|
149
|
+
const wikidataResponse = await fetch(
|
|
150
|
+
`https://www.wikidata.org/w/api.php?action=wbsearchentities&search=${urlQuery}&format=json&language=en&uselang=en&origin=*&type=item&limit=5`,
|
|
151
|
+
);
|
|
152
|
+
const searchResults = await wikidataResponse.json();
|
|
153
|
+
|
|
154
|
+
for (const [keyword, facets] of Object.entries(
|
|
155
|
+
WikidataHeuristic.ENTITIES,
|
|
156
|
+
)) {
|
|
157
|
+
const keywordRegex = new RegExp(`\\b${keyword}\\b`);
|
|
158
|
+
if (keywordRegex.test(searchResults.search[0]?.description)) {
|
|
159
|
+
const entityName = searchResults.search[0].label;
|
|
160
|
+
recommendations.push(
|
|
161
|
+
...facets.map(
|
|
162
|
+
sf =>
|
|
163
|
+
({
|
|
164
|
+
label: sf.label?.replace('__QUERY', entityName),
|
|
165
|
+
facets: sf.facets.map(f => {
|
|
166
|
+
const replaced = {
|
|
167
|
+
...f,
|
|
168
|
+
bucketKey: f.bucketKey.replace('__QUERY', query),
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
if (f.displayText) {
|
|
172
|
+
replaced.displayText = replaced.displayText?.replace(
|
|
173
|
+
'__QUERY',
|
|
174
|
+
entityName,
|
|
175
|
+
);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return replaced;
|
|
179
|
+
}),
|
|
180
|
+
}) as SmartFacet,
|
|
181
|
+
),
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return recommendations;
|
|
187
|
+
} catch {
|
|
188
|
+
return [];
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
}
|
|
@@ -28,9 +28,5 @@ export interface SmartFacetEvent {
|
|
|
28
28
|
export type KeywordFacetMap = Record<string, SmartFacet[]>;
|
|
29
29
|
|
|
30
30
|
export interface SmartQueryHeuristic {
|
|
31
|
-
/**
|
|
32
|
-
* Resolves to a recommended set of facets to apply for the given query
|
|
33
|
-
* @param query The search query to recommend facets for
|
|
34
|
-
*/
|
|
35
31
|
getRecommendedFacets(query: string): Promise<SmartFacet[]>;
|
|
36
32
|
}
|
|
@@ -1,24 +1,19 @@
|
|
|
1
1
|
import { dedupe } from './dedupe';
|
|
2
|
-
import { BrowserLanguageHeuristic } from './heuristics/browser-language
|
|
3
|
-
import { QueryKeywordsHeuristic } from './heuristics/query-keywords
|
|
4
|
-
import { WikidataHeuristic } from './heuristics/wikidata
|
|
2
|
+
import { BrowserLanguageHeuristic } from './heuristics/browser-language-heuristic';
|
|
3
|
+
import { QueryKeywordsHeuristic } from './heuristics/query-keywords-heuristic';
|
|
4
|
+
import { WikidataHeuristic } from './heuristics/wikidata-heuristic';
|
|
5
5
|
import type { SmartFacet, SmartQueryHeuristic } from './models';
|
|
6
6
|
|
|
7
7
|
export class SmartQueryHeuristicGroup implements SmartQueryHeuristic {
|
|
8
|
-
|
|
9
|
-
// prettier-ignore
|
|
10
|
-
private static readonly DEFAULT_HEURISTICS: (new () => SmartQueryHeuristic)[] = [
|
|
8
|
+
private static readonly HEURISTICS = [
|
|
11
9
|
QueryKeywordsHeuristic,
|
|
12
10
|
WikidataHeuristic,
|
|
13
|
-
BrowserLanguageHeuristic
|
|
11
|
+
BrowserLanguageHeuristic,
|
|
14
12
|
];
|
|
15
13
|
|
|
16
|
-
async getRecommendedFacets(
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
): Promise<SmartFacet[]> {
|
|
20
|
-
const promises = heuristics.map(HeuristicCtor =>
|
|
21
|
-
new HeuristicCtor().getRecommendedFacets(query)
|
|
14
|
+
async getRecommendedFacets(query: string): Promise<SmartFacet[]> {
|
|
15
|
+
const promises = SmartQueryHeuristicGroup.HEURISTICS.map(HeuristicCtor =>
|
|
16
|
+
new HeuristicCtor().getRecommendedFacets(query),
|
|
22
17
|
);
|
|
23
18
|
|
|
24
19
|
return dedupe((await Promise.all(promises)).flat());
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"browser-language-heuristic.js","sourceRoot":"","sources":["../../../../../../src/collection-facets/smart-facets/heuristics/browser-language/browser-language-heuristic.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,wBAAwB;IACnC,KAAK,CAAC,oBAAoB;QACxB,MAAM,mBAAmB,GAAG,SAAS,CAAC,QAAQ,CAAC;QAC/C,MAAM,YAAY,GAChB,wBAAwB,CAAC,sBAAsB,CAAC,mBAAmB,CAAC,CAAC;QACvE,IAAI,CAAC,YAAY;YAAE,OAAO,EAAE,CAAC;QAE7B,OAAO;YACL;gBACE,MAAM,EAAE;oBACN;wBACE,SAAS,EAAE,UAAU;wBACrB,SAAS,EAAE,YAAY;qBACxB;iBACF;aACF;SACF,CAAC;IACJ,CAAC;IAEO,MAAM,CAAC,sBAAsB,CAAC,QAAgB;QACpD,mEAAmE;QACnE,MAAM,YAAY,GAAG,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAC5C,OAAO,IAAI,IAAI,CAAC,YAAY,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,EAAE,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC;IAC9E,CAAC;CACF","sourcesContent":["import type { SmartQueryHeuristic, SmartFacet } from '../../models';\n\nexport class BrowserLanguageHeuristic implements SmartQueryHeuristic {\n async getRecommendedFacets(): Promise<SmartFacet[]> {\n const browserLanguageCode = navigator.language;\n const languageName =\n BrowserLanguageHeuristic.getLanguageDisplayName(browserLanguageCode);\n if (!languageName) return [];\n\n return [\n {\n facets: [\n {\n facetType: 'language',\n bucketKey: languageName,\n },\n ],\n },\n ];\n }\n\n private static getLanguageDisplayName(langCode: string): string | undefined {\n // Strip off any script/region/variant codes for greater generality\n const languageOnly = langCode.split('-')[0];\n return new Intl.DisplayNames(['en'], { type: 'language' }).of(languageOnly);\n }\n}\n"]}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
export { BrowserLanguageHeuristic } from './browser-language/browser-language-heuristic';
|
|
2
|
-
export { QueryKeywordsHeuristic } from './query-keywords/query-keywords-heuristic';
|
|
3
|
-
export { WikidataHeuristic } from './wikidata/wikidata-heuristic';
|
|
4
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/collection-facets/smart-facets/heuristics/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,+CAA+C,CAAC;AACzF,OAAO,EAAE,sBAAsB,EAAE,MAAM,2CAA2C,CAAC;AACnF,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC","sourcesContent":["export { BrowserLanguageHeuristic } from './browser-language/browser-language-heuristic';\nexport { QueryKeywordsHeuristic } from './query-keywords/query-keywords-heuristic';\nexport { WikidataHeuristic } from './wikidata/wikidata-heuristic';\n"]}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { QUERY_KEYWORDS } from './query-keywords-map';
|
|
2
|
-
// If the query contains X keyword but Y facet isn't selected, recommend facet Y
|
|
3
|
-
export class QueryKeywordsHeuristic {
|
|
4
|
-
async getRecommendedFacets(query) {
|
|
5
|
-
const recommendations = [];
|
|
6
|
-
for (const [keyword, facets] of Object.entries(QUERY_KEYWORDS)) {
|
|
7
|
-
if (query.includes(keyword)) {
|
|
8
|
-
recommendations.push(...facets);
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
return recommendations;
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
//# sourceMappingURL=query-keywords-heuristic.js.map
|