eventregistry 8.11.2 → 9.1.0

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 +44 -0
  28. package/dist/logger.js +144 -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,570 +1,588 @@
1
- "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- }
9
- return function (d, b) {
10
- extendStatics(d, b);
11
- function __() { this.constructor = d; }
12
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
13
- };
14
- })();
15
- var __assign = (this && this.__assign) || function () {
16
- __assign = Object.assign || function(t) {
17
- for (var s, i = 1, n = arguments.length; i < n; i++) {
18
- s = arguments[i];
19
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
20
- t[p] = s[p];
21
- }
22
- return t;
23
- };
24
- return __assign.apply(this, arguments);
25
- };
26
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
27
- return new (P || (P = Promise))(function (resolve, reject) {
28
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
31
- step((generator = generator.apply(thisArg, _arguments || [])).next());
32
- });
33
- };
34
- var __generator = (this && this.__generator) || function (thisArg, body) {
35
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
- function verb(n) { return function (v) { return step([n, v]); }; }
38
- function step(op) {
39
- if (f) throw new TypeError("Generator is already executing.");
40
- while (_) try {
41
- 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;
42
- if (y = 0, t) op = [op[0] & 2, t.value];
43
- switch (op[0]) {
44
- case 0: case 1: t = op; break;
45
- case 4: _.label++; return { value: op[1], done: false };
46
- case 5: _.label++; y = op[1]; op = [0]; continue;
47
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
- default:
49
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
- if (t[2]) _.ops.pop();
54
- _.trys.pop(); continue;
55
- }
56
- op = body.call(thisArg, _);
57
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
- }
60
- };
61
- var __rest = (this && this.__rest) || function (s, e) {
62
- var t = {};
63
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
64
- t[p] = s[p];
65
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
66
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) if (e.indexOf(p[i]) < 0)
67
- t[p[i]] = s[p[i]];
68
- return t;
69
- };
70
- var __read = (this && this.__read) || function (o, n) {
71
- var m = typeof Symbol === "function" && o[Symbol.iterator];
72
- if (!m) return o;
73
- var i = m.call(o), r, ar = [], e;
74
- try {
75
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
76
- }
77
- catch (error) { e = { error: error }; }
78
- finally {
79
- try {
80
- if (r && !r.done && (m = i["return"])) m.call(i);
81
- }
82
- finally { if (e) throw e.error; }
83
- }
84
- return ar;
85
- };
86
- var __spread = (this && this.__spread) || function () {
87
- for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
88
- return ar;
89
- };
90
- Object.defineProperty(exports, "__esModule", { value: true });
91
- var _ = require("lodash");
92
- var base_1 = require("./base");
93
- var returnInfo_1 = require("./returnInfo");
94
- /**
95
- * @class QueryEvent
96
- * Class for obtaining available info for one or more events in the Event Registry
97
- */
98
- var QueryEvent = /** @class */ (function (_super) {
99
- __extends(QueryEvent, _super);
100
- /**
101
- * @param eventUriOrList A single event uri or a list of event uris (max 50)
102
- * @param requestedResult The information to return as the result of the query. By default return the details of the event
103
- */
104
- function QueryEvent(eventUriOrList, requestedResult) {
105
- if (requestedResult === void 0) { requestedResult = new RequestEventInfo(); }
106
- var _this = _super.call(this) || this;
107
- _this.setVal("eventUri", eventUriOrList);
108
- _this.setRequestedResult(requestedResult);
109
- return _this;
110
- }
111
- /**
112
- * Set the single result type that you would like to be returned. Any previously set result types will be overwritten.
113
- * Result types can be the classes that extend RequestEvent base class (see classes below).
114
- */
115
- QueryEvent.prototype.setRequestedResult = function (requestEvent) {
116
- if (!(requestEvent instanceof RequestEvent)) {
117
- throw Error("QueryEvent class can only accept result requests that are of type RequestEvent");
118
- }
119
- this.path = requestEvent.path;
120
- this.resultTypeList = [requestEvent];
121
- };
122
- return QueryEvent;
123
- }(base_1.Query));
124
- exports.QueryEvent = QueryEvent;
125
- /**
126
- * @class QueryEventArticlesIter
127
- * Class for iterating through all the articles in the event via callbacks
128
- */
129
- var QueryEventArticlesIter = /** @class */ (function (_super) {
130
- __extends(QueryEventArticlesIter, _super);
131
- /**
132
- * @param er instance of EventRegistry class. used to obtain the necessary data
133
- * @param eventUri a single event for which we want to obtain the list of articles in it
134
- * @param args Object which contains a host of optional parameters
135
- */
136
- function QueryEventArticlesIter(er, eventUri, args) {
137
- if (args === void 0) { args = {}; }
138
- var _this = _super.call(this, eventUri) || this;
139
- _this.page = 0;
140
- _this.pages = 1;
141
- _this.items = [];
142
- _this.returnedSoFar = 0;
143
- _this.index = 0;
144
- _this.callback = _.noop;
145
- _this.doneCallback = _.noop;
146
- var _a = args.lang, lang = _a === void 0 ? undefined : _a, _b = args.sortBy, sortBy = _b === void 0 ? "cosSim" : _b, _c = args.sortByAsc, sortByAsc = _c === void 0 ? false : _c, _d = args.returnInfo, returnInfo = _d === void 0 ? undefined : _d, _e = args.maxItems, maxItems = _e === void 0 ? -1 : _e, _f = args.keywords, keywords = _f === void 0 ? undefined : _f, _g = args.conceptUri, conceptUri = _g === void 0 ? undefined : _g, _h = args.categoryUri, categoryUri = _h === void 0 ? undefined : _h, _j = args.sourceUri, sourceUri = _j === void 0 ? undefined : _j, _k = args.sourceLocationUri, sourceLocationUri = _k === void 0 ? undefined : _k, _l = args.sourceGroupUri, sourceGroupUri = _l === void 0 ? undefined : _l, _m = args.authorUri, authorUri = _m === void 0 ? undefined : _m, _o = args.locationUri, locationUri = _o === void 0 ? undefined : _o, _p = args.dateStart, dateStart = _p === void 0 ? undefined : _p, _q = args.dateEnd, dateEnd = _q === void 0 ? undefined : _q, _r = args.dateMentionStart, dateMentionStart = _r === void 0 ? undefined : _r, _s = args.dateMentionEnd, dateMentionEnd = _s === void 0 ? undefined : _s, _t = args.keywordsLoc, keywordsLoc = _t === void 0 ? "body" : _t, _u = args.startSourceRankPercentile, startSourceRankPercentile = _u === void 0 ? 0 : _u, _v = args.endSourceRankPercentile, endSourceRankPercentile = _v === void 0 ? 100 : _v, _w = args.minSentiment, minSentiment = _w === void 0 ? -1 : _w, _x = args.maxSentiment, maxSentiment = _x === void 0 ? 1 : _x;
147
- _this.er = er;
148
- _this.sortBy = sortBy;
149
- _this.sortByAsc = sortByAsc;
150
- _this.returnInfo = returnInfo;
151
- _this.maxItems = maxItems;
152
- _this.eventUri = eventUri;
153
- _this.setQueryArrVal(keywords, "keyword", "keywordOper", "and");
154
- _this.setQueryArrVal(conceptUri, "conceptUri", "conceptOper", "and");
155
- _this.setQueryArrVal(categoryUri, "categoryUri", "categoryOper", "or");
156
- _this.setQueryArrVal(sourceUri, "sourceUri", "sourceOper", "or");
157
- _this.setQueryArrVal(sourceLocationUri, "sourceLocationUri", undefined, "or");
158
- _this.setQueryArrVal(sourceGroupUri, "sourceGroupUri", "sourceGroupOper", "or");
159
- _this.setQueryArrVal(authorUri, "authorUri", "authorOper", "or");
160
- _this.setQueryArrVal(locationUri, "locationUri", undefined, "or");
161
- _this.setQueryArrVal(lang, "lang", undefined, "or");
162
- if (!_.isUndefined(dateStart)) {
163
- _this.setDateVal("dateStart", dateStart);
164
- }
165
- if (!_.isUndefined(dateEnd)) {
166
- _this.setDateVal("dateEnd", dateEnd);
167
- }
168
- if (!_.isUndefined(dateMentionStart)) {
169
- _this.setDateVal("dateMentionStart", dateMentionStart);
170
- }
171
- if (!_.isUndefined(dateMentionEnd)) {
172
- _this.setDateVal("dateMentionEnd", dateMentionEnd);
173
- }
174
- _this.setValIfNotDefault("keywordLoc", keywordsLoc, "body");
175
- if (startSourceRankPercentile < 0 || startSourceRankPercentile % 10 !== 0 || startSourceRankPercentile > 100) {
176
- throw new Error("StartSourceRankPercentile: Value should be in range 0-90 and divisible by 10.");
177
- }
178
- if (endSourceRankPercentile < 0 || endSourceRankPercentile % 10 !== 0 || endSourceRankPercentile > 100) {
179
- throw new Error("EndSourceRankPercentile: Value should be in range 0-90 and divisible by 10.");
180
- }
181
- if (startSourceRankPercentile > endSourceRankPercentile) {
182
- throw new Error("SourceRankPercentile: startSourceRankPercentile should be less than endSourceRankPercentile");
183
- }
184
- if (startSourceRankPercentile !== 0) {
185
- _this.setVal("startSourceRankPercentile", startSourceRankPercentile);
186
- }
187
- if (endSourceRankPercentile !== 100) {
188
- _this.setVal("endSourceRankPercentile", endSourceRankPercentile);
189
- }
190
- if (minSentiment > -1 && minSentiment <= 1) {
191
- _this.setVal("minSentiment", minSentiment);
192
- }
193
- if (maxSentiment >= -1 && maxSentiment < 1) {
194
- _this.setVal("maxSentiment", maxSentiment);
195
- }
196
- return _this;
197
- }
198
- /**
199
- * Async Iterator function that returns the next item in the list of articles
200
- */
201
- QueryEventArticlesIter.prototype[Symbol.asyncIterator] = function () {
202
- var _this = this;
203
- return {
204
- next: function () { return __awaiter(_this, void 0, void 0, function () {
205
- var item;
206
- return __generator(this, function (_a) {
207
- switch (_a.label) {
208
- case 0:
209
- if (!(this.index >= this.items.length)) return [3 /*break*/, 2];
210
- return [4 /*yield*/, this.getNextBatch()];
211
- case 1:
212
- _a.sent();
213
- _a.label = 2;
214
- case 2:
215
- item = this.items[this.index];
216
- this.index++;
217
- return [2 /*return*/, { value: item, done: !item }];
218
- }
219
- });
220
- }); },
221
- };
222
- };
223
- QueryEventArticlesIter.prototype.count = function () {
224
- return __awaiter(this, void 0, void 0, function () {
225
- var response;
226
- return __generator(this, function (_a) {
227
- switch (_a.label) {
228
- case 0:
229
- this.setRequestedResult(new RequestEventArticles(this.getQueryParams()));
230
- return [4 /*yield*/, this.er.execQuery(this)];
231
- case 1:
232
- response = _a.sent();
233
- if (_.has(response, "error")) {
234
- console.error(_.get(response, "error"));
235
- }
236
- return [2 /*return*/, _.get(response[this.eventUri], "articles.totalResults", 0)];
237
- }
238
- });
239
- });
240
- };
241
- /**
242
- * Execute query and fetch batches of articles of the specified size (articleBatchSize)
243
- * @param callback callback function that'll be called every time we get a new batch of articles from the backend
244
- * @param doneCallback callback function that'll be called when everything is complete
245
- */
246
- QueryEventArticlesIter.prototype.execQuery = function (callback, doneCallback) {
247
- if (callback) {
248
- this.callback = callback;
249
- }
250
- if (doneCallback) {
251
- this.doneCallback = doneCallback;
252
- }
253
- this.iterate();
254
- };
255
- QueryEventArticlesIter.prototype.iterate = function () {
256
- return __awaiter(this, void 0, void 0, function () {
257
- return __generator(this, function (_a) {
258
- switch (_a.label) {
259
- case 0:
260
- if (!this.current) return [3 /*break*/, 1];
261
- this.callback(this.current);
262
- this.index += 1;
263
- return [3 /*break*/, 3];
264
- case 1: return [4 /*yield*/, this.getNextBatch()];
265
- case 2:
266
- if (!(_a.sent())) {
267
- this.doneCallback(this.errorMessage);
268
- return [2 /*return*/];
269
- }
270
- _a.label = 3;
271
- case 3: return [2 /*return*/, this.iterate()];
272
- }
273
- });
274
- });
275
- };
276
- /**
277
- * Extract the results according to maxItems
278
- * @param response response from the backend
279
- */
280
- QueryEventArticlesIter.prototype.extractResults = function (response) {
281
- var results = _.get(response[this.eventUri], "articles.results", []);
282
- var extractedSize = this.maxItems !== -1 ? this.maxItems - this.returnedSoFar : _.size(results);
283
- return _.compact(_.pullAt(results, _.range(0, extractedSize)));
284
- };
285
- Object.defineProperty(QueryEventArticlesIter.prototype, "current", {
286
- get: function () {
287
- return this.items[this.index] || undefined;
288
- },
289
- enumerable: true,
290
- configurable: true
291
- });
292
- QueryEventArticlesIter.prototype.getNextBatch = function () {
293
- return __awaiter(this, void 0, void 0, function () {
294
- var response, error, results, error_1;
295
- return __generator(this, function (_a) {
296
- switch (_a.label) {
297
- case 0:
298
- _a.trys.push([0, 2, , 3]);
299
- this.page += 1;
300
- if (this.page > this.pages || (this.maxItems !== -1 && this.returnedSoFar >= this.maxItems)) {
301
- return [2 /*return*/, false];
302
- }
303
- this.setRequestedResult(new RequestEventArticles(__assign({ page: this.page, sortBy: this.sortBy, sortByAsc: this.sortByAsc, returnInfo: this.returnInfo }, this.getQueryParams())));
304
- if (this.er.verboseOutput) {
305
- console.log("Downloading page " + this.page + "...");
306
- }
307
- return [4 /*yield*/, this.er.execQuery(this, this.er.allowUseOfArchive)];
308
- case 1:
309
- response = _a.sent();
310
- error = _.get(response[this.eventUri], "error", "");
311
- if (error) {
312
- this.errorMessage = "Error while obtaining a list of articles: " + _.get(response[this.eventUri], "error");
313
- }
314
- else {
315
- this.pages = _.get(response[this.eventUri], "articles.pages", 0);
316
- }
317
- results = this.extractResults(response);
318
- this.returnedSoFar += _.size(results);
319
- this.items = __spread(this.items, results);
320
- return [2 /*return*/, true];
321
- case 2:
322
- error_1 = _a.sent();
323
- console.error(error_1);
324
- return [2 /*return*/, false];
325
- case 3: return [2 /*return*/];
326
- }
327
- });
328
- });
329
- };
330
- return QueryEventArticlesIter;
331
- }(QueryEvent));
332
- exports.QueryEventArticlesIter = QueryEventArticlesIter;
333
- var RequestEvent = /** @class */ (function (_super) {
334
- __extends(RequestEvent, _super);
335
- function RequestEvent() {
336
- var _this = _super !== null && _super.apply(this, arguments) || this;
337
- _this.path = "/api/v1/event/getEvent";
338
- return _this;
339
- }
340
- return RequestEvent;
341
- }(base_1.QueryParamsBase));
342
- exports.RequestEvent = RequestEvent;
343
- /**
344
- * @class RequestEventInfo
345
- * Return details about an event
346
- */
347
- var RequestEventInfo = /** @class */ (function (_super) {
348
- __extends(RequestEventInfo, _super);
349
- function RequestEventInfo(returnInfo) {
350
- if (returnInfo === void 0) { returnInfo = new returnInfo_1.ReturnInfo(); }
351
- var _this = _super.call(this) || this;
352
- _this.resultType = "info";
353
- _this.params = returnInfo.getParams("info");
354
- return _this;
355
- }
356
- return RequestEventInfo;
357
- }(RequestEvent));
358
- exports.RequestEventInfo = RequestEventInfo;
359
- /**
360
- * @class RequestEventArticles
361
- * Return articles about the event
362
- */
363
- var RequestEventArticles = /** @class */ (function (_super) {
364
- __extends(RequestEventArticles, _super);
365
- function RequestEventArticles(args) {
366
- if (args === void 0) { args = {}; }
367
- var _this = _super.call(this) || this;
368
- _this.resultType = "articles";
369
- var _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 100 : _b, _c = args.lang, lang = _c === void 0 ? undefined : _c, _d = args.keywords, keywords = _d === void 0 ? undefined : _d, _e = args.conceptUri, conceptUri = _e === void 0 ? undefined : _e, _f = args.categoryUri, categoryUri = _f === void 0 ? undefined : _f, _g = args.sourceUri, sourceUri = _g === void 0 ? undefined : _g, _h = args.sourceLocationUri, sourceLocationUri = _h === void 0 ? undefined : _h, _j = args.sourceGroupUri, sourceGroupUri = _j === void 0 ? undefined : _j, _k = args.authorUri, authorUri = _k === void 0 ? undefined : _k, _l = args.locationUri, locationUri = _l === void 0 ? undefined : _l, _m = args.dateStart, dateStart = _m === void 0 ? undefined : _m, _o = args.dateEnd, dateEnd = _o === void 0 ? undefined : _o, _p = args.dateMentionStart, dateMentionStart = _p === void 0 ? undefined : _p, _q = args.dateMentionEnd, dateMentionEnd = _q === void 0 ? undefined : _q, _r = args.keywordsLoc, keywordsLoc = _r === void 0 ? "body" : _r, _s = args.startSourceRankPercentile, startSourceRankPercentile = _s === void 0 ? 0 : _s, _t = args.endSourceRankPercentile, endSourceRankPercentile = _t === void 0 ? 100 : _t, _u = args.sortBy, sortBy = _u === void 0 ? "cosSim" : _u, _v = args.sortByAsc, sortByAsc = _v === void 0 ? false : _v, _w = args.returnInfo, returnInfo = _w === void 0 ? undefined : _w;
370
- if (page < 1) {
371
- throw new RangeError("Page has to be >= 1");
372
- }
373
- if (count > 100) {
374
- throw new RangeError("At most 100 articles can be returned per call");
375
- }
376
- _this.params = {};
377
- _this.params["articlesPage"] = page;
378
- _this.params["articlesCount"] = count;
379
- _this.params["articlesSortBy"] = sortBy;
380
- _this.params["articlesSortByAsc"] = sortByAsc;
381
- _this.setQueryArrVal(keywords, "keyword", "keywordOper", "and");
382
- _this.setQueryArrVal(conceptUri, "conceptUri", "conceptOper", "and");
383
- _this.setQueryArrVal(categoryUri, "categoryUri", "categoryOper", "or");
384
- _this.setQueryArrVal(sourceUri, "sourceUri", "sourceOper", "or");
385
- _this.setQueryArrVal(sourceLocationUri, "sourceLocationUri", undefined, "or");
386
- _this.setQueryArrVal(sourceGroupUri, "sourceGroupUri", "sourceGroupOper", "or");
387
- _this.setQueryArrVal(authorUri, "authorUri", "authorOper", "or");
388
- _this.setQueryArrVal(locationUri, "locationUri", undefined, "or");
389
- _this.setQueryArrVal(lang, "articlesLang", undefined, "or");
390
- if (!_.isUndefined(dateStart)) {
391
- _this.setDateVal("dateStart", dateStart);
392
- }
393
- if (!_.isUndefined(dateEnd)) {
394
- _this.setDateVal("dateEnd", dateEnd);
395
- }
396
- if (!_.isUndefined(dateMentionStart)) {
397
- _this.setDateVal("dateMentionStart", dateMentionStart);
398
- }
399
- if (!_.isUndefined(dateMentionEnd)) {
400
- _this.setDateVal("dateMentionEnd", dateMentionEnd);
401
- }
402
- _this.setValIfNotDefault("keywordLoc", keywordsLoc, "body");
403
- if (startSourceRankPercentile < 0 || startSourceRankPercentile % 10 !== 0 || startSourceRankPercentile > 100) {
404
- throw new Error("StartSourceRankPercentile: Value should be in range 0-90 and divisible by 10.");
405
- }
406
- if (endSourceRankPercentile < 0 || endSourceRankPercentile % 10 !== 0 || endSourceRankPercentile > 100) {
407
- throw new Error("EndSourceRankPercentile: Value should be in range 0-90 and divisible by 10.");
408
- }
409
- if (startSourceRankPercentile > endSourceRankPercentile) {
410
- throw new Error("SourceRankPercentile: startSourceRankPercentile should be less than endSourceRankPercentile");
411
- }
412
- if (startSourceRankPercentile !== 0) {
413
- _this.setVal("startSourceRankPercentile", startSourceRankPercentile);
414
- }
415
- if (endSourceRankPercentile !== 100) {
416
- _this.setVal("endSourceRankPercentile", endSourceRankPercentile);
417
- }
418
- if (!!returnInfo) {
419
- _this.params = _.extend({}, _this.params, _this.getQueryParams(), returnInfo.getParams("articles"));
420
- }
421
- return _this;
422
- }
423
- return RequestEventArticles;
424
- }(RequestEvent));
425
- exports.RequestEventArticles = RequestEventArticles;
426
- /**
427
- * @class RequestEventArticleUriWgts
428
- * Return just a list of article uris
429
- */
430
- var RequestEventArticleUriWgts = /** @class */ (function (_super) {
431
- __extends(RequestEventArticleUriWgts, _super);
432
- function RequestEventArticleUriWgts(args) {
433
- if (args === void 0) { args = {}; }
434
- var _this = _super.call(this) || this;
435
- _this.resultType = "uriWgtList";
436
- var _a = args.lang, lang = _a === void 0 ? undefined : _a, _b = args.sortBy, sortBy = _b === void 0 ? "cosSim" : _b, _c = args.sortByAsc, sortByAsc = _c === void 0 ? false : _c, unsupported = __rest(args, ["lang", "sortBy", "sortByAsc"]);
437
- if (!_.isEmpty(unsupported)) {
438
- console.warn("RequestEventArticleUriWgts: Unsupported parameters detected: " + JSON.stringify(unsupported) + ". Please check the documentation.");
439
- }
440
- _this.params = {};
441
- if (!_.isUndefined(lang)) {
442
- _this.params["articlesLang"] = lang;
443
- }
444
- _this.params["uriWgtListSortBy"] = sortBy;
445
- _this.params["uriWgtListSortByAsc"] = sortByAsc;
446
- return _this;
447
- }
448
- return RequestEventArticleUriWgts;
449
- }(RequestEvent));
450
- exports.RequestEventArticleUriWgts = RequestEventArticleUriWgts;
451
- /**
452
- * @class RequestEventKeywordAggr
453
- * Return keyword aggregate (tag-cloud) from articles in the event.
454
- */
455
- var RequestEventKeywordAggr = /** @class */ (function (_super) {
456
- __extends(RequestEventKeywordAggr, _super);
457
- /**
458
- * @param lang: language for which to compute the keywords
459
- */
460
- function RequestEventKeywordAggr(lang) {
461
- if (lang === void 0) { lang = "eng"; }
462
- var _this = _super.call(this) || this;
463
- _this.resultType = "keywordAggr";
464
- _this.params = {};
465
- _this.params["articlesLang"] = lang;
466
- return _this;
467
- }
468
- return RequestEventKeywordAggr;
469
- }(RequestEvent));
470
- exports.RequestEventKeywordAggr = RequestEventKeywordAggr;
471
- /**
472
- * @class RequestEventSourceAggr
473
- * Get news source distribution of articles in the event.
474
- */
475
- var RequestEventSourceAggr = /** @class */ (function (_super) {
476
- __extends(RequestEventSourceAggr, _super);
477
- function RequestEventSourceAggr() {
478
- var _this = _super !== null && _super.apply(this, arguments) || this;
479
- _this.resultType = "sourceExAggr";
480
- return _this;
481
- }
482
- return RequestEventSourceAggr;
483
- }(RequestEvent));
484
- exports.RequestEventSourceAggr = RequestEventSourceAggr;
485
- /**
486
- * @class RequestEventDateMentionAggr
487
- * Get dates that we found mentioned in the event articles and their frequencies.
488
- */
489
- var RequestEventDateMentionAggr = /** @class */ (function (_super) {
490
- __extends(RequestEventDateMentionAggr, _super);
491
- function RequestEventDateMentionAggr() {
492
- var _this = _super !== null && _super.apply(this, arguments) || this;
493
- _this.resultType = "dateMentionAggr";
494
- return _this;
495
- }
496
- return RequestEventDateMentionAggr;
497
- }(RequestEvent));
498
- exports.RequestEventDateMentionAggr = RequestEventDateMentionAggr;
499
- /**
500
- * @class RequestEventArticleTrend
501
- * Return trending information for the articles about the event.
502
- */
503
- var RequestEventArticleTrend = /** @class */ (function (_super) {
504
- __extends(RequestEventArticleTrend, _super);
505
- function RequestEventArticleTrend(args) {
506
- if (args === void 0) { args = {}; }
507
- var _this = _super.call(this) || this;
508
- _this.resultType = "articleTrend";
509
- var _a = args.lang, lang = _a === void 0 ? undefined : _a, _b = args.page, page = _b === void 0 ? 1 : _b, _c = args.count, count = _c === void 0 ? 100 : _c, _d = args.minArticleCosSim, minArticleCosSim = _d === void 0 ? -1 : _d, _e = args.returnInfo, returnInfo = _e === void 0 ? new returnInfo_1.ReturnInfo({ articleInfo: new returnInfo_1.ArticleInfoFlags({ bodyLen: 0 }) }) : _e, unsupported = __rest(args, ["lang", "page", "count", "minArticleCosSim", "returnInfo"]);
510
- if (!_.isEmpty(unsupported)) {
511
- console.warn("RequestEventArticleTrend: Unsupported parameters detected: " + JSON.stringify(unsupported) + ". Please check the documentation.");
512
- }
513
- if (page < 1) {
514
- throw new RangeError("Page has to be >= 1");
515
- }
516
- if (count > 100) {
517
- throw new RangeError("At most 100 articles can be returned per call");
518
- }
519
- _this.params = {};
520
- _this.params["articlesLang"] = lang;
521
- _this.params["articleTrendPage"] = page;
522
- _this.params["articleTrendCount"] = count;
523
- _this.params["articleTrendMinArticleCosSim"] = minArticleCosSim;
524
- _this.params = _.extend({}, _this.params, returnInfo.getParams("articleTrend"));
525
- return _this;
526
- }
527
- return RequestEventArticleTrend;
528
- }(RequestEvent));
529
- exports.RequestEventArticleTrend = RequestEventArticleTrend;
530
- /**
531
- * @class RequestEventSimilarEvents
532
- * Compute and return a list of similar events.
533
- */
534
- var RequestEventSimilarEvents = /** @class */ (function (_super) {
535
- __extends(RequestEventSimilarEvents, _super);
536
- function RequestEventSimilarEvents(args) {
537
- if (args === void 0) { args = {}; }
538
- var _this = _super.call(this) || this;
539
- _this.path = "/api/v1/event/getSimilarEvents";
540
- var conceptInfoList = args.conceptInfoList, _a = args.count, count = _a === void 0 ? 50 : _a, _b = args.dateStart, dateStart = _b === void 0 ? undefined : _b, _c = args.dateEnd, dateEnd = _c === void 0 ? undefined : _c, _d = args.addArticleTrendInfo, addArticleTrendInfo = _d === void 0 ? false : _d, _e = args.aggrHours, aggrHours = _e === void 0 ? 6 : _e, _f = args.returnInfo, returnInfo = _f === void 0 ? new returnInfo_1.ReturnInfo() : _f, unsupported = __rest(args, ["conceptInfoList", "count", "dateStart", "dateEnd", "addArticleTrendInfo", "aggrHours", "returnInfo"]);
541
- if (!_.isEmpty(unsupported)) {
542
- console.warn("RequestEventSimilarEvents: Unsupported parameters detected: " + JSON.stringify(unsupported) + ". Please check the documentation.");
543
- }
544
- if (count > 50) {
545
- throw new RangeError("At most 50 similar events can be returned per call");
546
- }
547
- if (!_.isArray(conceptInfoList)) {
548
- throw new Error("Concept info list is not an array");
549
- }
550
- _this.params = {};
551
- _this.params["action"] = "getSimilarEvents";
552
- _this.params["concepts"] = JSON.stringify(conceptInfoList);
553
- // Potential problem, verify that output corresponds the REST API docs.
554
- _this.params["eventsCount"] = count;
555
- if (!!dateStart) {
556
- _this.params["dateStart"] = base_1.QueryParamsBase.encodeDateTime(dateStart, "YYYY-MM-DD");
557
- }
558
- if (!!dateEnd) {
559
- _this.params["dateEnd"] = base_1.QueryParamsBase.encodeDateTime(dateEnd, "YYYY-MM-DD");
560
- }
561
- _this.params["addArticleTrendInfo"] = addArticleTrendInfo;
562
- _this.params["aggrHours"] = aggrHours;
563
- _this.params["resultType"] = "similarEvents";
564
- _this.params = _.extend({}, _this.params, returnInfo.getParams());
565
- return _this;
566
- }
567
- return RequestEventSimilarEvents;
568
- }(RequestEvent));
569
- exports.RequestEventSimilarEvents = RequestEventSimilarEvents;
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __assign = (this && this.__assign) || function () {
18
+ __assign = Object.assign || function(t) {
19
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
20
+ s = arguments[i];
21
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
+ t[p] = s[p];
23
+ }
24
+ return t;
25
+ };
26
+ return __assign.apply(this, arguments);
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
+ 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;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ var __rest = (this && this.__rest) || function (s, e) {
65
+ var t = {};
66
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
67
+ t[p] = s[p];
68
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
69
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
70
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
71
+ t[p[i]] = s[p[i]];
72
+ }
73
+ return t;
74
+ };
75
+ var __read = (this && this.__read) || function (o, n) {
76
+ var m = typeof Symbol === "function" && o[Symbol.iterator];
77
+ if (!m) return o;
78
+ var i = m.call(o), r, ar = [], e;
79
+ try {
80
+ while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
81
+ }
82
+ catch (error) { e = { error: error }; }
83
+ finally {
84
+ try {
85
+ if (r && !r.done && (m = i["return"])) m.call(i);
86
+ }
87
+ finally { if (e) throw e.error; }
88
+ }
89
+ return ar;
90
+ };
91
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
92
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
93
+ if (ar || !(i in from)) {
94
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
95
+ ar[i] = from[i];
96
+ }
97
+ }
98
+ return to.concat(ar || Array.prototype.slice.call(from));
99
+ };
100
+ Object.defineProperty(exports, "__esModule", { value: true });
101
+ exports.RequestEventSimilarEvents = exports.RequestEventArticleTrend = exports.RequestEventDateMentionAggr = exports.RequestEventSourceAggr = exports.RequestEventKeywordAggr = exports.RequestEventArticleUriWgts = exports.RequestEventArticles = exports.RequestEventInfo = exports.RequestEvent = exports.QueryEventArticlesIter = exports.QueryEvent = void 0;
102
+ var base_1 = require("./base");
103
+ var returnInfo_1 = require("./returnInfo");
104
+ var logger_1 = require("./logger");
105
+ /**
106
+ * @class QueryEvent
107
+ * Class for obtaining available info for one or more events in the Event Registry
108
+ */
109
+ var QueryEvent = /** @class */ (function (_super) {
110
+ __extends(QueryEvent, _super);
111
+ /**
112
+ * @param eventUriOrList A single event uri or a list of event uris (max 50)
113
+ * @param requestedResult The information to return as the result of the query. By default return the details of the event
114
+ */
115
+ function QueryEvent(eventUriOrList, requestedResult) {
116
+ if (requestedResult === void 0) { requestedResult = new RequestEventInfo(); }
117
+ var _this = _super.call(this) || this;
118
+ _this.setVal("eventUri", eventUriOrList);
119
+ _this.setRequestedResult(requestedResult);
120
+ return _this;
121
+ }
122
+ /**
123
+ * Set the single result type that you would like to be returned. Any previously set result types will be overwritten.
124
+ * Result types can be the classes that extend RequestEvent base class (see classes below).
125
+ */
126
+ QueryEvent.prototype.setRequestedResult = function (requestEvent) {
127
+ if (!(requestEvent instanceof RequestEvent)) {
128
+ throw Error("QueryEvent class can only accept result requests that are of type RequestEvent");
129
+ }
130
+ this.path = requestEvent.path;
131
+ this.resultTypeList = [requestEvent];
132
+ };
133
+ return QueryEvent;
134
+ }(base_1.Query));
135
+ exports.QueryEvent = QueryEvent;
136
+ /**
137
+ * @class QueryEventArticlesIter
138
+ * Class for iterating through all the articles in the event via callbacks
139
+ */
140
+ var QueryEventArticlesIter = /** @class */ (function (_super) {
141
+ __extends(QueryEventArticlesIter, _super);
142
+ /**
143
+ * @param er instance of EventRegistry class. used to obtain the necessary data
144
+ * @param eventUri a single event for which we want to obtain the list of articles in it
145
+ * @param args Object which contains a host of optional parameters
146
+ */
147
+ function QueryEventArticlesIter(er, eventUri, args) {
148
+ if (args === void 0) { args = {}; }
149
+ var _this = _super.call(this, eventUri) || this;
150
+ _this.page = 0;
151
+ _this.pages = 1;
152
+ _this.items = [];
153
+ _this.returnedSoFar = 0;
154
+ _this.index = 0;
155
+ _this.callback = function () { return undefined; };
156
+ _this.doneCallback = function () { return undefined; };
157
+ var _a = args.lang, lang = _a === void 0 ? undefined : _a, _b = args.sortBy, sortBy = _b === void 0 ? "cosSim" : _b, _c = args.sortByAsc, sortByAsc = _c === void 0 ? false : _c, _d = args.returnInfo, returnInfo = _d === void 0 ? undefined : _d, _e = args.maxItems, maxItems = _e === void 0 ? -1 : _e, _f = args.keywords, keywords = _f === void 0 ? undefined : _f, _g = args.conceptUri, conceptUri = _g === void 0 ? undefined : _g, _h = args.categoryUri, categoryUri = _h === void 0 ? undefined : _h, _j = args.sourceUri, sourceUri = _j === void 0 ? undefined : _j, _k = args.sourceLocationUri, sourceLocationUri = _k === void 0 ? undefined : _k, _l = args.sourceGroupUri, sourceGroupUri = _l === void 0 ? undefined : _l, _m = args.authorUri, authorUri = _m === void 0 ? undefined : _m, _o = args.locationUri, locationUri = _o === void 0 ? undefined : _o, _p = args.dateStart, dateStart = _p === void 0 ? undefined : _p, _q = args.dateEnd, dateEnd = _q === void 0 ? undefined : _q, _r = args.dateMentionStart, dateMentionStart = _r === void 0 ? undefined : _r, _s = args.dateMentionEnd, dateMentionEnd = _s === void 0 ? undefined : _s, _t = args.keywordsLoc, keywordsLoc = _t === void 0 ? "body" : _t, _u = args.keywordSearchMode, keywordSearchMode = _u === void 0 ? "phrase" : _u, // "simple", "exact", "phrase"]
158
+ _v = args.startSourceRankPercentile, // "simple", "exact", "phrase"]
159
+ startSourceRankPercentile = _v === void 0 ? 0 : _v, _w = args.endSourceRankPercentile, endSourceRankPercentile = _w === void 0 ? 100 : _w, _x = args.minSentiment, minSentiment = _x === void 0 ? -1 : _x, _y = args.maxSentiment, maxSentiment = _y === void 0 ? 1 : _y;
160
+ _this.er = er;
161
+ _this.sortBy = sortBy;
162
+ _this.sortByAsc = sortByAsc;
163
+ _this.returnInfo = returnInfo;
164
+ _this.maxItems = maxItems;
165
+ _this.eventUri = eventUri;
166
+ _this.setQueryArrVal(keywords, "keyword", "keywordOper", "and");
167
+ _this.setQueryArrVal(conceptUri, "conceptUri", "conceptOper", "and");
168
+ _this.setQueryArrVal(categoryUri, "categoryUri", "categoryOper", "or");
169
+ _this.setQueryArrVal(sourceUri, "sourceUri", "sourceOper", "or");
170
+ _this.setQueryArrVal(sourceLocationUri, "sourceLocationUri", undefined, "or");
171
+ _this.setQueryArrVal(sourceGroupUri, "sourceGroupUri", "sourceGroupOper", "or");
172
+ _this.setQueryArrVal(authorUri, "authorUri", "authorOper", "or");
173
+ _this.setQueryArrVal(locationUri, "locationUri", undefined, "or");
174
+ _this.setQueryArrVal(lang, "lang", undefined, "or");
175
+ if (dateStart !== undefined) {
176
+ _this.setDateVal("dateStart", dateStart);
177
+ }
178
+ if (dateEnd !== undefined) {
179
+ _this.setDateVal("dateEnd", dateEnd);
180
+ }
181
+ if (dateMentionStart !== undefined) {
182
+ _this.setDateVal("dateMentionStart", dateMentionStart);
183
+ }
184
+ if (dateMentionEnd !== undefined) {
185
+ _this.setDateVal("dateMentionEnd", dateMentionEnd);
186
+ }
187
+ _this.setValIfNotDefault("keywordLoc", keywordsLoc, "body");
188
+ _this.setValIfNotDefault("keywordSearchMode", keywordSearchMode, "phrase");
189
+ if (startSourceRankPercentile < 0 || startSourceRankPercentile % 10 !== 0 || startSourceRankPercentile > 100) {
190
+ throw new Error("StartSourceRankPercentile: Value should be in range 0-90 and divisible by 10.");
191
+ }
192
+ if (endSourceRankPercentile < 0 || endSourceRankPercentile % 10 !== 0 || endSourceRankPercentile > 100) {
193
+ throw new Error("EndSourceRankPercentile: Value should be in range 0-90 and divisible by 10.");
194
+ }
195
+ if (startSourceRankPercentile > endSourceRankPercentile) {
196
+ throw new Error("SourceRankPercentile: startSourceRankPercentile should be less than endSourceRankPercentile");
197
+ }
198
+ if (startSourceRankPercentile !== 0) {
199
+ _this.setVal("startSourceRankPercentile", startSourceRankPercentile);
200
+ }
201
+ if (endSourceRankPercentile !== 100) {
202
+ _this.setVal("endSourceRankPercentile", endSourceRankPercentile);
203
+ }
204
+ if (minSentiment > -1 && minSentiment <= 1) {
205
+ _this.setVal("minSentiment", minSentiment);
206
+ }
207
+ if (maxSentiment >= -1 && maxSentiment < 1) {
208
+ _this.setVal("maxSentiment", maxSentiment);
209
+ }
210
+ return _this;
211
+ }
212
+ /**
213
+ * Async Iterator function that returns the next item in the list of articles
214
+ */
215
+ QueryEventArticlesIter.prototype[Symbol.asyncIterator] = function () {
216
+ var _this = this;
217
+ return {
218
+ next: function () { return __awaiter(_this, void 0, void 0, function () {
219
+ var item;
220
+ return __generator(this, function (_a) {
221
+ switch (_a.label) {
222
+ case 0:
223
+ if (!(this.index >= this.items.length)) return [3 /*break*/, 2];
224
+ return [4 /*yield*/, this.getNextBatch()];
225
+ case 1:
226
+ _a.sent();
227
+ _a.label = 2;
228
+ case 2:
229
+ item = this.items[this.index];
230
+ this.index++;
231
+ return [2 /*return*/, { value: item, done: !item }];
232
+ }
233
+ });
234
+ }); },
235
+ };
236
+ };
237
+ QueryEventArticlesIter.prototype.count = function () {
238
+ return __awaiter(this, void 0, void 0, function () {
239
+ var response;
240
+ var _a, _b, _c, _d;
241
+ return __generator(this, function (_e) {
242
+ switch (_e.label) {
243
+ case 0:
244
+ this.setRequestedResult(new RequestEventArticles(this.getQueryParams()));
245
+ return [4 /*yield*/, this.er.execQuery(this)];
246
+ case 1:
247
+ response = _e.sent();
248
+ if (!!(response === null || response === void 0 ? void 0 : response.error)) {
249
+ this.er.logger.error((_a = response === null || response === void 0 ? void 0 : response.error) !== null && _a !== void 0 ? _a : "Error while obtaining a list of articles");
250
+ }
251
+ return [2 /*return*/, (_d = (_c = (_b = response[this.eventUri]) === null || _b === void 0 ? void 0 : _b.articles) === null || _c === void 0 ? void 0 : _c.totalResults) !== null && _d !== void 0 ? _d : 0];
252
+ }
253
+ });
254
+ });
255
+ };
256
+ /**
257
+ * Execute query and fetch batches of articles of the specified size (articleBatchSize)
258
+ * @param callback callback function that'll be called every time we get a new batch of articles from the backend
259
+ * @param doneCallback callback function that'll be called when everything is complete
260
+ */
261
+ QueryEventArticlesIter.prototype.execQuery = function (callback, doneCallback) {
262
+ if (callback) {
263
+ this.callback = callback;
264
+ }
265
+ if (doneCallback) {
266
+ this.doneCallback = doneCallback;
267
+ }
268
+ this.iterate();
269
+ };
270
+ QueryEventArticlesIter.prototype.iterate = function () {
271
+ return __awaiter(this, void 0, void 0, function () {
272
+ return __generator(this, function (_a) {
273
+ switch (_a.label) {
274
+ case 0:
275
+ if (!this.current) return [3 /*break*/, 1];
276
+ this.callback(this.current);
277
+ this.index += 1;
278
+ return [3 /*break*/, 3];
279
+ case 1: return [4 /*yield*/, this.getNextBatch()];
280
+ case 2:
281
+ if (!(_a.sent())) {
282
+ this.doneCallback(this.errorMessage);
283
+ return [2 /*return*/];
284
+ }
285
+ _a.label = 3;
286
+ case 3: return [2 /*return*/, this.iterate()];
287
+ }
288
+ });
289
+ });
290
+ };
291
+ /**
292
+ * Extract the results according to maxItems
293
+ * @param response response from the backend
294
+ */
295
+ QueryEventArticlesIter.prototype.extractResults = function (response) {
296
+ var _a, _b;
297
+ var results = ((_b = (_a = response[this.eventUri]) === null || _a === void 0 ? void 0 : _a.articles) === null || _b === void 0 ? void 0 : _b.results) || [];
298
+ var extractedSize = this.maxItems !== -1 ? this.maxItems - this.returnedSoFar : results.length;
299
+ var extractedResults = results.slice(0, extractedSize);
300
+ return extractedResults.filter(Boolean);
301
+ };
302
+ Object.defineProperty(QueryEventArticlesIter.prototype, "current", {
303
+ get: function () {
304
+ return this.items[this.index] || undefined;
305
+ },
306
+ enumerable: false,
307
+ configurable: true
308
+ });
309
+ QueryEventArticlesIter.prototype.getNextBatch = function () {
310
+ return __awaiter(this, void 0, void 0, function () {
311
+ var response, error, results, error_1;
312
+ var _a, _b, _c, _d;
313
+ return __generator(this, function (_e) {
314
+ switch (_e.label) {
315
+ case 0:
316
+ _e.trys.push([0, 2, , 3]);
317
+ this.page += 1;
318
+ if (this.page > this.pages || (this.maxItems !== -1 && this.returnedSoFar >= this.maxItems)) {
319
+ return [2 /*return*/, false];
320
+ }
321
+ this.setRequestedResult(new RequestEventArticles(__assign({ page: this.page, sortBy: this.sortBy, sortByAsc: this.sortByAsc, returnInfo: this.returnInfo }, this.getQueryParams())));
322
+ if (this.er.verboseOutput) {
323
+ this.er.logger.info("Downloading page ".concat(this.page, "..."));
324
+ }
325
+ return [4 /*yield*/, this.er.execQuery(this, this.er.allowUseOfArchive)];
326
+ case 1:
327
+ response = _e.sent();
328
+ error = ((_a = response[this.eventUri]) === null || _a === void 0 ? void 0 : _a.error) || "";
329
+ if (error) {
330
+ this.errorMessage = "Error while obtaining a list of articles: ".concat((_b = response[this.eventUri]) === null || _b === void 0 ? void 0 : _b.error);
331
+ }
332
+ else {
333
+ this.pages = ((_d = (_c = response[this.eventUri]) === null || _c === void 0 ? void 0 : _c.articles) === null || _d === void 0 ? void 0 : _d.pages) || 0;
334
+ }
335
+ results = this.extractResults(response);
336
+ this.returnedSoFar += results.length;
337
+ this.items = __spreadArray(__spreadArray([], __read(this.items), false), __read(results), false);
338
+ return [2 /*return*/, true];
339
+ case 2:
340
+ error_1 = _e.sent();
341
+ this.er.logger.error(error_1);
342
+ return [2 /*return*/, false];
343
+ case 3: return [2 /*return*/];
344
+ }
345
+ });
346
+ });
347
+ };
348
+ return QueryEventArticlesIter;
349
+ }(QueryEvent));
350
+ exports.QueryEventArticlesIter = QueryEventArticlesIter;
351
+ var RequestEvent = /** @class */ (function (_super) {
352
+ __extends(RequestEvent, _super);
353
+ function RequestEvent() {
354
+ var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
355
+ _this.path = "/api/v1/event/getEvent";
356
+ return _this;
357
+ }
358
+ return RequestEvent;
359
+ }(base_1.QueryParamsBase));
360
+ exports.RequestEvent = RequestEvent;
361
+ /**
362
+ * @class RequestEventInfo
363
+ * Return details about an event
364
+ */
365
+ var RequestEventInfo = /** @class */ (function (_super) {
366
+ __extends(RequestEventInfo, _super);
367
+ function RequestEventInfo(returnInfo) {
368
+ if (returnInfo === void 0) { returnInfo = new returnInfo_1.ReturnInfo(); }
369
+ var _this = _super.call(this) || this;
370
+ _this.resultType = "info";
371
+ _this.params = returnInfo.getParams("info");
372
+ return _this;
373
+ }
374
+ return RequestEventInfo;
375
+ }(RequestEvent));
376
+ exports.RequestEventInfo = RequestEventInfo;
377
+ /**
378
+ * @class RequestEventArticles
379
+ * Return articles about the event
380
+ */
381
+ var RequestEventArticles = /** @class */ (function (_super) {
382
+ __extends(RequestEventArticles, _super);
383
+ function RequestEventArticles(args) {
384
+ if (args === void 0) { args = {}; }
385
+ var _this = _super.call(this) || this;
386
+ _this.resultType = "articles";
387
+ var _a = args.page, page = _a === void 0 ? 1 : _a, _b = args.count, count = _b === void 0 ? 100 : _b, _c = args.lang, lang = _c === void 0 ? undefined : _c, _d = args.keywords, keywords = _d === void 0 ? undefined : _d, _e = args.conceptUri, conceptUri = _e === void 0 ? undefined : _e, _f = args.categoryUri, categoryUri = _f === void 0 ? undefined : _f, _g = args.sourceUri, sourceUri = _g === void 0 ? undefined : _g, _h = args.sourceLocationUri, sourceLocationUri = _h === void 0 ? undefined : _h, _j = args.sourceGroupUri, sourceGroupUri = _j === void 0 ? undefined : _j, _k = args.authorUri, authorUri = _k === void 0 ? undefined : _k, _l = args.locationUri, locationUri = _l === void 0 ? undefined : _l, _m = args.dateStart, dateStart = _m === void 0 ? undefined : _m, _o = args.dateEnd, dateEnd = _o === void 0 ? undefined : _o, _p = args.dateMentionStart, dateMentionStart = _p === void 0 ? undefined : _p, _q = args.dateMentionEnd, dateMentionEnd = _q === void 0 ? undefined : _q, _r = args.keywordsLoc, keywordsLoc = _r === void 0 ? "body" : _r, _s = args.startSourceRankPercentile, startSourceRankPercentile = _s === void 0 ? 0 : _s, _t = args.endSourceRankPercentile, endSourceRankPercentile = _t === void 0 ? 100 : _t, _u = args.sortBy, sortBy = _u === void 0 ? "cosSim" : _u, _v = args.sortByAsc, sortByAsc = _v === void 0 ? false : _v, _w = args.returnInfo, returnInfo = _w === void 0 ? undefined : _w;
388
+ if (page < 1) {
389
+ throw new RangeError("Page has to be >= 1");
390
+ }
391
+ if (count > 100) {
392
+ throw new RangeError("At most 100 articles can be returned per call");
393
+ }
394
+ _this.params = {};
395
+ _this.params["articlesPage"] = page;
396
+ _this.params["articlesCount"] = count;
397
+ _this.params["articlesSortBy"] = sortBy;
398
+ _this.params["articlesSortByAsc"] = sortByAsc;
399
+ _this.setQueryArrVal(keywords, "keyword", "keywordOper", "and");
400
+ _this.setQueryArrVal(conceptUri, "conceptUri", "conceptOper", "and");
401
+ _this.setQueryArrVal(categoryUri, "categoryUri", "categoryOper", "or");
402
+ _this.setQueryArrVal(sourceUri, "sourceUri", "sourceOper", "or");
403
+ _this.setQueryArrVal(sourceLocationUri, "sourceLocationUri", undefined, "or");
404
+ _this.setQueryArrVal(sourceGroupUri, "sourceGroupUri", "sourceGroupOper", "or");
405
+ _this.setQueryArrVal(authorUri, "authorUri", "authorOper", "or");
406
+ _this.setQueryArrVal(locationUri, "locationUri", undefined, "or");
407
+ _this.setQueryArrVal(lang, "articlesLang", undefined, "or");
408
+ if (dateStart !== undefined) {
409
+ _this.setDateVal("dateStart", dateStart);
410
+ }
411
+ if (dateEnd !== undefined) {
412
+ _this.setDateVal("dateEnd", dateEnd);
413
+ }
414
+ if (dateMentionStart !== undefined) {
415
+ _this.setDateVal("dateMentionStart", dateMentionStart);
416
+ }
417
+ if (dateMentionEnd !== undefined) {
418
+ _this.setDateVal("dateMentionEnd", dateMentionEnd);
419
+ }
420
+ _this.setValIfNotDefault("keywordLoc", keywordsLoc, "body");
421
+ if (startSourceRankPercentile < 0 || startSourceRankPercentile % 10 !== 0 || startSourceRankPercentile > 100) {
422
+ throw new Error("StartSourceRankPercentile: Value should be in range 0-90 and divisible by 10.");
423
+ }
424
+ if (endSourceRankPercentile < 0 || endSourceRankPercentile % 10 !== 0 || endSourceRankPercentile > 100) {
425
+ throw new Error("EndSourceRankPercentile: Value should be in range 0-90 and divisible by 10.");
426
+ }
427
+ if (startSourceRankPercentile > endSourceRankPercentile) {
428
+ throw new Error("SourceRankPercentile: startSourceRankPercentile should be less than endSourceRankPercentile");
429
+ }
430
+ if (startSourceRankPercentile !== 0) {
431
+ _this.setVal("startSourceRankPercentile", startSourceRankPercentile);
432
+ }
433
+ if (endSourceRankPercentile !== 100) {
434
+ _this.setVal("endSourceRankPercentile", endSourceRankPercentile);
435
+ }
436
+ if (returnInfo) {
437
+ _this.params = __assign(__assign(__assign({}, _this.params), _this.getQueryParams()), returnInfo.getParams("articles"));
438
+ }
439
+ return _this;
440
+ }
441
+ return RequestEventArticles;
442
+ }(RequestEvent));
443
+ exports.RequestEventArticles = RequestEventArticles;
444
+ /**
445
+ * @class RequestEventArticleUriWgts
446
+ * Return just a list of article uris
447
+ */
448
+ var RequestEventArticleUriWgts = /** @class */ (function (_super) {
449
+ __extends(RequestEventArticleUriWgts, _super);
450
+ function RequestEventArticleUriWgts(args) {
451
+ if (args === void 0) { args = {}; }
452
+ var _this = _super.call(this) || this;
453
+ _this.resultType = "uriWgtList";
454
+ var _a = args.lang, lang = _a === void 0 ? undefined : _a, _b = args.sortBy, sortBy = _b === void 0 ? "cosSim" : _b, _c = args.sortByAsc, sortByAsc = _c === void 0 ? false : _c, unsupported = __rest(args, ["lang", "sortBy", "sortByAsc"]);
455
+ if (Object.keys(unsupported).length > 0) {
456
+ logger_1.Logger.warn("RequestEventArticleUriWgts: Unsupported parameters detected: ".concat(JSON.stringify(unsupported), ". Please check the documentation."));
457
+ }
458
+ _this.params = {};
459
+ if (lang !== undefined) {
460
+ _this.params["articlesLang"] = lang;
461
+ }
462
+ _this.params["uriWgtListSortBy"] = sortBy;
463
+ _this.params["uriWgtListSortByAsc"] = sortByAsc;
464
+ return _this;
465
+ }
466
+ return RequestEventArticleUriWgts;
467
+ }(RequestEvent));
468
+ exports.RequestEventArticleUriWgts = RequestEventArticleUriWgts;
469
+ /**
470
+ * @class RequestEventKeywordAggr
471
+ * Return keyword aggregate (tag-cloud) from articles in the event.
472
+ */
473
+ var RequestEventKeywordAggr = /** @class */ (function (_super) {
474
+ __extends(RequestEventKeywordAggr, _super);
475
+ /**
476
+ * @param lang: language for which to compute the keywords
477
+ */
478
+ function RequestEventKeywordAggr(lang) {
479
+ if (lang === void 0) { lang = "eng"; }
480
+ var _this = _super.call(this) || this;
481
+ _this.resultType = "keywordAggr";
482
+ _this.params = {};
483
+ _this.params["articlesLang"] = lang;
484
+ return _this;
485
+ }
486
+ return RequestEventKeywordAggr;
487
+ }(RequestEvent));
488
+ exports.RequestEventKeywordAggr = RequestEventKeywordAggr;
489
+ /**
490
+ * @class RequestEventSourceAggr
491
+ * Get news source distribution of articles in the event.
492
+ */
493
+ var RequestEventSourceAggr = /** @class */ (function (_super) {
494
+ __extends(RequestEventSourceAggr, _super);
495
+ function RequestEventSourceAggr() {
496
+ var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
497
+ _this.resultType = "sourceExAggr";
498
+ return _this;
499
+ }
500
+ return RequestEventSourceAggr;
501
+ }(RequestEvent));
502
+ exports.RequestEventSourceAggr = RequestEventSourceAggr;
503
+ /**
504
+ * @class RequestEventDateMentionAggr
505
+ * Get dates that we found mentioned in the event articles and their frequencies.
506
+ */
507
+ var RequestEventDateMentionAggr = /** @class */ (function (_super) {
508
+ __extends(RequestEventDateMentionAggr, _super);
509
+ function RequestEventDateMentionAggr() {
510
+ var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
511
+ _this.resultType = "dateMentionAggr";
512
+ return _this;
513
+ }
514
+ return RequestEventDateMentionAggr;
515
+ }(RequestEvent));
516
+ exports.RequestEventDateMentionAggr = RequestEventDateMentionAggr;
517
+ /**
518
+ * @class RequestEventArticleTrend
519
+ * Return trending information for the articles about the event.
520
+ */
521
+ var RequestEventArticleTrend = /** @class */ (function (_super) {
522
+ __extends(RequestEventArticleTrend, _super);
523
+ function RequestEventArticleTrend(args) {
524
+ if (args === void 0) { args = {}; }
525
+ var _this = _super.call(this) || this;
526
+ _this.resultType = "articleTrend";
527
+ var _a = args.lang, lang = _a === void 0 ? undefined : _a, _b = args.page, page = _b === void 0 ? 1 : _b, _c = args.count, count = _c === void 0 ? 100 : _c, _d = args.minArticleCosSim, minArticleCosSim = _d === void 0 ? -1 : _d, _e = args.returnInfo, returnInfo = _e === void 0 ? new returnInfo_1.ReturnInfo({ articleInfo: new returnInfo_1.ArticleInfoFlags({ bodyLen: 0 }) }) : _e, unsupported = __rest(args, ["lang", "page", "count", "minArticleCosSim", "returnInfo"]);
528
+ if (Object.keys(unsupported).length > 0) {
529
+ logger_1.Logger.warn("RequestEventArticleTrend: Unsupported parameters detected: ".concat(JSON.stringify(unsupported), ". Please check the documentation."));
530
+ }
531
+ if (page < 1) {
532
+ throw new RangeError("Page has to be >= 1");
533
+ }
534
+ if (count > 100) {
535
+ throw new RangeError("At most 100 articles can be returned per call");
536
+ }
537
+ _this.params = {};
538
+ _this.params["articlesLang"] = lang;
539
+ _this.params["articleTrendPage"] = page;
540
+ _this.params["articleTrendCount"] = count;
541
+ _this.params["articleTrendMinArticleCosSim"] = minArticleCosSim;
542
+ _this.params = __assign(__assign({}, _this.params), returnInfo.getParams("articleTrend"));
543
+ return _this;
544
+ }
545
+ return RequestEventArticleTrend;
546
+ }(RequestEvent));
547
+ exports.RequestEventArticleTrend = RequestEventArticleTrend;
548
+ /**
549
+ * @class RequestEventSimilarEvents
550
+ * Compute and return a list of similar events.
551
+ */
552
+ var RequestEventSimilarEvents = /** @class */ (function (_super) {
553
+ __extends(RequestEventSimilarEvents, _super);
554
+ function RequestEventSimilarEvents(args) {
555
+ if (args === void 0) { args = {}; }
556
+ var _this = _super.call(this) || this;
557
+ _this.path = "/api/v1/event/getSimilarEvents";
558
+ var conceptInfoList = args.conceptInfoList, _a = args.count, count = _a === void 0 ? 50 : _a, _b = args.dateStart, dateStart = _b === void 0 ? undefined : _b, _c = args.dateEnd, dateEnd = _c === void 0 ? undefined : _c, _d = args.addArticleTrendInfo, addArticleTrendInfo = _d === void 0 ? false : _d, _e = args.aggrHours, aggrHours = _e === void 0 ? 6 : _e, _f = args.returnInfo, returnInfo = _f === void 0 ? new returnInfo_1.ReturnInfo() : _f, unsupported = __rest(args, ["conceptInfoList", "count", "dateStart", "dateEnd", "addArticleTrendInfo", "aggrHours", "returnInfo"]);
559
+ if (Object.keys(unsupported).length > 0) {
560
+ logger_1.Logger.warn("RequestEventSimilarEvents: Unsupported parameters detected: ".concat(JSON.stringify(unsupported), ". Please check the documentation."));
561
+ }
562
+ if (count > 50) {
563
+ throw new RangeError("At most 50 similar events can be returned per call");
564
+ }
565
+ if (!Array.isArray(conceptInfoList)) {
566
+ throw new Error("Concept info list is not an array");
567
+ }
568
+ _this.params = {};
569
+ _this.params["action"] = "getSimilarEvents";
570
+ _this.params["concepts"] = JSON.stringify(conceptInfoList);
571
+ // Potential problem, verify that output corresponds the REST API docs.
572
+ _this.params["eventsCount"] = count;
573
+ if (dateStart) {
574
+ _this.params["dateStart"] = base_1.QueryParamsBase.encodeDateTime(dateStart, "YYYY-MM-DD");
575
+ }
576
+ if (dateEnd) {
577
+ _this.params["dateEnd"] = base_1.QueryParamsBase.encodeDateTime(dateEnd, "YYYY-MM-DD");
578
+ }
579
+ _this.params["addArticleTrendInfo"] = addArticleTrendInfo;
580
+ _this.params["aggrHours"] = aggrHours;
581
+ _this.params["resultType"] = "similarEvents";
582
+ _this.params = __assign(__assign({}, _this.params), returnInfo.getParams());
583
+ return _this;
584
+ }
585
+ return RequestEventSimilarEvents;
586
+ }(RequestEvent));
587
+ exports.RequestEventSimilarEvents = RequestEventSimilarEvents;
570
588
  //# sourceMappingURL=queryEvent.js.map