wiki-entity 0.5.12 → 0.6.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/lib/index.js +25 -1
- package/lib/wikidata/index.js +1 -1
- package/lib/wikipedia/api.js +9 -9
- package/package.json +1 -1
- package/types/index.d.ts +1 -0
package/lib/index.js
CHANGED
|
@@ -19,7 +19,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
19
19
|
});
|
|
20
20
|
};
|
|
21
21
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
22
|
-
exports.getEntities = exports.WikipediaApi = exports.simplifyEntity = void 0;
|
|
22
|
+
exports.mapRedirects = exports.getEntities = exports.WikipediaApi = exports.simplifyEntity = void 0;
|
|
23
23
|
const wikidata_1 = require("./wikidata");
|
|
24
24
|
const api_1 = require("./wikipedia/api");
|
|
25
25
|
Object.defineProperty(exports, "WikipediaApi", { enumerable: true, get: function () { return api_1.Api; } });
|
|
@@ -100,3 +100,27 @@ function getEntities(params) {
|
|
|
100
100
|
});
|
|
101
101
|
}
|
|
102
102
|
exports.getEntities = getEntities;
|
|
103
|
+
function mapRedirects(titles, lang) {
|
|
104
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
105
|
+
const wikiApi = new api_1.Api();
|
|
106
|
+
return wikiApi
|
|
107
|
+
.redirects()
|
|
108
|
+
.query(lang, {
|
|
109
|
+
titles: titles.map((it) => it.replace(/\s+/g, "_")).join("|"),
|
|
110
|
+
redirects: "yes"
|
|
111
|
+
})
|
|
112
|
+
.then((apiResults) => {
|
|
113
|
+
const result = {};
|
|
114
|
+
apiResults.forEach((r) => {
|
|
115
|
+
var _a;
|
|
116
|
+
if ((_a = r.redirects) === null || _a === void 0 ? void 0 : _a.length) {
|
|
117
|
+
const it = r.redirects.find((it) => titles.includes(it));
|
|
118
|
+
if (it && it !== r.title)
|
|
119
|
+
result[it] = r.title;
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
return result;
|
|
123
|
+
});
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
exports.mapRedirects = mapRedirects;
|
package/lib/wikidata/index.js
CHANGED
package/lib/wikipedia/api.js
CHANGED
|
@@ -33,19 +33,19 @@ class Api {
|
|
|
33
33
|
if (data && data.query && data.query.pages) {
|
|
34
34
|
return Object.keys(data.query.pages)
|
|
35
35
|
.map((id) => data.query.pages[id])
|
|
36
|
-
.map((
|
|
36
|
+
.map((page) => {
|
|
37
37
|
const item = {
|
|
38
|
-
pageid:
|
|
39
|
-
title:
|
|
38
|
+
pageid: page.pageid,
|
|
39
|
+
title: page.title
|
|
40
40
|
};
|
|
41
|
-
if (
|
|
42
|
-
item.categories =
|
|
41
|
+
if (page["categories"]) {
|
|
42
|
+
item.categories = page["categories"].map((it) => it.title);
|
|
43
43
|
}
|
|
44
|
-
if (
|
|
45
|
-
item.redirects =
|
|
44
|
+
if (page["redirects"]) {
|
|
45
|
+
item.redirects = page["redirects"].map((it) => it.title);
|
|
46
46
|
}
|
|
47
|
-
if (
|
|
48
|
-
item.extract =
|
|
47
|
+
if (page["extract"]) {
|
|
48
|
+
item.extract = page["extract"];
|
|
49
49
|
}
|
|
50
50
|
return item;
|
|
51
51
|
});
|
package/package.json
CHANGED
package/types/index.d.ts
CHANGED
|
@@ -5,3 +5,4 @@ export { WikipediaApi };
|
|
|
5
5
|
export * from "./simpleEntity";
|
|
6
6
|
export * from "./types";
|
|
7
7
|
export declare function getEntities(params: WikiEntitiesParams): Promise<WikiEntity[]>;
|
|
8
|
+
export declare function mapRedirects(titles: string[], lang: string): Promise<Record<string, string>>;
|