eventregistry 8.11.2 → 9.1.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.
Files changed (65) hide show
  1. package/dist/analytics.d.ts +82 -82
  2. package/dist/analytics.js +336 -330
  3. package/dist/analytics.js.map +1 -1
  4. package/dist/base.d.ts +82 -81
  5. package/dist/base.js +261 -219
  6. package/dist/base.js.map +1 -1
  7. package/dist/counts.d.ts +81 -81
  8. package/dist/counts.js +162 -149
  9. package/dist/counts.js.map +1 -1
  10. package/dist/dailyShares.d.ts +10 -10
  11. package/dist/dailyShares.js +90 -77
  12. package/dist/dailyShares.js.map +1 -1
  13. package/dist/data.d.ts +269 -268
  14. package/dist/data.js +3 -3
  15. package/dist/eventForText.d.ts +48 -48
  16. package/dist/eventForText.js +126 -123
  17. package/dist/eventForText.js.map +1 -1
  18. package/dist/eventRegistry.d.ts +244 -224
  19. package/dist/eventRegistry.js +1098 -1018
  20. package/dist/eventRegistry.js.map +1 -1
  21. package/dist/index.d.ts +21 -20
  22. package/dist/index.js +128 -122
  23. package/dist/index.js.map +1 -1
  24. package/dist/info.d.ts +61 -61
  25. package/dist/info.js +171 -158
  26. package/dist/info.js.map +1 -1
  27. package/dist/logger.d.ts +45 -0
  28. package/dist/logger.js +156 -0
  29. package/dist/logger.js.map +1 -0
  30. package/dist/query.d.ts +53 -53
  31. package/dist/query.js +333 -290
  32. package/dist/query.js.map +1 -1
  33. package/dist/queryArticle.d.ts +61 -61
  34. package/dist/queryArticle.js +183 -168
  35. package/dist/queryArticle.js.map +1 -1
  36. package/dist/queryArticles.d.ts +144 -160
  37. package/dist/queryArticles.js +729 -701
  38. package/dist/queryArticles.js.map +1 -1
  39. package/dist/queryEvent.d.ts +140 -140
  40. package/dist/queryEvent.js +587 -569
  41. package/dist/queryEvent.js.map +1 -1
  42. package/dist/queryEvents.d.ts +210 -210
  43. package/dist/queryEvents.js +825 -798
  44. package/dist/queryEvents.js.map +1 -1
  45. package/dist/queryMentions.d.ts +96 -96
  46. package/dist/queryMentions.js +637 -600
  47. package/dist/queryMentions.js.map +1 -1
  48. package/dist/queryStory.d.ts +58 -58
  49. package/dist/queryStory.js +194 -174
  50. package/dist/queryStory.js.map +1 -1
  51. package/dist/recent.d.ts +23 -23
  52. package/dist/recent.js +199 -179
  53. package/dist/recent.js.map +1 -1
  54. package/dist/returnInfo.d.ts +68 -66
  55. package/dist/returnInfo.js +332 -304
  56. package/dist/returnInfo.js.map +1 -1
  57. package/dist/topicPage.d.ts +157 -157
  58. package/dist/topicPage.js +599 -604
  59. package/dist/topicPage.js.map +1 -1
  60. package/dist/trends.d.ts +35 -35
  61. package/dist/trends.js +115 -102
  62. package/dist/trends.js.map +1 -1
  63. package/dist/types.d.ts +2453 -2155
  64. package/dist/types.js +2 -2
  65. package/package.json +13 -13
