wiki-entity 0.5.6 → 0.5.7

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 CHANGED
@@ -1,30 +1,39 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
2
12
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
13
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
14
  return new (P || (P = Promise))(function (resolve, reject) {
4
15
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
16
  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); }
17
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
18
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
19
  });
9
20
  };
10
- function __export(m) {
11
- for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
12
- }
13
21
  Object.defineProperty(exports, "__esModule", { value: true });
22
+ exports.getEntities = exports.WikipediaApi = exports.simplifyEntity = void 0;
14
23
  const wikidata_1 = require("./wikidata");
15
24
  const api_1 = require("./wikipedia/api");
16
- exports.WikipediaApi = api_1.Api;
25
+ Object.defineProperty(exports, "WikipediaApi", { enumerable: true, get: function () { return api_1.Api; } });
17
26
  const utils_1 = require("./utils");
18
27
  const get_entity_types_1 = require("./wikidata/get_entity_types");
19
28
  var simplify_entity_1 = require("./wikidata/simplify_entity");
20
- exports.simplifyEntity = simplify_entity_1.simplifyEntity;
21
- __export(require("./simpleEntity"));
22
- __export(require("./types"));
29
+ Object.defineProperty(exports, "simplifyEntity", { enumerable: true, get: function () { return simplify_entity_1.simplifyEntity; } });
30
+ __exportStar(require("./simpleEntity"), exports);
31
+ __exportStar(require("./types"), exports);
23
32
  function getEntities(params) {
24
33
  return __awaiter(this, void 0, void 0, function* () {
25
34
  const lang = params.language || "en";
26
- const entities = yield wikidata_1.getEntities(params);
27
- const ids = Object.keys(entities).filter((id) => utils_1.isValidWikiId(id));
35
+ const entities = yield (0, wikidata_1.getEntities)(params);
36
+ const ids = Object.keys(entities).filter((id) => (0, utils_1.isValidWikiId)(id));
28
37
  if (ids.length === 0)
29
38
  return [];
30
39
  const wikiApi = new api_1.Api({}, params.httpTimeout);
@@ -73,7 +82,7 @@ function getEntities(params) {
73
82
  if (entities[id] && entities[id].sitelinks) {
74
83
  const enName = entities[id].sitelinks["en"];
75
84
  if (enName) {
76
- tasks.push(get_entity_types_1.getEntityTypesByName(enName, prefixes).then((types) => {
85
+ tasks.push((0, get_entity_types_1.getEntityTypesByName)(enName, prefixes).then((types) => {
77
86
  entities[id].types = types;
78
87
  }));
79
88
  }
package/lib/request.js CHANGED
@@ -1,9 +1,10 @@
1
1
  "use strict";
2
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
4
5
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
6
  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
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
@@ -11,7 +12,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
11
12
  const axios_1 = require("axios");
12
13
  function default_1(url, options) {
13
14
  return __awaiter(this, void 0, void 0, function* () {
14
- const response = yield axios_1.default(url, Object.assign({ method: "GET", responseType: "json", headers: { "User-Agent": "entity-finder" } }, options, { timeout: options.timeout || 10 * 1000 }));
15
+ const response = yield (0, axios_1.default)(url, Object.assign(Object.assign({ method: "GET", responseType: "json", headers: { "User-Agent": "entity-finder" } }, options), { timeout: options.timeout || 10 * 1000 }));
15
16
  return response.data;
16
17
  });
17
18
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToSimpleEntity = void 0;
3
4
  const getEntityType_1 = require("./getEntityType");
4
5
  const getEntityInstanceType_1 = require("./getEntityInstanceType");
5
6
  const getEntityTypeByExtract_1 = require("./getEntityTypeByExtract");
@@ -18,13 +19,13 @@ function convertToSimpleEntity(wikiEntity, lang, options) {
18
19
  if (wikiEntity.redirectsToId)
19
20
  entity.redirectsToId = wikiEntity.redirectsToId;
20
21
  if (wikiEntity.types) {
21
- entity.types = utils_1.uniq(wikiEntity.types.filter((item) => !/:(Thing|Agent)$/.test(item)));
22
+ entity.types = (0, utils_1.uniq)(wikiEntity.types.filter((item) => !/:(Thing|Agent)$/.test(item)));
22
23
  }
23
- entity.type = getEntityType_1.getEntityType(wikiEntity);
24
+ entity.type = (0, getEntityType_1.getEntityType)(wikiEntity);
24
25
  if (!entity.type) {
25
- entity.type = getEntityInstanceType_1.getEntityType(wikiEntity);
26
+ entity.type = (0, getEntityInstanceType_1.getEntityType)(wikiEntity);
26
27
  if (!entity.type && entity.about && !entity.types) {
27
- entity.type = getEntityTypeByExtract_1.getEntityTypeByExtract(entity.about, lang);
28
+ entity.type = (0, getEntityTypeByExtract_1.getEntityTypeByExtract)(entity.about, lang);
28
29
  }
29
30
  if (!entity.type && options.defaultType) {
30
31
  entity.type = options.defaultType;
@@ -37,14 +38,14 @@ function convertToSimpleEntity(wikiEntity, lang, options) {
37
38
  if (wikiEntity.claims) {
38
39
  const ids = Object.keys(wikiEntity.claims);
39
40
  if (ids.length) {
40
- entity.data = getEntityData_1.getEntityData(wikiEntity);
41
+ entity.data = (0, getEntityData_1.getEntityData)(wikiEntity);
41
42
  }
42
- entity.countryCodes = getEntityCountry_1.getEntityCountryCode(wikiEntity);
43
+ entity.countryCodes = (0, getEntityCountry_1.getEntityCountryCode)(wikiEntity);
43
44
  }
44
45
  return entity;
45
46
  }
46
47
  exports.convertToSimpleEntity = convertToSimpleEntity;
47
48
  function createCategories(entity) {
48
49
  let categories = entity.categories || [];
49
- return utils_1.uniq(categories);
50
+ return (0, utils_1.uniq)(categories);
50
51
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntityCountryCode = void 0;
3
4
  const countries = require('../../data/countries.json');
4
5
  function getEntityCountryCode(wikiEntity) {
5
6
  if (!wikiEntity) {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntityData = void 0;
3
4
  function getEntityData(wikiEntity) {
4
5
  if (!wikiEntity.claims) {
5
6
  return null;
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntityType = void 0;
3
4
  const simpleEntity_1 = require("./simpleEntity");
4
5
  function getEntityType(wikiEntity) {
5
6
  if (!wikiEntity.claims) {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntityType = void 0;
3
4
  const simpleEntity_1 = require("./simpleEntity");
4
5
  const TYPES_MAP = {
5
6
  'dbo:FictionalCharacter': simpleEntity_1.SimpleEntityType.WORK,
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntityTypeByExtract = void 0;
3
4
  const simpleEntity_1 = require("./simpleEntity");
4
5
  const MAP = {
5
6
  ro: [
@@ -1,6 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.convertToSimpleEntity = exports.SimpleEntityType = void 0;
3
4
  var simpleEntity_1 = require("./simpleEntity");
4
- exports.SimpleEntityType = simpleEntity_1.SimpleEntityType;
5
+ Object.defineProperty(exports, "SimpleEntityType", { enumerable: true, get: function () { return simpleEntity_1.SimpleEntityType; } });
5
6
  var convertToSimpleEntity_1 = require("./convertToSimpleEntity");
6
- exports.convertToSimpleEntity = convertToSimpleEntity_1.convertToSimpleEntity;
7
+ Object.defineProperty(exports, "convertToSimpleEntity", { enumerable: true, get: function () { return convertToSimpleEntity_1.convertToSimpleEntity; } });
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SIMPLE_ENTITY_TYPES = exports.SimpleEntityType = void 0;
3
4
  var SimpleEntityType;
4
5
  (function (SimpleEntityType) {
5
6
  SimpleEntityType["EVENT"] = "E";
package/lib/types.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.WikidataPropsParam = void 0;
3
4
  var WikidataPropsParam;
4
5
  (function (WikidataPropsParam) {
5
6
  WikidataPropsParam["info"] = "info";
package/lib/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isValidWikiId = exports.uniq = exports.eachSeries = void 0;
3
4
  function eachSeries(arr, iteratorFn) {
4
5
  return arr.reduce((p, item) => p.then(() => iteratorFn(item)), Promise.resolve());
5
6
  }
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
4
5
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
6
  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
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.validateParams = exports.getManyEntities = exports.getEntities = void 0;
11
13
  const request_1 = require("../request");
12
14
  const types_1 = require("../types");
13
15
  const utils_1 = require("../utils");
@@ -38,7 +40,7 @@ function getEntities(params) {
38
40
  else {
39
41
  delete qs.sites;
40
42
  }
41
- const data = yield request_1.default(API_URL, {
43
+ const data = yield (0, request_1.default)(API_URL, {
42
44
  params: qs,
43
45
  timeout: params.httpTimeout
44
46
  });
@@ -49,7 +51,7 @@ function getEntities(params) {
49
51
  const entity = entities[id];
50
52
  if (entity.redirects && entity.redirects.to)
51
53
  entity.redirectsToId = entity.redirects.to;
52
- if (!utils_1.isValidWikiId(id) || ~Object.keys(entities[id]).indexOf("missing")) {
54
+ if (!(0, utils_1.isValidWikiId)(id) || ~Object.keys(entities[id]).indexOf("missing")) {
53
55
  delete entities[id];
54
56
  }
55
57
  }
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getEntityTypesByName = void 0;
3
4
  const request_1 = require("../request");
4
5
  const PREFIXES_MAP = {
5
6
  "http://www.ontologydesignpatterns.org/ont/dul/DUL.owl#": "dul",
@@ -35,7 +36,7 @@ function parseTypes(types) {
35
36
  function dbpediaTypes(name) {
36
37
  const url = `http://dbpedia.org/resource/${name.replace(/\s+/g, "_")}`;
37
38
  const query = `SELECT ?type WHERE { <${url}> rdf:type ?type }`;
38
- return request_1.default("http://dbpedia.org/sparql", {
39
+ return (0, request_1.default)("http://dbpedia.org/sparql", {
39
40
  params: { query: query },
40
41
  timeout: 30 * 1000
41
42
  })
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.exploreEntityClaims = exports.getEntities = void 0;
3
4
  const types_1 = require("../types");
4
5
  const api_1 = require("./api");
5
6
  const simplify_entity_1 = require("./simplify_entity");
@@ -7,17 +8,17 @@ const utils_1 = require("../utils");
7
8
  function getEntities(params) {
8
9
  const claims = params.claims || "none";
9
10
  const lang = params.language || "en";
10
- return api_1.getManyEntities(params).then(function (entities) {
11
- const ids = Object.keys(entities).filter((id) => utils_1.isValidWikiId(id));
11
+ return (0, api_1.getManyEntities)(params).then(function (entities) {
12
+ const ids = Object.keys(entities).filter((id) => (0, utils_1.isValidWikiId)(id));
12
13
  ids.forEach((id) => {
13
- entities[id] = simplify_entity_1.simplifyEntity(lang, entities[id]);
14
+ entities[id] = (0, simplify_entity_1.simplifyEntity)(lang, entities[id]);
14
15
  });
15
16
  const tasks = [];
16
17
  if (~["all", "property"].indexOf(claims)) {
17
18
  tasks.push(exploreEntitiesProperties(entities, lang));
18
19
  }
19
20
  if (~["all", "item"].indexOf(claims)) {
20
- tasks.push(utils_1.eachSeries(ids, (id) => exploreEntityClaims(entities[id].claims, { language: lang })));
21
+ tasks.push((0, utils_1.eachSeries)(ids, (id) => exploreEntityClaims(entities[id].claims, { language: lang })));
21
22
  }
22
23
  return Promise.all(tasks).then(() => entities);
23
24
  });
@@ -35,7 +36,7 @@ function exploreEntitiesProperties(entities, lang) {
35
36
  if (!ids.length) {
36
37
  return Promise.resolve();
37
38
  }
38
- ids = utils_1.uniq(ids);
39
+ ids = (0, utils_1.uniq)(ids);
39
40
  return getEntities({
40
41
  ids: ids,
41
42
  language: lang,
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simplifyClaim = exports.simplifyPropertyClaims = exports.simplifyClaims = void 0;
3
4
  function simplifyClaims(claims) {
4
5
  const simpleClaims = {};
5
6
  for (let id in claims) {
@@ -1,5 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.simplifySitelinks = exports.simplifyLabels = exports.simplifyDescriptions = exports.simplifyAliases = exports.simplifyEntity = void 0;
3
4
  const simplify_claims_1 = require("./simplify_claims");
4
5
  function simplifyEntity(lang, data, options = {}) {
5
6
  const entity = { id: data.id };
@@ -24,7 +25,7 @@ function simplifyEntity(lang, data, options = {}) {
24
25
  if (options.sitelinks !== false && data.sitelinks)
25
26
  entity.sitelinks = simplifySitelinks(data.sitelinks);
26
27
  if (options.claims !== false && data.claims)
27
- entity.claims = simplify_claims_1.simplifyClaims(data.claims);
28
+ entity.claims = (0, simplify_claims_1.simplifyClaims)(data.claims);
28
29
  return entity;
29
30
  }
30
31
  exports.simplifyEntity = simplifyEntity;
@@ -1,13 +1,15 @@
1
1
  "use strict";
2
2
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
4
  return new (P || (P = Promise))(function (resolve, reject) {
4
5
  function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
6
  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
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
8
  step((generator = generator.apply(thisArg, _arguments || [])).next());
8
9
  });
9
10
  };
10
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.getRedirects = exports.getExtract = exports.getExtracts = exports.Api = void 0;
11
13
  const request_1 = require("../request");
12
14
  const API_URL = "https://$lang.wikipedia.org/w/api.php";
13
15
  class Api {
@@ -22,7 +24,7 @@ class Api {
22
24
  return __awaiter(this, void 0, void 0, function* () {
23
25
  if (qs)
24
26
  this.qs = Object.assign({}, this.qs, qs);
25
- const data = yield request_1.default(API_URL.replace("$lang", lang), {
27
+ const data = yield (0, request_1.default)(API_URL.replace("$lang", lang), {
26
28
  params: this.qs,
27
29
  timeout: this.httpTimeout
28
30
  });
@@ -89,7 +91,7 @@ function getExtracts(params) {
89
91
  exsectionformat: "plain",
90
92
  format: "json"
91
93
  };
92
- const data = yield request_1.default(API_URL.replace("$lang", params.lang), {
94
+ const data = yield (0, request_1.default)(API_URL.replace("$lang", params.lang), {
93
95
  params: qs
94
96
  });
95
97
  if (hasError(data))
@@ -101,7 +103,7 @@ function getExtracts(params) {
101
103
  });
102
104
  }
103
105
  exports.getExtracts = getExtracts;
104
- exports.getExtract = (lang, title, sentences) => getExtracts({
106
+ const getExtract = (lang, title, sentences) => getExtracts({
105
107
  lang: lang,
106
108
  titles: [title],
107
109
  sentences: sentences
@@ -111,6 +113,7 @@ exports.getExtract = (lang, title, sentences) => getExtracts({
111
113
  }
112
114
  return null;
113
115
  });
116
+ exports.getExtract = getExtract;
114
117
  function getRedirects(lang, title) {
115
118
  return __awaiter(this, void 0, void 0, function* () {
116
119
  const qs = {
@@ -120,7 +123,7 @@ function getRedirects(lang, title) {
120
123
  grdlimit: "max",
121
124
  format: "json"
122
125
  };
123
- const data = yield request_1.default(API_URL.replace("$lang", lang), {
126
+ const data = yield (0, request_1.default)(API_URL.replace("$lang", lang), {
124
127
  params: qs
125
128
  });
126
129
  if (hasError(data))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-entity",
3
- "version": "0.5.6",
3
+ "version": "0.5.7",
4
4
  "description": "Wiki entity fetcher",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./types/index.d.ts",
@@ -35,10 +35,10 @@
35
35
  },
36
36
  "homepage": "https://github.com/entitizer/wiki-entity#readme",
37
37
  "devDependencies": {
38
- "@types/node": "^10.12.18",
38
+ "@types/node": "latest",
39
39
  "debug": "^4.1.1",
40
- "mocha": "^5.2.0",
41
- "typescript": "^3.2.2"
40
+ "mocha": "^9.1.2",
41
+ "typescript": "latest"
42
42
  },
43
43
  "dependencies": {
44
44
  "axios": "^0.21.1"
@@ -27,5 +27,5 @@ export declare class Api {
27
27
  private addField;
28
28
  }
29
29
  export declare function getExtracts(params: ExtractsParamsType): Promise<ExtractType[]>;
30
- export declare const getExtract: (lang: string, title: string, sentences?: number) => Promise<ExtractType>;
30
+ export declare const getExtract: (lang: string, title: string, sentences?: number) => Promise<ExtractType | null>;
31
31
  export declare function getRedirects(lang: string, title: string): Promise<string[]>;