@internetarchive/collection-browser 2.8.0 → 2.8.1-alpha-webdev7002.1
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 +4 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/src/collection-facets/smart-facets/heuristics/{browser-language-heuristic.d.ts → browser-language/browser-language-heuristic.d.ts} +1 -1
- package/dist/src/collection-facets/smart-facets/heuristics/browser-language/browser-language-heuristic.js.map +1 -0
- package/dist/src/collection-facets/smart-facets/heuristics/index.d.ts +3 -0
- package/dist/src/collection-facets/smart-facets/heuristics/index.js +4 -0
- package/dist/src/collection-facets/smart-facets/heuristics/index.js.map +1 -0
- package/dist/src/collection-facets/smart-facets/heuristics/{query-keywords-heuristic.d.ts → query-keywords/query-keywords-heuristic.d.ts} +1 -2
- package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.js +14 -0
- package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.js.map +1 -0
- package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.d.ts +6 -0
- package/dist/src/collection-facets/smart-facets/heuristics/{query-keywords-heuristic.js → query-keywords/query-keywords-map.js} +13 -17
- package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.js.map +1 -0
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.d.ts +9 -0
- package/dist/src/collection-facets/smart-facets/heuristics/{wikidata-heuristic.js → wikidata/wikidata-entity-map.js} +9 -49
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.js.map +1 -0
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.d.ts +21 -0
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.js +75 -0
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.js.map +1 -0
- package/dist/src/collection-facets/smart-facets/models.d.ts +4 -0
- 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 +9 -7
- package/dist/src/collection-facets/smart-facets/smart-facet-heuristics.js.map +1 -1
- package/index.ts +15 -1
- package/package.json +1 -1
- package/src/collection-facets/smart-facets/heuristics/{browser-language-heuristic.ts → browser-language/browser-language-heuristic.ts} +1 -1
- package/src/collection-facets/smart-facets/heuristics/index.ts +3 -0
- package/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.ts +17 -0
- package/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.ts +42 -0
- package/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.ts +134 -0
- package/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.ts +89 -0
- package/src/collection-facets/smart-facets/models.ts +4 -0
- package/src/collection-facets/smart-facets/smart-facet-heuristics.ts +12 -7
- package/dist/src/collection-facets/smart-facets/heuristics/browser-language-heuristic.js.map +0 -1
- package/dist/src/collection-facets/smart-facets/heuristics/query-keywords-heuristic.js.map +0 -1
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata-heuristic.d.ts +0 -5
- package/dist/src/collection-facets/smart-facets/heuristics/wikidata-heuristic.js.map +0 -1
- package/src/collection-facets/smart-facets/heuristics/query-keywords-heuristic.ts +0 -55
- package/src/collection-facets/smart-facets/heuristics/wikidata-heuristic.ts +0 -191
- /package/dist/src/collection-facets/smart-facets/heuristics/{browser-language-heuristic.js → browser-language/browser-language-heuristic.js} +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +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 { CollectionDisplayMode, SortField, TileModel } from './src/models';
|
|
6
|
+
export { CollectionDisplayMode, SortField, TileModel, FacetOption, SelectedFacets, getDefaultSelectedFacets, } from './src/models';
|
|
7
7
|
export { CollectionBrowserLoadingTile } from './src/tiles/collection-browser-loading-tile';
|
|
8
8
|
export { CollectionTile } from './src/tiles/grid/collection-tile';
|
|
9
9
|
export { AccountTile } from './src/tiles/grid/account-tile';
|
|
@@ -11,3 +11,6 @@ export { ItemTile } from './src/tiles/grid/item-tile';
|
|
|
11
11
|
export { TileList } from './src/tiles/list/tile-list';
|
|
12
12
|
export { TileListCompact } from './src/tiles/list/tile-list-compact';
|
|
13
13
|
export { TileDispatcher } from './src/tiles/tile-dispatcher';
|
|
14
|
+
export { SmartQueryHeuristic, KeywordFacetMap, SmartFacet, } from './src/collection-facets/smart-facets/models';
|
|
15
|
+
export * from './src/collection-facets/smart-facets/heuristics/index';
|
|
16
|
+
export { SmartQueryHeuristicGroup } from './src/collection-facets/smart-facets/smart-facet-heuristics';
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { CollectionBrowser } from './src/collection-browser';
|
|
2
2
|
export { CollectionBrowserDataSource } from './src/data-source/collection-browser-data-source';
|
|
3
3
|
export { SortFilterBar } from './src/sort-filter-bar/sort-filter-bar';
|
|
4
|
-
export { SortField, TileModel } from './src/models';
|
|
4
|
+
export { SortField, TileModel, getDefaultSelectedFacets, } from './src/models';
|
|
5
5
|
export { CollectionBrowserLoadingTile } from './src/tiles/collection-browser-loading-tile';
|
|
6
6
|
export { CollectionTile } from './src/tiles/grid/collection-tile';
|
|
7
7
|
export { AccountTile } from './src/tiles/grid/account-tile';
|
|
@@ -9,4 +9,6 @@ export { ItemTile } from './src/tiles/grid/item-tile';
|
|
|
9
9
|
export { TileList } from './src/tiles/list/tile-list';
|
|
10
10
|
export { TileListCompact } from './src/tiles/list/tile-list-compact';
|
|
11
11
|
export { TileDispatcher } from './src/tiles/tile-dispatcher';
|
|
12
|
+
export * from './src/collection-facets/smart-facets/heuristics/index';
|
|
13
|
+
export { SmartQueryHeuristicGroup } from './src/collection-facets/smart-facets/smart-facet-heuristics';
|
|
12
14
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kDAAkD,CAAC;AAG/F,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,0BAA0B,CAAC;AAC7D,OAAO,EAAE,2BAA2B,EAAE,MAAM,kDAAkD,CAAC;AAG/F,OAAO,EAAE,aAAa,EAAE,MAAM,uCAAuC,CAAC;AACtE,OAAO,EAEL,SAAS,EACT,SAAS,EAGT,wBAAwB,GACzB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,4BAA4B,EAAE,MAAM,6CAA6C,CAAC;AAC3F,OAAO,EAAE,cAAc,EAAE,MAAM,kCAAkC,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,+BAA+B,CAAC;AAC5D,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,oCAAoC,CAAC;AACrE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAM7D,cAAc,uDAAuD,CAAC;AACtE,OAAO,EAAE,wBAAwB,EAAE,MAAM,6DAA6D,CAAC","sourcesContent":["export { CollectionBrowser } from './src/collection-browser';\nexport { CollectionBrowserDataSource } from './src/data-source/collection-browser-data-source';\nexport { CollectionBrowserDataSourceInterface } from './src/data-source/collection-browser-data-source-interface';\nexport { CollectionBrowserQueryState } from './src/data-source/collection-browser-query-state';\nexport { SortFilterBar } from './src/sort-filter-bar/sort-filter-bar';\nexport {\n CollectionDisplayMode,\n SortField,\n TileModel,\n FacetOption,\n SelectedFacets,\n getDefaultSelectedFacets,\n} from './src/models';\nexport { CollectionBrowserLoadingTile } from './src/tiles/collection-browser-loading-tile';\nexport { CollectionTile } from './src/tiles/grid/collection-tile';\nexport { AccountTile } from './src/tiles/grid/account-tile';\nexport { ItemTile } from './src/tiles/grid/item-tile';\nexport { TileList } from './src/tiles/list/tile-list';\nexport { TileListCompact } from './src/tiles/list/tile-list-compact';\nexport { TileDispatcher } from './src/tiles/tile-dispatcher';\nexport {\n SmartQueryHeuristic,\n KeywordFacetMap,\n SmartFacet,\n} from './src/collection-facets/smart-facets/models';\nexport * from './src/collection-facets/smart-facets/heuristics/index';\nexport { SmartQueryHeuristicGroup } from './src/collection-facets/smart-facets/smart-facet-heuristics';\n"]}
|
|
@@ -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/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"]}
|
|
@@ -0,0 +1,4 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,5 +1,4 @@
|
|
|
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;
|
|
4
3
|
getRecommendedFacets(query: string): Promise<SmartFacet[]>;
|
|
5
4
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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"]}
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (query.includes(keyword)) {
|
|
7
|
-
recommendations.push(...facets);
|
|
8
|
-
}
|
|
9
|
-
}
|
|
10
|
-
return recommendations;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
QueryKeywordsHeuristic.KEYWORDS = {
|
|
1
|
+
/**
|
|
2
|
+
* Map from keywords found in the search query to an array of
|
|
3
|
+
* likely-relevant "smart facets" for those keywords.
|
|
4
|
+
*/
|
|
5
|
+
export const QUERY_KEYWORDS = {
|
|
14
6
|
text: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
15
7
|
book: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
8
|
+
novel: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
9
|
+
magazine: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
10
|
+
newspaper: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
16
11
|
pdf: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
17
12
|
epub: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
18
13
|
audio: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
@@ -28,18 +23,19 @@ QueryKeywordsHeuristic.KEYWORDS = {
|
|
|
28
23
|
video: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
29
24
|
movie: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
30
25
|
film: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
26
|
+
animation: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
27
|
+
youtube: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
31
28
|
image: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
32
29
|
photo: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
33
30
|
picture: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
31
|
+
painting: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
34
32
|
software: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
35
33
|
app: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
36
34
|
program: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
37
35
|
game: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
38
36
|
etree: [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
39
37
|
concert: [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
40
|
-
'live music': [
|
|
41
|
-
{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] },
|
|
42
|
-
],
|
|
38
|
+
'live music': [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
43
39
|
dataset: [{ facets: [{ facetType: 'mediatype', bucketKey: 'data' }] }],
|
|
44
40
|
};
|
|
45
|
-
//# sourceMappingURL=query-keywords-
|
|
41
|
+
//# sourceMappingURL=query-keywords-map.js.map
|
package/dist/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-map.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACpE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACrE,QAAQ,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACxE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE,CAAC;IACzE,GAAG,EAAE,CAAC,EAAE,MAAM,EAAE,CAA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AAC;IACtE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IAC1E,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IACvE,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 novel: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],\n magazine: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],\n newspaper: [{ 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 animation: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],\n youtube: [{ 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 painting: [{ 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"]}
|
|
@@ -0,0 +1,9 @@
|
|
|
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>;
|
|
@@ -1,51 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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 = {
|
|
1
|
+
/**
|
|
2
|
+
* Map from Wikidata description keywords for a given entity to a
|
|
3
|
+
* set of likely-relevant "smart facets" for that query.
|
|
4
|
+
*
|
|
5
|
+
* The placeholder string "__QUERY" should be substituted for the actual
|
|
6
|
+
* queried entity when generating facet values.
|
|
7
|
+
*/
|
|
8
|
+
export const WIKIDATA_ENTITIES = {
|
|
49
9
|
'written work': [
|
|
50
10
|
{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] },
|
|
51
11
|
],
|
|
@@ -170,4 +130,4 @@ WikidataHeuristic.ENTITIES = {
|
|
|
170
130
|
},
|
|
171
131
|
],
|
|
172
132
|
};
|
|
173
|
-
//# sourceMappingURL=wikidata-
|
|
133
|
+
//# sourceMappingURL=wikidata-entity-map.js.map
|
package/dist/src/collection-facets/smart-facets/heuristics/wikidata/wikidata-entity-map.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
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,CAAC,MAAM,iBAAiB,GAA8B;IAC1D,cAAc,EAAE;QACd,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,OAAO,EAAE,CAAC,EAAE;KAC7D;IACD,UAAU,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EA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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"]}
|
|
@@ -0,0 +1,21 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,75 @@
|
|
|
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
|
|
@@ -0,0 +1 @@
|
|
|
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,WAAW,QAAQ,EAAE,CAAC;IACrF,CAAC;IAED;;;;;OAKG;IACK,wBAAwB,CAC9B,WAAyB,EACzB,KAAa;QAEb,OAAO,WAAW,CAAC,GAAG,CACpB,UAAU,CAAC,EAAE;;YACX,OAAA,CAAC;gBACC,oDAAoD;gBACpD,KAAK,EAAE,MAAA,UAAU,CAAC,KAAK,0CAAE,OAAO,CAAC,SAAS,EAAE,KAAK,CAAC;gBAClD,6EA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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"]}
|
|
@@ -21,6 +21,10 @@ 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
|
+
*/
|
|
24
28
|
getRecommendedFacets(query: string): Promise<SmartFacet[]>;
|
|
25
29
|
}
|
|
26
30
|
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 getRecommendedFacets(query: string): Promise<SmartFacet[]>;\n}\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 /**\n * Resolves to a recommended set of facets to apply for the given query\n * @param query The search query to recommend facets for\n */\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): Promise<SmartFacet[]>;
|
|
3
|
+
private static readonly DEFAULT_HEURISTICS;
|
|
4
|
+
getRecommendedFacets(query: string, heuristics?: (new () => SmartQueryHeuristic)[]): Promise<SmartFacet[]>;
|
|
5
5
|
}
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { dedupe } from './dedupe';
|
|
2
|
-
import { BrowserLanguageHeuristic } from './heuristics/browser-language-heuristic';
|
|
3
|
-
import { QueryKeywordsHeuristic } from './heuristics/query-keywords-heuristic';
|
|
4
|
-
import { WikidataHeuristic } from './heuristics/wikidata-heuristic';
|
|
2
|
+
import { BrowserLanguageHeuristic } from './heuristics/browser-language/browser-language-heuristic';
|
|
3
|
+
import { QueryKeywordsHeuristic } from './heuristics/query-keywords/query-keywords-heuristic';
|
|
4
|
+
import { WikidataHeuristic } from './heuristics/wikidata/wikidata-heuristic';
|
|
5
5
|
export class SmartQueryHeuristicGroup {
|
|
6
|
-
async getRecommendedFacets(query) {
|
|
7
|
-
const promises =
|
|
6
|
+
async getRecommendedFacets(query, heuristics = SmartQueryHeuristicGroup.DEFAULT_HEURISTICS) {
|
|
7
|
+
const promises = heuristics.map(HeuristicCtor => new HeuristicCtor().getRecommendedFacets(query));
|
|
8
8
|
return dedupe((await Promise.all(promises)).flat());
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
|
-
|
|
11
|
+
// Avoid collapsing the array onto one line
|
|
12
|
+
// prettier-ignore
|
|
13
|
+
SmartQueryHeuristicGroup.DEFAULT_HEURISTICS = [
|
|
12
14
|
QueryKeywordsHeuristic,
|
|
13
15
|
WikidataHeuristic,
|
|
14
|
-
BrowserLanguageHeuristic
|
|
16
|
+
BrowserLanguageHeuristic
|
|
15
17
|
];
|
|
16
18
|
//# 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,0DAA0D,CAAC;AACpG,OAAO,EAAE,sBAAsB,EAAE,MAAM,sDAAsD,CAAC;AAC9F,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAG7E,MAAM,OAAO,wBAAwB;IASnC,KAAK,CAAC,oBAAoB,CACxB,KAAa,EACb,UAAU,GAAG,wBAAwB,CAAC,kBAAkB;QAExD,MAAM,QAAQ,GAAG,UAAU,CAAC,GAAG,CAAC,aAAa,CAAC,EAAE,CAC9C,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;;AAjBD,2CAA2C;AAC3C,kBAAkB;AACM,2CAAkB,GAAsC;IAC9E,sBAAsB;IACtB,iBAAiB;IACjB,wBAAwB;CACzB,CAAC","sourcesContent":["import { dedupe } from './dedupe';\nimport { BrowserLanguageHeuristic } from './heuristics/browser-language/browser-language-heuristic';\nimport { QueryKeywordsHeuristic } from './heuristics/query-keywords/query-keywords-heuristic';\nimport { WikidataHeuristic } from './heuristics/wikidata/wikidata-heuristic';\nimport type { SmartFacet, SmartQueryHeuristic } from './models';\n\nexport class SmartQueryHeuristicGroup implements SmartQueryHeuristic {\n // Avoid collapsing the array onto one line\n // prettier-ignore\n private static readonly DEFAULT_HEURISTICS: (new () => SmartQueryHeuristic)[] = [\n QueryKeywordsHeuristic,\n WikidataHeuristic,\n BrowserLanguageHeuristic\n ];\n\n async getRecommendedFacets(\n query: string,\n heuristics = SmartQueryHeuristicGroup.DEFAULT_HEURISTICS,\n ): Promise<SmartFacet[]> {\n const promises = 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,7 +3,14 @@ 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 {
|
|
6
|
+
export {
|
|
7
|
+
CollectionDisplayMode,
|
|
8
|
+
SortField,
|
|
9
|
+
TileModel,
|
|
10
|
+
FacetOption,
|
|
11
|
+
SelectedFacets,
|
|
12
|
+
getDefaultSelectedFacets,
|
|
13
|
+
} from './src/models';
|
|
7
14
|
export { CollectionBrowserLoadingTile } from './src/tiles/collection-browser-loading-tile';
|
|
8
15
|
export { CollectionTile } from './src/tiles/grid/collection-tile';
|
|
9
16
|
export { AccountTile } from './src/tiles/grid/account-tile';
|
|
@@ -11,3 +18,10 @@ export { ItemTile } from './src/tiles/grid/item-tile';
|
|
|
11
18
|
export { TileList } from './src/tiles/list/tile-list';
|
|
12
19
|
export { TileListCompact } from './src/tiles/list/tile-list-compact';
|
|
13
20
|
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
package/src/collection-facets/smart-facets/heuristics/query-keywords/query-keywords-heuristic.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
novel: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
11
|
+
magazine: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
12
|
+
newspaper: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
13
|
+
pdf: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
14
|
+
epub: [{ facets: [{ facetType: 'mediatype', bucketKey: 'texts' }] }],
|
|
15
|
+
audio: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
16
|
+
song: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
17
|
+
music: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
18
|
+
listen: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
19
|
+
podcast: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
20
|
+
radio: [{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] }],
|
|
21
|
+
stream: [
|
|
22
|
+
{ facets: [{ facetType: 'mediatype', bucketKey: 'audio' }] },
|
|
23
|
+
{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] },
|
|
24
|
+
],
|
|
25
|
+
video: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
26
|
+
movie: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
27
|
+
film: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
28
|
+
animation: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
29
|
+
youtube: [{ facets: [{ facetType: 'mediatype', bucketKey: 'movies' }] }],
|
|
30
|
+
image: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
31
|
+
photo: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
32
|
+
picture: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
33
|
+
painting: [{ facets: [{ facetType: 'mediatype', bucketKey: 'image' }] }],
|
|
34
|
+
software: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
35
|
+
app: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
36
|
+
program: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
37
|
+
game: [{ facets: [{ facetType: 'mediatype', bucketKey: 'software' }] }],
|
|
38
|
+
etree: [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
39
|
+
concert: [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
40
|
+
'live music': [{ facets: [{ facetType: 'mediatype', bucketKey: 'etree' }] }],
|
|
41
|
+
dataset: [{ facets: [{ facetType: 'mediatype', bucketKey: 'data' }] }],
|
|
42
|
+
};
|
|
@@ -0,0 +1,134 @@
|
|
|
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
|
+
};
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
}
|
|
@@ -28,5 +28,9 @@ 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
|
+
*/
|
|
31
35
|
getRecommendedFacets(query: string): Promise<SmartFacet[]>;
|
|
32
36
|
}
|
|
@@ -1,18 +1,23 @@
|
|
|
1
1
|
import { dedupe } from './dedupe';
|
|
2
|
-
import { BrowserLanguageHeuristic } from './heuristics/browser-language-heuristic';
|
|
3
|
-
import { QueryKeywordsHeuristic } from './heuristics/query-keywords-heuristic';
|
|
4
|
-
import { WikidataHeuristic } from './heuristics/wikidata-heuristic';
|
|
2
|
+
import { BrowserLanguageHeuristic } from './heuristics/browser-language/browser-language-heuristic';
|
|
3
|
+
import { QueryKeywordsHeuristic } from './heuristics/query-keywords/query-keywords-heuristic';
|
|
4
|
+
import { WikidataHeuristic } from './heuristics/wikidata/wikidata-heuristic';
|
|
5
5
|
import type { SmartFacet, SmartQueryHeuristic } from './models';
|
|
6
6
|
|
|
7
7
|
export class SmartQueryHeuristicGroup implements SmartQueryHeuristic {
|
|
8
|
-
|
|
8
|
+
// Avoid collapsing the array onto one line
|
|
9
|
+
// prettier-ignore
|
|
10
|
+
private static readonly DEFAULT_HEURISTICS: (new () => SmartQueryHeuristic)[] = [
|
|
9
11
|
QueryKeywordsHeuristic,
|
|
10
12
|
WikidataHeuristic,
|
|
11
|
-
BrowserLanguageHeuristic
|
|
13
|
+
BrowserLanguageHeuristic
|
|
12
14
|
];
|
|
13
15
|
|
|
14
|
-
async getRecommendedFacets(
|
|
15
|
-
|
|
16
|
+
async getRecommendedFacets(
|
|
17
|
+
query: string,
|
|
18
|
+
heuristics = SmartQueryHeuristicGroup.DEFAULT_HEURISTICS,
|
|
19
|
+
): Promise<SmartFacet[]> {
|
|
20
|
+
const promises = heuristics.map(HeuristicCtor =>
|
|
16
21
|
new HeuristicCtor().getRecommendedFacets(query),
|
|
17
22
|
);
|
|
18
23
|
|
package/dist/src/collection-facets/smart-facets/heuristics/browser-language-heuristic.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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 +0,0 @@
|
|
|
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,CA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M,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IAC1E,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,SAAS,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IACvE,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;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 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"wikidata-heuristic.js","sourceRoot":"","sources":["../../../../../src/collection-facets/smart-facets/heuristics/wikidata-heuristic.ts"],"names":[],"mappings":"AAMA,4EAA4E;AAC5E,m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SAAS,EAAE,SAAS,EAAE,SAAS,EAAE;aAC/C;SACF;KACF;IACD,MAAM,EAAE;QACN;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,UAAU,EAAE;QACV;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,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 {\n SmartQueryHeuristic,\n KeywordFacetMap,\n SmartFacet,\n} from '../models';\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"]}
|
|
@@ -1,55 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,191 +0,0 @@
|
|
|
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
|
-
}
|