@@ -1,1019 +1,1099 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- var __rest = (this && this.__rest) || function (s, e) {
49
- var t = {};
50
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
51
- t[p] = s[p];
52
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
53
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
54
- t[p[i]] = s[p[i]];
55
- return t;
56
- };
57
- Object.defineProperty(exports, "__esModule", { value: true });
58
- var axios_1 = require("axios");
59
- var fs = require("fs");
60
- var _ = require("lodash");
61
- var moment = require("moment");
62
- var semaphore_async_await_1 = require("semaphore-async-await");
63
- var winston = require("winston");
64
- var returnInfo_1 = require("./returnInfo");
65
- var base_1 = require("./base");
66
- /**
67
- * @class EventRegistry
68
- * Main class responsible for obtaining results form the Event Registry
69
- */
70
- var EventRegistry = /** @class */ (function () {
71
- function EventRegistry(config) {
72
- if (config === void 0) { config = {}; }
73
- var _this = this;
74
- this.config = {
75
- host: "http://eventregistry.org",
76
- hostAnalytics: "http://analytics.eventregistry.org",
77
- logging: false,
78
- minDelayBetweenRequests: 1,
79
- repeatFailedRequestCount: 2,
80
- verboseOutput: false,
81
- allowUseOfArchive: true,
82
- };
83
- this.headers = {};
84
- this.dailyAvailableRequests = -1;
85
- this.remainingAvailableRequests = -1;
86
- this.lastQueryTime = 0;
87
- this._logRequests = false;
88
- this.stopStatusCodes = [
89
- 204,
90
- 400,
91
- 401,
92
- 403,
93
- 530,
94
- ];
95
- this.lock = new semaphore_async_await_1.default(1);
96
- if (!!config.apiKey && !!config.printHostInfo) {
97
- console.log("using user provided API key for making requests");
98
- }
99
- if (fs && fs.existsSync(this.config.settingsFName || "settings.json")) {
100
- var localConfig = JSON.parse(fs.readFileSync(this.config.settingsFName || "settings.json", "utf8"));
101
- this.config = __assign({}, this.config, localConfig, config);
102
- if (!_.isNil(config.apiKey)) {
103
- if (!!config.printHostInfo) {
104
- console.log("found apiKey in settings file which will be used for making requests");
105
- }
106
- this.config.apiKey = config.apiKey;
107
- }
108
- }
109
- else {
110
- this.config = __assign({}, this.config, config);
111
- }
112
- if (this.config.logging) {
113
- this.logger = winston.createLogger({
114
- level: "info",
115
- format: winston.format.json(),
116
- transports: [
117
- new winston.transports.File({
118
- filename: "logs/error.log",
119
- level: "error",
120
- }),
121
- new winston.transports.File({ filename: "logs/info.log" }),
122
- ],
123
- });
124
- }
125
- this._logRequests = this.config.logging;
126
- this.initRequestLogger();
127
- if (_.isNil(this.config.apiKey)) {
128
- console.info("No API key was provided. You will be allowed to perform only a very limited number of requests per day.");
129
- }
130
- if (!!config.printHostInfo) {
131
- console.log("Event Registry host: " + config.host);
132
- console.log("Text analytics host: " + config.hostAnalytics);
133
- }
134
- this.config.minDelayBetweenRequests *= 1000;
135
- axios_1.default.interceptors.response.use(undefined, function (err) {
136
- // If config does not exist or the retry option is not set, reject
137
- if (!err.config || !err.config.retry) {
138
- return Promise.reject(err);
139
- }
140
- if (_.includes(_this.stopStatusCodes, err.response.status)) {
141
- return Promise.reject(err);
142
- }
143
- // Set the variable for keeping track of the retry count
144
- err.config.__retryCount = err.config.__retryCount || 0;
145
- // Check if we've maxed out the total number of retries
146
- if (err.config.__retryCount >= err.config.retry) {
147
- // Reject with the error
148
- return Promise.reject(err);
149
- }
150
- err.config.__retryCount += 1;
151
- return new Promise(function (resolve) {
152
- setTimeout(function () { return resolve(); }, err.config.retryDelay || 1);
153
- }).then(function () { return axios_1.default(err.config); });
154
- });
155
- }
156
- /**
157
- * Should all requests be logged to a file or not?
158
- */
159
- EventRegistry.prototype.setLogging = function (logging) {
160
- this._logRequests = logging;
161
- this.initRequestLogger();
162
- };
163
- Object.defineProperty(EventRegistry.prototype, "allowUseOfArchive", {
164
- get: function () {
165
- return this.config.allowUseOfArchive;
166
- },
167
- enumerable: true,
168
- configurable: true
169
- });
170
- Object.defineProperty(EventRegistry.prototype, "verboseOutput", {
171
- get: function () {
172
- return this.config.verboseOutput;
173
- },
174
- enumerable: true,
175
- configurable: true
176
- });
177
- /**
178
- * Main method for executing the search queries.
179
- * @param query instance of Query class
180
- */
181
- EventRegistry.prototype.execQuery = function (query, allowUseOfArchive) {
182
- if (allowUseOfArchive === void 0) { allowUseOfArchive = this.config.allowUseOfArchive; }
183
- return __awaiter(this, void 0, void 0, function () {
184
- var params, request;
185
- return __generator(this, function (_a) {
186
- switch (_a.label) {
187
- case 0:
188
- params = query.getQueryParams();
189
- return [4 /*yield*/, this.jsonRequest(query.path, params, allowUseOfArchive)];
190
- case 1:
191
- request = _a.sent();
192
- if (!_.has(request, "data") && this.config.verboseOutput) {
193
- this.logger.error("Request did not return with the 'data' property.");
194
- }
195
- return [2 /*return*/, _.get(request, "data", {})];
196
- }
197
- });
198
- });
199
- };
200
- EventRegistry.prototype.jsonRequestAnalytics = function (path, parameters, headers, cookies) {
201
- return __awaiter(this, void 0, void 0, function () {
202
- var request, args, cookieString, errorMessage, error_1;
203
- return __generator(this, function (_a) {
204
- switch (_a.label) {
205
- case 0: return [4 /*yield*/, this.lock.acquire()];
206
- case 1:
207
- _a.sent();
208
- _a.label = 2;
209
- case 2:
210
- _a.trys.push([2, 4, 5, 6]);
211
- _.set(parameters, "apiKey", this.config.apiKey);
212
- args = {
213
- url: path,
214
- method: "POST",
215
- baseURL: this.config.hostAnalytics,
216
- data: parameters,
217
- timeout: 600000,
218
- responseType: "json",
219
- maxRedirects: 5,
220
- };
221
- if (!!headers) {
222
- _.set(args, "headers", headers);
223
- }
224
- if (!!cookies) {
225
- cookieString = Object.keys(cookies).map(function (key) { return key + "=" + cookies[key]; }).join(";") + ";";
226
- _.set(args, "headers.Cookie", cookieString);
227
- }
228
- return [4 /*yield*/, axios_1.default.request(args)];
229
- case 3:
230
- request = _a.sent();
231
- this.headers = _.get(request, "headers", {});
232
- if (_.get(request, "status") !== 200) {
233
- throw new Error(_.get(request, "statusText"));
234
- }
235
- errorMessage = _.get(request, "data.error", "");
236
- if (errorMessage) {
237
- throw new Error(errorMessage);
238
- }
239
- return [3 /*break*/, 6];
240
- case 4:
241
- error_1 = _a.sent();
242
- request = { data: { error: error_1 } };
243
- if (this.config.verboseOutput) {
244
- console.error("Event Registry Analytics exception while executing the request.");
245
- if (error_1 && error_1.stack && error_1.message) {
246
- console.error(error_1.message);
247
- }
248
- else {
249
- console.error(_.get(error_1, "response.status") + ": " + _.get(error_1, "response.statusText") + " => " + _.get(error_1, "response.data"));
250
- }
251
- }
252
- // try to print out the error that should be passed by in case the server is down or responds with errors
253
- if (this.config.logging) {
254
- this.logger.error(_.get(error_1, "errno", error_1));
255
- }
256
- return [3 /*break*/, 6];
257
- case 5:
258
- this.lock.release();
259
- return [7 /*endfinally*/];
260
- case 6: return [2 /*return*/, request];
261
- }
262
- });
263
- });
264
- };
265
- /**
266
- * Make a request for json data
267
- * @param path url on er (e.g. "/api/v1/article")
268
- * @param parameters Optional parameters to be included in the request
269
- */
270
- EventRegistry.prototype.jsonRequest = function (path, parameters, allowUseOfArchive) {
271
- if (allowUseOfArchive === void 0) { allowUseOfArchive = this.config.allowUseOfArchive; }
272
- return __awaiter(this, void 0, void 0, function () {
273
- var request, current, errorMessage, error_2;
274
- return __generator(this, function (_a) {
275
- switch (_a.label) {
276
- case 0:
277
- current = moment.utc().milliseconds();
278
- if (!(this.lastQueryTime && current - this.lastQueryTime < this.config.minDelayBetweenRequests)) return [3 /*break*/, 2];
279
- return [4 /*yield*/, base_1.sleep(this.config.minDelayBetweenRequests - (current - this.lastQueryTime))];
280
- case 1:
281
- _a.sent();
282
- _a.label = 2;
283
- case 2: return [4 /*yield*/, this.lock.acquire()];
284
- case 3:
285
- _a.sent();
286
- if (this._logRequests) {
287
- if (!_.isEmpty(parameters)) {
288
- this.requestLogger.info("# " + JSON.stringify(parameters) + "\n");
289
- }
290
- this.requestLogger.info(path + "\n\n");
291
- }
292
- this.lastQueryTime = current;
293
- _a.label = 4;
294
- case 4:
295
- _a.trys.push([4, 6, 7, 8]);
296
- _.set(parameters, "apiKey", this.config.apiKey);
297
- if (!allowUseOfArchive) {
298
- _.set(parameters, "forceMaxDataTimeWindow", 31);
299
- }
300
- return [4 /*yield*/, axios_1.default.request({
301
- url: path,
302
- method: "POST",
303
- baseURL: this.config.host,
304
- data: parameters,
305
- timeout: 600000,
306
- responseType: "json",
307
- maxRedirects: 5,
308
- retry: this.config.repeatFailedRequestCount,
309
- })];
310
- case 5:
311
- request = _a.sent();
312
- this.headers = _.get(request, "headers", {});
313
- if (_.get(request, "status") !== 200) {
314
- throw new Error(_.get(request, "statusText"));
315
- }
316
- if (this.getLastHeader("warning")) {
317
- console.warn("WARNING: " + this.getLastHeader("warning"));
318
- }
319
- this.dailyAvailableRequests = _.toNumber(this.getLastHeader("x-ratelimit-limit", "-1"));
320
- this.remainingAvailableRequests = _.toNumber(this.getLastHeader("x-ratelimit-remaining", "-1"));
321
- errorMessage = _.get(request, "data.error", "");
322
- if (errorMessage) {
323
- throw new Error(errorMessage);
324
- }
325
- return [3 /*break*/, 8];
326
- case 6:
327
- error_2 = _a.sent();
328
- request = { data: { error: error_2 } };
329
- // try to print out the error that should be passed by in case the server is down or responds with errors
330
- if (this.config.verboseOutput) {
331
- console.error("Event Registry exception while executing the request.");
332
- if (error_2 && error_2.stack && error_2.message) {
333
- console.error(error_2.message);
334
- }
335
- else {
336
- console.error(_.get(error_2, "response.status") + ": " + _.get(error_2, "response.statusText") + " => " + _.get(error_2, "response.data"));
337
- }
338
- }
339
- if (this.config.logging) {
340
- this.logger.error(_.get(error_2, "errno", error_2));
341
- }
342
- return [3 /*break*/, 8];
343
- case 7:
344
- this.lock.release();
345
- return [7 /*endfinally*/];
346
- case 8: return [2 /*return*/, request];
347
- }
348
- });
349
- });
350
- };
351
- /**
352
- * get the number of requests that are still available for the user today. Information is only accessible after you make some query.
353
- */
354
- EventRegistry.prototype.getRemainingAvailableRequests = function () {
355
- return this.remainingAvailableRequests;
356
- };
357
- /**
358
- * get the total number of requests that the user can make in a day. Information is only accessible after you make some query.
359
- */
360
- EventRegistry.prototype.getDailyAvailableRequests = function () {
361
- return this.dailyAvailableRequests;
362
- };
363
- /**
364
- * Return the headers returned in the response object of the last executed request
365
- */
366
- EventRegistry.prototype.getLastHeaders = function () {
367
- return this.headers;
368
- };
369
- /**
370
- * Get a value of the header headerName that was set in the headers in the last response object
371
- */
372
- EventRegistry.prototype.getLastHeader = function (headerName, dfltVal) {
373
- return _.get(this.headers, headerName, dfltVal);
374
- };
375
- /**
376
- * print some statistics about the last executed request
377
- */
378
- EventRegistry.prototype.printLastReqStats = function () {
379
- console.log("Tokens used by the request: " + this.getLastHeader("req-tokens"));
380
- console.log("Performed action: " + this.getLastHeader("req-action"));
381
- console.log("Was archive used for the query: " + (this.getLastReqArchiveUse() ? "Yes" : "No"));
382
- };
383
- /**
384
- * return true or false depending on whether the last request used the archive or not
385
- */
386
- EventRegistry.prototype.getLastReqArchiveUse = function () {
387
- return this.getLastHeader("req-archive", "0") === "1";
388
- };
389
- /**
390
- * Return the number of used and total available tokens. Can be used at any time (also before making queries)
391
- */
392
- EventRegistry.prototype.getUsageInfo = function () {
393
- return __awaiter(this, void 0, void 0, function () {
394
- var request;
395
- return __generator(this, function (_a) {
396
- switch (_a.label) {
397
- case 0: return [4 /*yield*/, this.jsonRequest("/api/v1/usage")];
398
- case 1:
399
- request = _a.sent();
400
- return [2 /*return*/, request.data];
401
- }
402
- });
403
- });
404
- };
405
- EventRegistry.prototype.getServiceStatus = function () {
406
- return __awaiter(this, void 0, void 0, function () {
407
- var request;
408
- return __generator(this, function (_a) {
409
- switch (_a.label) {
410
- case 0: return [4 /*yield*/, this.jsonRequest("/api/v1/getServiceStatus")];
411
- case 1:
412
- request = _a.sent();
413
- return [2 /*return*/, request.data];
414
- }
415
- });
416
- });
417
- };
418
- EventRegistry.prototype.getUrl = function (query) {
419
- if (!(query instanceof base_1.QueryParamsBase)) {
420
- if (this.config.verboseOutput) {
421
- console.warn("query parameter should be an instance of a class that has Query as a base class, such as QueryArticles or QueryEvents");
422
- }
423
- }
424
- var allParams = query.getQueryParams();
425
- return this.config.host + query.path + "?" + _.join(_.map(_.keys(allParams), function (key) { return key + "=" + allParams[key]; }), "&");
426
- };
427
- /**
428
- * Return a list of concepts that contain the given prefix.
429
- * Returned matching concepts are sorted based on their frequency of occurrence in news (from most to least frequent)
430
- * @param prefix input text that should be contained in the concept
431
- * @param args Object which contains a host of optional parameters
432
- */
433
- EventRegistry.prototype.suggestConcepts = function (prefix, args) {
434
- if (args === void 0) { args = {}; }
435
- return __awaiter(this, void 0, void 0, function () {
436
- var _a, sources, _b, lang, _c, conceptLang, _d, page, _e, count, _f, returnInfo, otherParams, params, request;
437
- return __generator(this, function (_g) {
438
- switch (_g.label) {
439
- case 0:
440
- _a = args.sources, sources = _a === void 0 ? ["concepts"] : _a, _b = args.lang, lang = _b === void 0 ? "eng" : _b, _c = args.conceptLang, conceptLang = _c === void 0 ? "eng" : _c, _d = args.page, page = _d === void 0 ? 1 : _d, _e = args.count, count = _e === void 0 ? 20 : _e, _f = args.returnInfo, returnInfo = _f === void 0 ? new returnInfo_1.ReturnInfo() : _f, otherParams = __rest(args, ["sources", "lang", "conceptLang", "page", "count", "returnInfo"]);
441
- if (page <= 0) {
442
- throw new RangeError("page parameter should be above 0");
443
- }
444
- params = {
445
- prefix: prefix,
446
- source: sources,
447
- lang: lang,
448
- conceptLang: conceptLang,
449
- page: page,
450
- count: count,
451
- };
452
- params = _.extend({}, params, otherParams, returnInfo.getParams());
453
- return [4 /*yield*/, this.jsonRequest("/api/v1/suggestConceptsFast", params)];
454
- case 1:
455
- request = _g.sent();
456
- return [2 /*return*/, request.data];
457
- }
458
- });
459
- });
460
- };
461
- /**
462
- * Return a list of dmoz categories that contain the prefix
463
- * @param prefix input text that should be contained in the category name
464
- * @param args Object which contains a host of optional parameters
465
- */
466
- EventRegistry.prototype.suggestCategories = function (prefix, args) {
467
- if (args === void 0) { args = {}; }
468
- return __awaiter(this, void 0, void 0, function () {
469
- var _a, page, _b, count, _c, returnInfo, otherParams, params, request;
470
- return __generator(this, function (_d) {
471
- switch (_d.label) {
472
- case 0:
473
- _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 20 : _b, _c = args.returnInfo, returnInfo = _c === void 0 ? new returnInfo_1.ReturnInfo() : _c, otherParams = __rest(args, ["page", "count", "returnInfo"]);
474
- if (page <= 0) {
475
- throw new RangeError("page parameter should be above 0");
476
- }
477
- params = { prefix: prefix, page: page, count: count };
478
- params = _.extend({}, params, otherParams, returnInfo.getParams());
479
- return [4 /*yield*/, this.jsonRequest("/api/v1/suggestCategoriesFast", params)];
480
- case 1:
481
- request = _d.sent();
482
- return [2 /*return*/, request.data];
483
- }
484
- });
485
- });
486
- };
487
- /**
488
- * Return a list of news sources that match the prefix
489
- * @param prefix input text that should be contained in the source name or uri
490
- * @param args Object which contains a host of optional parameters
491
- */
492
- EventRegistry.prototype.suggestNewsSources = function (prefix, args) {
493
- if (args === void 0) { args = {}; }
494
- return __awaiter(this, void 0, void 0, function () {
495
- var _a, page, _b, count, _c, dataType, otherParams, request;
496
- return __generator(this, function (_d) {
497
- switch (_d.label) {
498
- case 0:
499
- _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 20 : _b, _c = args.dataType, dataType = _c === void 0 ? ["news", "pr", "blog"] : _c, otherParams = __rest(args, ["page", "count", "dataType"]);
500
- if (page <= 0) {
501
- throw new RangeError("page parameter should be above 0");
502
- }
503
- return [4 /*yield*/, this.jsonRequest("/api/v1/suggestSourcesFast", __assign({ prefix: prefix, page: page, dataType: dataType, count: count }, otherParams))];
504
- case 1:
505
- request = _d.sent();
506
- return [2 /*return*/, request.data];
507
- }
508
- });
509
- });
510
- };
511
- /**
512
- * Return a list of news source groups that match the prefix
513
- * @param prefix input text that should be contained in the source group name or uri
514
- * @param args Object which contains a host of optional parameters
515
- */
516
- EventRegistry.prototype.suggestSourceGroups = function (prefix, args) {
517
- if (args === void 0) { args = {}; }
518
- return __awaiter(this, void 0, void 0, function () {
519
- var _a, page, _b, count, otherParams, request;
520
- return __generator(this, function (_c) {
521
- switch (_c.label) {
522
- case 0:
523
- _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 20 : _b, otherParams = __rest(args, ["page", "count"]);
524
- if (page <= 0) {
525
- throw new RangeError("page parameter should be above 0");
526
- }
527
- return [4 /*yield*/, this.jsonRequest("/api/v1/suggestSourceGroups", __assign({ prefix: prefix, page: page, count: count }, otherParams))];
528
- case 1:
529
- request = _c.sent();
530
- return [2 /*return*/, request.data];
531
- }
532
- });
533
- });
534
- };
535
- /**
536
- * Return a list of geo locations (cities or countries) that contain the prefix
537
- * @param prefix input text that should be contained in the location name
538
- * @param args Object which contains a host of optional parameters
539
- */
540
- EventRegistry.prototype.suggestLocations = function (prefix, args) {
541
- if (args === void 0) { args = {}; }
542
- return __awaiter(this, void 0, void 0, function () {
543
- var _a, sources, _b, lang, _c, count, _d, countryUri, sortByDistanceTo, _e, returnInfo, otherParams, params, request;
544
- return __generator(this, function (_f) {
545
- switch (_f.label) {
546
- case 0:
547
- _a = args.sources, sources = _a === void 0 ? ["place", "country"] : _a, _b = args.lang, lang = _b === void 0 ? "eng" : _b, _c = args.count, count = _c === void 0 ? 20 : _c, _d = args.countryUri, countryUri = _d === void 0 ? "" : _d, sortByDistanceTo = args.sortByDistanceTo, _e = args.returnInfo, returnInfo = _e === void 0 ? new returnInfo_1.ReturnInfo() : _e, otherParams = __rest(args, ["sources", "lang", "count", "countryUri", "sortByDistanceTo", "returnInfo"]);
548
- params = {
549
- prefix: prefix,
550
- count: count,
551
- source: sources,
552
- lang: lang,
553
- countryUri: countryUri,
554
- };
555
- params = _.extend({}, params, otherParams, returnInfo.getParams());
556
- if (sortByDistanceTo) {
557
- if (!_.isArray(sortByDistanceTo)) {
558
- throw new Error("sortByDistanceTo has to contain a tuple with latitude and longitude of the location");
559
- }
560
- if (_.size(sortByDistanceTo) !== 2) {
561
- throw new Error("The sortByDistanceTo should contain two numbers");
562
- }
563
- params["closeToLat"] = sortByDistanceTo[0];
564
- params["closeToLon"] = sortByDistanceTo[1];
565
- }
566
- return [4 /*yield*/, this.jsonRequest("/api/v1/suggestLocationsFast", params)];
567
- case 1:
568
- request = _f.sent();
569
- return [2 /*return*/, request.data];
570
- }
571
- });
572
- });
573
- };
574
- /**
575
- * Return a list of geo locations (cities or places) that are close to the provided (lat, long) values
576
- * @param latitude latitude part of the coordinate
577
- * @param longitude longitude part of the coordinate
578
- * @param radiusKm radius in kilometers around the coordinates inside which the locations should be returned
579
- * @param args Object which contains a host of optional parameters
580
- */
581
- EventRegistry.prototype.suggestLocationsAtCoordinate = function (latitude, longitude, radiusKm, args) {
582
- if (args === void 0) { args = {}; }
583
- return __awaiter(this, void 0, void 0, function () {
584
- var _a, limitToCities, _b, lang, _c, count, _d, ignoreNonWiki, _e, returnInfo, otherParams, params, request;
585
- return __generator(this, function (_f) {
586
- switch (_f.label) {
587
- case 0:
588
- _a = args.limitToCities, limitToCities = _a === void 0 ? false : _a, _b = args.lang, lang = _b === void 0 ? "eng" : _b, _c = args.count, count = _c === void 0 ? 20 : _c, _d = args.ignoreNonWiki, ignoreNonWiki = _d === void 0 ? true : _d, _e = args.returnInfo, returnInfo = _e === void 0 ? new returnInfo_1.ReturnInfo() : _e, otherParams = __rest(args, ["limitToCities", "lang", "count", "ignoreNonWiki", "returnInfo"]);
589
- if (!_.isNumber(latitude)) {
590
- throw new Error("The 'latitude' should be a number");
591
- }
592
- if (!_.isNumber(longitude)) {
593
- throw new Error("The 'longitude' should be a number");
594
- }
595
- params = {
596
- action: "getLocationsAtCoordinate",
597
- lat: latitude,
598
- lon: longitude,
599
- radius: radiusKm,
600
- limitToCities: limitToCities,
601
- count: count,
602
- lang: lang,
603
- };
604
- params = _.extend({}, params, otherParams, returnInfo.getParams());
605
- return [4 /*yield*/, this.jsonRequest("/api/v1/suggestLocationsFast", params)];
606
- case 1:
607
- request = _f.sent();
608
- return [2 /*return*/, request.data];
609
- }
610
- });
611
- });
612
- };
613
- /**
614
- * Return a list of news sources that are close to the provided (lat, long) values
615
- * @param latitude latitude part of the coordinate
616
- * @param longitude longitude part of the coordinate
617
- * @param radiusKm radius in kilometers around the coordinates inside which the news sources should be located
618
- * @param count number of returned suggestions
619
- */
620
- EventRegistry.prototype.suggestSourcesAtCoordinate = function (latitude, longitude, radiusKm, count) {
621
- if (count === void 0) { count = 20; }
622
- var otherParams = [];
623
- for (var _i = 4; _i < arguments.length; _i++) {
624
- otherParams[_i - 4] = arguments[_i];
625
- }
626
- return __awaiter(this, void 0, void 0, function () {
627
- var params, request;
628
- return __generator(this, function (_a) {
629
- switch (_a.label) {
630
- case 0:
631
- if (!_.isNumber(latitude)) {
632
- throw new Error("The 'latitude' should be a number");
633
- }
634
- if (!_.isNumber(longitude)) {
635
- throw new Error("The 'longitude' should be a number");
636
- }
637
- params = __assign({ action: "getSourcesAtCoordinate", lat: latitude, lon: longitude, radius: radiusKm, count: count }, otherParams);
638
- return [4 /*yield*/, this.jsonRequest("/api/v1/suggestSourcesFast", params)];
639
- case 1:
640
- request = _a.sent();
641
- return [2 /*return*/, request.data];
642
- }
643
- });
644
- });
645
- };
646
- /**
647
- * Return a list of news sources that are close to the provided (lat, long) values
648
- * @param conceptUri concept that represents a geographic location for which we would like to obtain a list of sources located at the place
649
- * @param args Object which contains a host of optional parameters
650
- */
651
- EventRegistry.prototype.suggestSourcesAtPlace = function (conceptUri, args) {
652
- if (args === void 0) { args = {}; }
653
- return __awaiter(this, void 0, void 0, function () {
654
- var _a, page, _b, count, _c, dataType, otherParams, params, request;
655
- return __generator(this, function (_d) {
656
- switch (_d.label) {
657
- case 0:
658
- _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 20 : _b, _c = args.dataType, dataType = _c === void 0 ? "news" : _c, otherParams = __rest(args, ["page", "count", "dataType"]);
659
- params = __assign({ action: "getSourcesAtPlace", conceptUri: conceptUri, page: page, count: count, dataType: dataType }, otherParams);
660
- return [4 /*yield*/, this.jsonRequest("/api/v1/suggestSourcesFast", params)];
661
- case 1:
662
- request = _d.sent();
663
- return [2 /*return*/, request.data];
664
- }
665
- });
666
- });
667
- };
668
- /**
669
- * Return a list of news sources that match the prefix
670
- * @param prefix: input text that should be contained in the author name and source url
671
- * @param page: page of results
672
- * @param count: number of returned suggestions
673
- */
674
- EventRegistry.prototype.suggestAuthors = function (prefix, page, count) {
675
- if (page === void 0) { page = 1; }
676
- if (count === void 0) { count = 20; }
677
- var otherParams = [];
678
- for (var _i = 3; _i < arguments.length; _i++) {
679
- otherParams[_i - 3] = arguments[_i];
680
- }
681
- return __awaiter(this, void 0, void 0, function () {
682
- var params, request;
683
- return __generator(this, function (_a) {
684
- switch (_a.label) {
685
- case 0:
686
- if (page <= 0) {
687
- throw new Error("Page parameter should be above 0.");
688
- }
689
- params = __assign({ prefix: prefix,
690
- page: page,
691
- count: count }, otherParams);
692
- return [4 /*yield*/, this.jsonRequest("/api/v1/suggestAuthorsFast", params)];
693
- case 1:
694
- request = _a.sent();
695
- return [2 /*return*/, request.data];
696
- }
697
- });
698
- });
699
- };
700
- /**
701
- * Return a list of concept classes that match the given prefix
702
- * @param prefix input text that should be contained in the category name
703
- * @param args Object which contains a host of optional parameters
704
- */
705
- EventRegistry.prototype.suggestConceptClasses = function (prefix, args) {
706
- if (args === void 0) { args = {}; }
707
- return __awaiter(this, void 0, void 0, function () {
708
- var _a, lang, _b, conceptLang, _c, source, _d, page, _e, count, _f, returnInfo, otherParams, params, request;
709
- return __generator(this, function (_g) {
710
- switch (_g.label) {
711
- case 0:
712
- _a = args.lang, lang = _a === void 0 ? "eng" : _a, _b = args.conceptLang, conceptLang = _b === void 0 ? "eng" : _b, _c = args.source, source = _c === void 0 ? ["dbpedia", "custom"] : _c, _d = args.page, page = _d === void 0 ? 1 : _d, _e = args.count, count = _e === void 0 ? 20 : _e, _f = args.returnInfo, returnInfo = _f === void 0 ? new returnInfo_1.ReturnInfo() : _f, otherParams = __rest(args, ["lang", "conceptLang", "source", "page", "count", "returnInfo"]);
713
- if (page < 1) {
714
- throw new Error("page parameter should be above 0");
715
- }
716
- params = { prefix: prefix, lang: lang, conceptLang: conceptLang, source: source, page: page, count: count };
717
- params = _.extend({}, params, otherParams, returnInfo.getParams());
718
- return [4 /*yield*/, this.jsonRequest("/api/v1/suggestConceptClasses", params)];
719
- case 1:
720
- request = _g.sent();
721
- return [2 /*return*/, request.data];
722
- }
723
- });
724
- });
725
- };
726
- /**
727
- * return a concept uri that is the best match for the given concept label
728
- * if there are multiple matches for the given conceptLabel,
729
- * they are sorted based on their frequency of occurrence in news (most to least frequent)
730
- * @param conceptLabel partial or full name of the concept for which to return the concept uri
731
- * @param args Object which contains a host of optional parameters
732
- */
733
- EventRegistry.prototype.getConceptUri = function (conceptLabel, args) {
734
- if (args === void 0) { args = {}; }
735
- return __awaiter(this, void 0, void 0, function () {
736
- var _a, lang, _b, sources, matches;
737
- return __generator(this, function (_c) {
738
- switch (_c.label) {
739
- case 0:
740
- _a = args.lang, lang = _a === void 0 ? "eng" : _a, _b = args.sources, sources = _b === void 0 ? ["concepts"] : _b;
741
- return [4 /*yield*/, this.suggestConcepts(conceptLabel, { lang: lang, sources: sources })];
742
- case 1:
743
- matches = _c.sent();
744
- return [2 /*return*/, _.get(_.first(matches), "uri", undefined)];
745
- }
746
- });
747
- });
748
- };
749
- /**
750
- * Return a location uri that is the best match for the given location label
751
- * @param locationLabel partial or full location name for which to return the location uri
752
- * @param args Object which contains a host of optional parameters
753
- */
754
- EventRegistry.prototype.getLocationUri = function (locationLabel, args) {
755
- if (args === void 0) { args = {}; }
756
- return __awaiter(this, void 0, void 0, function () {
757
- var _a, lang, _b, sources, countryUri, sortByDistanceTo, matches;
758
- return __generator(this, function (_c) {
759
- switch (_c.label) {
760
- case 0:
761
- _a = args.lang, lang = _a === void 0 ? "eng" : _a, _b = args.sources, sources = _b === void 0 ? ["place", "country"] : _b, countryUri = args.countryUri, sortByDistanceTo = args.sortByDistanceTo;
762
- return [4 /*yield*/, this.suggestLocations(locationLabel, { lang: lang, sources: sources, countryUri: countryUri, sortByDistanceTo: sortByDistanceTo })];
763
- case 1:
764
- matches = _c.sent();
765
- return [2 /*return*/, _.get(_.first(matches), "wikiUri", undefined)];
766
- }
767
- });
768
- });
769
- };
770
- /**
771
- * Return a category uri that is the best match for the given label
772
- * @param categoryLabel partial or full name of the category for which to return category uri
773
- */
774
- EventRegistry.prototype.getCategoryUri = function (categoryLabel) {
775
- return __awaiter(this, void 0, void 0, function () {
776
- var matches;
777
- return __generator(this, function (_a) {
778
- switch (_a.label) {
779
- case 0: return [4 /*yield*/, this.suggestCategories(categoryLabel)];
780
- case 1:
781
- matches = _a.sent();
782
- return [2 /*return*/, _.get(_.first(matches), "uri", undefined)];
783
- }
784
- });
785
- });
786
- };
787
- /**
788
- * Return the news source that best matches the source name
789
- * @param sourceName partial or full name of the source or source uri for which to return source uri
790
- * @param dataType: return the source uri that provides content of these data types
791
- */
792
- EventRegistry.prototype.getNewsSourceUri = function (sourceName, dataType) {
793
- if (dataType === void 0) { dataType = ["news", "pr", "blog"]; }
794
- return __awaiter(this, void 0, void 0, function () {
795
- var matches;
796
- return __generator(this, function (_a) {
797
- switch (_a.label) {
798
- case 0: return [4 /*yield*/, this.suggestNewsSources(sourceName, { dataType: dataType })];
799
- case 1:
800
- matches = _a.sent();
801
- return [2 /*return*/, _.get(_.first(matches), "uri", undefined)];
802
- }
803
- });
804
- });
805
- };
806
- /**
807
- * alternative (shorter) name for the method getNewsSourceUri()
808
- */
809
- EventRegistry.prototype.getSourceUri = function (sourceName, dataType) {
810
- if (dataType === void 0) { dataType = ["news", "pr", "blog"]; }
811
- return __awaiter(this, void 0, void 0, function () {
812
- return __generator(this, function (_a) {
813
- switch (_a.label) {
814
- case 0: return [4 /*yield*/, this.getNewsSourceUri(sourceName, dataType)];
815
- case 1: return [2 /*return*/, _a.sent()];
816
- }
817
- });
818
- });
819
- };
820
- /**
821
- * Return the URI of the source group that best matches the name
822
- * @param sourceGroupName partial or full name of the source group
823
- */
824
- EventRegistry.prototype.getSourceGroupUri = function (sourceGroupName) {
825
- return __awaiter(this, void 0, void 0, function () {
826
- var matches;
827
- return __generator(this, function (_a) {
828
- switch (_a.label) {
829
- case 0: return [4 /*yield*/, this.suggestSourceGroups(sourceGroupName)];
830
- case 1:
831
- matches = _a.sent();
832
- return [2 /*return*/, _.get(_.first(matches), "uri", undefined)];
833
- }
834
- });
835
- });
836
- };
837
- /**
838
- * Return a uri of the concept class that is the best match for the given label
839
- * @param classLabel partial or full name of the concept class for which to return class uri
840
- * @param lang language in which the class label is specified
841
- */
842
- EventRegistry.prototype.getConceptClassUri = function (classLabel, lang) {
843
- if (lang === void 0) { lang = "eng"; }
844
- return __awaiter(this, void 0, void 0, function () {
845
- var matches;
846
- return __generator(this, function (_a) {
847
- switch (_a.label) {
848
- case 0: return [4 /*yield*/, this.suggestConceptClasses(classLabel, { lang: lang })];
849
- case 1:
850
- matches = _a.sent();
851
- return [2 /*return*/, _.get(_.first(matches), "uri", undefined)];
852
- }
853
- });
854
- });
855
- };
856
- /**
857
- * Return detailed information about a particular concept
858
- * @param conceptUri uri of the concept
859
- * @param returnInfo what details about the concept should be included in the returned information
860
- */
861
- EventRegistry.prototype.getConceptInfo = function (conceptUri, returnInfo) {
862
- return __awaiter(this, void 0, void 0, function () {
863
- var conceptInfo, params, request;
864
- return __generator(this, function (_a) {
865
- switch (_a.label) {
866
- case 0:
867
- if (!returnInfo) {
868
- conceptInfo = new returnInfo_1.ConceptInfoFlags({ synonyms: true, image: true, description: true });
869
- returnInfo = new returnInfo_1.ReturnInfo({ conceptInfo: conceptInfo });
870
- }
871
- params = {
872
- uri: conceptUri,
873
- action: "getInfo",
874
- };
875
- params = _.extend({}, params, returnInfo.getParams());
876
- return [4 /*yield*/, this.jsonRequest("/api/v1/concept/getInfo", params)];
877
- case 1:
878
- request = _a.sent();
879
- return [2 /*return*/, request.data];
880
- }
881
- });
882
- });
883
- };
884
- /**
885
- * return author uri that is the best match for the given author name (and potentially source url)
886
- * if there are multiple matches for the given author name, they are sorted based on the number of articles they have written (from most to least frequent)
887
- * @param authorName: partial or full name of the author, potentially also containing the source url (e.g. "george brown nytimes")
888
- */
889
- EventRegistry.prototype.getAuthorUri = function (authorName) {
890
- return __awaiter(this, void 0, void 0, function () {
891
- var matches;
892
- return __generator(this, function (_a) {
893
- switch (_a.label) {
894
- case 0: return [4 /*yield*/, this.suggestAuthors(authorName)];
895
- case 1:
896
- matches = _a.sent();
897
- return [2 /*return*/, _.get(_.first(matches), "uri", undefined)];
898
- }
899
- });
900
- });
901
- };
902
- EventRegistry.getUriFromUriWgt = function (uriWgtList) {
903
- if (!_.isArray(uriWgtList)) {
904
- throw new Error("uriWgtList has to be a list of strings that represent article uris");
905
- }
906
- return _.map(uriWgtList, function (uriWgt) { return _.first(_.split(uriWgt, ":")); });
907
- };
908
- // Additional utility functions
909
- /**
910
- * If you have article urls and you want to query them in ER you first have to obtain their uris in the ER.
911
- * @param articleUrls a single article url or a list of article urls
912
- */
913
- EventRegistry.prototype.getArticleUris = function (articleUrls) {
914
- return __awaiter(this, void 0, void 0, function () {
915
- var request;
916
- return __generator(this, function (_a) {
917
- switch (_a.label) {
918
- case 0:
919
- if (!_.isArray(articleUrls) && !_.isString(articleUrls)) {
920
- throw new Error("Expected a single article url or a list of urls");
921
- }
922
- return [4 /*yield*/, this.jsonRequest("/api/v1/articleMapper", { articleUrl: articleUrls })];
923
- case 1:
924
- request = _a.sent();
925
- return [2 /*return*/, request.data];
926
- }
927
- });
928
- });
929
- };
930
- /**
931
- * Return information about the latest imported article
932
- */
933
- EventRegistry.prototype.getSourceGroups = function () {
934
- return __awaiter(this, void 0, void 0, function () {
935
- var request;
936
- return __generator(this, function (_a) {
937
- switch (_a.label) {
938
- case 0: return [4 /*yield*/, this.jsonRequest("/api/v1/sourceGroup/getSourceGroups", { action: "getSourceGroups" })];
939
- case 1:
940
- request = _a.sent();
941
- return [2 /*return*/, request.data];
942
- }
943
- });
944
- });
945
- };
946
- /**
947
- * Return info about the source group
948
- */
949
- EventRegistry.prototype.getSourceGroup = function (sourceGroupUri) {
950
- return __awaiter(this, void 0, void 0, function () {
951
- var request;
952
- return __generator(this, function (_a) {
953
- switch (_a.label) {
954
- case 0: return [4 /*yield*/, this.jsonRequest("/api/v1/sourceGroup/getSourceGroupInfo", { action: "getSourceGroupInfo", uri: sourceGroupUri })];
955
- case 1:
956
- request = _a.sent();
957
- return [2 /*return*/, request.data];
958
- }
959
- });
960
- });
961
- };
962
- EventRegistry.prototype.initRequestLogger = function () {
963
- if (this._logRequests && _.isUndefined(this.requestLogger)) {
964
- this.requestLogger = winston.createLogger({
965
- level: "info",
966
- format: winston.format.json(),
967
- transports: [
968
- new winston.transports.File({ filename: "logs/requests.log" }),
969
- ],
970
- });
971
- }
972
- };
973
- return EventRegistry;
974
- }());
975
- exports.EventRegistry = EventRegistry;
976
- /**
977
- * @class ArticleMapper
978
- * Create instance of article mapper it will map from article urls to article uris
979
- * the mappings can be remembered so it will not repeat requests for the same article urls
980
- */
981
- var ArticleMapper = /** @class */ (function () {
982
- function ArticleMapper(er, rememberMapping) {
983
- if (rememberMapping === void 0) { rememberMapping = true; }
984
- this.articleUrlToUri = {};
985
- this.rememberMappings = true;
986
- this.er = er;
987
- this.rememberMappings = rememberMapping;
988
- }
989
- /**
990
- * Given the article url, return an array with 0, 1 or more article uris.
991
- * Not all returned article uris are necessarily valid anymore.
992
- * For news sources of lower importance we remove the duplicated articles and just keep the latest content
993
- * @param articleUrl string containing the article url
994
- */
995
- ArticleMapper.prototype.getArticleUri = function (articleUrl) {
996
- return __awaiter(this, void 0, void 0, function () {
997
- var response, value;
998
- return __generator(this, function (_a) {
999
- switch (_a.label) {
1000
- case 0:
1001
- if (_.has(this.articleUrlToUri, articleUrl)) {
1002
- return [2 /*return*/, _.get(this.articleUrlToUri, articleUrl)];
1003
- }
1004
- return [4 /*yield*/, this.er.getArticleUris(articleUrl)];
1005
- case 1:
1006
- response = _a.sent();
1007
- value = _.get(response, articleUrl, undefined);
1008
- if (this.rememberMappings && value) {
1009
- this.articleUrlToUri[articleUrl] = value;
1010
- }
1011
- return [2 /*return*/, value];
1012
- }
1013
- });
1014
- });
1015
- };
1016
- return ArticleMapper;
1017
- }());
1018
- exports.ArticleMapper = ArticleMapper;
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ var __rest = (this && this.__rest) || function (s, e) {
50
+ var t = {};
51
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
52
+ t[p] = s[p];
53
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
54
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
55
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
56
+ t[p[i]] = s[p[i]];
57
+ }
58
+ return t;
59
+ };
60
+ Object.defineProperty(exports, "__esModule", { value: true });
61
+ exports.ArticleMapper = exports.EventRegistry = void 0;
62
+ var axios_1 = require("axios");
63
+ var fs = require("fs");
64
+ var moment = require("moment");
65
+ var semaphore_async_await_1 = require("semaphore-async-await");
66
+ var returnInfo_1 = require("./returnInfo");
67
+ var base_1 = require("./base");
68
+ var logger_1 = require("./logger");
69
+ /**
70
+ * @class EventRegistry
71
+ * Main class responsible for obtaining results form the Event Registry
72
+ */
73
+ var EventRegistry = /** @class */ (function () {
74
+ function EventRegistry(config) {
75
+ if (config === void 0) { config = {}; }
76
+ var _this = this;
77
+ var _a, _b;
78
+ this.config = {
79
+ host: "http://eventregistry.org",
80
+ hostAnalytics: "http://analytics.eventregistry.org",
81
+ logging: false,
82
+ minDelayBetweenRequests: 1,
83
+ repeatFailedRequestCount: 2,
84
+ verboseOutput: false,
85
+ allowUseOfArchive: true,
86
+ };
87
+ this.headers = {};
88
+ this.dailyAvailableRequests = -1;
89
+ this.remainingAvailableRequests = -1;
90
+ this.lastQueryTime = 0;
91
+ this._logRequests = false;
92
+ this.stopStatusCodes = [
93
+ 204,
94
+ 400,
95
+ 401,
96
+ 403,
97
+ 530,
98
+ ];
99
+ this.lock = new semaphore_async_await_1.default(1);
100
+ this._logRequests = this.config.logging;
101
+ this.logger = logger_1.Logger.createInstance({ logging: this.config.logging, logRequests: this._logRequests });
102
+ if (fs && fs.existsSync(this.config.settingsFName || "settings.json")) {
103
+ var localConfig = JSON.parse(fs.readFileSync(this.config.settingsFName || "settings.json", "utf8"));
104
+ this.config = __assign(__assign(__assign({}, this.config), localConfig), config);
105
+ if ((config === null || config === void 0 ? void 0 : config.apiKey) !== undefined) {
106
+ this.logger.debug("found apiKey in settings file which will be used for making requests");
107
+ this.config.apiKey = config.apiKey;
108
+ }
109
+ }
110
+ else {
111
+ this.config = __assign(__assign({}, this.config), config);
112
+ if (!!config.apiKey) {
113
+ this.logger.debug("using user provided API key for making requests");
114
+ }
115
+ }
116
+ if (((_a = this.config) === null || _a === void 0 ? void 0 : _a.apiKey) === undefined || ((_b = this.config) === null || _b === void 0 ? void 0 : _b.apiKey) === null) {
117
+ this.logger.info("No API key was provided. You will be allowed to perform only a very limited number of requests per day.");
118
+ }
119
+ this.logger.debug("Event Registry host: ".concat(this.config.host));
120
+ this.logger.debug("Text analytics host: ".concat(this.config.hostAnalytics));
121
+ this.config.minDelayBetweenRequests *= 1000;
122
+ axios_1.default.interceptors.response.use(undefined, function (err) {
123
+ // If config does not exist or the retry option is not set, reject
124
+ if (!err.config || !err.config.retry) {
125
+ return Promise.reject(err);
126
+ }
127
+ if (_this.stopStatusCodes.includes(err.response.status)) {
128
+ return Promise.reject(err);
129
+ }
130
+ // Set the variable for keeping track of the retry count
131
+ err.config.__retryCount = err.config.__retryCount || 0;
132
+ // Check if we've maxed out the total number of retries
133
+ if (err.config.__retryCount >= err.config.retry) {
134
+ // Reject with the error
135
+ return Promise.reject(err);
136
+ }
137
+ err.config.__retryCount += 1;
138
+ return new Promise(function (resolve) {
139
+ setTimeout(function () { return resolve(); }, err.config.retryDelay || 1);
140
+ }).then(function () { return (0, axios_1.default)(err.config); });
141
+ });
142
+ }
143
+ /**
144
+ * Should all requests be logged to a file or not?
145
+ */
146
+ EventRegistry.prototype.setLogging = function (logging) {
147
+ this._logRequests = logging;
148
+ this.logger.toggleRequestLogging(logging);
149
+ };
150
+ Object.defineProperty(EventRegistry.prototype, "allowUseOfArchive", {
151
+ get: function () {
152
+ return this.config.allowUseOfArchive;
153
+ },
154
+ enumerable: false,
155
+ configurable: true
156
+ });
157
+ Object.defineProperty(EventRegistry.prototype, "verboseOutput", {
158
+ get: function () {
159
+ return this.config.verboseOutput;
160
+ },
161
+ enumerable: false,
162
+ configurable: true
163
+ });
164
+ /**
165
+ * Main method for executing the search queries.
166
+ * @param query instance of Query class
167
+ */
168
+ EventRegistry.prototype.execQuery = function (query_1) {
169
+ return __awaiter(this, arguments, void 0, function (query, allowUseOfArchive) {
170
+ var params, request;
171
+ var _a;
172
+ if (allowUseOfArchive === void 0) { allowUseOfArchive = this.config.allowUseOfArchive; }
173
+ return __generator(this, function (_b) {
174
+ switch (_b.label) {
175
+ case 0:
176
+ params = query.getQueryParams();
177
+ return [4 /*yield*/, this.jsonRequest(query.path, params, allowUseOfArchive)];
178
+ case 1:
179
+ request = _b.sent();
180
+ if (!(request === null || request === void 0 ? void 0 : request.data) && ((_a = this.config) === null || _a === void 0 ? void 0 : _a.verboseOutput)) {
181
+ this.logger.error("Request did not return with the 'data' property.");
182
+ }
183
+ return [2 /*return*/, ((request === null || request === void 0 ? void 0 : request.data) || {})];
184
+ }
185
+ });
186
+ });
187
+ };
188
+ EventRegistry.prototype.jsonRequestAnalytics = function (path, parameters, headers, cookies) {
189
+ return __awaiter(this, void 0, void 0, function () {
190
+ var request, args, cookieString, errorMessage, error_1;
191
+ var _a, _b, _c, _d, _e, _f;
192
+ return __generator(this, function (_g) {
193
+ switch (_g.label) {
194
+ case 0: return [4 /*yield*/, this.lock.acquire()];
195
+ case 1:
196
+ _g.sent();
197
+ _g.label = 2;
198
+ case 2:
199
+ _g.trys.push([2, 4, 5, 6]);
200
+ parameters = __assign(__assign({}, parameters), { apiKey: (_a = this.config) === null || _a === void 0 ? void 0 : _a.apiKey });
201
+ args = {
202
+ url: path,
203
+ method: "POST",
204
+ baseURL: this.config.hostAnalytics,
205
+ data: parameters,
206
+ timeout: 600000,
207
+ responseType: "json",
208
+ maxRedirects: 5,
209
+ };
210
+ if (!!headers) {
211
+ args = __assign(__assign({}, args), { headers: headers });
212
+ }
213
+ if (!!cookies) {
214
+ cookieString = Object.keys(cookies).map(function (key) { return key + "=" + cookies[key]; }).join(";") + ";";
215
+ args = __assign(__assign({}, args), { headers: __assign(__assign({}, args.headers), { Cookie: cookieString }) });
216
+ }
217
+ return [4 /*yield*/, axios_1.default.request(args)];
218
+ case 3:
219
+ request = _g.sent();
220
+ this.headers = (request === null || request === void 0 ? void 0 : request.headers) || {};
221
+ if ((request === null || request === void 0 ? void 0 : request.status) !== 200) {
222
+ throw new Error(request === null || request === void 0 ? void 0 : request.statusText);
223
+ }
224
+ errorMessage = ((_b = request === null || request === void 0 ? void 0 : request.data) === null || _b === void 0 ? void 0 : _b.error) || "";
225
+ if (errorMessage) {
226
+ throw new Error(errorMessage);
227
+ }
228
+ return [3 /*break*/, 6];
229
+ case 4:
230
+ error_1 = _g.sent();
231
+ request = { data: { error: error_1 } };
232
+ if (this.config.verboseOutput) {
233
+ this.logger.error("Event Registry Analytics exception while executing the request.");
234
+ if (error_1 && error_1.stack && error_1.message) {
235
+ this.logger.error(error_1.message);
236
+ }
237
+ else {
238
+ this.logger.error("".concat((_c = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _c === void 0 ? void 0 : _c.status, ": ").concat((_d = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _d === void 0 ? void 0 : _d.statusText, " => ").concat((_e = error_1 === null || error_1 === void 0 ? void 0 : error_1.response) === null || _e === void 0 ? void 0 : _e.data));
239
+ }
240
+ }
241
+ // try to print out the error that should be passed by in case the server is down or responds with errors
242
+ if ((_f = this.config) === null || _f === void 0 ? void 0 : _f.logging) {
243
+ this.logger.error((error_1 === null || error_1 === void 0 ? void 0 : error_1.errno) || error_1);
244
+ }
245
+ return [3 /*break*/, 6];
246
+ case 5:
247
+ this.lock.release();
248
+ return [7 /*endfinally*/];
249
+ case 6: return [2 /*return*/, request];
250
+ }
251
+ });
252
+ });
253
+ };
254
+ /**
255
+ * Make a request for json data
256
+ * @param path url on er (e.g. "/api/v1/article")
257
+ * @param parameters Optional parameters to be included in the request
258
+ */
259
+ EventRegistry.prototype.jsonRequest = function (path_1, parameters_1) {
260
+ return __awaiter(this, arguments, void 0, function (path, parameters, allowUseOfArchive) {
261
+ var request, current, errorMessage, error_2;
262
+ var _a, _b, _c, _d, _e, _f;
263
+ if (allowUseOfArchive === void 0) { allowUseOfArchive = this.config.allowUseOfArchive; }
264
+ return __generator(this, function (_g) {
265
+ switch (_g.label) {
266
+ case 0:
267
+ current = moment.utc().milliseconds();
268
+ if (!(this.lastQueryTime && current - this.lastQueryTime < this.config.minDelayBetweenRequests)) return [3 /*break*/, 2];
269
+ return [4 /*yield*/, (0, base_1.sleep)(this.config.minDelayBetweenRequests - (current - this.lastQueryTime))];
270
+ case 1:
271
+ _g.sent();
272
+ _g.label = 2;
273
+ case 2: return [4 /*yield*/, this.lock.acquire()];
274
+ case 3:
275
+ _g.sent();
276
+ if (this._logRequests) {
277
+ if (Object.keys(parameters || {}).length > 0) {
278
+ this.logger.logRequest("# " + JSON.stringify(parameters) + "\n");
279
+ }
280
+ this.logger.logRequest(path + "\n\n");
281
+ }
282
+ this.lastQueryTime = current;
283
+ _g.label = 4;
284
+ case 4:
285
+ _g.trys.push([4, 6, 7, 8]);
286
+ parameters = __assign(__assign({}, parameters), { apiKey: (_a = this.config) === null || _a === void 0 ? void 0 : _a.apiKey });
287
+ if (!allowUseOfArchive) {
288
+ parameters = __assign(__assign({}, parameters), { forceMaxDataTimeWindow: 31 });
289
+ }
290
+ return [4 /*yield*/, axios_1.default.request({
291
+ url: path,
292
+ method: "POST",
293
+ baseURL: this.config.host,
294
+ data: parameters,
295
+ timeout: 600000,
296
+ responseType: "json",
297
+ maxRedirects: 5,
298
+ retry: this.config.repeatFailedRequestCount,
299
+ })];
300
+ case 5:
301
+ request = _g.sent();
302
+ this.headers = (request === null || request === void 0 ? void 0 : request.headers) || {};
303
+ if ((request === null || request === void 0 ? void 0 : request.status) !== 200) {
304
+ throw new Error(request === null || request === void 0 ? void 0 : request.statusText);
305
+ }
306
+ if (this.getLastHeader("warning")) {
307
+ this.logger.warn("WARNING: ".concat(this.getLastHeader("warning")));
308
+ }
309
+ this.dailyAvailableRequests = Number(this.getLastHeader("x-ratelimit-limit", "-1"));
310
+ this.remainingAvailableRequests = Number(this.getLastHeader("x-ratelimit-remaining", "-1"));
311
+ errorMessage = ((_b = request === null || request === void 0 ? void 0 : request.data) === null || _b === void 0 ? void 0 : _b.error) || "";
312
+ if (errorMessage) {
313
+ throw new Error(errorMessage);
314
+ }
315
+ return [3 /*break*/, 8];
316
+ case 6:
317
+ error_2 = _g.sent();
318
+ request = { data: { error: error_2 } };
319
+ // try to print out the error that should be passed by in case the server is down or responds with errors
320
+ if (this.config.verboseOutput) {
321
+ this.logger.error("Event Registry exception while executing the request.");
322
+ if (error_2 && error_2.stack && error_2.message) {
323
+ this.logger.error(error_2.message);
324
+ }
325
+ else {
326
+ this.logger.error("".concat((_c = error_2 === null || error_2 === void 0 ? void 0 : error_2.response) === null || _c === void 0 ? void 0 : _c.status, ": ").concat((_d = error_2 === null || error_2 === void 0 ? void 0 : error_2.response) === null || _d === void 0 ? void 0 : _d.statusText, " => ").concat((_e = error_2 === null || error_2 === void 0 ? void 0 : error_2.response) === null || _e === void 0 ? void 0 : _e.data));
327
+ }
328
+ }
329
+ if ((_f = this.config) === null || _f === void 0 ? void 0 : _f.logging) {
330
+ this.logger.error((error_2 === null || error_2 === void 0 ? void 0 : error_2.errno) || error_2);
331
+ }
332
+ return [3 /*break*/, 8];
333
+ case 7:
334
+ this.lock.release();
335
+ return [7 /*endfinally*/];
336
+ case 8: return [2 /*return*/, request];
337
+ }
338
+ });
339
+ });
340
+ };
341
+ /**
342
+ * get the number of requests that are still available for the user today. Information is only accessible after you make some query.
343
+ */
344
+ EventRegistry.prototype.getRemainingAvailableRequests = function () {
345
+ return this.remainingAvailableRequests;
346
+ };
347
+ /**
348
+ * get the total number of requests that the user can make in a day. Information is only accessible after you make some query.
349
+ */
350
+ EventRegistry.prototype.getDailyAvailableRequests = function () {
351
+ return this.dailyAvailableRequests;
352
+ };
353
+ /**
354
+ * Return the headers returned in the response object of the last executed request
355
+ */
356
+ EventRegistry.prototype.getLastHeaders = function () {
357
+ return this.headers;
358
+ };
359
+ /**
360
+ * Get a value of the header headerName that was set in the headers in the last response object
361
+ */
362
+ EventRegistry.prototype.getLastHeader = function (headerName, dfltVal) {
363
+ var _a, _b;
364
+ return (_b = (_a = this.headers) === null || _a === void 0 ? void 0 : _a[headerName]) !== null && _b !== void 0 ? _b : dfltVal;
365
+ };
366
+ /**
367
+ * print some statistics about the last executed request
368
+ */
369
+ EventRegistry.prototype.printLastReqStats = function () {
370
+ this.logger.info("Tokens used by the request: ".concat(this.getLastHeader("req-tokens")));
371
+ this.logger.info("Performed action: ".concat(this.getLastHeader("req-action")));
372
+ this.logger.info("Was archive used for the query: ".concat(this.getLastReqArchiveUse() ? "Yes" : "No"));
373
+ };
374
+ /**
375
+ * return true or false depending on whether the last request used the archive or not
376
+ */
377
+ EventRegistry.prototype.getLastReqArchiveUse = function () {
378
+ return this.getLastHeader("req-archive", "0") === "1";
379
+ };
380
+ /**
381
+ * Return the number of used and total available tokens. Can be used at any time (also before making queries)
382
+ */
383
+ EventRegistry.prototype.getUsageInfo = function () {
384
+ return __awaiter(this, void 0, void 0, function () {
385
+ var request;
386
+ return __generator(this, function (_a) {
387
+ switch (_a.label) {
388
+ case 0: return [4 /*yield*/, this.jsonRequest("/api/v1/usage")];
389
+ case 1:
390
+ request = _a.sent();
391
+ return [2 /*return*/, request.data];
392
+ }
393
+ });
394
+ });
395
+ };
396
+ EventRegistry.prototype.getServiceStatus = function () {
397
+ return __awaiter(this, void 0, void 0, function () {
398
+ var request;
399
+ return __generator(this, function (_a) {
400
+ switch (_a.label) {
401
+ case 0: return [4 /*yield*/, this.jsonRequest("/api/v1/getServiceStatus")];
402
+ case 1:
403
+ request = _a.sent();
404
+ return [2 /*return*/, request.data];
405
+ }
406
+ });
407
+ });
408
+ };
409
+ EventRegistry.prototype.getUrl = function (query) {
410
+ var _a;
411
+ if (!(query instanceof base_1.QueryParamsBase)) {
412
+ if (this.config.verboseOutput) {
413
+ this.logger.warn("query parameter should be an instance of a class that has Query as a base class, such as QueryArticles or QueryEvents");
414
+ }
415
+ }
416
+ var allParams = query.getQueryParams();
417
+ return "".concat((_a = this.config) === null || _a === void 0 ? void 0 : _a.host).concat(query === null || query === void 0 ? void 0 : query.path, "?").concat(Object.keys(allParams).map(function (key) { return "".concat(key, "=").concat(allParams[key]); }).join("&"));
418
+ };
419
+ /**
420
+ * Return a list of concepts that contain the given prefix.
421
+ * Returned matching concepts are sorted based on their frequency of occurrence in news (from most to least frequent)
422
+ * @param prefix input text that should be contained in the concept
423
+ * @param args Object which contains a host of optional parameters
424
+ */
425
+ EventRegistry.prototype.suggestConcepts = function (prefix_1) {
426
+ return __awaiter(this, arguments, void 0, function (prefix, args) {
427
+ var _a, sources, _b, lang, _c, conceptLang, _d, page, _e, count, _f, returnInfo, otherParams, params, request;
428
+ if (args === void 0) { args = {}; }
429
+ return __generator(this, function (_g) {
430
+ switch (_g.label) {
431
+ case 0:
432
+ _a = args.sources, sources = _a === void 0 ? ["concepts"] : _a, _b = args.lang, lang = _b === void 0 ? "eng" : _b, _c = args.conceptLang, conceptLang = _c === void 0 ? "eng" : _c, _d = args.page, page = _d === void 0 ? 1 : _d, _e = args.count, count = _e === void 0 ? 20 : _e, _f = args.returnInfo, returnInfo = _f === void 0 ? new returnInfo_1.ReturnInfo() : _f, otherParams = __rest(args, ["sources", "lang", "conceptLang", "page", "count", "returnInfo"]);
433
+ if (page <= 0) {
434
+ throw new RangeError("page parameter should be above 0");
435
+ }
436
+ params = {
437
+ prefix: prefix,
438
+ source: sources,
439
+ lang: lang,
440
+ conceptLang: conceptLang,
441
+ page: page,
442
+ count: count,
443
+ };
444
+ params = __assign(__assign(__assign({}, params), otherParams), returnInfo.getParams());
445
+ return [4 /*yield*/, this.jsonRequest("/api/v1/suggestConceptsFast", params)];
446
+ case 1:
447
+ request = _g.sent();
448
+ return [2 /*return*/, request.data];
449
+ }
450
+ });
451
+ });
452
+ };
453
+ /**
454
+ * Return a list of dmoz categories that contain the prefix
455
+ * @param prefix input text that should be contained in the category name
456
+ * @param args Object which contains a host of optional parameters
457
+ */
458
+ EventRegistry.prototype.suggestCategories = function (prefix_1) {
459
+ return __awaiter(this, arguments, void 0, function (prefix, args) {
460
+ var _a, page, _b, count, _c, returnInfo, otherParams, params, request;
461
+ if (args === void 0) { args = {}; }
462
+ return __generator(this, function (_d) {
463
+ switch (_d.label) {
464
+ case 0:
465
+ _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 20 : _b, _c = args.returnInfo, returnInfo = _c === void 0 ? new returnInfo_1.ReturnInfo() : _c, otherParams = __rest(args, ["page", "count", "returnInfo"]);
466
+ if (page <= 0) {
467
+ throw new RangeError("page parameter should be above 0");
468
+ }
469
+ params = { prefix: prefix, page: page, count: count };
470
+ params = __assign(__assign(__assign({}, params), otherParams), returnInfo.getParams());
471
+ return [4 /*yield*/, this.jsonRequest("/api/v1/suggestCategoriesFast", params)];
472
+ case 1:
473
+ request = _d.sent();
474
+ return [2 /*return*/, request.data];
475
+ }
476
+ });
477
+ });
478
+ };
479
+ /**
480
+ * Return a list of news sources that match the prefix
481
+ * @param prefix input text that should be contained in the source name or uri
482
+ * @param args Object which contains a host of optional parameters
483
+ */
484
+ EventRegistry.prototype.suggestNewsSources = function (prefix_1) {
485
+ return __awaiter(this, arguments, void 0, function (prefix, args) {
486
+ var _a, page, _b, count, _c, dataType, otherParams, request;
487
+ if (args === void 0) { args = {}; }
488
+ return __generator(this, function (_d) {
489
+ switch (_d.label) {
490
+ case 0:
491
+ _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 20 : _b, _c = args.dataType, dataType = _c === void 0 ? ["news", "pr", "blog"] : _c, otherParams = __rest(args, ["page", "count", "dataType"]);
492
+ if (page <= 0) {
493
+ throw new RangeError("page parameter should be above 0");
494
+ }
495
+ return [4 /*yield*/, this.jsonRequest("/api/v1/suggestSourcesFast", __assign({ prefix: prefix, page: page, dataType: dataType, count: count }, otherParams))];
496
+ case 1:
497
+ request = _d.sent();
498
+ return [2 /*return*/, request.data];
499
+ }
500
+ });
501
+ });
502
+ };
503
+ /**
504
+ * Return a list of news source groups that match the prefix
505
+ * @param prefix input text that should be contained in the source group name or uri
506
+ * @param args Object which contains a host of optional parameters
507
+ */
508
+ EventRegistry.prototype.suggestSourceGroups = function (prefix_1) {
509
+ return __awaiter(this, arguments, void 0, function (prefix, args) {
510
+ var _a, page, _b, count, otherParams, request;
511
+ if (args === void 0) { args = {}; }
512
+ return __generator(this, function (_c) {
513
+ switch (_c.label) {
514
+ case 0:
515
+ _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 20 : _b, otherParams = __rest(args, ["page", "count"]);
516
+ if (page <= 0) {
517
+ throw new RangeError("page parameter should be above 0");
518
+ }
519
+ return [4 /*yield*/, this.jsonRequest("/api/v1/suggestSourceGroups", __assign({ prefix: prefix, page: page, count: count }, otherParams))];
520
+ case 1:
521
+ request = _c.sent();
522
+ return [2 /*return*/, request.data];
523
+ }
524
+ });
525
+ });
526
+ };
527
+ /**
528
+ * Return a list of geo locations (cities or countries) that contain the prefix
529
+ * @param prefix input text that should be contained in the location name
530
+ * @param args Object which contains a host of optional parameters
531
+ */
532
+ EventRegistry.prototype.suggestLocations = function (prefix_1) {
533
+ return __awaiter(this, arguments, void 0, function (prefix, args) {
534
+ var _a, sources, _b, lang, _c, count, _d, countryUri, sortByDistanceTo, _e, returnInfo, otherParams, params, request;
535
+ if (args === void 0) { args = {}; }
536
+ return __generator(this, function (_f) {
537
+ switch (_f.label) {
538
+ case 0:
539
+ _a = args.sources, sources = _a === void 0 ? ["place", "country"] : _a, _b = args.lang, lang = _b === void 0 ? "eng" : _b, _c = args.count, count = _c === void 0 ? 20 : _c, _d = args.countryUri, countryUri = _d === void 0 ? "" : _d, sortByDistanceTo = args.sortByDistanceTo, _e = args.returnInfo, returnInfo = _e === void 0 ? new returnInfo_1.ReturnInfo() : _e, otherParams = __rest(args, ["sources", "lang", "count", "countryUri", "sortByDistanceTo", "returnInfo"]);
540
+ params = {
541
+ prefix: prefix,
542
+ count: count,
543
+ source: sources,
544
+ lang: lang,
545
+ countryUri: countryUri,
546
+ };
547
+ params = __assign(__assign(__assign({}, params), otherParams), returnInfo === null || returnInfo === void 0 ? void 0 : returnInfo.getParams());
548
+ if (sortByDistanceTo) {
549
+ if (!Array.isArray(sortByDistanceTo)) {
550
+ throw new Error("sortByDistanceTo has to contain a tuple with latitude and longitude of the location");
551
+ }
552
+ if (sortByDistanceTo.length !== 2) {
553
+ throw new Error("The sortByDistanceTo should contain two numbers");
554
+ }
555
+ params["closeToLat"] = sortByDistanceTo[0];
556
+ params["closeToLon"] = sortByDistanceTo[1];
557
+ }
558
+ return [4 /*yield*/, this.jsonRequest("/api/v1/suggestLocationsFast", params)];
559
+ case 1:
560
+ request = _f.sent();
561
+ return [2 /*return*/, request === null || request === void 0 ? void 0 : request.data];
562
+ }
563
+ });
564
+ });
565
+ };
566
+ /**
567
+ * Return a list of geo locations (cities or places) that are close to the provided (lat, long) values
568
+ * @param latitude latitude part of the coordinate
569
+ * @param longitude longitude part of the coordinate
570
+ * @param radiusKm radius in kilometers around the coordinates inside which the locations should be returned
571
+ * @param args Object which contains a host of optional parameters
572
+ */
573
+ EventRegistry.prototype.suggestLocationsAtCoordinate = function (latitude_1, longitude_1, radiusKm_1) {
574
+ return __awaiter(this, arguments, void 0, function (latitude, longitude, radiusKm, args) {
575
+ var _a, limitToCities, _b, lang, _c, count, _d, ignoreNonWiki, _e, returnInfo, otherParams, params, request;
576
+ if (args === void 0) { args = {}; }
577
+ return __generator(this, function (_f) {
578
+ switch (_f.label) {
579
+ case 0:
580
+ _a = args.limitToCities, limitToCities = _a === void 0 ? false : _a, _b = args.lang, lang = _b === void 0 ? "eng" : _b, _c = args.count, count = _c === void 0 ? 20 : _c, _d = args.ignoreNonWiki, ignoreNonWiki = _d === void 0 ? true : _d, _e = args.returnInfo, returnInfo = _e === void 0 ? new returnInfo_1.ReturnInfo() : _e, otherParams = __rest(args, ["limitToCities", "lang", "count", "ignoreNonWiki", "returnInfo"]);
581
+ if (typeof latitude !== "number") {
582
+ throw new Error("The 'latitude' should be a number");
583
+ }
584
+ if (typeof longitude !== "number") {
585
+ throw new Error("The 'longitude' should be a number");
586
+ }
587
+ params = {
588
+ action: "getLocationsAtCoordinate",
589
+ lat: latitude,
590
+ lon: longitude,
591
+ radius: radiusKm,
592
+ limitToCities: limitToCities,
593
+ count: count,
594
+ lang: lang,
595
+ };
596
+ params = __assign(__assign(__assign({}, params), otherParams), returnInfo === null || returnInfo === void 0 ? void 0 : returnInfo.getParams());
597
+ return [4 /*yield*/, this.jsonRequest("/api/v1/suggestLocationsFast", params)];
598
+ case 1:
599
+ request = _f.sent();
600
+ return [2 /*return*/, request === null || request === void 0 ? void 0 : request.data];
601
+ }
602
+ });
603
+ });
604
+ };
605
+ /**
606
+ * Return a list of news sources that are close to the provided (lat, long) values
607
+ * @param latitude latitude part of the coordinate
608
+ * @param longitude longitude part of the coordinate
609
+ * @param radiusKm radius in kilometers around the coordinates inside which the news sources should be located
610
+ * @param count number of returned suggestions
611
+ */
612
+ EventRegistry.prototype.suggestSourcesAtCoordinate = function (latitude_1, longitude_1, radiusKm_1) {
613
+ return __awaiter(this, arguments, void 0, function (latitude, longitude, radiusKm, count) {
614
+ var _i, params, request;
615
+ if (count === void 0) { count = 20; }
616
+ var otherParams = [];
617
+ for (_i = 4; _i < arguments.length; _i++) {
618
+ otherParams[_i - 4] = arguments[_i];
619
+ }
620
+ return __generator(this, function (_a) {
621
+ switch (_a.label) {
622
+ case 0:
623
+ if (typeof latitude !== "number") {
624
+ throw new Error("The 'latitude' should be a number");
625
+ }
626
+ if (typeof longitude !== "number") {
627
+ throw new Error("The 'longitude' should be a number");
628
+ }
629
+ params = __assign({ action: "getSourcesAtCoordinate", lat: latitude, lon: longitude, radius: radiusKm, count: count }, otherParams);
630
+ return [4 /*yield*/, this.jsonRequest("/api/v1/suggestSourcesFast", params)];
631
+ case 1:
632
+ request = _a.sent();
633
+ return [2 /*return*/, request === null || request === void 0 ? void 0 : request.data];
634
+ }
635
+ });
636
+ });
637
+ };
638
+ /**
639
+ * Return a list of news sources that are close to the provided (lat, long) values
640
+ * @param conceptUri concept that represents a geographic location for which we would like to obtain a list of sources located at the place
641
+ * @param args Object which contains a host of optional parameters
642
+ */
643
+ EventRegistry.prototype.suggestSourcesAtPlace = function (conceptUri_1) {
644
+ return __awaiter(this, arguments, void 0, function (conceptUri, args) {
645
+ var _a, page, _b, count, _c, dataType, otherParams, params, request;
646
+ if (args === void 0) { args = {}; }
647
+ return __generator(this, function (_d) {
648
+ switch (_d.label) {
649
+ case 0:
650
+ _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 20 : _b, _c = args.dataType, dataType = _c === void 0 ? "news" : _c, otherParams = __rest(args, ["page", "count", "dataType"]);
651
+ params = __assign({ action: "getSourcesAtPlace", conceptUri: conceptUri, page: page, count: count, dataType: dataType }, otherParams);
652
+ return [4 /*yield*/, this.jsonRequest("/api/v1/suggestSourcesFast", params)];
653
+ case 1:
654
+ request = _d.sent();
655
+ return [2 /*return*/, request.data];
656
+ }
657
+ });
658
+ });
659
+ };
660
+ /**
661
+ * Return a list of news sources that match the prefix
662
+ * @param prefix: input text that should be contained in the author name and source url
663
+ * @param page: page of results
664
+ * @param count: number of returned suggestions
665
+ */
666
+ EventRegistry.prototype.suggestAuthors = function (prefix_1) {
667
+ return __awaiter(this, arguments, void 0, function (prefix, page, count) {
668
+ var _i, params, request;
669
+ if (page === void 0) { page = 1; }
670
+ if (count === void 0) { count = 20; }
671
+ var otherParams = [];
672
+ for (_i = 3; _i < arguments.length; _i++) {
673
+ otherParams[_i - 3] = arguments[_i];
674
+ }
675
+ return __generator(this, function (_a) {
676
+ switch (_a.label) {
677
+ case 0:
678
+ if (page <= 0) {
679
+ throw new Error("Page parameter should be above 0.");
680
+ }
681
+ params = __assign({ prefix: prefix, page: page, count: count }, otherParams);
682
+ return [4 /*yield*/, this.jsonRequest("/api/v1/suggestAuthorsFast", params)];
683
+ case 1:
684
+ request = _a.sent();
685
+ return [2 /*return*/, request.data];
686
+ }
687
+ });
688
+ });
689
+ };
690
+ /**
691
+ * Return a list of event types that match the prefix
692
+ * @param prefix: input text that should be contained in the industry name
693
+ * @param page: page of results
694
+ * @param count: number of returned suggestions
695
+ */
696
+ EventRegistry.prototype.suggestEventTypes = function (prefix_1) {
697
+ return __awaiter(this, arguments, void 0, function (prefix, page, count) {
698
+ var _i, params, request;
699
+ if (page === void 0) { page = 1; }
700
+ if (count === void 0) { count = 20; }
701
+ var otherParams = [];
702
+ for (_i = 3; _i < arguments.length; _i++) {
703
+ otherParams[_i - 3] = arguments[_i];
704
+ }
705
+ return __generator(this, function (_a) {
706
+ switch (_a.label) {
707
+ case 0:
708
+ if (page <= 0) {
709
+ throw new Error("Page parameter should be above 0.");
710
+ }
711
+ params = __assign({ prefix: prefix, page: page, count: count }, otherParams);
712
+ return [4 /*yield*/, this.jsonRequest("/api/v1/eventType/suggestEventTypes", params)];
713
+ case 1:
714
+ request = _a.sent();
715
+ return [2 /*return*/, request.data];
716
+ }
717
+ });
718
+ });
719
+ };
720
+ /**
721
+ * Return a list of industries that match the prefix. Note: Industries can only be used when querying mentions (QueryMentions, QueryMentionsIter)
722
+ * @param prefix: input text that should be contained in the industry name
723
+ * @param page: page of results
724
+ * @param count: number of returned suggestions
725
+ */
726
+ EventRegistry.prototype.suggestIndustries = function (prefix_1) {
727
+ return __awaiter(this, arguments, void 0, function (prefix, page, count) {
728
+ var _i, params, request;
729
+ if (page === void 0) { page = 1; }
730
+ if (count === void 0) { count = 20; }
731
+ var otherParams = [];
732
+ for (_i = 3; _i < arguments.length; _i++) {
733
+ otherParams[_i - 3] = arguments[_i];
734
+ }
735
+ return __generator(this, function (_a) {
736
+ switch (_a.label) {
737
+ case 0:
738
+ if (page <= 0) {
739
+ throw new Error("Page parameter should be above 0.");
740
+ }
741
+ params = __assign({ prefix: prefix, page: page, count: count }, otherParams);
742
+ return [4 /*yield*/, this.jsonRequest("/api/v1/eventType/suggestIndustries", params)];
743
+ case 1:
744
+ request = _a.sent();
745
+ return [2 /*return*/, request.data];
746
+ }
747
+ });
748
+ });
749
+ };
750
+ /**
751
+ * Return a list of SDG uris. Note: Industries can only be used when querying mentions (QueryMentions, QueryMentionsIter)
752
+ */
753
+ EventRegistry.prototype.getSdgUris = function () {
754
+ return __awaiter(this, void 0, void 0, function () {
755
+ var request;
756
+ return __generator(this, function (_a) {
757
+ switch (_a.label) {
758
+ case 0: return [4 /*yield*/, this.jsonRequest("/api/v1/eventType/sdg/getItems")];
759
+ case 1:
760
+ request = _a.sent();
761
+ return [2 /*return*/, request.data];
762
+ }
763
+ });
764
+ });
765
+ };
766
+ /**
767
+ * Return a list of SASB uris. Note: SASB uris can only be used when querying mentions (QueryMentions, QueryMentionsIter)
768
+ */
769
+ EventRegistry.prototype.getSasbUris = function () {
770
+ return __awaiter(this, void 0, void 0, function () {
771
+ var request;
772
+ return __generator(this, function (_a) {
773
+ switch (_a.label) {
774
+ case 0: return [4 /*yield*/, this.jsonRequest("/api/v1/eventType/sasb/getItems")];
775
+ case 1:
776
+ request = _a.sent();
777
+ return [2 /*return*/, request.data];
778
+ }
779
+ });
780
+ });
781
+ };
782
+ /**
783
+ * Return a list of concept classes that match the given prefix
784
+ * @param prefix input text that should be contained in the category name
785
+ * @param args Object which contains a host of optional parameters
786
+ */
787
+ EventRegistry.prototype.suggestConceptClasses = function (prefix_1) {
788
+ return __awaiter(this, arguments, void 0, function (prefix, args) {
789
+ var _a, lang, _b, conceptLang, _c, source, _d, page, _e, count, _f, returnInfo, otherParams, params, request;
790
+ if (args === void 0) { args = {}; }
791
+ return __generator(this, function (_g) {
792
+ switch (_g.label) {
793
+ case 0:
794
+ _a = args.lang, lang = _a === void 0 ? "eng" : _a, _b = args.conceptLang, conceptLang = _b === void 0 ? "eng" : _b, _c = args.source, source = _c === void 0 ? ["dbpedia", "custom"] : _c, _d = args.page, page = _d === void 0 ? 1 : _d, _e = args.count, count = _e === void 0 ? 20 : _e, _f = args.returnInfo, returnInfo = _f === void 0 ? new returnInfo_1.ReturnInfo() : _f, otherParams = __rest(args, ["lang", "conceptLang", "source", "page", "count", "returnInfo"]);
795
+ if (page < 1) {
796
+ throw new Error("page parameter should be above 0");
797
+ }
798
+ params = { prefix: prefix, lang: lang, conceptLang: conceptLang, source: source, page: page, count: count };
799
+ params = __assign(__assign(__assign({}, params), otherParams), returnInfo === null || returnInfo === void 0 ? void 0 : returnInfo.getParams());
800
+ return [4 /*yield*/, this.jsonRequest("/api/v1/suggestConceptClasses", params)];
801
+ case 1:
802
+ request = _g.sent();
803
+ return [2 /*return*/, request === null || request === void 0 ? void 0 : request.data];
804
+ }
805
+ });
806
+ });
807
+ };
808
+ /**
809
+ * return a concept uri that is the best match for the given concept label
810
+ * if there are multiple matches for the given conceptLabel,
811
+ * they are sorted based on their frequency of occurrence in news (most to least frequent)
812
+ * @param conceptLabel partial or full name of the concept for which to return the concept uri
813
+ * @param args Object which contains a host of optional parameters
814
+ */
815
+ EventRegistry.prototype.getConceptUri = function (conceptLabel_1) {
816
+ return __awaiter(this, arguments, void 0, function (conceptLabel, args) {
817
+ var _a, lang, _b, sources, matches;
818
+ var _c;
819
+ if (args === void 0) { args = {}; }
820
+ return __generator(this, function (_d) {
821
+ switch (_d.label) {
822
+ case 0:
823
+ _a = args.lang, lang = _a === void 0 ? "eng" : _a, _b = args.sources, sources = _b === void 0 ? ["concepts"] : _b;
824
+ return [4 /*yield*/, this.suggestConcepts(conceptLabel, { lang: lang, sources: sources })];
825
+ case 1:
826
+ matches = _d.sent();
827
+ return [2 /*return*/, (_c = matches === null || matches === void 0 ? void 0 : matches[0]) === null || _c === void 0 ? void 0 : _c.uri];
828
+ }
829
+ });
830
+ });
831
+ };
832
+ /**
833
+ * Return a location uri that is the best match for the given location label
834
+ * @param locationLabel partial or full location name for which to return the location uri
835
+ * @param args Object which contains a host of optional parameters
836
+ */
837
+ EventRegistry.prototype.getLocationUri = function (locationLabel_1) {
838
+ return __awaiter(this, arguments, void 0, function (locationLabel, args) {
839
+ var _a, lang, _b, sources, countryUri, sortByDistanceTo, matches;
840
+ var _c;
841
+ if (args === void 0) { args = {}; }
842
+ return __generator(this, function (_d) {
843
+ switch (_d.label) {
844
+ case 0:
845
+ _a = args.lang, lang = _a === void 0 ? "eng" : _a, _b = args.sources, sources = _b === void 0 ? ["place", "country"] : _b, countryUri = args.countryUri, sortByDistanceTo = args.sortByDistanceTo;
846
+ return [4 /*yield*/, this.suggestLocations(locationLabel, { lang: lang, sources: sources, countryUri: countryUri, sortByDistanceTo: sortByDistanceTo })];
847
+ case 1:
848
+ matches = _d.sent();
849
+ return [2 /*return*/, (_c = matches === null || matches === void 0 ? void 0 : matches[0]) === null || _c === void 0 ? void 0 : _c.wikiUri];
850
+ }
851
+ });
852
+ });
853
+ };
854
+ /**
855
+ * Return a category uri that is the best match for the given label
856
+ * @param categoryLabel partial or full name of the category for which to return category uri
857
+ */
858
+ EventRegistry.prototype.getCategoryUri = function (categoryLabel) {
859
+ return __awaiter(this, void 0, void 0, function () {
860
+ var matches;
861
+ var _a;
862
+ return __generator(this, function (_b) {
863
+ switch (_b.label) {
864
+ case 0: return [4 /*yield*/, this.suggestCategories(categoryLabel)];
865
+ case 1:
866
+ matches = _b.sent();
867
+ return [2 /*return*/, (_a = matches === null || matches === void 0 ? void 0 : matches[0]) === null || _a === void 0 ? void 0 : _a.uri];
868
+ }
869
+ });
870
+ });
871
+ };
872
+ /**
873
+ * Return the news source that best matches the source name
874
+ * @param sourceName partial or full name of the source or source uri for which to return source uri
875
+ * @param dataType: return the source uri that provides content of these data types
876
+ */
877
+ EventRegistry.prototype.getNewsSourceUri = function (sourceName_1) {
878
+ return __awaiter(this, arguments, void 0, function (sourceName, dataType) {
879
+ var matches;
880
+ var _a;
881
+ if (dataType === void 0) { dataType = ["news", "pr", "blog"]; }
882
+ return __generator(this, function (_b) {
883
+ switch (_b.label) {
884
+ case 0: return [4 /*yield*/, this.suggestNewsSources(sourceName, { dataType: dataType })];
885
+ case 1:
886
+ matches = _b.sent();
887
+ return [2 /*return*/, (_a = matches === null || matches === void 0 ? void 0 : matches[0]) === null || _a === void 0 ? void 0 : _a.uri];
888
+ }
889
+ });
890
+ });
891
+ };
892
+ /**
893
+ * alternative (shorter) name for the method getNewsSourceUri()
894
+ */
895
+ EventRegistry.prototype.getSourceUri = function (sourceName_1) {
896
+ return __awaiter(this, arguments, void 0, function (sourceName, dataType) {
897
+ if (dataType === void 0) { dataType = ["news", "pr", "blog"]; }
898
+ return __generator(this, function (_a) {
899
+ switch (_a.label) {
900
+ case 0: return [4 /*yield*/, this.getNewsSourceUri(sourceName, dataType)];
901
+ case 1: return [2 /*return*/, _a.sent()];
902
+ }
903
+ });
904
+ });
905
+ };
906
+ /**
907
+ * Return the URI of the source group that best matches the name
908
+ * @param sourceGroupName partial or full name of the source group
909
+ */
910
+ EventRegistry.prototype.getSourceGroupUri = function (sourceGroupName) {
911
+ return __awaiter(this, void 0, void 0, function () {
912
+ var matches;
913
+ var _a;
914
+ return __generator(this, function (_b) {
915
+ switch (_b.label) {
916
+ case 0: return [4 /*yield*/, this.suggestSourceGroups(sourceGroupName)];
917
+ case 1:
918
+ matches = _b.sent();
919
+ return [2 /*return*/, (_a = matches === null || matches === void 0 ? void 0 : matches[0]) === null || _a === void 0 ? void 0 : _a.uri];
920
+ }
921
+ });
922
+ });
923
+ };
924
+ /**
925
+ * Return a uri of the concept class that is the best match for the given label
926
+ * @param classLabel partial or full name of the concept class for which to return class uri
927
+ * @param lang language in which the class label is specified
928
+ */
929
+ EventRegistry.prototype.getConceptClassUri = function (classLabel_1) {
930
+ return __awaiter(this, arguments, void 0, function (classLabel, lang) {
931
+ var matches;
932
+ var _a;
933
+ if (lang === void 0) { lang = "eng"; }
934
+ return __generator(this, function (_b) {
935
+ switch (_b.label) {
936
+ case 0: return [4 /*yield*/, this.suggestConceptClasses(classLabel, { lang: lang })];
937
+ case 1:
938
+ matches = _b.sent();
939
+ return [2 /*return*/, (_a = matches === null || matches === void 0 ? void 0 : matches[0]) === null || _a === void 0 ? void 0 : _a.uri];
940
+ }
941
+ });
942
+ });
943
+ };
944
+ /**
945
+ * Return detailed information about a particular concept
946
+ * @param conceptUri uri of the concept
947
+ * @param returnInfo what details about the concept should be included in the returned information
948
+ */
949
+ EventRegistry.prototype.getConceptInfo = function (conceptUri, returnInfo) {
950
+ return __awaiter(this, void 0, void 0, function () {
951
+ var conceptInfo, params, request;
952
+ var _a;
953
+ return __generator(this, function (_b) {
954
+ switch (_b.label) {
955
+ case 0:
956
+ if (!returnInfo) {
957
+ conceptInfo = new returnInfo_1.ConceptInfoFlags({ synonyms: true, image: true, description: true });
958
+ returnInfo = new returnInfo_1.ReturnInfo({ conceptInfo: conceptInfo });
959
+ }
960
+ params = {
961
+ uri: conceptUri,
962
+ action: "getInfo",
963
+ };
964
+ params = __assign(__assign({}, params), ((_a = returnInfo === null || returnInfo === void 0 ? void 0 : returnInfo.getParams()) !== null && _a !== void 0 ? _a : {}));
965
+ return [4 /*yield*/, this.jsonRequest("/api/v1/concept/getInfo", params)];
966
+ case 1:
967
+ request = _b.sent();
968
+ return [2 /*return*/, request.data];
969
+ }
970
+ });
971
+ });
972
+ };
973
+ /**
974
+ * return author uri that is the best match for the given author name (and potentially source url)
975
+ * if there are multiple matches for the given author name, they are sorted based on the number of articles they have written (from most to least frequent)
976
+ * @param authorName: partial or full name of the author, potentially also containing the source url (e.g. "george brown nytimes")
977
+ */
978
+ EventRegistry.prototype.getAuthorUri = function (authorName) {
979
+ return __awaiter(this, void 0, void 0, function () {
980
+ var matches;
981
+ var _a;
982
+ return __generator(this, function (_b) {
983
+ switch (_b.label) {
984
+ case 0: return [4 /*yield*/, this.suggestAuthors(authorName)];
985
+ case 1:
986
+ matches = _b.sent();
987
+ return [2 /*return*/, (_a = matches === null || matches === void 0 ? void 0 : matches[0]) === null || _a === void 0 ? void 0 : _a.uri];
988
+ }
989
+ });
990
+ });
991
+ };
992
+ EventRegistry.getUriFromUriWgt = function (uriWgtList) {
993
+ if (!Array.isArray(uriWgtList)) {
994
+ throw new Error("uriWgtList has to be a list of strings that represent article uris");
995
+ }
996
+ return uriWgtList.map(function (uriWgt) { return uriWgt.split(":")[0]; });
997
+ };
998
+ // Additional utility functions
999
+ /**
1000
+ * If you have article urls and you want to query them in ER you first have to obtain their uris in the ER.
1001
+ * @param articleUrls a single article url or a list of article urls
1002
+ */
1003
+ EventRegistry.prototype.getArticleUris = function (articleUrls) {
1004
+ return __awaiter(this, void 0, void 0, function () {
1005
+ var request;
1006
+ return __generator(this, function (_a) {
1007
+ switch (_a.label) {
1008
+ case 0:
1009
+ if (!Array.isArray(articleUrls) && typeof articleUrls !== "string") {
1010
+ throw new Error("Expected a single article url or a list of urls");
1011
+ }
1012
+ return [4 /*yield*/, this.jsonRequest("/api/v1/articleMapper", { articleUrl: articleUrls })];
1013
+ case 1:
1014
+ request = _a.sent();
1015
+ return [2 /*return*/, request.data];
1016
+ }
1017
+ });
1018
+ });
1019
+ };
1020
+ /**
1021
+ * Return information about the latest imported article
1022
+ */
1023
+ EventRegistry.prototype.getSourceGroups = function () {
1024
+ return __awaiter(this, void 0, void 0, function () {
1025
+ var request;
1026
+ return __generator(this, function (_a) {
1027
+ switch (_a.label) {
1028
+ case 0: return [4 /*yield*/, this.jsonRequest("/api/v1/sourceGroup/getSourceGroups", { action: "getSourceGroups" })];
1029
+ case 1:
1030
+ request = _a.sent();
1031
+ return [2 /*return*/, request.data];
1032
+ }
1033
+ });
1034
+ });
1035
+ };
1036
+ /**
1037
+ * Return info about the source group
1038
+ */
1039
+ EventRegistry.prototype.getSourceGroup = function (sourceGroupUri) {
1040
+ return __awaiter(this, void 0, void 0, function () {
1041
+ var request;
1042
+ return __generator(this, function (_a) {
1043
+ switch (_a.label) {
1044
+ case 0: return [4 /*yield*/, this.jsonRequest("/api/v1/sourceGroup/getSourceGroupInfo", { action: "getSourceGroupInfo", uri: sourceGroupUri })];
1045
+ case 1:
1046
+ request = _a.sent();
1047
+ return [2 /*return*/, request.data];
1048
+ }
1049
+ });
1050
+ });
1051
+ };
1052
+ return EventRegistry;
1053
+ }());
1054
+ exports.EventRegistry = EventRegistry;
1055
+ /**
1056
+ * @class ArticleMapper
1057
+ * Create instance of article mapper it will map from article urls to article uris
1058
+ * the mappings can be remembered so it will not repeat requests for the same article urls
1059
+ */
1060
+ var ArticleMapper = /** @class */ (function () {
1061
+ function ArticleMapper(er, rememberMapping) {
1062
+ if (rememberMapping === void 0) { rememberMapping = true; }
1063
+ this.articleUrlToUri = {};
1064
+ this.rememberMappings = true;
1065
+ this.er = er;
1066
+ this.rememberMappings = rememberMapping;
1067
+ }
1068
+ /**
1069
+ * Given the article url, return an array with 0, 1 or more article uris.
1070
+ * Not all returned article uris are necessarily valid anymore.
1071
+ * For news sources of lower importance we remove the duplicated articles and just keep the latest content
1072
+ * @param articleUrl string containing the article url
1073
+ */
1074
+ ArticleMapper.prototype.getArticleUri = function (articleUrl) {
1075
+ return __awaiter(this, void 0, void 0, function () {
1076
+ var response, value;
1077
+ var _a;
1078
+ return __generator(this, function (_b) {
1079
+ switch (_b.label) {
1080
+ case 0:
1081
+ if (this.articleUrlToUri.hasOwnProperty(articleUrl)) {
1082
+ return [2 /*return*/, this.articleUrlToUri[articleUrl]];
1083
+ }
1084
+ return [4 /*yield*/, this.er.getArticleUris(articleUrl)];
1085
+ case 1:
1086
+ response = _b.sent();
1087
+ value = response === null || response === void 0 ? void 0 : response[articleUrl];
1088
+ if (this.rememberMappings && value) {
1089
+ this.articleUrlToUri = __assign(__assign({}, this.articleUrlToUri), (_a = {}, _a[articleUrl] = value, _a));
1090
+ }
1091
+ return [2 /*return*/, value];
1092
+ }
1093
+ });
1094
+ });
1095
+ };
1096
+ return ArticleMapper;
1097
+ }());
1098
+ exports.ArticleMapper = ArticleMapper;
1019
1099
  //# sourceMappingURL=eventRegistry.js.map