eventregistry 8.10.1 → 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 (59) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/{src → dist}/types.d.ts +199 -255
  3. package/dist/types.js +3 -0
  4. package/dist/types.js.map +1 -0
  5. package/package.json +6 -5
  6. package/dist/correlations.d.ts +0 -50
  7. package/dist/correlations.js +0 -397
  8. package/dist/correlations.js.map +0 -1
  9. package/examples/autoSuggestionsExamples.ts +0 -46
  10. package/examples/countsExamples.ts +0 -34
  11. package/examples/dailySharesExamples.ts +0 -54
  12. package/examples/eventForTextExamples.ts +0 -32
  13. package/examples/feedOfNewArticlesExamples.ts +0 -82
  14. package/examples/feedOfNewEventsExamples.ts +0 -70
  15. package/examples/queryArticleExamples.ts +0 -42
  16. package/examples/queryArticlesExamples.ts +0 -248
  17. package/examples/queryEventExamples.ts +0 -99
  18. package/examples/queryEventsExamples.ts +0 -232
  19. package/examples/queryMentionsExamples.ts +0 -20
  20. package/examples/topicPageExamples.ts +0 -99
  21. package/examples/trendsExamples.ts +0 -34
  22. package/src/analytics.ts +0 -181
  23. package/src/base.ts +0 -198
  24. package/src/counts.ts +0 -119
  25. package/src/dailyShares.ts +0 -48
  26. package/src/eventForText.ts +0 -61
  27. package/src/eventRegistry.ts +0 -733
  28. package/src/index.ts +0 -125
  29. package/src/info.ts +0 -121
  30. package/src/query.ts +0 -257
  31. package/src/queryArticle.ts +0 -139
  32. package/src/queryArticles.ts +0 -608
  33. package/src/queryEvent.ts +0 -473
  34. package/src/queryEvents.ts +0 -689
  35. package/src/queryMentions.ts +0 -516
  36. package/src/queryStory.ts +0 -152
  37. package/src/recent.ts +0 -63
  38. package/src/returnInfo.ts +0 -363
  39. package/src/topicPage.ts +0 -479
  40. package/src/trends.ts +0 -63
  41. package/test/index.d.ts +0 -18
  42. package/test/jasmine.json +0 -10
  43. package/test/spec/analytics.spec.ts +0 -150
  44. package/test/spec/autoSuggestions.spec.ts +0 -54
  45. package/test/spec/info.spec.ts +0 -84
  46. package/test/spec/invalidQueries.spec.ts +0 -147
  47. package/test/spec/queryArticle.spec.ts +0 -62
  48. package/test/spec/queryArticles.spec.ts +0 -541
  49. package/test/spec/queryArticlesComplex.spec.ts +0 -298
  50. package/test/spec/queryEvent.spec.ts +0 -194
  51. package/test/spec/queryEvents.spec.ts +0 -491
  52. package/test/spec/queryEventsComplex.spec.ts +0 -188
  53. package/test/spec/queryPaging.spec.ts +0 -318
  54. package/test/spec/returnInfo.spec.ts +0 -34
  55. package/test/spec/topicPage.spec.ts +0 -83
  56. package/test/spec/utils.ts +0 -436
  57. package/test/tsconfig.json +0 -31
  58. package/tsconfig.json +0 -32
  59. package/tslint.json +0 -25
