eventregistry 8.11.1 → 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
package/dist/analytics.js CHANGED
@@ -1,331 +1,337 @@
1
- "use strict";
2
- var __assign = (this && this.__assign) || function () {
3
- __assign = Object.assign || function(t) {
4
- for (var s, i = 1, n = arguments.length; i < n; i++) {
5
- s = arguments[i];
6
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
- t[p] = s[p];
8
- }
9
- return t;
10
- };
11
- return __assign.apply(this, arguments);
12
- };
13
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
- return new (P || (P = Promise))(function (resolve, reject) {
15
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
16
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
17
- function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
18
- step((generator = generator.apply(thisArg, _arguments || [])).next());
19
- });
20
- };
21
- var __generator = (this && this.__generator) || function (thisArg, body) {
22
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
23
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
24
- function verb(n) { return function (v) { return step([n, v]); }; }
25
- function step(op) {
26
- if (f) throw new TypeError("Generator is already executing.");
27
- while (_) try {
28
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
29
- if (y = 0, t) op = [op[0] & 2, t.value];
30
- switch (op[0]) {
31
- case 0: case 1: t = op; break;
32
- case 4: _.label++; return { value: op[1], done: false };
33
- case 5: _.label++; y = op[1]; op = [0]; continue;
34
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
35
- default:
36
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
37
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
38
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
39
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
40
- if (t[2]) _.ops.pop();
41
- _.trys.pop(); continue;
42
- }
43
- op = body.call(thisArg, _);
44
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
45
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
- }
47
- };
48
- Object.defineProperty(exports, "__esModule", { value: true });
49
- var _ = require("lodash");
50
- // The Analytics class can be used for access the text analytics services provided by the Event Registry.
51
- // These include:
52
- // - text annotation: identifying the list of entities and non-entities mentioned in the provided text
53
- // - text categorization: identification of up to 5 categories that describe the topic of the given text.
54
- // The list of available categories come from DMOZ open directory. Currently, only English text can be categorized!
55
- // - sentiment detection: what is the sentiment expressed in the given text
56
- // - language detection: detect in which language is the given text written
57
- // NOTE: the functionality is currently in BETA. The API calls or the provided outputs may change in the future.
58
- var Analytics = /** @class */ (function () {
59
- /**
60
- * @param eventRegistry: instance of EventRegistry class
61
- */
62
- function Analytics(er) {
63
- this.er = er;
64
- }
65
- /**
66
- * Identify the list of entities and nonentities mentioned in the text
67
- * @param text input text to annotate
68
- * @param lang language of the provided document (can be an ISO2 or ISO3 code). If None is provided, the language will be automatically detected
69
- */
70
- Analytics.prototype.annotate = function (text, lang, customParams) {
71
- return __awaiter(this, void 0, void 0, function () {
72
- var params, _a, _b;
73
- return __generator(this, function (_c) {
74
- switch (_c.label) {
75
- case 0:
76
- params = { lang: lang, text: text };
77
- if (!_.isUndefined(customParams)) {
78
- params = __assign({}, params, customParams);
79
- }
80
- _b = (_a = _).get;
81
- return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/annotate", params)];
82
- case 1: return [2 /*return*/, _b.apply(_a, [_c.sent(), "data"])];
83
- }
84
- });
85
- });
86
- };
87
- /**
88
- * Determine the set of up to 5 categories the text is about. Currently, only English text can be categorized!
89
- * @param text input text to categorize
90
- * @param taxonomy: which taxonomy use for categorization. Options:
91
- * - "dmoz" (over 5000 categories in 3 levels, English language only)
92
- * - "news" (general news categorization, 9 categories, any langauge)
93
- */
94
- Analytics.prototype.categorize = function (text, taxonomy) {
95
- if (taxonomy === void 0) { taxonomy = "dmoz"; }
96
- return __awaiter(this, void 0, void 0, function () {
97
- var _a, _b;
98
- return __generator(this, function (_c) {
99
- switch (_c.label) {
100
- case 0:
101
- _b = (_a = _).get;
102
- return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/categorize", { text: text, taxonomy: taxonomy })];
103
- case 1: return [2 /*return*/, _b.apply(_a, [_c.sent(), "data"])];
104
- }
105
- });
106
- });
107
- };
108
- /**
109
- * determine the sentiment of the provided text in English language
110
- * @param text input text to categorize
111
- * @param method method to use to compute the sentiment. possible values are "vocabulary" (vocabulary based sentiment analysis) and "rnn" (neural network based sentiment classification)
112
- */
113
- Analytics.prototype.sentiment = function (text, method, sentences, returnSentences) {
114
- if (method === void 0) { method = "vocabulary"; }
115
- if (sentences === void 0) { sentences = 10; }
116
- if (returnSentences === void 0) { returnSentences = true; }
117
- return __awaiter(this, void 0, void 0, function () {
118
- var params, _a, _b;
119
- return __generator(this, function (_c) {
120
- switch (_c.label) {
121
- case 0:
122
- if (!_.includes(["vocabulary", "rnn"], method)) {
123
- throw new Error("method: Please pass in either 'vocabulary' or 'rnn'");
124
- }
125
- params = {
126
- text: text,
127
- method: method,
128
- sentences: sentences,
129
- returnSentences: returnSentences,
130
- };
131
- _b = (_a = _).get;
132
- return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/sentiment", params)];
133
- case 1: return [2 /*return*/, _b.apply(_a, [_c.sent(), "data"])];
134
- }
135
- });
136
- });
137
- };
138
- Analytics.prototype.semanticSimilarity = function (text1, text2, distanceMeasure) {
139
- if (distanceMeasure === void 0) { distanceMeasure = "cosine"; }
140
- return __awaiter(this, void 0, void 0, function () {
141
- var _a, _b;
142
- return __generator(this, function (_c) {
143
- switch (_c.label) {
144
- case 0:
145
- _b = (_a = _).get;
146
- return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/semanticSimilarity", { text1: text1, text2: text2, distanceMeasure: distanceMeasure })];
147
- case 1: return [2 /*return*/, _b.apply(_a, [_c.sent(), "data"])];
148
- }
149
- });
150
- });
151
- };
152
- /**
153
- * Determine the language of the given text
154
- * @param text input text to analyse
155
- */
156
- Analytics.prototype.detectLanguage = function (text) {
157
- return __awaiter(this, void 0, void 0, function () {
158
- var _a, _b;
159
- return __generator(this, function (_c) {
160
- switch (_c.label) {
161
- case 0:
162
- _b = (_a = _).get;
163
- return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/detectLanguage", { text: text })];
164
- case 1: return [2 /*return*/, _b.apply(_a, [_c.sent(), "data"])];
165
- }
166
- });
167
- });
168
- };
169
- /**
170
- * Extract all available information about an article available at url `url`.
171
- * Returned information will include article title, body, authors, links in the articles,...
172
- * @param url article url that'll be used for extraction
173
- * @param proxyUrl proxy that should be used for downloading article information. format: {schema}://{username}:{pass}@{proxy url/ip}
174
- */
175
- Analytics.prototype.extractArticleInfo = function (url, proxyUrl, headers, cookies) {
176
- return __awaiter(this, void 0, void 0, function () {
177
- var params, _a, _b;
178
- return __generator(this, function (_c) {
179
- switch (_c.label) {
180
- case 0:
181
- params = { url: url };
182
- if (!!proxyUrl) {
183
- _.set(params, "proxyUrl", proxyUrl);
184
- }
185
- _b = (_a = _).get;
186
- return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/extractArticleInfo", params, headers, cookies)];
187
- case 1: return [2 /*return*/, _b.apply(_a, [_c.sent(), "data"])];
188
- }
189
- });
190
- });
191
- };
192
- /**
193
- * Extract named entities from the provided text. Supported languages are English, German, Spanish and Chinese.
194
- * @param text: text on which to extract named entities
195
- */
196
- Analytics.prototype.ner = function (text) {
197
- return __awaiter(this, void 0, void 0, function () {
198
- var _a, _b;
199
- return __generator(this, function (_c) {
200
- switch (_c.label) {
201
- case 0:
202
- _b = (_a = _).get;
203
- return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/ner", { text: text })];
204
- case 1: return [2 /*return*/, _b.apply(_a, [_c.sent(), "data"])];
205
- }
206
- });
207
- });
208
- };
209
- /**
210
- * Create a new topic and train it using the tweets that match the twitterQuery
211
- * @param twitterQuery string containing the content to search for. It can be a Twitter user account (using "@" prefix or user's Twitter url),a hash tag (using "#" prefix) or a regular keyword.
212
- * @param args Object which contains a host of optional parameters
213
- */
214
- Analytics.prototype.trainTopicOnTweets = function (twitterQuery, args) {
215
- if (args === void 0) { args = {}; }
216
- return __awaiter(this, void 0, void 0, function () {
217
- var _a, useTweetText, _b, useIdfNormalization, _c, normalization, _d, maxTweets, _e, maxUsedLinks, _f, ignoreConceptTypes, _g, maxConcepts, _h, maxCategories, _j, notifyEmailAddress, params, _k, _l;
218
- return __generator(this, function (_m) {
219
- switch (_m.label) {
220
- case 0:
221
- _a = args.useTweetText, useTweetText = _a === void 0 ? true : _a, _b = args.useIdfNormalization, useIdfNormalization = _b === void 0 ? true : _b, _c = args.normalization, normalization = _c === void 0 ? "linear" : _c, _d = args.maxTweets, maxTweets = _d === void 0 ? 2000 : _d, _e = args.maxUsedLinks, maxUsedLinks = _e === void 0 ? 500 : _e, _f = args.ignoreConceptTypes, ignoreConceptTypes = _f === void 0 ? [] : _f, _g = args.maxConcepts, maxConcepts = _g === void 0 ? 20 : _g, _h = args.maxCategories, maxCategories = _h === void 0 ? 10 : _h, _j = args.notifyEmailAddress, notifyEmailAddress = _j === void 0 ? undefined : _j;
222
- if (maxTweets > 5000) {
223
- throw new Error("We can analyze at most 5000 tweets");
224
- }
225
- params = {
226
- twitterQuery: twitterQuery,
227
- useTweetText: useTweetText,
228
- useIdfNormalization: useIdfNormalization,
229
- normalization: normalization,
230
- maxTweets: maxTweets,
231
- maxUsedLinks: maxUsedLinks,
232
- maxConcepts: maxConcepts,
233
- maxCategories: maxCategories,
234
- };
235
- if (notifyEmailAddress) {
236
- _.set(params, "notifyEmailAddress", notifyEmailAddress);
237
- }
238
- if (!_.isEmpty(ignoreConceptTypes)) {
239
- _.set(params, "ignoreConceptTypes", ignoreConceptTypes);
240
- }
241
- _l = (_k = _).get;
242
- return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/trainTopicOnTwitter", params)];
243
- case 1: return [2 /*return*/, _l.apply(_k, [_m.sent(), "data"])];
244
- }
245
- });
246
- });
247
- };
248
- /**
249
- * Create a new topic to train. The user should remember the "uri" parameter returned in the result.
250
- * @param name name of the topic we want to create
251
- * @returns object containing the "uri" property that should be used in the follow-up call to trainTopic* methods
252
- */
253
- Analytics.prototype.trainTopicCreateTopic = function (name) {
254
- return __awaiter(this, void 0, void 0, function () {
255
- var _a, _b;
256
- return __generator(this, function (_c) {
257
- switch (_c.label) {
258
- case 0:
259
- _b = (_a = _).get;
260
- return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/trainTopic", { action: "createTopic", name: name })];
261
- case 1: return [2 /*return*/, _b.apply(_a, [_c.sent(), "data"])];
262
- }
263
- });
264
- });
265
- };
266
- /**
267
- * If the topic is already existing, clear the definition of the topic. Use this if you want to retrain an existing topic
268
- * @param uri uri of the topic (obtained by calling trainTopicCreateTopic method) to clear
269
- */
270
- Analytics.prototype.trainTopicClearTopic = function (uri) {
271
- return __awaiter(this, void 0, void 0, function () {
272
- var _a, _b;
273
- return __generator(this, function (_c) {
274
- switch (_c.label) {
275
- case 0:
276
- _b = (_a = _).get;
277
- return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/trainTopic", { action: "clearTopic", uri: uri })];
278
- case 1: return [2 /*return*/, _b.apply(_a, [_c.sent(), "data"])];
279
- }
280
- });
281
- });
282
- };
283
- /**
284
- * Add the information extracted from the provided "text" to the topic with uri "uri".
285
- * @param uri uri of the topic (obtained by calling trainTopicCreateTopic method)
286
- * @param text text to analyze and extract information from
287
- */
288
- Analytics.prototype.trainTopicAddDocument = function (uri, text) {
289
- return __awaiter(this, void 0, void 0, function () {
290
- var _a, _b;
291
- return __generator(this, function (_c) {
292
- switch (_c.label) {
293
- case 0:
294
- _b = (_a = _).get;
295
- return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/trainTopic", { action: "addDocument", uri: uri, text: text })];
296
- case 1: return [2 /*return*/, _b.apply(_a, [_c.sent(), "data"])];
297
- }
298
- });
299
- });
300
- };
301
- /**
302
- * Retrieve topic for the topic for which you have already finished training
303
- * @param uri uri of the topic (obtained by calling trainTopicCreateTopic method)
304
- * @returns returns the trained topic: { concepts: [], categories: [] }
305
- */
306
- Analytics.prototype.trainTopicGetTrainedTopic = function (uri, args) {
307
- if (args === void 0) { args = {}; }
308
- return __awaiter(this, void 0, void 0, function () {
309
- var _a, maxConcepts, _b, maxCategories, _c, idfNormalization, params, _d, _e;
310
- return __generator(this, function (_f) {
311
- switch (_f.label) {
312
- case 0:
313
- _a = args.maxConcepts, maxConcepts = _a === void 0 ? 20 : _a, _b = args.maxCategories, maxCategories = _b === void 0 ? 10 : _b, _c = args.idfNormalization, idfNormalization = _c === void 0 ? true : _c;
314
- params = {
315
- action: "getTrainedTopic",
316
- uri: uri,
317
- maxConcepts: maxConcepts,
318
- maxCategories: maxCategories,
319
- idfNormalization: idfNormalization,
320
- };
321
- _e = (_d = _).get;
322
- return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/trainTopic", params)];
323
- case 1: return [2 /*return*/, _e.apply(_d, [_f.sent(), "data"])];
324
- }
325
- });
326
- });
327
- };
328
- return Analytics;
329
- }());
330
- exports.Analytics = Analytics;
1
+ "use strict";
2
+ var __assign = (this && this.__assign) || function () {
3
+ __assign = Object.assign || function(t) {
4
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
5
+ s = arguments[i];
6
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
7
+ t[p] = s[p];
8
+ }
9
+ return t;
10
+ };
11
+ return __assign.apply(this, arguments);
12
+ };
13
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
14
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
15
+ return new (P || (P = Promise))(function (resolve, reject) {
16
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
17
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
18
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
19
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
20
+ });
21
+ };
22
+ var __generator = (this && this.__generator) || function (thisArg, body) {
23
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
24
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
25
+ function verb(n) { return function (v) { return step([n, v]); }; }
26
+ function step(op) {
27
+ if (f) throw new TypeError("Generator is already executing.");
28
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
29
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
30
+ if (y = 0, t) op = [op[0] & 2, t.value];
31
+ switch (op[0]) {
32
+ case 0: case 1: t = op; break;
33
+ case 4: _.label++; return { value: op[1], done: false };
34
+ case 5: _.label++; y = op[1]; op = [0]; continue;
35
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
36
+ default:
37
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
38
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
39
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
40
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
41
+ if (t[2]) _.ops.pop();
42
+ _.trys.pop(); continue;
43
+ }
44
+ op = body.call(thisArg, _);
45
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
46
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
47
+ }
48
+ };
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.Analytics = void 0;
51
+ // The Analytics class can be used for access the text analytics services provided by the Event Registry.
52
+ // These include:
53
+ // - text annotation: identifying the list of entities and non-entities mentioned in the provided text
54
+ // - text categorization: identification of up to 5 categories that describe the topic of the given text.
55
+ // The list of available categories come from DMOZ open directory. Currently, only English text can be categorized!
56
+ // - sentiment detection: what is the sentiment expressed in the given text
57
+ // - language detection: detect in which language is the given text written
58
+ // NOTE: the functionality is currently in BETA. The API calls or the provided outputs may change in the future.
59
+ var Analytics = /** @class */ (function () {
60
+ /**
61
+ * @param eventRegistry: instance of EventRegistry class
62
+ */
63
+ function Analytics(er) {
64
+ this.er = er;
65
+ }
66
+ /**
67
+ * Identify the list of entities and nonentities mentioned in the text
68
+ * @param text input text to annotate
69
+ * @param lang language of the provided document (can be an ISO2 or ISO3 code). If None is provided, the language will be automatically detected
70
+ */
71
+ Analytics.prototype.annotate = function (text, lang, customParams) {
72
+ return __awaiter(this, void 0, void 0, function () {
73
+ var params, response;
74
+ return __generator(this, function (_a) {
75
+ switch (_a.label) {
76
+ case 0:
77
+ params = { lang: lang, text: text };
78
+ if (!!customParams) {
79
+ params = __assign(__assign({}, params), customParams);
80
+ }
81
+ return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/annotate", params)];
82
+ case 1:
83
+ response = _a.sent();
84
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
85
+ }
86
+ });
87
+ });
88
+ };
89
+ /**
90
+ * Determine the set of up to 5 categories the text is about. Currently, only English text can be categorized!
91
+ * @param text input text to categorize
92
+ * @param taxonomy: which taxonomy use for categorization. Options:
93
+ * - "dmoz" (over 5000 categories in 3 levels, English language only)
94
+ * - "news" (general news categorization, 9 categories, any langauge)
95
+ */
96
+ Analytics.prototype.categorize = function (text_1) {
97
+ return __awaiter(this, arguments, void 0, function (text, taxonomy) {
98
+ var response;
99
+ if (taxonomy === void 0) { taxonomy = "dmoz"; }
100
+ return __generator(this, function (_a) {
101
+ switch (_a.label) {
102
+ case 0: return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/categorize", { text: text, taxonomy: taxonomy })];
103
+ case 1:
104
+ response = _a.sent();
105
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
106
+ }
107
+ });
108
+ });
109
+ };
110
+ /**
111
+ * determine the sentiment of the provided text in English language
112
+ * @param text input text to categorize
113
+ * @param method method to use to compute the sentiment. possible values are "vocabulary" (vocabulary based sentiment analysis) and "rnn" (neural network based sentiment classification)
114
+ */
115
+ Analytics.prototype.sentiment = function (text_1) {
116
+ return __awaiter(this, arguments, void 0, function (text, method, sentences, returnSentences) {
117
+ var params, response;
118
+ if (method === void 0) { method = "vocabulary"; }
119
+ if (sentences === void 0) { sentences = 10; }
120
+ if (returnSentences === void 0) { returnSentences = true; }
121
+ return __generator(this, function (_a) {
122
+ switch (_a.label) {
123
+ case 0:
124
+ if (!["vocabulary", "rnn"].includes(method)) {
125
+ throw new Error("method: Please pass in either 'vocabulary' or 'rnn'");
126
+ }
127
+ params = {
128
+ text: text,
129
+ method: method,
130
+ sentences: sentences,
131
+ returnSentences: returnSentences,
132
+ };
133
+ return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/sentiment", params)];
134
+ case 1:
135
+ response = _a.sent();
136
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
137
+ }
138
+ });
139
+ });
140
+ };
141
+ Analytics.prototype.semanticSimilarity = function (text1_1, text2_1) {
142
+ return __awaiter(this, arguments, void 0, function (text1, text2, distanceMeasure) {
143
+ var response;
144
+ if (distanceMeasure === void 0) { distanceMeasure = "cosine"; }
145
+ return __generator(this, function (_a) {
146
+ switch (_a.label) {
147
+ case 0: return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/semanticSimilarity", { text1: text1, text2: text2, distanceMeasure: distanceMeasure })];
148
+ case 1:
149
+ response = _a.sent();
150
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
151
+ }
152
+ });
153
+ });
154
+ };
155
+ /**
156
+ * Determine the language of the given text
157
+ * @param text input text to analyse
158
+ */
159
+ Analytics.prototype.detectLanguage = function (text) {
160
+ return __awaiter(this, void 0, void 0, function () {
161
+ var response;
162
+ return __generator(this, function (_a) {
163
+ switch (_a.label) {
164
+ case 0: return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/detectLanguage", { text: text })];
165
+ case 1:
166
+ response = _a.sent();
167
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
168
+ }
169
+ });
170
+ });
171
+ };
172
+ /**
173
+ * Extract all available information about an article available at url `url`.
174
+ * Returned information will include article title, body, authors, links in the articles,...
175
+ * @param url article url that'll be used for extraction
176
+ * @param proxyUrl proxy that should be used for downloading article information. format: {schema}://{username}:{pass}@{proxy url/ip}
177
+ */
178
+ Analytics.prototype.extractArticleInfo = function (url, proxyUrl, headers, cookies) {
179
+ return __awaiter(this, void 0, void 0, function () {
180
+ var params, response;
181
+ return __generator(this, function (_a) {
182
+ switch (_a.label) {
183
+ case 0:
184
+ params = { url: url };
185
+ if (!!proxyUrl) {
186
+ params.proxyUrl = proxyUrl;
187
+ }
188
+ return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/extractArticleInfo", params, headers, cookies)];
189
+ case 1:
190
+ response = _a.sent();
191
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
192
+ }
193
+ });
194
+ });
195
+ };
196
+ /**
197
+ * Extract named entities from the provided text. Supported languages are English, German, Spanish and Chinese.
198
+ * @param text: text on which to extract named entities
199
+ */
200
+ Analytics.prototype.ner = function (text) {
201
+ return __awaiter(this, void 0, void 0, function () {
202
+ var response;
203
+ return __generator(this, function (_a) {
204
+ switch (_a.label) {
205
+ case 0: return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/ner", { text: text })];
206
+ case 1:
207
+ response = _a.sent();
208
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
209
+ }
210
+ });
211
+ });
212
+ };
213
+ /**
214
+ * Create a new topic and train it using the tweets that match the twitterQuery
215
+ * @param twitterQuery string containing the content to search for. It can be a Twitter user account (using "@" prefix or user's Twitter url),a hash tag (using "#" prefix) or a regular keyword.
216
+ * @param args Object which contains a host of optional parameters
217
+ */
218
+ Analytics.prototype.trainTopicOnTweets = function (twitterQuery_1) {
219
+ return __awaiter(this, arguments, void 0, function (twitterQuery, args) {
220
+ var _a, useTweetText, _b, useIdfNormalization, _c, normalization, _d, maxTweets, _e, maxUsedLinks, _f, ignoreConceptTypes, _g, maxConcepts, _h, maxCategories, _j, notifyEmailAddress, params, response;
221
+ if (args === void 0) { args = {}; }
222
+ return __generator(this, function (_k) {
223
+ switch (_k.label) {
224
+ case 0:
225
+ _a = args.useTweetText, useTweetText = _a === void 0 ? true : _a, _b = args.useIdfNormalization, useIdfNormalization = _b === void 0 ? true : _b, _c = args.normalization, normalization = _c === void 0 ? "linear" : _c, _d = args.maxTweets, maxTweets = _d === void 0 ? 2000 : _d, _e = args.maxUsedLinks, maxUsedLinks = _e === void 0 ? 500 : _e, _f = args.ignoreConceptTypes, ignoreConceptTypes = _f === void 0 ? [] : _f, _g = args.maxConcepts, maxConcepts = _g === void 0 ? 20 : _g, _h = args.maxCategories, maxCategories = _h === void 0 ? 10 : _h, _j = args.notifyEmailAddress, notifyEmailAddress = _j === void 0 ? undefined : _j;
226
+ if (maxTweets > 5000) {
227
+ throw new Error("We can analyze at most 5000 tweets");
228
+ }
229
+ params = {
230
+ twitterQuery: twitterQuery,
231
+ useTweetText: useTweetText,
232
+ useIdfNormalization: useIdfNormalization,
233
+ normalization: normalization,
234
+ maxTweets: maxTweets,
235
+ maxUsedLinks: maxUsedLinks,
236
+ maxConcepts: maxConcepts,
237
+ maxCategories: maxCategories,
238
+ };
239
+ if (notifyEmailAddress) {
240
+ params.notifyEmailAddress = notifyEmailAddress;
241
+ }
242
+ if (ignoreConceptTypes && Object.keys(ignoreConceptTypes).length > 0) {
243
+ params.ignoreConceptTypes = ignoreConceptTypes;
244
+ }
245
+ return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/trainTopicOnTwitter", params)];
246
+ case 1:
247
+ response = _k.sent();
248
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
249
+ }
250
+ });
251
+ });
252
+ };
253
+ /**
254
+ * Create a new topic to train. The user should remember the "uri" parameter returned in the result.
255
+ * @param name name of the topic we want to create
256
+ * @returns object containing the "uri" property that should be used in the follow-up call to trainTopic* methods
257
+ */
258
+ Analytics.prototype.trainTopicCreateTopic = function (name) {
259
+ return __awaiter(this, void 0, void 0, function () {
260
+ var response;
261
+ return __generator(this, function (_a) {
262
+ switch (_a.label) {
263
+ case 0: return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/trainTopic", { action: "createTopic", name: name })];
264
+ case 1:
265
+ response = _a.sent();
266
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
267
+ }
268
+ });
269
+ });
270
+ };
271
+ /**
272
+ * If the topic is already existing, clear the definition of the topic. Use this if you want to retrain an existing topic
273
+ * @param uri uri of the topic (obtained by calling trainTopicCreateTopic method) to clear
274
+ */
275
+ Analytics.prototype.trainTopicClearTopic = function (uri) {
276
+ return __awaiter(this, void 0, void 0, function () {
277
+ var response;
278
+ return __generator(this, function (_a) {
279
+ switch (_a.label) {
280
+ case 0: return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/trainTopic", { action: "clearTopic", uri: uri })];
281
+ case 1:
282
+ response = _a.sent();
283
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
284
+ }
285
+ });
286
+ });
287
+ };
288
+ /**
289
+ * Add the information extracted from the provided "text" to the topic with uri "uri".
290
+ * @param uri uri of the topic (obtained by calling trainTopicCreateTopic method)
291
+ * @param text text to analyze and extract information from
292
+ */
293
+ Analytics.prototype.trainTopicAddDocument = function (uri, text) {
294
+ return __awaiter(this, void 0, void 0, function () {
295
+ var response;
296
+ return __generator(this, function (_a) {
297
+ switch (_a.label) {
298
+ case 0: return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/trainTopic", { action: "addDocument", uri: uri, text: text })];
299
+ case 1:
300
+ response = _a.sent();
301
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
302
+ }
303
+ });
304
+ });
305
+ };
306
+ /**
307
+ * Retrieve topic for the topic for which you have already finished training
308
+ * @param uri uri of the topic (obtained by calling trainTopicCreateTopic method)
309
+ * @returns returns the trained topic: { concepts: [], categories: [] }
310
+ */
311
+ Analytics.prototype.trainTopicGetTrainedTopic = function (uri_1) {
312
+ return __awaiter(this, arguments, void 0, function (uri, args) {
313
+ var _a, maxConcepts, _b, maxCategories, _c, idfNormalization, params, response;
314
+ if (args === void 0) { args = {}; }
315
+ return __generator(this, function (_d) {
316
+ switch (_d.label) {
317
+ case 0:
318
+ _a = args.maxConcepts, maxConcepts = _a === void 0 ? 20 : _a, _b = args.maxCategories, maxCategories = _b === void 0 ? 10 : _b, _c = args.idfNormalization, idfNormalization = _c === void 0 ? true : _c;
319
+ params = {
320
+ action: "getTrainedTopic",
321
+ uri: uri,
322
+ maxConcepts: maxConcepts,
323
+ maxCategories: maxCategories,
324
+ idfNormalization: idfNormalization,
325
+ };
326
+ return [4 /*yield*/, this.er.jsonRequestAnalytics("/api/v1/trainTopic", params)];
327
+ case 1:
328
+ response = _d.sent();
329
+ return [2 /*return*/, response === null || response === void 0 ? void 0 : response.data];
330
+ }
331
+ });
332
+ });
333
+ };
334
+ return Analytics;
335
+ }());
336
+ exports.Analytics = Analytics;
331
337
  //# sourceMappingURL=analytics.js.map