eventregistry 8.9.2 → 8.10.2

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 (71) hide show
  1. package/CHANGELOG.md +17 -1
  2. package/dist/eventRegistry.js +2 -2
  3. package/dist/eventRegistry.js.map +1 -1
  4. package/dist/index.d.ts +1 -0
  5. package/dist/index.js +13 -0
  6. package/dist/index.js.map +1 -1
  7. package/dist/queryArticles.js +6 -0
  8. package/dist/queryArticles.js.map +1 -1
  9. package/dist/queryEvents.js +6 -0
  10. package/dist/queryEvents.js.map +1 -1
  11. package/dist/queryMentions.d.ts +95 -0
  12. package/dist/queryMentions.js +579 -0
  13. package/dist/queryMentions.js.map +1 -0
  14. package/dist/topicPage.js +2 -2
  15. package/dist/topicPage.js.map +1 -1
  16. package/{src → dist}/types.d.ts +284 -195
  17. package/dist/types.js +3 -0
  18. package/dist/types.js.map +1 -0
  19. package/package.json +6 -5
  20. package/dist/correlations.d.ts +0 -50
  21. package/dist/correlations.js +0 -397
  22. package/dist/correlations.js.map +0 -1
  23. package/examples/autoSuggestionsExamples.ts +0 -46
  24. package/examples/countsExamples.ts +0 -34
  25. package/examples/dailySharesExamples.ts +0 -54
  26. package/examples/eventForTextExamples.ts +0 -32
  27. package/examples/feedOfNewArticlesExamples.ts +0 -82
  28. package/examples/feedOfNewEventsExamples.ts +0 -70
  29. package/examples/queryArticleExamples.ts +0 -42
  30. package/examples/queryArticlesExamples.ts +0 -242
  31. package/examples/queryEventExamples.ts +0 -99
  32. package/examples/queryEventsExamples.ts +0 -232
  33. package/examples/topicPageExamples.ts +0 -97
  34. package/examples/trendsExamples.ts +0 -34
  35. package/src/analytics.ts +0 -181
  36. package/src/base.ts +0 -198
  37. package/src/counts.ts +0 -119
  38. package/src/dailyShares.ts +0 -48
  39. package/src/eventForText.ts +0 -61
  40. package/src/eventRegistry.ts +0 -733
  41. package/src/index.ts +0 -111
  42. package/src/info.ts +0 -121
  43. package/src/query.ts +0 -257
  44. package/src/queryArticle.ts +0 -139
  45. package/src/queryArticles.ts +0 -603
  46. package/src/queryEvent.ts +0 -473
  47. package/src/queryEvents.ts +0 -684
  48. package/src/queryStory.ts +0 -152
  49. package/src/recent.ts +0 -63
  50. package/src/returnInfo.ts +0 -363
  51. package/src/topicPage.ts +0 -479
  52. package/src/trends.ts +0 -63
  53. package/test/index.d.ts +0 -18
  54. package/test/jasmine.json +0 -10
  55. package/test/spec/analytics.spec.ts +0 -150
  56. package/test/spec/autoSuggestions.spec.ts +0 -54
  57. package/test/spec/info.spec.ts +0 -84
  58. package/test/spec/invalidQueries.spec.ts +0 -147
  59. package/test/spec/queryArticle.spec.ts +0 -62
  60. package/test/spec/queryArticles.spec.ts +0 -541
  61. package/test/spec/queryArticlesComplex.spec.ts +0 -298
  62. package/test/spec/queryEvent.spec.ts +0 -194
  63. package/test/spec/queryEvents.spec.ts +0 -491
  64. package/test/spec/queryEventsComplex.spec.ts +0 -188
  65. package/test/spec/queryPaging.spec.ts +0 -318
  66. package/test/spec/returnInfo.spec.ts +0 -34
  67. package/test/spec/topicPage.spec.ts +0 -83
  68. package/test/spec/utils.ts +0 -436
  69. package/test/tsconfig.json +0 -31
  70. package/tsconfig.json +0 -32
  71. package/tslint.json +0 -25
