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
package/src/base.ts
DELETED
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
|
-
import * as moment from "moment";
|
|
3
|
-
import { ReturnInfo } from "./returnInfo";
|
|
4
|
-
|
|
5
|
-
export const mainLangs = ["eng", "deu", "zho", "slv", "spa"];
|
|
6
|
-
export const allLangs = [ "eng", "deu", "spa", "cat", "por", "ita", "fra", "rus", "ara", "tur", "zho", "slv", "hrv", "srp" ];
|
|
7
|
-
// Utility classes for Event Registry
|
|
8
|
-
|
|
9
|
-
export class QueryItems {
|
|
10
|
-
public static AND = (items) => new QueryItems("$and", items);
|
|
11
|
-
public static OR = (items) => new QueryItems("$or", items);
|
|
12
|
-
|
|
13
|
-
private oper;
|
|
14
|
-
private items;
|
|
15
|
-
|
|
16
|
-
constructor(oper, items) {
|
|
17
|
-
this.oper = oper;
|
|
18
|
-
this.items = items;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public getOper() {
|
|
22
|
-
return this.oper;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
public getItems() {
|
|
26
|
-
return this.items;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* @class QueryParamsBase
|
|
32
|
-
* Base class for Query and AdminQuery
|
|
33
|
-
* used for storing parameters for a query. Parameter values can either be
|
|
34
|
-
* simple values (set by setVal()) or an array of values (set by multiple
|
|
35
|
-
* calls to addArrayVal() method)
|
|
36
|
-
*/
|
|
37
|
-
export class QueryParamsBase {
|
|
38
|
-
protected params = {};
|
|
39
|
-
|
|
40
|
-
/**
|
|
41
|
-
* Encode datetime into UTC ISO format which can be sent to ER.
|
|
42
|
-
*/
|
|
43
|
-
public static encodeDateTime(val: string | Date, format?: string): string {
|
|
44
|
-
const datetime = moment.utc(val);
|
|
45
|
-
if (!datetime.isValid()) {
|
|
46
|
-
throw new Error("Datetime was not recognizable. Use `new Date()` or string in ISO format");
|
|
47
|
-
}
|
|
48
|
-
return _.isNil(format) ? datetime.toISOString() : datetime.format(format);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* Return the parameters.
|
|
53
|
-
*/
|
|
54
|
-
public getQueryParams() {
|
|
55
|
-
return this.params;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* Set a value of a property in the query.
|
|
60
|
-
*/
|
|
61
|
-
public setVal(key: string, value: unknown) {
|
|
62
|
-
_.set(this.params, key, value);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* Do we have in the query property named 'key'?
|
|
67
|
-
*/
|
|
68
|
-
public hasVal(key: string): boolean {
|
|
69
|
-
return _.has(this.params, key);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
/**
|
|
73
|
-
* Remove the value of a property key (if existing).
|
|
74
|
-
*/
|
|
75
|
-
public clearVal(key: string) {
|
|
76
|
-
_.unset(this.params, key);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Add a value to an array of values for a property.
|
|
81
|
-
*/
|
|
82
|
-
public addArrayVal(key: string, val: unknown) {
|
|
83
|
-
_.update(this.params, key, (value) => [...(value || []), val]);
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
/**
|
|
87
|
-
* Set value in query params if the 'val' is different from 'defVal'.
|
|
88
|
-
*/
|
|
89
|
-
public setValIfNotDefault(propName: string, val: unknown, defVal: unknown) {
|
|
90
|
-
if (val !== defVal) {
|
|
91
|
-
this.setVal(propName, val);
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Set a property value that represents date.
|
|
97
|
-
* Value can be string in YYYY-MM-DD format or a Date object.
|
|
98
|
-
*/
|
|
99
|
-
public setDateVal(propName: string, val: string | Date) {
|
|
100
|
-
this.setVal(propName, QueryParamsBase.encodeDateTime(val, "YYYY-MM-DD"));
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Parse the value "value" and use it to set the property propName and the operator with name propOperName
|
|
105
|
-
* @param value String, QueryItems or an array.
|
|
106
|
-
* @param propName Values to be set using property name propName.
|
|
107
|
-
* @param propOperName Property to set containing the "and" or "or". Relevant only if multiple items are provided in "value". Can be None if only one value is possible.
|
|
108
|
-
* @param defaultOperName Which operator should be used in case "value" is an array. If an array, we will print also a warning to suggest use of QueryItems.
|
|
109
|
-
*/
|
|
110
|
-
public setQueryArrVal(value: string | QueryItems | any[], propName: string, propOperName: string | undefined, defaultOperName) {
|
|
111
|
-
if (!value) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (value instanceof QueryItems) {
|
|
116
|
-
this.params[propName] = value.getItems();
|
|
117
|
-
const formattedOperator = _.replace(value.getOper(), "$", "");
|
|
118
|
-
if (propOperName) {
|
|
119
|
-
this.params[propOperName] = formattedOperator;
|
|
120
|
-
}
|
|
121
|
-
if (_.isUndefined(propOperName) && formattedOperator !== defaultOperName) {
|
|
122
|
-
throw new Error(`An invalid operator type '${formattedOperator}' was used for property '${propName}'`);
|
|
123
|
-
}
|
|
124
|
-
} else if (_.isString(value)) {
|
|
125
|
-
this.params[propName] = value;
|
|
126
|
-
} else if (_.isArray(value)) {
|
|
127
|
-
this.params[propName] = value;
|
|
128
|
-
if (!_.isUndefined(propOperName)) {
|
|
129
|
-
this.params[propOperName] = defaultOperName;
|
|
130
|
-
if (_.size(value) > 1) {
|
|
131
|
-
console.warn(`
|
|
132
|
-
Warning: The value of parameter '${propName}' was provided as a list and '${defaultOperName}' operator was used implicitly between the items.
|
|
133
|
-
We suggest specifying the list using the QueryItems.AND() or QueryItems.OR() to ensure the appropriate operator is used.
|
|
134
|
-
`);
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
} else {
|
|
138
|
-
throw new Error(`Parameter '${propName}' was of unsupported type. It should either be None, a string or an instance of QueryItems`);
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
export abstract class Query<T> extends QueryParamsBase {
|
|
144
|
-
public resultTypeList: T[];
|
|
145
|
-
/**
|
|
146
|
-
* Set it to a default path.
|
|
147
|
-
*/
|
|
148
|
-
protected internalPath: string;
|
|
149
|
-
protected params = {};
|
|
150
|
-
|
|
151
|
-
public get path() {
|
|
152
|
-
return this.internalPath;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
public set path(path) {
|
|
156
|
-
this.internalPath = path;
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
/**
|
|
160
|
-
* Prepare the request parameters
|
|
161
|
-
*/
|
|
162
|
-
public getQueryParams() {
|
|
163
|
-
if (_.isEmpty(this.resultTypeList)) {
|
|
164
|
-
throw new Error("The query does not have any result type specified. No sense in performing such a query");
|
|
165
|
-
}
|
|
166
|
-
const allParams = this.params;
|
|
167
|
-
_.each(this.resultTypeList, (resultType) => {
|
|
168
|
-
_.extend(allParams, _.get(resultType, "params"));
|
|
169
|
-
});
|
|
170
|
-
const formattedResultTypeList = this.getFormattedResultTypeList();
|
|
171
|
-
if (!_.isEmpty(formattedResultTypeList)) {
|
|
172
|
-
_.set(allParams, "resultType", formattedResultTypeList);
|
|
173
|
-
}
|
|
174
|
-
return _.cloneDeep(allParams);
|
|
175
|
-
}
|
|
176
|
-
|
|
177
|
-
public getFormattedResultTypeList() {
|
|
178
|
-
if (!_.every(this.resultTypeList, (result) => _.has(result, "resultType"))) {
|
|
179
|
-
return [];
|
|
180
|
-
}
|
|
181
|
-
if (_.size(this.resultTypeList) === 1) {
|
|
182
|
-
return _.get(_.first(this.resultTypeList), "resultType");
|
|
183
|
-
} else {
|
|
184
|
-
return _.map(this.resultTypeList, "resultType");
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
public abstract setRequestedResult(args);
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Utility function used in conjunction with a async/await and/or Promise
|
|
193
|
-
*/
|
|
194
|
-
export function sleep(ms) {
|
|
195
|
-
return new Promise((resolve) => {
|
|
196
|
-
setTimeout(resolve, ms);
|
|
197
|
-
});
|
|
198
|
-
}
|
package/src/counts.ts
DELETED
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
|
-
import { QueryParamsBase } from "./base";
|
|
3
|
-
import { ReturnInfo } from "./returnInfo";
|
|
4
|
-
import { EventRegistryStatic } from "./types";
|
|
5
|
-
|
|
6
|
-
// provides classes for obtaining information about how frequently individual concepts or categories
|
|
7
|
-
// have been mentioned in news articles (if source == "news") of in social media (if source == "social")
|
|
8
|
-
|
|
9
|
-
export abstract class CountsBase extends QueryParamsBase {
|
|
10
|
-
public get path() {
|
|
11
|
-
return "/api/v1/counters";
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* @class GetCounts
|
|
17
|
-
* Obtain information about how frequently a concept or category is mentioned in the articles on particular dates
|
|
18
|
-
* by specifying source="custom" one can obtain counts for custom concepts, such as stocks, macroeconomic indicators, etc. The uri
|
|
19
|
-
* for these can be found using EventRegistry.getCustomConceptUri() method.
|
|
20
|
-
* Usage example:
|
|
21
|
-
*
|
|
22
|
-
* q = GetCounts([er.getConceptUri("Obama"), er.getConceptUri("ebola")])
|
|
23
|
-
* ret = er.execQuery(q)
|
|
24
|
-
*
|
|
25
|
-
* Return object:
|
|
26
|
-
*
|
|
27
|
-
* {
|
|
28
|
-
* "http://en.wikipedia.org/wiki/Barack_Obama": [
|
|
29
|
-
* {
|
|
30
|
-
* "count": 1,
|
|
31
|
-
* "date": "2015-05-07"
|
|
32
|
-
* },
|
|
33
|
-
* {
|
|
34
|
-
* "count": 4,
|
|
35
|
-
* "date": "2015-05-08"
|
|
36
|
-
* },
|
|
37
|
-
* ...
|
|
38
|
-
* ],
|
|
39
|
-
* "http://en.wikipedia.org/wiki/Ebola_virus_disease": [
|
|
40
|
-
* {
|
|
41
|
-
* "count": 0,
|
|
42
|
-
* "date": "2015-05-07"
|
|
43
|
-
* },
|
|
44
|
-
* ...
|
|
45
|
-
* ]
|
|
46
|
-
* }
|
|
47
|
-
*
|
|
48
|
-
* @param uriOrUriList: concept/category uri or a list of uris
|
|
49
|
-
* @param args Object which contains a host of optional parameters
|
|
50
|
-
*/
|
|
51
|
-
export class GetCounts extends CountsBase {
|
|
52
|
-
constructor(uriOrUriList: string | string[], args: EventRegistryStatic.Counts.Arguments = {}) {
|
|
53
|
-
super();
|
|
54
|
-
const {source = "news", type = "concept", dateStart = undefined, dateEnd = undefined, returnInfo = new ReturnInfo()} = args;
|
|
55
|
-
this.setVal("action", "getCounts");
|
|
56
|
-
this.setVal("source", source);
|
|
57
|
-
this.setVal("type", type);
|
|
58
|
-
this.setVal("uri", uriOrUriList);
|
|
59
|
-
if (!_.isUndefined(dateStart)) {
|
|
60
|
-
this.setDateVal("dateStart", dateStart);
|
|
61
|
-
}
|
|
62
|
-
if (!_.isUndefined(dateEnd)) {
|
|
63
|
-
this.setDateVal("dateEnd", dateEnd);
|
|
64
|
-
}
|
|
65
|
-
this.params = _.extend({}, this.params, returnInfo.getParams());
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* @class GetCountsEx
|
|
71
|
-
* Obtain information about how frequently a concept or category is mentioned in the articles on particular dates
|
|
72
|
-
* Similar to GetCounts, but the output is more friendly for a larger set of provided uris/ids at once
|
|
73
|
-
* Usage example:
|
|
74
|
-
* q = GetCountsEx(type = "category")
|
|
75
|
-
* q.queryById(range(10)) # return trends of first 10 categories
|
|
76
|
-
* ret = er.execQuery(q)
|
|
77
|
-
* Return object:
|
|
78
|
-
* {
|
|
79
|
-
* "categoryInfo": [
|
|
80
|
-
* {
|
|
81
|
-
* "id": 0,
|
|
82
|
-
* "label": "Root",
|
|
83
|
-
* "uri": "http://www.dmoz.org"
|
|
84
|
-
* },
|
|
85
|
-
* {
|
|
86
|
-
* "id": 1,
|
|
87
|
-
* "label": "Recreation",
|
|
88
|
-
* "uri": "http://www.dmoz.org/Recreation"
|
|
89
|
-
* },
|
|
90
|
-
* ...
|
|
91
|
-
* ],
|
|
92
|
-
* "counts": [
|
|
93
|
-
* {
|
|
94
|
-
* "0": 23, "1": 42, "2": 52, "3": 32, "4": 21, "5": 65, "6": 32, "7": 654, "8": 1, "9": 34,
|
|
95
|
-
* "date": "2015-05-07"
|
|
96
|
-
* },
|
|
97
|
-
* ...
|
|
98
|
-
* ]
|
|
99
|
-
* }
|
|
100
|
-
* @param uriOrUriList: concept/category uri or a list of uris
|
|
101
|
-
* @param args Object which contains a host of optional parameters
|
|
102
|
-
*/
|
|
103
|
-
export class GetCountsEx extends CountsBase {
|
|
104
|
-
constructor(uriOrUriList: string | string[], args: EventRegistryStatic.Counts.Arguments = {}) {
|
|
105
|
-
super();
|
|
106
|
-
const {source = "news", type = "concept", dateStart = undefined, dateEnd = undefined, returnInfo = new ReturnInfo()} = args;
|
|
107
|
-
this.setVal("action", "GetCountsEx");
|
|
108
|
-
this.setVal("source", source);
|
|
109
|
-
this.setVal("type", type);
|
|
110
|
-
this.setVal("uri", uriOrUriList);
|
|
111
|
-
if (!_.isUndefined(dateStart)) {
|
|
112
|
-
this.setDateVal("dateStart", dateStart);
|
|
113
|
-
}
|
|
114
|
-
if (!_.isUndefined(dateEnd)) {
|
|
115
|
-
this.setDateVal("dateEnd", dateEnd);
|
|
116
|
-
}
|
|
117
|
-
this.params = _.extend({}, this.params, returnInfo.getParams());
|
|
118
|
-
}
|
|
119
|
-
}
|
package/src/dailyShares.ts
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
|
-
import * as moment from "moment";
|
|
3
|
-
import { QueryParamsBase } from "./base";
|
|
4
|
-
import { ReturnInfo } from "./returnInfo";
|
|
5
|
-
import { EventRegistryStatic } from "./types";
|
|
6
|
-
|
|
7
|
-
// Using the bottom classes you can obtain information about articles and events that
|
|
8
|
-
// were shared the most on social media (Twitter and Facebook) on a particular day.
|
|
9
|
-
// Given a date, articles published on that date are checked and top shared ones are returned.
|
|
10
|
-
// For an event, events on that day are checked and top shared ones are returned.
|
|
11
|
-
// Social score for an article is computed as the sum of shares on facebook and twitter.
|
|
12
|
-
// Social score for an event is computed by checking 30 top shared articles in the event and averaging their social scores.
|
|
13
|
-
|
|
14
|
-
export class GetTopSharedArticles extends QueryParamsBase {
|
|
15
|
-
constructor(args: EventRegistryStatic.DailyShares.Arguments = {}) {
|
|
16
|
-
const {date = moment().format("YYYY-MM-DD"), count = 20, returnInfo = new ReturnInfo()} = args;
|
|
17
|
-
super();
|
|
18
|
-
this.setVal("action", "getArticles");
|
|
19
|
-
this.setVal("resultType", "articles");
|
|
20
|
-
this.setVal("articlesCount", count);
|
|
21
|
-
this.setVal("articlesSortBy", "socialScore");
|
|
22
|
-
this.setDateVal("dateStart", date);
|
|
23
|
-
this.setDateVal("dateEnd", date);
|
|
24
|
-
this.params = _.extend({}, this.params, returnInfo.getParams("articles"));
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
public get path() {
|
|
28
|
-
return "/api/v1/article";
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
export class GetTopSharedEvents extends QueryParamsBase {
|
|
33
|
-
constructor(args: EventRegistryStatic.DailyShares.Arguments = {}) {
|
|
34
|
-
const {date = moment().format("YYYY-MM-DD"), count = 20, returnInfo = new ReturnInfo()} = args;
|
|
35
|
-
super();
|
|
36
|
-
this.setVal("action", "getEvents");
|
|
37
|
-
this.setVal("resultType", "events");
|
|
38
|
-
this.setVal("eventsCount", count);
|
|
39
|
-
this.setVal("eventsSortBy", "socialScore");
|
|
40
|
-
this.setDateVal("dateStart", date);
|
|
41
|
-
this.setDateVal("dateEnd", date);
|
|
42
|
-
this.params = _.extend({}, this.params, returnInfo.getParams("events"));
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
public get path() {
|
|
46
|
-
return "/api/v1/event";
|
|
47
|
-
}
|
|
48
|
-
}
|
package/src/eventForText.ts
DELETED
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
|
-
import { QueryParamsBase, sleep } from "./base";
|
|
3
|
-
import { EventRegistry } from "./eventRegistry";
|
|
4
|
-
/**
|
|
5
|
-
* The GetEventForText class can be used to find the event(s) that best matches the given input text.
|
|
6
|
-
* The request is performed asynchronously.
|
|
7
|
-
*
|
|
8
|
-
* Note: The functionality can only be used to find the events in the last 5 days. Older events cannot
|
|
9
|
-
* be matched in this way
|
|
10
|
-
*
|
|
11
|
-
* Return info from the compute() method is in the form:
|
|
12
|
-
*
|
|
13
|
-
* [
|
|
14
|
-
* {
|
|
15
|
-
* "cosSim": 0.07660648086468567,
|
|
16
|
-
* "eventUri": "4969",
|
|
17
|
-
* "storyUri": "eng-af6ce79f-cb91-4010-8ddf-7ad924bc5638-40591"
|
|
18
|
-
* },
|
|
19
|
-
* {
|
|
20
|
-
* "cosSim": 0.05851939237670918,
|
|
21
|
-
* "eventUri": "5157",
|
|
22
|
-
* "storyUri": "eng-af6ce79f-cb91-4010-8ddf-7ad924bc5638-56286"
|
|
23
|
-
* },
|
|
24
|
-
* ...
|
|
25
|
-
* ]
|
|
26
|
-
*
|
|
27
|
-
* Where
|
|
28
|
-
* - cosSim represents the cosine similarity of the document to the cluster
|
|
29
|
-
* - eventUri is the uri of the corresponding event in the Event Registry
|
|
30
|
-
* - storyUri is the uri of the story in the Event Registry
|
|
31
|
-
*
|
|
32
|
-
* You can use QueryEvent or QueryStory to obtain more information about these events/stories
|
|
33
|
-
*
|
|
34
|
-
*/
|
|
35
|
-
export class GetEventForText extends QueryParamsBase {
|
|
36
|
-
private er: EventRegistry;
|
|
37
|
-
private nrOfEventsToReturn: number;
|
|
38
|
-
/**
|
|
39
|
-
* @param er instance of EventRegistry class
|
|
40
|
-
* @param nrOfEventsToReturn number of events to return for the given text
|
|
41
|
-
*/
|
|
42
|
-
constructor(er: EventRegistry, nrOfEventsToReturn: number = 5) {
|
|
43
|
-
super();
|
|
44
|
-
this.er = er;
|
|
45
|
-
this.nrOfEventsToReturn = nrOfEventsToReturn;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Compute the list of most similar events for the given text
|
|
50
|
-
* @param text text for which to find the most similar event
|
|
51
|
-
* @param lang language in which the text is written
|
|
52
|
-
*/
|
|
53
|
-
public async compute(text: string, lang: string = "eng") {
|
|
54
|
-
const params = {lang: lang, text: text, topClustersCount: this.nrOfEventsToReturn};
|
|
55
|
-
const response = await this.er.jsonRequest("/api/v1/getEventForText/getEventForText", params);
|
|
56
|
-
if (_.has(response, "topStories")) {
|
|
57
|
-
return _.get(response, "topStories", []);
|
|
58
|
-
}
|
|
59
|
-
return response;
|
|
60
|
-
}
|
|
61
|
-
}
|