@@ -1,491 +0,0 @@
1
- import * as _ from "lodash";
2
- import {
3
- BaseQuery,
4
- ComplexEventQuery,
5
- ConceptInfoFlags,
6
- EventInfoFlags,
7
- QueryEventArticlesIter,
8
- QueryEvents,
9
- QueryEventsIter,
10
- RequestEventsCategoryAggr,
11
- RequestEventsConceptAggr,
12
- RequestEventsConceptMatrix,
13
- RequestEventsConceptTrends,
14
- RequestEventsInfo,
15
- RequestEventsKeywordAggr,
16
- RequestEventsSourceAggr,
17
- RequestEventsUriWgtList,
18
- ReturnInfo,
19
- } from "../../src/index";
20
- import { Utils } from "./utils";
21
-
22
- describe("Query Events", () => {
23
- const er = Utils.initAPI();
24
- const utils = new Utils();
25
- let query: QueryEvents;
26
- let requestEventsInfo: RequestEventsInfo;
27
-
28
- beforeAll(async (done) => {
29
- requestEventsInfo = new RequestEventsInfo({count: 10, returnInfo: utils.returnInfo});
30
- query = new QueryEvents({conceptUri: await er.getConceptUri("Obama")});
31
- done();
32
- });
33
-
34
- it("should test event list", async (done) => {
35
- query.setRequestedResult(requestEventsInfo);
36
- const response = await er.execQuery(query);
37
- expect(response).toBeValidGeneralEventList();
38
- done();
39
- });
40
-
41
- it("should test event list with keyword search", async (done) => {
42
- const q1 = new QueryEvents({keywords: "germany"});
43
- q1.setRequestedResult(requestEventsInfo);
44
- const response1 = await er.execQuery(q1);
45
- expect(response1).toBeValidGeneralEventList();
46
-
47
- const q2 = new QueryEvents({keywords: "germany"});
48
- q2.setRequestedResult(requestEventsInfo);
49
- const response2 = await er.execQuery(q2);
50
- expect(response2).toBeValidGeneralEventList();
51
-
52
- const results1 = _.sortBy(response1["events"]["results"], "id");
53
- const results2 = _.sortBy(response2["events"]["results"], "id");
54
- expect(_.size(results1)).toEqual(_.size(results2), "Keyword search should return responses of the same size");
55
- done();
56
- });
57
-
58
- it("should test event list with source search", async (done) => {
59
- const q1 = new QueryEvents({sourceUri: await er.getNewsSourceUri("bbc")});
60
- q1.setRequestedResult(requestEventsInfo);
61
- const response1 = await er.execQuery(q1);
62
- expect(response1).toBeValidGeneralEventList();
63
-
64
- const q2 = new QueryEvents({sourceUri: await er.getNewsSourceUri("bbc")});
65
- q2.setRequestedResult(requestEventsInfo);
66
- const response2 = await er.execQuery(q2);
67
- expect(response2).toBeValidGeneralEventList();
68
-
69
- const results1 = _.sortBy(response1["events"]["results"], "id");
70
- const results2 = _.sortBy(response2["events"]["results"], "id");
71
- expect(_.size(results1)).toEqual(_.size(results2), "Source search should return responses of the same size");
72
- done();
73
- });
74
-
75
- it("should test event list with category search", async (done) => {
76
- const q1 = new QueryEvents({categoryUri: await er.getCategoryUri("disa")});
77
- q1.setRequestedResult(requestEventsInfo);
78
- const response1 = await er.execQuery(q1);
79
- expect(response1).toBeValidGeneralEventList();
80
-
81
- const q2 = new QueryEvents({categoryUri: await er.getCategoryUri("disa")});
82
- q2.setRequestedResult(requestEventsInfo);
83
- const response2 = await er.execQuery(q2);
84
- expect(response2).toBeValidGeneralEventList();
85
-
86
- const results1 = _.sortBy(response1["events"]["results"], "id");
87
- const results2 = _.sortBy(response2["events"]["results"], "id");
88
- expect(_.size(results1)).toEqual(_.size(results2), "Source search should return responses of the same size");
89
- done();
90
- });
91
-
92
- it("should test event list with author search", async (done) => {
93
- const authorUri = await er.getAuthorUri("associated");
94
- const q1 = new QueryEvents({authorUri});
95
- const response1 = await er.execQuery(q1);
96
- const q2 = QueryEvents.initWithComplexQuery(new ComplexEventQuery(new BaseQuery({authorUri})));
97
- const response2 = await er.execQuery(q2);
98
- const results1 = _.sortBy(response1["events"]["results"], "id");
99
- const results2 = _.sortBy(response2["events"]["results"], "id");
100
- expect(_.size(results1)).toEqual(_.size(results2), "Author search should return responses of the same size");
101
- done();
102
- });
103
-
104
- it("should test event list with language search", async (done) => {
105
- const q1 = new QueryEvents({lang: "spa"});
106
- q1.setRequestedResult(requestEventsInfo);
107
- const response1 = await er.execQuery(q1);
108
- expect(response1).toBeValidGeneralEventList();
109
- done();
110
- });
111
-
112
- it("should test event list with minimal articles search", async (done) => {
113
- const q1 = new QueryEvents({minArticlesInEvent: 100});
114
- q1.setRequestedResult(requestEventsInfo);
115
- const response1 = await er.execQuery(q1);
116
- expect(response1).toBeValidGeneralEventList();
117
- done();
118
- });
119
-
120
- it("should test search by keyword", async (done) => {
121
- const q1 = new QueryEvents({keywords: "car"});
122
- const evInfo = new EventInfoFlags({ concepts: false,
123
- articleCounts: false,
124
- title: false,
125
- summary: false,
126
- categories: false,
127
- location: false,
128
- stories: false,
129
- imageCount: 0,
130
- });
131
- const retInfo1 = new ReturnInfo({ conceptInfo: new ConceptInfoFlags({type: "org"}), eventInfo: evInfo});
132
- const reqEvInfo = new RequestEventsInfo({ page: 1,
133
- count: 10,
134
- sortBy: "date",
135
- sortByAsc: true,
136
- returnInfo: retInfo1,
137
- });
138
- q1.setRequestedResult(reqEvInfo);
139
- const response = await er.execQuery(q1);
140
- expect(_.has(response, "events")).toBeTruthy("Results should contain events");
141
- const events = _.get(response, "events.results", []);
142
- let lastEventDate = _.isEmpty(events) ? "" : _.get(_.first(events), "eventDate");
143
- _.each(events, (event) => {
144
- expect(event.eventDate >= lastEventDate).toBeTruthy("Events are not sorted by date");
145
- lastEventDate = event.eventDate;
146
- expect(_.has(event, "articleCounts")).toBeFalsy("Event should not contain articleCounts");
147
- expect(_.has(event, "categories")).toBeFalsy("Event should not contain categories");
148
- expect(_.has(event, "concepts")).toBeFalsy("Event should not contain concepts");
149
- expect(_.has(event, "location")).toBeFalsy("Event should not contain location");
150
- expect(_.has(event, "stories")).toBeFalsy("Event should not contain stories");
151
- expect(_.has(event, "images")).toBeFalsy("Event should not contain images");
152
- expect(_.has(event, "title")).toBeFalsy("Event should not contain title");
153
- expect(_.has(event, "summary")).toBeFalsy("Event should not contain summary");
154
- });
155
- done();
156
- });
157
-
158
- it("should test search by keyword rev", async (done) => {
159
- const q1 = new QueryEvents({keywords: "car"});
160
- const evInfo = new EventInfoFlags({ concepts: false,
161
- articleCounts: false,
162
- title: false,
163
- summary: false,
164
- categories: false,
165
- location: false,
166
- stories: false,
167
- imageCount: 0,
168
- });
169
- const retInfo1 = new ReturnInfo({ conceptInfo: new ConceptInfoFlags({type: "org"}), eventInfo: evInfo});
170
- const reqEvInfo = new RequestEventsInfo({ page: 1,
171
- count: 10,
172
- sortBy: "date",
173
- sortByAsc: false,
174
- returnInfo: retInfo1,
175
- });
176
- q1.setRequestedResult(reqEvInfo);
177
- const response = await er.execQuery(q1);
178
- expect(_.has(response, "events")).toBeTruthy("Results should contain events");
179
- const events = _.get(response, "events.results", []);
180
- let lastEventDate = _.isEmpty(events) ? "" : _.get(_.first(events), "eventDate");
181
- _.each(events, (event) => {
182
- expect(event.eventDate <= lastEventDate).toBeTruthy("Events are not sorted by date");
183
- lastEventDate = event.eventDate;
184
- expect(_.has(event, "articleCounts")).toBeFalsy("Event should not contain articleCounts");
185
- expect(_.has(event, "categories")).toBeFalsy("Event should not contain categories");
186
- expect(_.has(event, "concepts")).toBeFalsy("Event should not contain concepts");
187
- expect(_.has(event, "location")).toBeFalsy("Event should not contain location");
188
- expect(_.has(event, "stories")).toBeFalsy("Event should not contain stories");
189
- expect(_.has(event, "images")).toBeFalsy("Event should not contain images");
190
- expect(_.has(event, "title")).toBeFalsy("Event should not contain title");
191
- expect(_.has(event, "summary")).toBeFalsy("Event should not contain summary");
192
- });
193
- done();
194
- });
195
-
196
- it("should test search by keyword (2)", async (done) => {
197
- const q1 = new QueryEvents({keywords: "car"});
198
- const returnInfo = new ReturnInfo({ conceptInfo: new ConceptInfoFlags({type: ["org", "loc"], lang: "spa"})});
199
- const reqEvConceptsTrends = new RequestEventsConceptTrends({conceptCount: 5, returnInfo});
200
- q1.setRequestedResult(reqEvConceptsTrends);
201
- const response = await er.execQuery(q1);
202
- expect(_.has(response, "conceptTrends")).toBeTruthy("Results should contain conceptAggr");
203
- _.each(_.get(response, "conceptTrends.conceptInfo", []), (concept) => {
204
- expect(concept.type === "loc" || concept.type === "org").toBeTruthy("Got concept of invalid type");
205
- expect(_.has(concept, "label.spa")).toBeTruthy("Concept did not contain label in expected language");
206
- });
207
- done();
208
- });
209
-
210
- it("should test search by location", async (done) => {
211
- const q = new QueryEvents({locationUri: await er.getLocationUri("Germany")});
212
- q.setRequestedResult(new RequestEventsInfo({sortBy: "size", sortByAsc: false}));
213
- const response = await er.execQuery(q);
214
- const results = _.get(response, "events.results", []);
215
- let lastSize = !_.isEmpty(results) ? results[0].totalArticleCount : 0;
216
- _.each(results, (event) => {
217
- expect(event.totalArticleCount <= lastSize).toBeTruthy("Events are not sorted by size");
218
- lastSize = event.totalArticleCount;
219
- });
220
- done();
221
- });
222
-
223
- it("should test event list with combined search", async (done) => {
224
- const conceptUri = await er.getConceptUri("Merkel");
225
- const categoryUri = await er.getCategoryUri("Business");
226
- const q1 = new QueryEvents({keywords: "germany", conceptUri: [conceptUri], categoryUri: [categoryUri]});
227
- q1.setRequestedResult(new RequestEventsInfo({count: 10, returnInfo: utils.returnInfo}));
228
- const response1 = await er.execQuery(q1);
229
- expect(response1).toBeValidGeneralEventList();
230
-
231
- const q2 = new QueryEvents({keywords: "germany", conceptUri, categoryUri});
232
- q2.setRequestedResult(new RequestEventsInfo({count: 10, returnInfo: utils.returnInfo}));
233
- const response2 = await er.execQuery(q2);
234
- expect(response2).toBeValidGeneralEventList();
235
-
236
- const results1 = _.sortBy(response1["events"]["results"], "id");
237
- const results2 = _.sortBy(response2["events"]["results"], "id");
238
- expect(_.size(results1)).toEqual(_.size(results2), "Source search should return responses of the same size");
239
- done();
240
- });
241
-
242
- it("should test concept trends", async (done) => {
243
- const requestEventsConceptTrends = new RequestEventsConceptTrends({conceptCount: 5, returnInfo: utils.returnInfo});
244
- query.setRequestedResult(requestEventsConceptTrends);
245
- const response = await er.execQuery(query);
246
- expect(_.has(response, "conceptTrends")).toBeTruthy("Expected to get 'conceptTrends'");
247
- expect(_.has(response, "conceptTrends.trends")).toBeTruthy("Expected to get 'trends' property in conceptTrends");
248
- expect(_.has(response, "conceptTrends.conceptInfo")).toBeTruthy("Expected to get 'conceptInfo' property in conceptTrends");
249
- expect(_.size(_.get(response, "conceptTrends.conceptInfo", []))).toBeLessThanOrEqual(5, "Expected to get 5 concepts or less in concept trends");
250
- const trends = _.get(response, "conceptTrends.trends");
251
- expect(_.isEmpty(trends)).toBeFalsy("Expected to get trends for some days");
252
- _.each(trends, (trend) => {
253
- expect(_.has(trend, "date")).toBeTruthy("A trend should have a date");
254
- expect(_.has(trend, "conceptFreq")).toBeTruthy("A trend should have a conceptFreq");
255
- expect(_.has(trend, "totArts")).toBeTruthy("A trend should have a totArts property");
256
- expect(_.size(_.get(trend, "conceptFreq", []))).toBeLessThanOrEqual(5, "Concept frequencies should contain 5 elements - one for each concept");
257
- });
258
-
259
- _.each(_.get(response, "conceptTrends.conceptInfo", []), (concept) => {
260
- expect(concept).toBeValidConcept();
261
- });
262
- done();
263
- });
264
-
265
- it("should test concept aggregates", async (done) => {
266
- const requestEventsConceptAggr = new RequestEventsConceptAggr({conceptCount: 100, returnInfo: utils.returnInfo});
267
- query.setRequestedResult(requestEventsConceptAggr);
268
- const response = await er.execQuery(query);
269
- expect(_.has(response, "conceptAggr")).toBeTruthy("Expected to get 'conceptAggr'");
270
- const concepts = _.get(response, "conceptAggr.results", []);
271
- // TODO: If the ConceptCount is included then we return 150 aggregates
272
- // expect(_.size(concepts)).toEqual(100, "Expected a different number of concept in conceptAggr");
273
- _.each(concepts, (concept) => {
274
- expect(concept).toBeValidConcept();
275
- });
276
- done();
277
- });
278
-
279
- it("should test keyword aggregates", async (done) => {
280
- const requestEventsKeywordAggr = new RequestEventsKeywordAggr();
281
- query.setRequestedResult(requestEventsKeywordAggr);
282
- const response = await er.execQuery(query);
283
- expect(_.has(response, "keywordAggr")).toBeTruthy("Expected to get 'keywordAggr'");
284
- const keywords = _.get(response, "keywordAggr.results", []);
285
- expect(_.size(keywords)).toBeGreaterThan(0, "Expected to get some keywords");
286
- _.each(keywords, (kw) => {
287
- expect(_.has(kw, "keyword")).toBeTruthy("Expected a keyword property");
288
- expect(_.has(kw, "weight")).toBeTruthy("Expected a weight property");
289
- });
290
- done();
291
- });
292
-
293
- it("should test category aggregates", async (done) => {
294
- const requestEventsCategoryAggr = new RequestEventsCategoryAggr(utils.returnInfo);
295
- query.setRequestedResult(requestEventsCategoryAggr);
296
- const response = await er.execQuery(query);
297
- expect(_.has(response, "categoryAggr")).toBeTruthy("Expected to get 'categoryAggr'");
298
- const categories = _.get(response, "categoryAggr.results", []);
299
- expect(_.size(categories)).toBeGreaterThan(0, "Expected to get some categories");
300
- _.each(categories, (category) => {
301
- expect(category).toBeValidCategory();
302
- });
303
- done();
304
- });
305
-
306
- it("should test concept matrix", async (done) => {
307
- const requestEventsConceptMatrix = new RequestEventsConceptMatrix({conceptCount: 20, returnInfo: utils.returnInfo});
308
- query.setRequestedResult(requestEventsConceptMatrix);
309
- const response = await er.execQuery(query);
310
- expect(_.has(response, "conceptMatrix")).toBeTruthy("Expected to get 'conceptMatrix'");
311
- const matrix = _.get(response, "conceptMatrix");
312
- expect(_.has(matrix, "scoreMatrix")).toBeTruthy("Expecting 'scoreMatrix' property in conceptMatrix");
313
- expect(_.has(matrix, "freqMatrix")).toBeTruthy("Expecting 'freqMatrix' property in conceptMatrix");
314
- expect(_.has(matrix, "concepts")).toBeTruthy("Expecting 'concepts' property in conceptMatrix");
315
- expect(_.size(_.get(matrix, "concepts", []))).toEqual(20, "Expected 20 concepts");
316
- _.each(_.get(matrix, "concepts", []), (concept) => {
317
- expect(concept).toBeValidConcept();
318
- });
319
- done();
320
- });
321
-
322
- it("should test source aggregates", async (done) => {
323
- const requestEventsSourceAggr = new RequestEventsSourceAggr({sourceCount: 15, returnInfo: utils.returnInfo});
324
- query.setRequestedResult(requestEventsSourceAggr);
325
- const response = await er.execQuery(query);
326
- expect(_.has(response, "sourceAggr")).toBeTruthy("Expected to get 'sourceAggr'");
327
- const sources = _.get(response, "sourceAggr.countsPerSource", []);
328
- expect(_.size(sources)).toEqual(15, "Expected 15 sources");
329
- _.each(sources, (sourceInfo) => {
330
- expect(_.get(sourceInfo, "source")).toBeValidSource();
331
- expect(_.has(sourceInfo, "counts")).toBeTruthy("Source info should contain counts object");
332
- expect(_.has(sourceInfo, "counts.frequency")).toBeTruthy("Counts should contain a frequency");
333
- expect(_.has(sourceInfo, "counts.total")).toBeTruthy("Counts should contain total");
334
- });
335
- _.each(_.get(response, "sourceAggr.countsPerCountry"), (country) => {
336
- if (_.get(country, "uri") === "http://en.wikipedia.org/wiki/Australia_(continent)") return;
337
- expect(_.get(country, "type")).toEqual("loc", "Country should be a location");
338
- expect(_.get(country, "frequency")).toBeGreaterThan(0);
339
- });
340
- done();
341
- });
342
-
343
- it("should test search by source", async (done) => {
344
- const q = new QueryEvents({sourceUri: await er.getNewsSourceUri("bbc")});
345
- q.setRequestedResult(new RequestEventsUriWgtList());
346
- const response = await er.execQuery(q);
347
- expect(_.has(response, "uriWgtList")).toBeTruthy("Results should contain uriWgtList");
348
- done();
349
- });
350
-
351
- it("should test search by source (2)", async (done) => {
352
- const q = new QueryEvents({sourceUri: await er.getNewsSourceUri("bbc")});
353
- const eventInfo = new EventInfoFlags({concepts: true, articleCounts: true, title: true, summary: true, categories: true, stories: true, imageCount: 1});
354
- const returnInfo1 = new ReturnInfo({conceptInfo: new ConceptInfoFlags({lang: "deu", type: "wiki"}), eventInfo});
355
- q.setRequestedResult(new RequestEventsInfo({page: 1, count: 50, sortBy: "size", sortByAsc: true, returnInfo: returnInfo1}));
356
- const response = await er.execQuery(q);
357
-
358
- expect(_.has(response, "events")).toBeTruthy("Results should contain events");
359
-
360
- const events = _.get(response, "events.results", []);
361
- expect(_.size(events)).toBeLessThanOrEqual(50, "Returned list of events was too long");
362
-
363
- let lastArtCount = 0;
364
-
365
- _.each(events, (event) => {
366
- expect(_.has(event, "articleCounts")).toBeTruthy("Event should contain articleCounts");
367
- expect(_.has(event, "categories")).toBeTruthy("Event should contain categories");
368
- expect(_.has(event, "concepts")).toBeTruthy("Event should contain concepts");
369
- expect(_.has(event, "stories")).toBeTruthy("Event should contain stories");
370
- expect(_.has(event, "title")).toBeTruthy("Event should contain title");
371
- expect(_.has(event, "summary")).toBeTruthy("Event should contain summary");
372
- expect(_.has(event, "images")).toBeTruthy("Event should contain images");
373
- expect(_.has(event, "location")).toBeTruthy("Event should contain location");
374
-
375
- lastArtCount = event.totalArticleCount;
376
- _.each(_.get(event, "concepts", []), (concept) => {
377
- expect(_.has(concept, "label.deu")).toBeTruthy("Concept should contain label in german language");
378
- expect(concept.type === "wiki").toBeTruthy("Got concept of invalid type");
379
- });
380
- });
381
- done();
382
- });
383
-
384
- it("should test search by source (3)", async (done) => {
385
- const q = new QueryEvents({sourceUri: await er.getNewsSourceUri("bbc")});
386
- q.setRequestedResult(new RequestEventsConceptAggr({conceptCount: 5, returnInfo: new ReturnInfo({conceptInfo: new ConceptInfoFlags({type: ["org", "loc"]})})}));
387
- const response = await er.execQuery(q);
388
- expect(_.has(response, "conceptAggr")).toBeTruthy("Results should contain conceptAggr");
389
- const concepts = _.get(response, "conceptAggr.results", []);
390
- expect(_.size(concepts)).toBeLessThanOrEqual(10, "Received a list of concepts that is too long");
391
- _.each(concepts, (concept) => {
392
- expect(concept.type === "loc" || concept.type === "org").toBeTruthy("Got concept of invalid type");
393
- });
394
- done();
395
- });
396
-
397
- it("should query events iterator (1)", async (done) => {
398
- const conceptUri = await er.getConceptUri("Obama");
399
- const q = new QueryEventsIter(er, {keywords: "germany", conceptUri});
400
- let eventsSize = 0;
401
- q.execQuery((item) => {
402
- eventsSize += 1;
403
- }, async () => {
404
- const q2 = new QueryEvents({keywords: "germany", conceptUri});
405
- const response = await er.execQuery(q2);
406
- expect(_.get(response, "events.totalResults")).toEqual(eventsSize);
407
- done();
408
- });
409
- });
410
-
411
- it("should query events iterator (2)", async (done) => {
412
- const conceptUri = await er.getConceptUri("Obama");
413
- const q = new QueryEventsIter(er, { lang: ["eng"], keywords: "trump", conceptUri: conceptUri, returnInfo: utils.returnInfo, maxItems: 5 });
414
- q.execQuery((item) => {
415
- expect(item).toContainConcept(conceptUri);
416
- let someArticlesHasText = false;
417
- new QueryEventArticlesIter(er, item["uri"], { lang: ["eng"], returnInfo: utils.returnInfo, maxItems: 5 }).execQuery((article) => {
418
- someArticlesHasText = someArticlesHasText || _.includes(_.deburr(_.toLower(_.get(article, "body"))), "trump");
419
- }, () => {
420
- expect(someArticlesHasText).toBeTruthy("At least one of the articles was expected to contain 'trump'");
421
- done();
422
- });
423
- });
424
- });
425
-
426
- it("should query events iterator (3)", async (done) => {
427
- const categoryUri = await er.getCategoryUri("business");
428
- const q = new QueryEventsIter(er, { keywords: "obama trump", categoryUri, returnInfo: utils.returnInfo });
429
- q.execQuery((item) => {
430
- expect(item).toContainCategory(categoryUri);
431
- let includesKeywordObama = false;
432
- let includesKeywordTrump = false;
433
-
434
- new QueryEventArticlesIter(er, item["uri"], { returnInfo: utils.returnInfo }).execQuery((article) => {
435
- const text = _.deburr(_.toLower(_.get(article, "body")));
436
- includesKeywordObama = includesKeywordObama || _.includes(text, "obama");
437
- includesKeywordTrump = includesKeywordTrump || _.includes(text, "trump");
438
- }, () => {
439
- expect(includesKeywordObama).toBeTruthy("At least one of the articles was expected to contain 'obama'");
440
- expect(includesKeywordTrump).toBeTruthy("At least one of the articles was expected to contain 'trump'");
441
- done();
442
- });
443
- });
444
- });
445
-
446
- it("should query events iterator (4)", async (done) => {
447
- const obamaUri = await er.getConceptUri("Obama");
448
- const politicsUri = await er.getConceptUri("politics");
449
- const chinaUri = await er.getConceptUri("china");
450
- const unitedStatesUri = await er.getConceptUri("united states");
451
-
452
- const srcDailyCallerUri = await er.getNewsSourceUri("daily caller");
453
- const srcAawsatUri = await er.getNewsSourceUri("aawsat");
454
- const srcSvodkaUri = await er.getNewsSourceUri("svodka");
455
-
456
- const catBusinessUri = await er.getCategoryUri("business");
457
- const catPoliticsUri = await er.getCategoryUri("politics");
458
- const queryConfig = {
459
- conceptUri: obamaUri,
460
- maxItems: 10,
461
- ignoreConceptUri: [politicsUri, chinaUri, unitedStatesUri],
462
- ignoreKeywords: ["trump", "politics", "michelle"],
463
- ignoreSourceUri: [srcDailyCallerUri, srcAawsatUri, srcSvodkaUri],
464
- ignoreCategoryUri: [catBusinessUri, catPoliticsUri],
465
- returnInfo: new ReturnInfo({ conceptInfo: new ConceptInfoFlags({ maxConceptsPerType: 350 })}),
466
- };
467
- const q = new QueryEventsIter(er, queryConfig);
468
- q.execQuery((item) => {
469
- expect(item).toContainConcept(obamaUri);
470
- expect(item).not.toContainConcept(politicsUri);
471
- expect(item).not.toContainConcept(chinaUri);
472
- expect(item).not.toContainConcept(unitedStatesUri);
473
- expect(item).not.toContainCategory(catBusinessUri);
474
- expect(item).not.toContainCategory(catPoliticsUri);
475
- new QueryEventArticlesIter(er, item["uri"], {returnInfo: utils.returnInfo, lang: ["eng"]}).execQuery((article) => {
476
- const text = _.deburr(_.toLower(_.get(article, "body")));
477
- expect(text).not.toContain("trump");
478
- expect(text).not.toContain("politics");
479
- expect(text).not.toContain("michelle");
480
- const hasArticleFromSource1 = article["source"]["uri"] === srcDailyCallerUri;
481
- const hasArticleFromSource2 = article["source"]["uri"] === srcAawsatUri;
482
- const hasArticleFromSource3 = article["source"]["uri"] === srcSvodkaUri;
483
- expect(hasArticleFromSource1).toBeFalsy();
484
- expect(hasArticleFromSource2).toBeFalsy();
485
- expect(hasArticleFromSource3).toBeFalsy();
486
- });
487
- }, () => {
488
- done();
489
- });
490
- });
491
- });