package/src/queryEvent.ts DELETED
@@ -1,473 +0,0 @@
1
- import * as _ from "lodash";
2
- import { Query, QueryParamsBase } from "./base";
3
- import { EventRegistry } from "./eventRegistry";
4
- import { ArticleInfoFlags, ReturnInfo } from "./returnInfo";
5
- import { EventRegistryStatic } from "./types";
6
- /**
7
- * @class QueryEvent
8
- * Class for obtaining available info for one or more events in the Event Registry
9
- */
10
- export class QueryEvent extends Query<RequestEvent> {
11
- /**
12
- * @param eventUriOrList A single event uri or a list of event uris (max 50)
13
- * @param requestedResult The information to return as the result of the query. By default return the details of the event
14
- */
15
- constructor(eventUriOrList: string | string[], requestedResult = new RequestEventInfo()) {
16
- super();
17
- this.setVal("eventUri", eventUriOrList);
18
- this.setRequestedResult(requestedResult);
19
- }
20
-
21
- /**
22
- * Set the single result type that you would like to be returned. Any previously set result types will be overwritten.
23
- * Result types can be the classes that extend RequestEvent base class (see classes below).
24
- */
25
- public setRequestedResult(requestEvent: RequestEvent) {
26
- if (!(requestEvent instanceof RequestEvent)) {
27
- throw Error("QueryEvent class can only accept result requests that are of type RequestEvent");
28
- }
29
- this.path = requestEvent.path;
30
- this.resultTypeList = [requestEvent];
31
- }
32
-
33
- }
34
-
35
- /**
36
- * @class QueryEventArticlesIter
37
- * Class for iterating through all the articles in the event via callbacks
38
- */
39
- export class QueryEventArticlesIter extends QueryEvent {
40
- private readonly er: EventRegistry;
41
- private readonly sortBy;
42
- private readonly sortByAsc;
43
- private readonly returnInfo;
44
- private readonly eventUri;
45
- private readonly maxItems;
46
- private page = 0;
47
- private pages = 1;
48
- private items = [];
49
- private returnedSoFar = 0;
50
- private index = 0;
51
- private callback: (item) => void = _.noop;
52
- private doneCallback: (error?) => void = _.noop;
53
- private errorMessage;
54
-
55
- /**
56
- * @param er instance of EventRegistry class. used to obtain the necessary data
57
- * @param eventUri a single event for which we want to obtain the list of articles in it
58
- * @param args Object which contains a host of optional parameters
59
- */
60
- constructor(er: EventRegistry, eventUri: string, args: EventRegistryStatic.QueryEvent.IteratorArguments = {}) {
61
- super(eventUri);
62
- const {
63
- lang = undefined,
64
- sortBy = "cosSim",
65
- sortByAsc = false,
66
- returnInfo = undefined,
67
- maxItems = -1,
68
- keywords = undefined,
69
- conceptUri = undefined,
70
- categoryUri = undefined,
71
- sourceUri = undefined,
72
- sourceLocationUri = undefined,
73
- sourceGroupUri = undefined,
74
- authorUri = undefined,
75
- locationUri = undefined,
76
- dateStart = undefined,
77
- dateEnd = undefined,
78
- dateMentionStart = undefined,
79
- dateMentionEnd = undefined,
80
- keywordsLoc = "body",
81
- startSourceRankPercentile = 0,
82
- endSourceRankPercentile = 100,
83
- minSentiment = -1,
84
- maxSentiment = 1,
85
- } = args;
86
- this.er = er;
87
- this.sortBy = sortBy;
88
- this.sortByAsc = sortByAsc;
89
- this.returnInfo = returnInfo;
90
- this.maxItems = maxItems;
91
- this.eventUri = eventUri;
92
- this.setQueryArrVal(keywords, "keyword", "keywordOper", "and");
93
- this.setQueryArrVal(conceptUri, "conceptUri", "conceptOper", "and");
94
- this.setQueryArrVal(categoryUri, "categoryUri", "categoryOper", "or");
95
- this.setQueryArrVal(sourceUri, "sourceUri", "sourceOper", "or");
96
- this.setQueryArrVal(sourceLocationUri, "sourceLocationUri", undefined, "or");
97
- this.setQueryArrVal(sourceGroupUri, "sourceGroupUri", "sourceGroupOper", "or");
98
- this.setQueryArrVal(authorUri, "authorUri", "authorOper", "or");
99
- this.setQueryArrVal(locationUri, "locationUri", undefined, "or");
100
- this.setQueryArrVal(lang, "lang", undefined, "or");
101
-
102
- if (!_.isUndefined(dateStart)) {
103
- this.setDateVal("dateStart", dateStart);
104
- }
105
-
106
- if (!_.isUndefined(dateEnd)) {
107
- this.setDateVal("dateEnd", dateEnd);
108
- }
109
-
110
- if (!_.isUndefined(dateMentionStart)) {
111
- this.setDateVal("dateMentionStart", dateMentionStart);
112
- }
113
-
114
- if (!_.isUndefined(dateMentionEnd)) {
115
- this.setDateVal("dateMentionEnd", dateMentionEnd);
116
- }
117
-
118
- this.setValIfNotDefault("keywordLoc", keywordsLoc, "body");
119
-
120
- if (startSourceRankPercentile < 0 || startSourceRankPercentile % 10 !== 0 || startSourceRankPercentile > 100) {
121
- throw new Error("StartSourceRankPercentile: Value should be in range 0-90 and divisible by 10.");
122
- }
123
- if (endSourceRankPercentile < 0 || endSourceRankPercentile % 10 !== 0 || endSourceRankPercentile > 100) {
124
- throw new Error("EndSourceRankPercentile: Value should be in range 0-90 and divisible by 10.");
125
- }
126
- if (startSourceRankPercentile > endSourceRankPercentile) {
127
- throw new Error("SourceRankPercentile: startSourceRankPercentile should be less than endSourceRankPercentile");
128
- }
129
-
130
- if (startSourceRankPercentile !== 0 ) {
131
- this.setVal("startSourceRankPercentile", startSourceRankPercentile);
132
- }
133
-
134
- if (endSourceRankPercentile !== 100 ) {
135
- this.setVal("endSourceRankPercentile", endSourceRankPercentile);
136
- }
137
-
138
- if (minSentiment > -1 && minSentiment <= 1 ) {
139
- this.setVal("minSentiment", minSentiment);
140
- }
141
-
142
- if (maxSentiment >= -1 && maxSentiment < 1 ) {
143
- this.setVal("maxSentiment", maxSentiment);
144
- }
145
- }
146
-
147
- public async count() {
148
- this.setRequestedResult(new RequestEventArticles(this.getQueryParams()));
149
- const response = await this.er.execQuery(this);
150
- if (_.has(response, "error")) {
151
- console.error(_.get(response, "error"));
152
- }
153
- return _.get(response[this.eventUri], "articles.totalResults", 0);
154
- }
155
- /**
156
- * Execute query and fetch batches of articles of the specified size (articleBatchSize)
157
- * @param callback callback function that'll be called every time we get a new batch of articles from the backend
158
- * @param doneCallback callback function that'll be called when everything is complete
159
- */
160
- public execQuery(callback: (item) => void, doneCallback?: (error) => void) {
161
- if (callback) { this.callback = callback; }
162
- if (doneCallback) { this.doneCallback = doneCallback; }
163
- this.iterate();
164
- }
165
-
166
- private async iterate() {
167
- if (this.current) {
168
- this.callback(this.current);
169
- this.index += 1;
170
- } else if (!await this.getNextBatch()) {
171
- this.doneCallback(this.errorMessage);
172
- return;
173
- }
174
- return this.iterate();
175
- }
176
-
177
- /**
178
- * Extract the results according to maxItems
179
- * @param response response from the backend
180
- */
181
- private extractResults(response): Array<{[name: string]: any}> {
182
- const results = _.get(response[this.eventUri], "articles.results", []);
183
- const extractedSize = this.maxItems !== -1 ? this.maxItems - this.returnedSoFar : _.size(results);
184
- return _.compact(_.pullAt(results, _.range(0, extractedSize)) as Array<{}>);
185
- }
186
-
187
- private get current() {
188
- return this.items[this.index] || undefined;
189
- }
190
-
191
- private async getNextBatch() {
192
- try {
193
- this.page += 1;
194
- if (this.page > this.pages || (this.maxItems !== -1 && this.returnedSoFar >= this.maxItems)) {
195
- return false;
196
- }
197
- this.setRequestedResult(new RequestEventArticles({
198
- page: this.page,
199
- sortBy: this.sortBy,
200
- sortByAsc: this.sortByAsc,
201
- returnInfo: this.returnInfo,
202
- ...this.getQueryParams(),
203
- }));
204
- if (this.er.verboseOutput) {
205
- console.log(`Downloading page ${this.page}...`);
206
- }
207
- const response = await this.er.execQuery(this);
208
- const error = _.get(response[this.eventUri], "error", "");
209
- if (error) {
210
- this.errorMessage = `Error while obtaining a list of articles: ${_.get(response[this.eventUri], "error")}`;
211
- } else {
212
- this.pages = _.get(response[this.eventUri], "articles.pages", 0);
213
- }
214
- const results = this.extractResults(response);
215
- this.returnedSoFar += _.size(results);
216
- this.items = [...this.items, ...results];
217
- return true;
218
- } catch (error) {
219
- console.error(error);
220
- return false;
221
- }
222
- }
223
- }
224
- export class RequestEvent extends QueryParamsBase {
225
- public path = "/api/v1/event/getEvent";
226
- }
227
-
228
- /**
229
- * @class RequestEventInfo
230
- * Return details about an event
231
- */
232
- export class RequestEventInfo extends RequestEvent {
233
- public resultType = "info";
234
- public params;
235
- constructor(returnInfo = new ReturnInfo()) {
236
- super();
237
- this.params = returnInfo.getParams("info");
238
- }
239
- }
240
-
241
- /**
242
- * @class RequestEventArticles
243
- * Return articles about the event
244
- */
245
- export class RequestEventArticles extends RequestEvent {
246
- public resultType = "articles";
247
- public params;
248
-
249
- constructor(args: EventRegistryStatic.QueryEvent.RequestEventArticlesArguments = {}) {
250
- super();
251
- const {
252
- page = 1,
253
- count = 100,
254
- lang = undefined,
255
- keywords = undefined,
256
- conceptUri = undefined,
257
- categoryUri = undefined,
258
- sourceUri = undefined,
259
- sourceLocationUri = undefined,
260
- sourceGroupUri = undefined,
261
- authorUri = undefined,
262
- locationUri = undefined,
263
- dateStart = undefined,
264
- dateEnd = undefined,
265
- dateMentionStart = undefined,
266
- dateMentionEnd = undefined,
267
- keywordsLoc = "body",
268
- startSourceRankPercentile = 0,
269
- endSourceRankPercentile = 100,
270
- sortBy = "cosSim",
271
- sortByAsc = false,
272
- returnInfo = undefined,
273
- } = args;
274
-
275
- if (page < 1) {
276
- throw new RangeError("Page has to be >= 1");
277
- }
278
- if (count > 100) {
279
- throw new RangeError("At most 100 articles can be returned per call");
280
- }
281
- this.params = {};
282
- this.params["articlesPage"] = page;
283
- this.params["articlesCount"] = count;
284
- this.params["articlesSortBy"] = sortBy;
285
- this.params["articlesSortByAsc"] = sortByAsc;
286
- this.setQueryArrVal(keywords, "keyword", "keywordOper", "and");
287
- this.setQueryArrVal(conceptUri, "conceptUri", "conceptOper", "and");
288
- this.setQueryArrVal(categoryUri, "categoryUri", "categoryOper", "or");
289
- this.setQueryArrVal(sourceUri, "sourceUri", "sourceOper", "or");
290
- this.setQueryArrVal(sourceLocationUri, "sourceLocationUri", undefined, "or");
291
- this.setQueryArrVal(sourceGroupUri, "sourceGroupUri", "sourceGroupOper", "or");
292
- this.setQueryArrVal(authorUri, "authorUri", "authorOper", "or");
293
- this.setQueryArrVal(locationUri, "locationUri", undefined, "or");
294
- this.setQueryArrVal(lang, "lang", undefined, "or");
295
- if (!_.isUndefined(dateStart)) {
296
- this.setDateVal("dateStart", dateStart);
297
- }
298
- if (!_.isUndefined(dateEnd)) {
299
- this.setDateVal("dateEnd", dateEnd);
300
- }
301
- if (!_.isUndefined(dateMentionStart)) {
302
- this.setDateVal("dateMentionStart", dateMentionStart);
303
- }
304
- if (!_.isUndefined(dateMentionEnd)) {
305
- this.setDateVal("dateMentionEnd", dateMentionEnd);
306
- }
307
- this.setValIfNotDefault("keywordLoc", keywordsLoc, "body");
308
- if (startSourceRankPercentile < 0 || startSourceRankPercentile % 10 !== 0 || startSourceRankPercentile > 100) {
309
- throw new Error("StartSourceRankPercentile: Value should be in range 0-90 and divisible by 10.");
310
- }
311
- if (endSourceRankPercentile < 0 || endSourceRankPercentile % 10 !== 0 || endSourceRankPercentile > 100) {
312
- throw new Error("EndSourceRankPercentile: Value should be in range 0-90 and divisible by 10.");
313
- }
314
- if (startSourceRankPercentile > endSourceRankPercentile) {
315
- throw new Error("SourceRankPercentile: startSourceRankPercentile should be less than endSourceRankPercentile");
316
- }
317
-
318
- if (startSourceRankPercentile !== 0 ) {
319
- this.setVal("startSourceRankPercentile", startSourceRankPercentile);
320
- }
321
-
322
- if (endSourceRankPercentile !== 100 ) {
323
- this.setVal("endSourceRankPercentile", endSourceRankPercentile);
324
- }
325
-
326
- if (!!returnInfo) {
327
- this.params = _.extend({}, this.params, this.getQueryParams(), returnInfo.getParams("articles"));
328
- }
329
- }
330
- }
331
-
332
- /**
333
- * @class RequestEventArticleUriWgts
334
- * Return just a list of article uris
335
- */
336
- export class RequestEventArticleUriWgts extends RequestEvent {
337
- public resultType = "uriWgtList";
338
- public params;
339
-
340
- constructor(args: EventRegistryStatic.QueryEvent.RequestEventArticleUriWgtsArguments = {}) {
341
- super();
342
- const {
343
- lang = undefined,
344
- sortBy = "cosSim",
345
- sortByAsc = false,
346
- ...unsupported
347
- } = args;
348
- if (!_.isEmpty(unsupported)) {
349
- console.warn(`RequestEventArticleUriWgts: Unsupported parameters detected: ${JSON.stringify(unsupported)}. Please check the documentation.`);
350
- }
351
- this.params = {};
352
- if (!_.isUndefined(lang)) {
353
- this.params["articlesLang"] = lang;
354
- }
355
- this.params["uriWgtListSortBy"] = sortBy;
356
- this.params["uriWgtListSortByAsc"] = sortByAsc;
357
- }
358
- }
359
-
360
- /**
361
- * @class RequestEventKeywordAggr
362
- * Return keyword aggregate (tag-cloud) from articles in the event.
363
- */
364
- export class RequestEventKeywordAggr extends RequestEvent {
365
- public resultType = "keywordAggr";
366
- public params;
367
- /**
368
- * @param lang: language for which to compute the keywords
369
- */
370
- constructor(lang = "eng") {
371
- super();
372
- this.params = {};
373
- this.params["articlesLang"] = lang;
374
- }
375
- }
376
- /**
377
- * @class RequestEventSourceAggr
378
- * Get news source distribution of articles in the event.
379
- */
380
- export class RequestEventSourceAggr extends RequestEvent {
381
- public resultType = "sourceExAggr";
382
- }
383
-
384
- /**
385
- * @class RequestEventDateMentionAggr
386
- * Get dates that we found mentioned in the event articles and their frequencies.
387
- */
388
- export class RequestEventDateMentionAggr extends RequestEvent {
389
- public resultType = "dateMentionAggr";
390
- }
391
-
392
- /**
393
- * @class RequestEventArticleTrend
394
- * Return trending information for the articles about the event.
395
- */
396
- export class RequestEventArticleTrend extends RequestEvent {
397
- public resultType = "articleTrend";
398
- public params;
399
-
400
- constructor(args: EventRegistryStatic.QueryEvent.RequestEventArticleTrendArguments = {}) {
401
- super();
402
- const {
403
- lang = undefined,
404
- page = 1,
405
- count = 100,
406
- minArticleCosSim = -1,
407
- returnInfo = new ReturnInfo({articleInfo: new ArticleInfoFlags({bodyLen: 0})}),
408
- ...unsupported
409
- } = args;
410
- if (!_.isEmpty(unsupported)) {
411
- console.warn(`RequestEventArticleTrend: Unsupported parameters detected: ${JSON.stringify(unsupported)}. Please check the documentation.`);
412
- }
413
- if (page < 1) {
414
- throw new RangeError("Page has to be >= 1");
415
- }
416
- if (count > 100) {
417
- throw new RangeError("At most 100 articles can be returned per call");
418
- }
419
- this.params = {};
420
- this.params["articlesLang"] = lang;
421
- this.params["articleTrendPage"] = page;
422
- this.params["articleTrendCount"] = count;
423
- this.params["articleTrendMinArticleCosSim"] = minArticleCosSim;
424
- this.params = _.extend({}, this.params, returnInfo.getParams("articleTrend"));
425
- }
426
- }
427
-
428
- /**
429
- * @class RequestEventSimilarEvents
430
- * Compute and return a list of similar events.
431
- */
432
- export class RequestEventSimilarEvents extends RequestEvent {
433
- public path = "/api/v1/event/getSimilarEvents";
434
- public params;
435
- constructor(args: EventRegistryStatic.QueryEvent.RequestEventSimilarEventsArguments = {}) {
436
- super();
437
- const {
438
- conceptInfoList,
439
- count = 50,
440
- dateStart = undefined,
441
- dateEnd = undefined,
442
- addArticleTrendInfo = false,
443
- aggrHours = 6,
444
- returnInfo = new ReturnInfo(),
445
- ...unsupported
446
- } = args;
447
- if (!_.isEmpty(unsupported)) {
448
- console.warn(`RequestEventSimilarEvents: Unsupported parameters detected: ${JSON.stringify(unsupported)}. Please check the documentation.`);
449
- }
450
- if (count > 50) {
451
- throw new RangeError("At most 50 similar events can be returned per call");
452
- }
453
- if (!_.isArray(conceptInfoList)) {
454
- throw new Error("Concept info list is not an array");
455
- }
456
- this.params = {};
457
- this.params["action"] = "getSimilarEvents";
458
-
459
- this.params["concepts"] = JSON.stringify(conceptInfoList);
460
- // Potential problem, verify that output corresponds the REST API docs.
461
- this.params["eventsCount"] = count;
462
- if (!!dateStart) {
463
- this.params["dateStart"] = QueryParamsBase.encodeDateTime(dateStart, "YYYY-MM-DD");
464
- }
465
- if (!!dateEnd) {
466
- this.params["dateEnd"] = QueryParamsBase.encodeDateTime(dateEnd, "YYYY-MM-DD");
467
- }
468
- this.params["addArticleTrendInfo"] = addArticleTrendInfo;
469
- this.params["aggrHours"] = aggrHours;
470
- this.params["resultType"] = "similarEvents";
471
- this.params = _.extend({}, this.params, returnInfo.getParams());
472
- }
473
- }