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.
- package/CHANGELOG.md +17 -1
- package/dist/eventRegistry.js +2 -2
- package/dist/eventRegistry.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/queryArticles.js +6 -0
- package/dist/queryArticles.js.map +1 -1
- package/dist/queryEvents.js +6 -0
- package/dist/queryEvents.js.map +1 -1
- package/dist/queryMentions.d.ts +95 -0
- package/dist/queryMentions.js +579 -0
- package/dist/queryMentions.js.map +1 -0
- package/dist/topicPage.js +2 -2
- package/dist/topicPage.js.map +1 -1
- package/{src → dist}/types.d.ts +284 -195
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/package.json +6 -5
- package/dist/correlations.d.ts +0 -50
- package/dist/correlations.js +0 -397
- package/dist/correlations.js.map +0 -1
- package/examples/autoSuggestionsExamples.ts +0 -46
- package/examples/countsExamples.ts +0 -34
- package/examples/dailySharesExamples.ts +0 -54
- package/examples/eventForTextExamples.ts +0 -32
- package/examples/feedOfNewArticlesExamples.ts +0 -82
- package/examples/feedOfNewEventsExamples.ts +0 -70
- package/examples/queryArticleExamples.ts +0 -42
- package/examples/queryArticlesExamples.ts +0 -242
- package/examples/queryEventExamples.ts +0 -99
- package/examples/queryEventsExamples.ts +0 -232
- package/examples/topicPageExamples.ts +0 -97
- package/examples/trendsExamples.ts +0 -34
- package/src/analytics.ts +0 -181
- package/src/base.ts +0 -198
- package/src/counts.ts +0 -119
- package/src/dailyShares.ts +0 -48
- package/src/eventForText.ts +0 -61
- package/src/eventRegistry.ts +0 -733
- package/src/index.ts +0 -111
- package/src/info.ts +0 -121
- package/src/query.ts +0 -257
- package/src/queryArticle.ts +0 -139
- package/src/queryArticles.ts +0 -603
- package/src/queryEvent.ts +0 -473
- package/src/queryEvents.ts +0 -684
- package/src/queryStory.ts +0 -152
- package/src/recent.ts +0 -63
- package/src/returnInfo.ts +0 -363
- package/src/topicPage.ts +0 -479
- package/src/trends.ts +0 -63
- package/test/index.d.ts +0 -18
- package/test/jasmine.json +0 -10
- package/test/spec/analytics.spec.ts +0 -150
- package/test/spec/autoSuggestions.spec.ts +0 -54
- package/test/spec/info.spec.ts +0 -84
- package/test/spec/invalidQueries.spec.ts +0 -147
- package/test/spec/queryArticle.spec.ts +0 -62
- package/test/spec/queryArticles.spec.ts +0 -541
- package/test/spec/queryArticlesComplex.spec.ts +0 -298
- package/test/spec/queryEvent.spec.ts +0 -194
- package/test/spec/queryEvents.spec.ts +0 -491
- package/test/spec/queryEventsComplex.spec.ts +0 -188
- package/test/spec/queryPaging.spec.ts +0 -318
- package/test/spec/returnInfo.spec.ts +0 -34
- package/test/spec/topicPage.spec.ts +0 -83
- package/test/spec/utils.ts +0 -436
- package/test/tsconfig.json +0 -31
- package/tsconfig.json +0 -32
- package/tslint.json +0 -25
|
@@ -1,541 +0,0 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
|
-
import {
|
|
3
|
-
ConceptInfoFlags,
|
|
4
|
-
QueryArticles,
|
|
5
|
-
QueryArticlesIter,
|
|
6
|
-
RequestArticlesCategoryAggr,
|
|
7
|
-
RequestArticlesConceptAggr,
|
|
8
|
-
RequestArticlesConceptMatrix,
|
|
9
|
-
RequestArticlesConceptTrends,
|
|
10
|
-
RequestArticlesInfo,
|
|
11
|
-
RequestArticlesKeywordAggr,
|
|
12
|
-
RequestArticlesSourceAggr,
|
|
13
|
-
RequestArticlesUriWgtList,
|
|
14
|
-
ReturnInfo,
|
|
15
|
-
} from "../../src/index";
|
|
16
|
-
import { Utils } from "./utils";
|
|
17
|
-
|
|
18
|
-
describe("Query Articles", () => {
|
|
19
|
-
const er = Utils.initAPI();
|
|
20
|
-
const utils = new Utils();
|
|
21
|
-
let query: QueryArticles;
|
|
22
|
-
let requestArticlesInfo: RequestArticlesInfo;
|
|
23
|
-
|
|
24
|
-
beforeAll(async (done) => {
|
|
25
|
-
query = new QueryArticles({conceptUri: await er.getConceptUri("Obama")});
|
|
26
|
-
requestArticlesInfo = new RequestArticlesInfo({count: 30, returnInfo: new ReturnInfo({articleInfo: utils.articleInfo, conceptInfo: utils.conceptInfo, locationInfo: utils.locationInfo})});
|
|
27
|
-
done();
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it("should return list of articles", async (done) => {
|
|
31
|
-
try {
|
|
32
|
-
query.setRequestedResult(requestArticlesInfo);
|
|
33
|
-
const response = await er.execQuery(query);
|
|
34
|
-
expect(response).toBeValidGeneralArticleList();
|
|
35
|
-
} catch (error) {
|
|
36
|
-
console.log(error);
|
|
37
|
-
} finally {
|
|
38
|
-
done();
|
|
39
|
-
}
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it("should return list of article uris and weights", async (done) => {
|
|
43
|
-
try {
|
|
44
|
-
const conceptUri = await er.getConceptUri("germany");
|
|
45
|
-
const iter = new QueryArticlesIter(er, {conceptUri});
|
|
46
|
-
const expectedCount = await iter.count();
|
|
47
|
-
const q = new QueryArticles({conceptUri});
|
|
48
|
-
let items = [];
|
|
49
|
-
const count = 20000;
|
|
50
|
-
const pages = _.ceil(expectedCount / count) + 1;
|
|
51
|
-
for (let page = 1; page <= pages; page++) {
|
|
52
|
-
q.setRequestedResult(new RequestArticlesUriWgtList({page, count}));
|
|
53
|
-
const response = await er.execQuery(q);
|
|
54
|
-
items = [...items, ..._.get(response, "uriWgtList.results", [])];
|
|
55
|
-
}
|
|
56
|
-
expect(expectedCount).toBe(_.size(items), `We did not retrieve all item uris. We were expecting ${expectedCount}, but got ${_.size(items)} uris`);
|
|
57
|
-
let lastWgt;
|
|
58
|
-
for ( const item of items) {
|
|
59
|
-
const wgt = _.parseInt(_.last(_.split(item, ":")));
|
|
60
|
-
if (_.isNil(lastWgt)) {
|
|
61
|
-
lastWgt = wgt;
|
|
62
|
-
} else {
|
|
63
|
-
expect(lastWgt).toBeGreaterThanOrEqual(wgt, "Previous weight is not greater or equal to current");
|
|
64
|
-
lastWgt = wgt;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
} catch (error) {
|
|
68
|
-
console.log(error);
|
|
69
|
-
} finally {
|
|
70
|
-
done();
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
it("should return list of articles with keyword search", async (done) => {
|
|
75
|
-
try {
|
|
76
|
-
const q1 = new QueryArticles({keywords: "iphone"});
|
|
77
|
-
q1.setRequestedResult(requestArticlesInfo);
|
|
78
|
-
const res1 = await er.execQuery(q1);
|
|
79
|
-
expect(res1).toBeValidGeneralArticleList();
|
|
80
|
-
|
|
81
|
-
const q2 = new QueryArticles({keywords: "iphone"});
|
|
82
|
-
q2.setRequestedResult(requestArticlesInfo);
|
|
83
|
-
const res2 = await er.execQuery(q2);
|
|
84
|
-
expect(res2).toBeValidGeneralArticleList();
|
|
85
|
-
|
|
86
|
-
const results1 = _.sortBy(res1["articles"]["results"], "id");
|
|
87
|
-
const results2 = _.sortBy(res2["articles"]["results"], "id");
|
|
88
|
-
expect(_.size(results1)).toEqual(_.size(results2), "Keyword search should return responses of the same size");
|
|
89
|
-
} catch (error) {
|
|
90
|
-
console.log(error);
|
|
91
|
-
} finally {
|
|
92
|
-
done();
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
it("should return list of articles with keyword title search ('iphone')", (done) => {
|
|
97
|
-
try {
|
|
98
|
-
const q = new QueryArticlesIter(er, {keywords: "iphone", keywordsLoc: "title", lang: "eng", returnInfo: new ReturnInfo({articleInfo: utils.articleInfo}), maxItems: 50});
|
|
99
|
-
q.execQuery((item) => {
|
|
100
|
-
expect(_.deburr(_.toLower(_.get(item, "title")))).toContain("iphone");
|
|
101
|
-
}, (errorMessage) => {
|
|
102
|
-
if (errorMessage) {
|
|
103
|
-
console.error(errorMessage);
|
|
104
|
-
}
|
|
105
|
-
done();
|
|
106
|
-
});
|
|
107
|
-
} catch (error) {
|
|
108
|
-
console.error(error);
|
|
109
|
-
done();
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
it("should return list of articles with keyword title search ('home')", (done) => {
|
|
114
|
-
try {
|
|
115
|
-
const q = new QueryArticlesIter(er, {keywords: "home", keywordsLoc: "title", lang: "eng", returnInfo: new ReturnInfo({articleInfo: utils.articleInfo}), maxItems: 50});
|
|
116
|
-
q.execQuery((item) => {
|
|
117
|
-
expect(_.deburr(_.toLower(_.get(item, "title")))).toContain("home");
|
|
118
|
-
}, (errorMessage) => {
|
|
119
|
-
if (errorMessage) {
|
|
120
|
-
console.error(errorMessage);
|
|
121
|
-
}
|
|
122
|
-
done();
|
|
123
|
-
});
|
|
124
|
-
} catch (error) {
|
|
125
|
-
console.error(error);
|
|
126
|
-
done();
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it("should return list of articles with keyword body search ('home')", (done) => {
|
|
131
|
-
try {
|
|
132
|
-
const returnInfo = new ReturnInfo({articleInfo: utils.articleInfo});
|
|
133
|
-
const q = new QueryArticlesIter(er, {keywords: "home", keywordsLoc: "body", lang: "eng", returnInfo: returnInfo, maxItems: 50});
|
|
134
|
-
q.execQuery((item) => {
|
|
135
|
-
expect(_.deburr(_.toLower(_.get(item, "body")))).toContain("home");
|
|
136
|
-
}, (errorMessage) => {
|
|
137
|
-
if (errorMessage) {
|
|
138
|
-
console.error(errorMessage);
|
|
139
|
-
}
|
|
140
|
-
done();
|
|
141
|
-
});
|
|
142
|
-
} catch (error) {
|
|
143
|
-
console.error(error);
|
|
144
|
-
done();
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it("should return list of articles with keyword body search ('Jack')", (done) => {
|
|
149
|
-
try {
|
|
150
|
-
const q = new QueryArticlesIter(er, {keywords: "Jack", keywordsLoc: "body", lang: "eng", returnInfo: new ReturnInfo({articleInfo: utils.articleInfo}), maxItems: 50});
|
|
151
|
-
q.execQuery((item) => {
|
|
152
|
-
expect(item).toContainBodyText("Jack");
|
|
153
|
-
}, (errorMessage) => {
|
|
154
|
-
if (errorMessage) {
|
|
155
|
-
console.error(errorMessage);
|
|
156
|
-
}
|
|
157
|
-
done();
|
|
158
|
-
});
|
|
159
|
-
} catch (error) {
|
|
160
|
-
console.error(error);
|
|
161
|
-
done();
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
it("should return list with publisher search", async (done) => {
|
|
166
|
-
try {
|
|
167
|
-
const sourceUri = await er.getNewsSourceUri("bbc");
|
|
168
|
-
const q1 = new QueryArticles({sourceUri});
|
|
169
|
-
q1.setRequestedResult(requestArticlesInfo);
|
|
170
|
-
const res1 = await er.execQuery(q1);
|
|
171
|
-
expect(res1).toBeValidGeneralArticleList();
|
|
172
|
-
_.each(_.get(res1, "articles.results"), (article) => {
|
|
173
|
-
expect(_.get(article, "source.uri")).toBe(sourceUri, "Article is not from the specified source");
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
const q2 = new QueryArticles({sourceUri});
|
|
177
|
-
q2.setRequestedResult(requestArticlesInfo);
|
|
178
|
-
const res2 = await er.execQuery(q2);
|
|
179
|
-
expect(res2).toBeValidGeneralArticleList();
|
|
180
|
-
|
|
181
|
-
const results1 = _.sortBy(res1["articles"]["results"], "id");
|
|
182
|
-
const results2 = _.sortBy(res2["articles"]["results"], "id");
|
|
183
|
-
expect(_.size(results1)).toEqual(_.size(results2), "Publisher search should return responses of the same size");
|
|
184
|
-
expect(_.map(results1, "id")).toEqual(_.map(results2, "id"), "Publisher search should return equal responses");
|
|
185
|
-
} catch (error) {
|
|
186
|
-
console.error(error);
|
|
187
|
-
} finally {
|
|
188
|
-
done();
|
|
189
|
-
}
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it("should return list with author search", async (done) => {
|
|
193
|
-
try {
|
|
194
|
-
const authorUri = await er.getAuthorUri("associated");
|
|
195
|
-
const q1 = new QueryArticles({authorUri});
|
|
196
|
-
q1.setRequestedResult(requestArticlesInfo);
|
|
197
|
-
const response = await er.execQuery(q1);
|
|
198
|
-
expect(response).toBeValidGeneralArticleList();
|
|
199
|
-
for (const article of _.get(response, "articles.results", [])) {
|
|
200
|
-
let foundAuthor = false;
|
|
201
|
-
for (const author of _.get(article, "authors")) {
|
|
202
|
-
if (author.uri === authorUri) {
|
|
203
|
-
foundAuthor = true;
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
expect(foundAuthor).toBeTruthy();
|
|
207
|
-
}
|
|
208
|
-
} catch (error) {
|
|
209
|
-
console.error(error);
|
|
210
|
-
} finally {
|
|
211
|
-
done();
|
|
212
|
-
}
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("should return list with category search", async (done) => {
|
|
216
|
-
try {
|
|
217
|
-
const categoryUri = await er.getCategoryUri("disa");
|
|
218
|
-
const q1 = new QueryArticles({categoryUri});
|
|
219
|
-
q1.setRequestedResult(requestArticlesInfo);
|
|
220
|
-
const res1 = await er.execQuery(q1);
|
|
221
|
-
expect(res1).toBeValidGeneralArticleList();
|
|
222
|
-
|
|
223
|
-
const q2 = new QueryArticles({categoryUri});
|
|
224
|
-
q2.setRequestedResult(requestArticlesInfo);
|
|
225
|
-
const res2 = await er.execQuery(q2);
|
|
226
|
-
expect(res2).toBeValidGeneralArticleList();
|
|
227
|
-
|
|
228
|
-
const results1 = _.sortBy(res1["articles"]["results"], "id");
|
|
229
|
-
const results2 = _.sortBy(res2["articles"]["results"], "id");
|
|
230
|
-
expect(_.size(results1)).toEqual(_.size(results2), "Category search should return responses of the same size");
|
|
231
|
-
expect(_.map(results1, "id")).toEqual(_.map(results2, "id"), "Category search should return equal responses");
|
|
232
|
-
} catch (error) {
|
|
233
|
-
console.error(error);
|
|
234
|
-
} finally {
|
|
235
|
-
done();
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
it("should return list with lang search", async (done) => {
|
|
240
|
-
try {
|
|
241
|
-
const q1 = new QueryArticles({lang: "deu"});
|
|
242
|
-
q1.setRequestedResult(requestArticlesInfo);
|
|
243
|
-
const res1 = await er.execQuery(q1);
|
|
244
|
-
expect(res1).toBeValidGeneralArticleList();
|
|
245
|
-
for (const article of _.get(res1, "articles.results")) {
|
|
246
|
-
expect(_.get(article, "lang")).toBe("deu", "Article is not in the specified language");
|
|
247
|
-
}
|
|
248
|
-
} catch (error) {
|
|
249
|
-
console.error(error);
|
|
250
|
-
} finally {
|
|
251
|
-
done();
|
|
252
|
-
}
|
|
253
|
-
});
|
|
254
|
-
|
|
255
|
-
it("should return list with location search", async (done) => {
|
|
256
|
-
try {
|
|
257
|
-
const locationUri = await er.getLocationUri("united");
|
|
258
|
-
const q1 = new QueryArticles({locationUri});
|
|
259
|
-
q1.setRequestedResult(requestArticlesInfo);
|
|
260
|
-
const res1 = await er.execQuery(q1);
|
|
261
|
-
expect(res1).toBeValidGeneralArticleList();
|
|
262
|
-
|
|
263
|
-
const q2 = new QueryArticles({locationUri});
|
|
264
|
-
q2.setRequestedResult(requestArticlesInfo);
|
|
265
|
-
const res2 = await er.execQuery(q2);
|
|
266
|
-
expect(res2).toBeValidGeneralArticleList();
|
|
267
|
-
|
|
268
|
-
const results1 = _.sortBy(res1["articles"]["results"], "id");
|
|
269
|
-
const results2 = _.sortBy(res2["articles"]["results"], "id");
|
|
270
|
-
expect(_.size(results1)).toEqual(_.size(results2), "Location search should return responses of the same size");
|
|
271
|
-
expect(_.map(results1, "id")).toEqual(_.map(results2, "id"), "Location search should return equal responses");
|
|
272
|
-
} catch (error) {
|
|
273
|
-
console.error(error);
|
|
274
|
-
} finally {
|
|
275
|
-
done();
|
|
276
|
-
}
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
it("should return list with combined search", async (done) => {
|
|
280
|
-
try {
|
|
281
|
-
const keywords = "germany";
|
|
282
|
-
const lang = ["eng", "deu"];
|
|
283
|
-
const conceptUri = await er.getConceptUri("Merkel");
|
|
284
|
-
const categoryUri = await er.getCategoryUri("Business");
|
|
285
|
-
|
|
286
|
-
const q1 = new QueryArticles({keywords, lang, conceptUri, categoryUri});
|
|
287
|
-
q1.setRequestedResult(requestArticlesInfo);
|
|
288
|
-
const res1 = await er.execQuery(q1);
|
|
289
|
-
expect(res1).toBeValidGeneralArticleList();
|
|
290
|
-
|
|
291
|
-
const q2 = new QueryArticles({keywords, lang, conceptUri, categoryUri});
|
|
292
|
-
q2.setRequestedResult(requestArticlesInfo);
|
|
293
|
-
const res2 = await er.execQuery(q2);
|
|
294
|
-
expect(res2).toBeValidGeneralArticleList();
|
|
295
|
-
|
|
296
|
-
const results1 = _.sortBy(res1["articles"]["results"], "id");
|
|
297
|
-
const results2 = _.sortBy(res2["articles"]["results"], "id");
|
|
298
|
-
expect(_.size(results1)).toEqual(_.size(results2), "Combined search should return responses of the same size");
|
|
299
|
-
expect(_.map(results1, "id")).toEqual(_.map(results2, "id"), "Combined search should return equal responses");
|
|
300
|
-
} catch (error) {
|
|
301
|
-
console.error(error);
|
|
302
|
-
} finally {
|
|
303
|
-
done();
|
|
304
|
-
}
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
it("should return list of concept trends", async (done) => {
|
|
308
|
-
try {
|
|
309
|
-
const conceptInfo = new ConceptInfoFlags({
|
|
310
|
-
synonyms: true,
|
|
311
|
-
image: true,
|
|
312
|
-
description: true,
|
|
313
|
-
trendingScore: true,
|
|
314
|
-
});
|
|
315
|
-
const returnInfo = new ReturnInfo({conceptInfo});
|
|
316
|
-
const requestArticlesConceptTrends = new RequestArticlesConceptTrends({conceptUris: [await er.getConceptUri("Obama"), await er.getConceptUri("Trump")], returnInfo});
|
|
317
|
-
query.setRequestedResult(requestArticlesConceptTrends);
|
|
318
|
-
const response = await er.execQuery(query);
|
|
319
|
-
// Check that we get the expected properties
|
|
320
|
-
expect(_.has(response, "conceptTrends")).toBeTruthy("Expected to get 'conceptTrends'");
|
|
321
|
-
expect(_.has(response, "conceptTrends.trends")).toBeTruthy("Expected to get 'trends' property in conceptTrends");
|
|
322
|
-
expect(_.has(response, "conceptTrends.conceptInfo")).toBeTruthy("Expected to get 'conceptInfo' property in conceptTrends");
|
|
323
|
-
expect(_.size(_.get(response, "conceptTrends.conceptInfo"))).toBe(2, "Expected to get 2 concepts in concept trends");
|
|
324
|
-
|
|
325
|
-
const trends = _.get(response, "conceptTrends.trends");
|
|
326
|
-
expect(!_.isEmpty(trends)).toBeTruthy();
|
|
327
|
-
for (const trend of trends) {
|
|
328
|
-
expect(_.has(trend, "date")).toBeTruthy("A trend should have a date");
|
|
329
|
-
expect(_.has(trend, "conceptFreq")).toBeTruthy("A trend should have a conceptFreq");
|
|
330
|
-
expect(_.has(trend, "totArts")).toBeTruthy("A trend should have a totArts property");
|
|
331
|
-
expect(_.size(_.get(trend, "conceptFreq"))).toBeLessThanOrEqual(2, "Concept frequencies should contain 2 elements - one for each concept");
|
|
332
|
-
}
|
|
333
|
-
const concepts = _.get(response, "conceptTrends.conceptInfo");
|
|
334
|
-
for (const concept of concepts) {
|
|
335
|
-
expect(concept).toBeValidConcept();
|
|
336
|
-
}
|
|
337
|
-
} catch (error) {
|
|
338
|
-
console.error(error);
|
|
339
|
-
} finally {
|
|
340
|
-
done();
|
|
341
|
-
}
|
|
342
|
-
});
|
|
343
|
-
|
|
344
|
-
it("should return aggregate of concepts of resulting articles", async (done) => {
|
|
345
|
-
try {
|
|
346
|
-
const requestArticlesConceptAggr = new RequestArticlesConceptAggr({conceptCount: 50, returnInfo: new ReturnInfo({articleInfo: utils.articleInfo, conceptInfo: utils.conceptInfo, locationInfo: utils.locationInfo})});
|
|
347
|
-
query.setRequestedResult(requestArticlesConceptAggr);
|
|
348
|
-
const response = await er.execQuery(query);
|
|
349
|
-
|
|
350
|
-
expect(_.has(response, "conceptAggr")).toBeTruthy("Expected to get 'conceptAggr'");
|
|
351
|
-
const concepts = _.get(response, "conceptAggr.results");
|
|
352
|
-
expect(_.size(concepts)).toEqual(50, "Expected a different number of concepts in 'conceptAggr'");
|
|
353
|
-
for (const concept of concepts) {
|
|
354
|
-
expect(concept).toBeValidConcept();
|
|
355
|
-
}
|
|
356
|
-
} catch (error) {
|
|
357
|
-
console.error(error);
|
|
358
|
-
} finally {
|
|
359
|
-
done();
|
|
360
|
-
}
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
it("should return aggregate of keywords of resulting articles", async (done) => {
|
|
364
|
-
try {
|
|
365
|
-
const requestArticlesKeywordAggr = new RequestArticlesKeywordAggr({articlesSampleSize: 100});
|
|
366
|
-
query.setRequestedResult(requestArticlesKeywordAggr);
|
|
367
|
-
const response = await er.execQuery(query);
|
|
368
|
-
|
|
369
|
-
expect(_.has(response, "keywordAggr")).toBeTruthy("Expected to get 'keywordAggr'");
|
|
370
|
-
const keywords = _.get(response, "keywordAggr.results", []);
|
|
371
|
-
expect(_.size(keywords)).toBeGreaterThan(0, "Expected to get some keywords");
|
|
372
|
-
for (const keyword of keywords) {
|
|
373
|
-
expect(_.has(keyword, "keyword")).toBeTruthy("Expected a keyword property");
|
|
374
|
-
expect(_.has(keyword, "weight")).toBeTruthy("Expected a weight property");
|
|
375
|
-
}
|
|
376
|
-
} catch (error) {
|
|
377
|
-
console.error(error);
|
|
378
|
-
} finally {
|
|
379
|
-
done();
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
it("should return aggregate of categories of resulting articles", async (done) => {
|
|
384
|
-
try {
|
|
385
|
-
const requestArticlesCategoryAggr = new RequestArticlesCategoryAggr({returnInfo: new ReturnInfo({articleInfo: utils.articleInfo, categoryInfo: utils.categoryInfo})});
|
|
386
|
-
query.setRequestedResult(requestArticlesCategoryAggr);
|
|
387
|
-
const response = await er.execQuery(query);
|
|
388
|
-
|
|
389
|
-
expect(_.has(response, "categoryAggr")).toBeTruthy("Expected to get 'categoryAggr'");
|
|
390
|
-
const categories = _.get(response, "categoryAggr.results", []);
|
|
391
|
-
expect(_.size(categories)).toBeGreaterThan(0, "Expected to get a non empty category aggregates");
|
|
392
|
-
for (const category of categories) {
|
|
393
|
-
expect(category).toBeValidCategory();
|
|
394
|
-
}
|
|
395
|
-
} catch (error) {
|
|
396
|
-
console.error(error);
|
|
397
|
-
} finally {
|
|
398
|
-
done();
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
it("should return concept matrix of resulting articles", async (done) => {
|
|
403
|
-
try {
|
|
404
|
-
const requestArticlesConceptMatrix = new RequestArticlesConceptMatrix({conceptCount: 20, returnInfo: new ReturnInfo({articleInfo: utils.articleInfo, conceptInfo: utils.conceptInfo, locationInfo: utils.locationInfo})});
|
|
405
|
-
query.setRequestedResult(requestArticlesConceptMatrix);
|
|
406
|
-
const response = await er.execQuery(query);
|
|
407
|
-
|
|
408
|
-
expect(_.has(response, "conceptMatrix")).toBeTruthy("Expected to get 'conceptMatrix'");
|
|
409
|
-
const matrix = _.get(response, "conceptMatrix");
|
|
410
|
-
expect(_.has(matrix, "sampleSize")).toBeTruthy("Expecting 'sampleSize' property in conceptMatrix");
|
|
411
|
-
expect(_.has(matrix, "freqMatrix")).toBeTruthy("Expecting 'freqMatrix' property in conceptMatrix");
|
|
412
|
-
expect(_.has(matrix, "concepts")).toBeTruthy("Expecting 'concepts' property in conceptMatrix");
|
|
413
|
-
expect(_.size(_.get(matrix, "concepts"))).toEqual(20, "Expected 20 concepts");
|
|
414
|
-
for (const concept of _.get(matrix, "concepts")) {
|
|
415
|
-
expect(concept).toBeValidConcept();
|
|
416
|
-
}
|
|
417
|
-
} catch (error) {
|
|
418
|
-
console.error(error);
|
|
419
|
-
} finally {
|
|
420
|
-
done();
|
|
421
|
-
}
|
|
422
|
-
});
|
|
423
|
-
|
|
424
|
-
it("should aggregate of sources of resulting articles", async (done) => {
|
|
425
|
-
try {
|
|
426
|
-
const requestArticlesSourceAggr = new RequestArticlesSourceAggr({returnInfo: new ReturnInfo({articleInfo: utils.articleInfo, sourceInfo: utils.sourceInfo})});
|
|
427
|
-
query.setRequestedResult(requestArticlesSourceAggr);
|
|
428
|
-
const response = await er.execQuery(query);
|
|
429
|
-
|
|
430
|
-
expect(_.has(response, "sourceAggr")).toBeTruthy("Expected to get 'sourceAggr'");
|
|
431
|
-
for (const sourceInfo of _.get(response, "sourceAggr.countsPerSource")) {
|
|
432
|
-
expect(_.get(sourceInfo, "source")).toBeValidSource();
|
|
433
|
-
expect(_.has(sourceInfo, "counts")).toBeTruthy("Source info should contain counts object");
|
|
434
|
-
expect(_.has(sourceInfo, "counts.frequency")).toBeTruthy("Counts should contain a frequency");
|
|
435
|
-
expect(_.has(sourceInfo, "counts.total")).toBeTruthy("Counts should contain a total");
|
|
436
|
-
}
|
|
437
|
-
for (const country of _.get(response, "sourceAggr.countsPerCountry")) {
|
|
438
|
-
if (_.get(country, "uri") === "http://en.wikipedia.org/wiki/Australia_(continent)") return;
|
|
439
|
-
expect(_.get(country, "type")).toEqual("loc", "Country should be a location");
|
|
440
|
-
expect(_.get(country, "frequency")).toBeGreaterThan(0);
|
|
441
|
-
}
|
|
442
|
-
} catch (error) {
|
|
443
|
-
console.error(error);
|
|
444
|
-
} finally {
|
|
445
|
-
done();
|
|
446
|
-
}
|
|
447
|
-
});
|
|
448
|
-
|
|
449
|
-
it("should test query articles iterator (1)", async (done) => {
|
|
450
|
-
try {
|
|
451
|
-
const keywords = "trump";
|
|
452
|
-
const conceptUri = await er.getConceptUri("Obama");
|
|
453
|
-
const sourceUri = await er.getNewsSourceUri("bbc");
|
|
454
|
-
const q = new QueryArticlesIter(er, { keywords, conceptUri, sourceUri});
|
|
455
|
-
let articlesSize = 0;
|
|
456
|
-
const itemCount = await q.count();
|
|
457
|
-
q.execQuery((item) => articlesSize += 1, () => {
|
|
458
|
-
expect(itemCount).toEqual(articlesSize);
|
|
459
|
-
done();
|
|
460
|
-
});
|
|
461
|
-
} catch (error) {
|
|
462
|
-
console.error(error);
|
|
463
|
-
done();
|
|
464
|
-
}
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
it("should test query articles iterator (2)", async (done) => {
|
|
468
|
-
try {
|
|
469
|
-
const q = new QueryArticles({keywords: "trump"});
|
|
470
|
-
q.setRequestedResult(new RequestArticlesUriWgtList({page: 2, count: 100}));
|
|
471
|
-
const response = await er.execQuery(q);
|
|
472
|
-
expect(_.size(_.get(response, "uriWgtList.results", []))).not.toBe(0, "No results were obtained for second page of uris");
|
|
473
|
-
} catch (error) {
|
|
474
|
-
console.error(error);
|
|
475
|
-
} finally {
|
|
476
|
-
done();
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
it("should test query articles iterator (3)", async (done) => {
|
|
481
|
-
try {
|
|
482
|
-
const conceptUri = await er.getConceptUri("Obama");
|
|
483
|
-
const sourceUri = await er.getNewsSourceUri("bbc");
|
|
484
|
-
const categoryUri = await er.getCategoryUri("business");
|
|
485
|
-
const q = new QueryArticlesIter(er, { conceptUri, sourceUri, categoryUri, returnInfo: new ReturnInfo({articleInfo: utils.articleInfo}), maxItems: 50 });
|
|
486
|
-
q.execQuery((item) => {
|
|
487
|
-
expect(item).toContainConcept(conceptUri);
|
|
488
|
-
expect(item).toContainSource(sourceUri);
|
|
489
|
-
expect(item).toContainCategory(categoryUri);
|
|
490
|
-
}, () => {
|
|
491
|
-
done();
|
|
492
|
-
});
|
|
493
|
-
} catch (error) {
|
|
494
|
-
console.error(error);
|
|
495
|
-
done();
|
|
496
|
-
}
|
|
497
|
-
});
|
|
498
|
-
|
|
499
|
-
it("should test query articles iterator (4)", async (done) => {
|
|
500
|
-
try {
|
|
501
|
-
const conceptUri = await er.getConceptUri("Obama");
|
|
502
|
-
const ignoreConceptUri = [await er.getConceptUri("politics"), await er.getConceptUri("china"), await er.getConceptUri("united states")];
|
|
503
|
-
const ignoreKeywords = ["trump", "politics", "michelle"];
|
|
504
|
-
const ignoreSourceUri = [await er.getNewsSourceUri("daily caller"), await er.getNewsSourceUri("aawsat"), await er.getNewsSourceUri("svodka")];
|
|
505
|
-
const ignoreCategoryUri = [await er.getCategoryUri("business"), await er.getCategoryUri("politics")];
|
|
506
|
-
// const ignoreLang = "zho";
|
|
507
|
-
const queryConfig = {
|
|
508
|
-
conceptUri,
|
|
509
|
-
ignoreConceptUri,
|
|
510
|
-
ignoreKeywords,
|
|
511
|
-
ignoreSourceUri,
|
|
512
|
-
ignoreCategoryUri,
|
|
513
|
-
returnInfo: new ReturnInfo({articleInfo: utils.articleInfo}),
|
|
514
|
-
maxItems: 10,
|
|
515
|
-
articleBatchSize: 5,
|
|
516
|
-
};
|
|
517
|
-
const q = new QueryArticlesIter(er, queryConfig);
|
|
518
|
-
q.execQuery((item) => {
|
|
519
|
-
expect(item).toContainConcept(conceptUri);
|
|
520
|
-
_.each(ignoreConceptUri, (uri) => {
|
|
521
|
-
expect(item).not.toContainConcept(uri);
|
|
522
|
-
});
|
|
523
|
-
_.each(ignoreKeywords, (text) => {
|
|
524
|
-
expect(item).not.toContainBodyText(text);
|
|
525
|
-
});
|
|
526
|
-
_.each(ignoreSourceUri, (uri) => {
|
|
527
|
-
expect(item).not.toContainSource(uri);
|
|
528
|
-
});
|
|
529
|
-
_.each(ignoreCategoryUri, (uri) => {
|
|
530
|
-
expect(item).not.toContainCategory(uri);
|
|
531
|
-
});
|
|
532
|
-
}, () => {
|
|
533
|
-
done();
|
|
534
|
-
});
|
|
535
|
-
} catch (error) {
|
|
536
|
-
console.error(error);
|
|
537
|
-
done();
|
|
538
|
-
}
|
|
539
|
-
});
|
|
540
|
-
|
|
541
|
-
});
|