wiki-entity 0.5.5 → 0.5.6
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 -30
- package/lib/wikidata/index.js +1 -3
- package/lib/wikipedia/api.js +4 -4
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
2
10
|
function __export(m) {
|
|
3
11
|
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
|
|
4
12
|
}
|
|
@@ -13,30 +21,21 @@ exports.simplifyEntity = simplify_entity_1.simplifyEntity;
|
|
|
13
21
|
__export(require("./simpleEntity"));
|
|
14
22
|
__export(require("./types"));
|
|
15
23
|
function getEntities(params) {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
.
|
|
19
|
-
const entities = wikiDataEntities;
|
|
24
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const lang = params.language || "en";
|
|
26
|
+
const entities = yield wikidata_1.getEntities(params);
|
|
20
27
|
const ids = Object.keys(entities).filter((id) => utils_1.isValidWikiId(id));
|
|
21
|
-
if (ids.length === 0)
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
const tasks = [];
|
|
28
|
+
if (ids.length === 0)
|
|
29
|
+
return [];
|
|
25
30
|
const wikiApi = new api_1.Api({}, params.httpTimeout);
|
|
26
|
-
|
|
27
|
-
if (params.extract) {
|
|
28
|
-
callWikiApi = true;
|
|
31
|
+
if (params.extract)
|
|
29
32
|
wikiApi.extract(params.extract);
|
|
30
|
-
|
|
31
|
-
if (params.redirects) {
|
|
32
|
-
callWikiApi = true;
|
|
33
|
+
if (params.redirects)
|
|
33
34
|
wikiApi.redirects();
|
|
34
|
-
|
|
35
|
-
if (params.categories) {
|
|
36
|
-
callWikiApi = true;
|
|
35
|
+
if (params.categories)
|
|
37
36
|
wikiApi.categories();
|
|
38
|
-
|
|
39
|
-
if (
|
|
37
|
+
const tasks = [];
|
|
38
|
+
if (entities[ids[0]] && entities[ids[0]].sitelinks) {
|
|
40
39
|
const titleIds = ids.reduce((prev, id) => {
|
|
41
40
|
if (entities[id] &&
|
|
42
41
|
entities[id].sitelinks &&
|
|
@@ -57,15 +56,13 @@ function getEntities(params) {
|
|
|
57
56
|
})
|
|
58
57
|
.then((apiResults) => apiResults.forEach((result) => {
|
|
59
58
|
const entity = entities[titleIds[result.title]];
|
|
60
|
-
|
|
59
|
+
entity.pageid = result.pageid;
|
|
60
|
+
if (params.extract)
|
|
61
61
|
entity.extract = result.extract;
|
|
62
|
-
|
|
63
|
-
if (params.redirects) {
|
|
62
|
+
if (params.redirects)
|
|
64
63
|
entity.redirects = result.redirects;
|
|
65
|
-
|
|
66
|
-
if (params.categories) {
|
|
64
|
+
if (params.categories)
|
|
67
65
|
entity.categories = result.categories;
|
|
68
|
-
}
|
|
69
66
|
})));
|
|
70
67
|
}
|
|
71
68
|
if (params.types === true || Array.isArray(params.types)) {
|
|
@@ -83,11 +80,9 @@ function getEntities(params) {
|
|
|
83
80
|
}
|
|
84
81
|
});
|
|
85
82
|
}
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
return Object.keys(resultEntities)
|
|
90
|
-
.map((id) => resultEntities[id])
|
|
83
|
+
yield Promise.all(tasks);
|
|
84
|
+
return Object.keys(entities)
|
|
85
|
+
.map((id) => entities[id])
|
|
91
86
|
.filter((it) => !!it);
|
|
92
87
|
});
|
|
93
88
|
}
|
package/lib/wikidata/index.js
CHANGED
|
@@ -10,9 +10,7 @@ function getEntities(params) {
|
|
|
10
10
|
return api_1.getManyEntities(params).then(function (entities) {
|
|
11
11
|
const ids = Object.keys(entities).filter((id) => utils_1.isValidWikiId(id));
|
|
12
12
|
ids.forEach((id) => {
|
|
13
|
-
console.log(`initial`, JSON.stringify(entities[id]));
|
|
14
13
|
entities[id] = simplify_entity_1.simplifyEntity(lang, entities[id]);
|
|
15
|
-
console.log(`simplified`, JSON.stringify(entities[id]));
|
|
16
14
|
});
|
|
17
15
|
const tasks = [];
|
|
18
16
|
if (~["all", "property"].indexOf(claims)) {
|
|
@@ -102,7 +100,7 @@ function exploreEntityClaims(claims, params) {
|
|
|
102
100
|
pa.forEach((pai) => {
|
|
103
101
|
const val = claims[pai.pid].values[pai.index];
|
|
104
102
|
for (var prop in item) {
|
|
105
|
-
if (~["label", "
|
|
103
|
+
if (~["label", "description"].indexOf(prop)) {
|
|
106
104
|
val[prop] = item[prop];
|
|
107
105
|
}
|
|
108
106
|
}
|
package/lib/wikipedia/api.js
CHANGED
|
@@ -33,14 +33,14 @@ class Api {
|
|
|
33
33
|
.map((id) => data.query.pages[id])
|
|
34
34
|
.map((data) => {
|
|
35
35
|
const item = {
|
|
36
|
-
pageid: data
|
|
37
|
-
title: data
|
|
36
|
+
pageid: data.pageid,
|
|
37
|
+
title: data.title
|
|
38
38
|
};
|
|
39
39
|
if (data["categories"]) {
|
|
40
|
-
item.categories = data["categories"].map((
|
|
40
|
+
item.categories = data["categories"].map((it) => it.title);
|
|
41
41
|
}
|
|
42
42
|
if (data["redirects"]) {
|
|
43
|
-
item.redirects = data["redirects"].map((
|
|
43
|
+
item.redirects = data["redirects"].map((it) => it.title);
|
|
44
44
|
}
|
|
45
45
|
if (data["extract"]) {
|
|
46
46
|
item.extract = data["extract"];
|