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,232 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
BaseQuery,
|
|
3
|
-
CombinedQuery,
|
|
4
|
-
ComplexEventQuery,
|
|
5
|
-
ConceptInfoFlags,
|
|
6
|
-
EventInfoFlags,
|
|
7
|
-
EventRegistry,
|
|
8
|
-
QueryEvents,
|
|
9
|
-
QueryEventsIter,
|
|
10
|
-
QueryItems,
|
|
11
|
-
RequestEventsCategoryAggr,
|
|
12
|
-
RequestEventsConceptAggr,
|
|
13
|
-
RequestEventsConceptGraph,
|
|
14
|
-
RequestEventsConceptTrends,
|
|
15
|
-
RequestEventsInfo,
|
|
16
|
-
RequestEventsLocAggr,
|
|
17
|
-
RequestEventsTimeAggr,
|
|
18
|
-
ReturnInfo,
|
|
19
|
-
} from "eventregistry";
|
|
20
|
-
|
|
21
|
-
// examples of how to search for events using different search criteria
|
|
22
|
-
|
|
23
|
-
const er = new EventRegistry();
|
|
24
|
-
|
|
25
|
-
// get the concept URI that matches label "Barack Obama"
|
|
26
|
-
er.getConceptUri("Obama").then((conceptUri) => {
|
|
27
|
-
console.info(`Concept uri for 'Obama' ${conceptUri}`);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
// USE OF ITERATOR
|
|
31
|
-
// example of using the QueryEventsIter to easily iterate through all results matching the search
|
|
32
|
-
|
|
33
|
-
// query for events related to Barack Obama. return the matching events sorted from the latest to oldest event
|
|
34
|
-
// use the iterator class and easily iterate over all matching events
|
|
35
|
-
// we specify maxItems to limit the results to maximum 300 results
|
|
36
|
-
er.getConceptUri("Obama").then((conceptUri) => {
|
|
37
|
-
const iter = new QueryEventsIter(er, {conceptUri: conceptUri, sortBy: "date", maxItems: 300});
|
|
38
|
-
iter.execQuery((event) => {
|
|
39
|
-
console.info(event);
|
|
40
|
-
});
|
|
41
|
-
});
|
|
42
|
-
/**
|
|
43
|
-
* find events that:
|
|
44
|
-
* - are about Barack Obama
|
|
45
|
-
* - that were covered also by New York Times
|
|
46
|
-
* - that occurred in 2015
|
|
47
|
-
* - return events sorted by how much were articles in the event shared on social media (instead of relevance, which is default)
|
|
48
|
-
*/
|
|
49
|
-
Promise.all([er.getConceptUri("Obama"), er.getSourceUri("new york times")]).then(([obamaUri, nytimesUri]) => {
|
|
50
|
-
const query = new QueryEvents({conceptUri: obamaUri, dateStart: "2015-01-01", dateEnd: "2015-12-31", sourceUri: nytimesUri});
|
|
51
|
-
// return a list of event URIs (i.e. ["eng-234", "deu-234", ...])
|
|
52
|
-
query.setRequestedResult(new RequestEventsInfo({sortBy: "socialScore"}));
|
|
53
|
-
const res1 = er.execQuery(query);
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* find events that:
|
|
58
|
-
* - contain articles that mention words Apple, Google and Samsung
|
|
59
|
-
* - contain at least one article from a news source that is located in Italy
|
|
60
|
-
*/
|
|
61
|
-
er.getLocationUri("Italy").then((italyUri) => {
|
|
62
|
-
const query = new QueryEvents({keywords: QueryItems.AND(["Apple", "Google", "Samsung"]), sourceLocationUri: italyUri});
|
|
63
|
-
const res1 = er.execQuery(query);
|
|
64
|
-
|
|
65
|
-
/**
|
|
66
|
-
* use the previous query, but change the return details to return information about 30 events sorted from latest to oldest
|
|
67
|
-
* when providing the concept information include the labels of the concept in German language
|
|
68
|
-
*/
|
|
69
|
-
const returnInfo = new ReturnInfo({conceptInfo: new ConceptInfoFlags({lang: "deu", type: ["person", "wiki"]})});
|
|
70
|
-
const requestEventsInfo = new RequestEventsInfo({count: 30, sortBy: "date", sortByAsc: false, returnInfo: returnInfo});
|
|
71
|
-
query.setRequestedResult(requestEventsInfo);
|
|
72
|
-
const res2 = er.execQuery(query);
|
|
73
|
-
|
|
74
|
-
// use the previous query, but this time compute most relevant concepts of type organization or location extracted from events about Obama
|
|
75
|
-
const returnInfo1 = new ReturnInfo({conceptInfo: new ConceptInfoFlags({type: ["org", "loc"]})});
|
|
76
|
-
const requestEventsConceptAggr = new RequestEventsConceptAggr({conceptCount: 20, returnInfo: returnInfo1});
|
|
77
|
-
query.setRequestedResult(requestEventsConceptAggr);
|
|
78
|
-
const res3 = er.execQuery(query);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
// get the URI for the BBC news source
|
|
82
|
-
er.getNewsSourceUri("BBC").then((sourceUri) => {
|
|
83
|
-
console.info(`Source uri for 'BBC' is ${sourceUri}`);
|
|
84
|
-
// query for events that were reported by BBC News
|
|
85
|
-
const query = new QueryEvents({sourceUri});
|
|
86
|
-
// return details about 30 events that have been most recently reported by BBC
|
|
87
|
-
const requestEventsInfo = new RequestEventsInfo({count: 30, sortBy: "date", sortByAsc: false});
|
|
88
|
-
query.setRequestedResult(requestEventsInfo);
|
|
89
|
-
const res = er.execQuery(query);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
// get the category URI that matches label "society issues"
|
|
93
|
-
er.getCategoryUri("society issues").then((categoryUri) => {
|
|
94
|
-
console.info(`Category uri for 'society issues' is ${categoryUri}`);
|
|
95
|
-
// query for events related to issues in society
|
|
96
|
-
const query = new QueryEvents({categoryUri});
|
|
97
|
-
// return 30 events that were reported in the highest number of articles
|
|
98
|
-
const requestEventsInfo = new RequestEventsInfo({count: 30, sortBy: "size", sortByAsc: false});
|
|
99
|
-
query.setRequestedResult(requestEventsInfo);
|
|
100
|
-
const res = er.execQuery(query);
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
//
|
|
104
|
-
// OTHER AGGREGATES (INSTEAD OF OBTAINING EVENTS)
|
|
105
|
-
//
|
|
106
|
-
// find events that occurred in Germany between 2014-04-16 and 2014-04-28
|
|
107
|
-
// from the resulting events produce:
|
|
108
|
-
|
|
109
|
-
er.getLocationUri("Germany").then((germanyUri) => {
|
|
110
|
-
const q = new QueryEvents({locationUri: germanyUri, dateStart: "2017-12-16", dateEnd: "2018-01-28"});
|
|
111
|
-
// get the list of top concepts about the events that match criteria
|
|
112
|
-
q.setRequestedResult(new RequestEventsConceptAggr());
|
|
113
|
-
const res1 = er.execQuery(q);
|
|
114
|
-
// find where the events occurred geographically
|
|
115
|
-
q.setRequestedResult(new RequestEventsLocAggr());
|
|
116
|
-
const res2 = er.execQuery(q);
|
|
117
|
-
// find when the events matching the criteria occurred
|
|
118
|
-
q.setRequestedResult(new RequestEventsTimeAggr());
|
|
119
|
-
const res3 = er.execQuery(q);
|
|
120
|
-
// the trending information about the top people involved in these events
|
|
121
|
-
q.setRequestedResult(new RequestEventsConceptTrends({conceptCount: 40, returnInfo: new ReturnInfo({conceptInfo: new ConceptInfoFlags({type: ["person"]})})}));
|
|
122
|
-
const res4 = er.execQuery(q);
|
|
123
|
-
// get the top categories about the same events
|
|
124
|
-
q.setRequestedResult(new RequestEventsCategoryAggr());
|
|
125
|
-
const res5 = er.execQuery(q);
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// find events that occurred in Berlin between 2014-04-16 and 2014-04-28
|
|
129
|
-
// from the resulting events produce
|
|
130
|
-
// - the trending information about the top people involved in these events
|
|
131
|
-
// - info about the categories of these events
|
|
132
|
-
// - general information about the 20 most recent events in that time span
|
|
133
|
-
|
|
134
|
-
er.getLocationUri("Berlin").then((locationUri) => {
|
|
135
|
-
const query = new QueryEvents({locationUri: locationUri, dateStart: "2015-04-16", dateEnd: "2015-04-28"});
|
|
136
|
-
const returnInfo = new ReturnInfo({conceptInfo: new ConceptInfoFlags({type: ["person"]})});
|
|
137
|
-
const requestEventsConceptTrends = new RequestEventsConceptTrends({conceptCount: 40, returnInfo});
|
|
138
|
-
query.setRequestedResult(requestEventsConceptTrends);
|
|
139
|
-
const res1 = er.execQuery(query);
|
|
140
|
-
|
|
141
|
-
query.setRequestedResult(new RequestEventsCategoryAggr());
|
|
142
|
-
const res2 = er.execQuery(query);
|
|
143
|
-
|
|
144
|
-
query.setRequestedResult(new RequestEventsInfo());
|
|
145
|
-
const res3 = er.execQuery(query);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
// query for events about Obama and produce the concept co-occurrence graph - which concepts appear frequently together in the matching events
|
|
149
|
-
er.getConceptUri("Obama").then((conceptUri) => {
|
|
150
|
-
const query = new QueryEvents();
|
|
151
|
-
const requestEventsConceptGraph = new RequestEventsConceptGraph({conceptCount: 200, linkCount: 500, eventsSampleSize: 2000});
|
|
152
|
-
query.setRequestedResult(requestEventsConceptGraph);
|
|
153
|
-
const res = er.execQuery(query);
|
|
154
|
-
});
|
|
155
|
-
|
|
156
|
-
// COMPLEX QUERIES
|
|
157
|
-
// examples of complex queries that combine various OR and AND operators
|
|
158
|
-
|
|
159
|
-
// events that are occurred between 2017-02-05 and 2017-02-05 and are not about business
|
|
160
|
-
er.getCategoryUri("Business").then((categoryUri) => {
|
|
161
|
-
const query = QueryEvents.initWithComplexQuery(`
|
|
162
|
-
{
|
|
163
|
-
"$query": {
|
|
164
|
-
"dateStart": "2017-02-05", "dateEnd": "2017-02-06",
|
|
165
|
-
"$not": {
|
|
166
|
-
"categoryUri": "${categoryUri}"
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
`);
|
|
171
|
-
const res = er.execQuery(query);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* get events that:
|
|
176
|
-
* - happened on 2017-02-05
|
|
177
|
-
* - are about trump, or
|
|
178
|
-
* - are about politics, or
|
|
179
|
-
* - are about Merkel and business
|
|
180
|
-
* and did not happen on 2017-02-04 or are about Obama
|
|
181
|
-
*/
|
|
182
|
-
Promise.all([
|
|
183
|
-
er.getConceptUri("Trump"),
|
|
184
|
-
er.getConceptUri("Obama"),
|
|
185
|
-
er.getCategoryUri("politics"),
|
|
186
|
-
er.getConceptUri("merkel"),
|
|
187
|
-
er.getCategoryUri("business"),
|
|
188
|
-
]).then(([trumpUri, obamaUri, politicsUri, merkelUri, businessUri]) => {
|
|
189
|
-
const qStr = `
|
|
190
|
-
{
|
|
191
|
-
"$query": {
|
|
192
|
-
"$or": [
|
|
193
|
-
{ "dateStart": "2017-02-05", "dateEnd": "2017-02-05" },
|
|
194
|
-
{ "conceptUri": "${trumpUri}" },
|
|
195
|
-
{ "categoryUri": "${politicsUri}" },
|
|
196
|
-
{
|
|
197
|
-
"$and": [
|
|
198
|
-
{ "conceptUri": "${merkelUri}" },
|
|
199
|
-
{ "categoryUri": "${businessUri}" }
|
|
200
|
-
]
|
|
201
|
-
}
|
|
202
|
-
],
|
|
203
|
-
"$not": {
|
|
204
|
-
"$or": [
|
|
205
|
-
{ "dateStart": "2017-02-04", "dateEnd": "2017-02-04" },
|
|
206
|
-
{ "conceptUri": "${obamaUri}" }
|
|
207
|
-
]
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
}
|
|
211
|
-
`;
|
|
212
|
-
const q1 = QueryEvents.initWithComplexQuery(qStr);
|
|
213
|
-
const res = er.execQuery(q1);
|
|
214
|
-
|
|
215
|
-
const cq = new ComplexEventQuery(CombinedQuery.OR([
|
|
216
|
-
new BaseQuery({dateStart: "2017-02-04", dateEnd: "2017-02-05"}),
|
|
217
|
-
new BaseQuery({conceptUri: trumpUri}),
|
|
218
|
-
new BaseQuery({categoryUri: politicsUri}),
|
|
219
|
-
], CombinedQuery.OR([
|
|
220
|
-
new BaseQuery({dateStart: "2017-02-04", dateEnd: "2017-02-04"}),
|
|
221
|
-
new BaseQuery({conceptUri: obamaUri}),
|
|
222
|
-
])));
|
|
223
|
-
|
|
224
|
-
const returnInfo = new ReturnInfo({eventInfo: new EventInfoFlags({concepts: true, categories: true, stories: true})});
|
|
225
|
-
|
|
226
|
-
const iter = QueryEventsIter.initWithComplexQuery(er, cq, {returnInfo, maxItems: 10});
|
|
227
|
-
// example of an ITERATOR with a COMPLEX QUERY
|
|
228
|
-
iter.execQuery((event) => {
|
|
229
|
-
console.info(event);
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
});
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import { TopicPage, EventRegistry, ArticleInfoFlags, ReturnInfo } from "eventregistry";
|
|
2
|
-
|
|
3
|
-
const er = new EventRegistry();
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* create a topic page directly
|
|
7
|
-
*/
|
|
8
|
-
async function createTopicPage1() {
|
|
9
|
-
const topic = new TopicPage(er);
|
|
10
|
-
topic.addKeyword("renewable energy", 30);
|
|
11
|
-
topic.addConcept(await er.getConceptUri("biofuel"), 50);
|
|
12
|
-
topic.addConcept(await er.getConceptUri("solar energy"), 50);
|
|
13
|
-
topic.addConcept(await er.getCategoryUri("renewable"), 50);
|
|
14
|
-
// skip articles that are duplicates of other articles
|
|
15
|
-
topic.articleHasDuplicateFilter = "skipHasDuplicates";
|
|
16
|
-
topic.articleHasEventFilter = "skipArticlesWithoutEvent";
|
|
17
|
-
// get first 2 pages of articles sorted by relevance to the topic page
|
|
18
|
-
const articles1 = await topic.getArticles({page: 1, sortBy: "rel"});
|
|
19
|
-
const articles2 = await topic.getArticles({page: 2, sortBy: "rel"});
|
|
20
|
-
// get first page of events
|
|
21
|
-
const events1 = await topic.getEvents({page: 1, sortBy: "rel"});
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* create a topic page directly, set the article threshold, restrict results to set concepts and keywords
|
|
26
|
-
*/
|
|
27
|
-
async function createTopicPage2() {
|
|
28
|
-
const topic = new TopicPage(er);
|
|
29
|
-
topic.addConcept(await er.getCategoryUri("renewable"), 50);
|
|
30
|
-
|
|
31
|
-
topic.addKeyword("renewable energy", 30);
|
|
32
|
-
topic.addConcept(await er.getConceptUri("biofuel"), 50);
|
|
33
|
-
topic.addConcept(await er.getConceptUri("solar energy"), 50);
|
|
34
|
-
|
|
35
|
-
// require that the results will mention at least one of the concepts and keywords specified
|
|
36
|
-
// (even though they might have the category about renewable energy, that will not be enough
|
|
37
|
-
// for an article to be among the results)
|
|
38
|
-
topic.restrictToSetConceptsAndKeywords = true;
|
|
39
|
-
// limit results to English, German and Spanish results
|
|
40
|
-
topic.languages = ["eng", "deu", "spa"];
|
|
41
|
-
// get results that are at most 3 days old
|
|
42
|
-
topic.maxDaysBack = 3;
|
|
43
|
-
// require that the articles that will be returned should get at least a total score of 30 points or more
|
|
44
|
-
// based on the specified list of conditions
|
|
45
|
-
topic.articleThreshold = 30;
|
|
46
|
-
const articleInfo = new ArticleInfoFlags ({concepts: true, categories: true});
|
|
47
|
-
const returnInfo = new ReturnInfo({articleInfo: articleInfo});
|
|
48
|
-
// get first page of articles sorted by date (from most recent backward) to the topic page
|
|
49
|
-
const articles = await topic.getArticles({page: 1, sortBy: "date", returnInfo: returnInfo});
|
|
50
|
-
for (const article of articles) {
|
|
51
|
-
console.log(article);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
async function loadERTopicPage() {
|
|
56
|
-
let articles;
|
|
57
|
-
try {
|
|
58
|
-
const topic = new TopicPage(er);
|
|
59
|
-
await topic.loadTopicPageFromER("265e373d-ebf6-487f-a346-f87c198ec8dd");
|
|
60
|
-
articles = await topic.getArticles({page: 1, sortBy: "date"});
|
|
61
|
-
} catch (error) {
|
|
62
|
-
console.error(error);
|
|
63
|
-
} finally {
|
|
64
|
-
return articles;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async function saveAndLoadTopicPage() {
|
|
69
|
-
const topic = new TopicPage(er);
|
|
70
|
-
topic.addKeyword("renewable energy", 30);
|
|
71
|
-
const articles1 = await topic.getArticles({page: 1});
|
|
72
|
-
// get the definition of the topic page as an object
|
|
73
|
-
// you can save this and later load it
|
|
74
|
-
const definition = topic.saveTopicPageDefinition();
|
|
75
|
-
const topic2 = new TopicPage(er);
|
|
76
|
-
topic2.loadTopicPageFromDefinition(definition);
|
|
77
|
-
const articles2 = await topic2.getArticles({page: 1});
|
|
78
|
-
// articles1 and articles2 should be (almost) the same
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async function saveAndLoadTopicPageFromFile() {
|
|
82
|
-
const topic = new TopicPage(er);
|
|
83
|
-
topic.addKeyword("renewable energy", 30);
|
|
84
|
-
const articles1 = await topic.getArticles({page: 1});
|
|
85
|
-
// save the definition to a file and later load it
|
|
86
|
-
const definition = topic.saveTopicPageDefinitionToFile("topic.json");
|
|
87
|
-
const topic2 = new TopicPage(er);
|
|
88
|
-
topic2.loadTopicPageFromFile("topic.json");
|
|
89
|
-
const articles2 = await topic2.getArticles({page: 1});
|
|
90
|
-
// articles1 and articles2 should be (almost) the same
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
createTopicPage1();
|
|
94
|
-
createTopicPage2();
|
|
95
|
-
loadERTopicPage();
|
|
96
|
-
saveAndLoadTopicPage();
|
|
97
|
-
saveAndLoadTopicPageFromFile();
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { CategoryInfoFlags, ConceptInfoFlags, EventRegistry, GetTrendingCategories, GetTrendingConceptGroups, GetTrendingConcepts, ReturnInfo } from "eventregistry";
|
|
2
|
-
|
|
3
|
-
// examples that illustrate how to obtain the currently top trending concepts or categories
|
|
4
|
-
// The trends can be computed based on the number of mentions in the news or based on the shares on social media
|
|
5
|
-
|
|
6
|
-
const er = new EventRegistry();
|
|
7
|
-
|
|
8
|
-
const returnInfo1 = new ReturnInfo({conceptInfo: new ConceptInfoFlags({trendingHistory: true})});
|
|
9
|
-
// top 10 top trending concepts in the news
|
|
10
|
-
const q1 = new GetTrendingConcepts({source: "news", count: 10, returnInfo: returnInfo1});
|
|
11
|
-
er.execQuery(q1).then((response) => {
|
|
12
|
-
console.info(response);
|
|
13
|
-
});
|
|
14
|
-
|
|
15
|
-
// get 20 most trending concept for each entity type
|
|
16
|
-
const q2 = new GetTrendingConceptGroups({source: "news"});
|
|
17
|
-
// get top trends for individual concept groups - people, locations and organisations
|
|
18
|
-
q2.getConceptTypeGroups();
|
|
19
|
-
er.execQuery(q2).then((response) => {
|
|
20
|
-
console.info(response);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
// top 20 trending concepts in the social media
|
|
24
|
-
const q3 = new GetTrendingConcepts({source: "social", count: 20, returnInfo: returnInfo1});
|
|
25
|
-
er.execQuery(q3).then((response) => {
|
|
26
|
-
console.info(response);
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
// top 10 trending categories in the news
|
|
30
|
-
const returnInfo2 = new ReturnInfo({categoryInfo: new CategoryInfoFlags({parentUri: true, childrenUris: true, trendingHistory: true})});
|
|
31
|
-
const q4 = new GetTrendingCategories({source: "news", count: 10, returnInfo: returnInfo2});
|
|
32
|
-
er.execQuery(q4).then((response) => {
|
|
33
|
-
console.info(response);
|
|
34
|
-
});
|
package/src/analytics.ts
DELETED
|
@@ -1,181 +0,0 @@
|
|
|
1
|
-
import * as _ from "lodash";
|
|
2
|
-
import { EventRegistry } from "./eventRegistry";
|
|
3
|
-
import { EventRegistryStatic } from "./types";
|
|
4
|
-
|
|
5
|
-
// The Analytics class can be used for access the text analytics services provided by the Event Registry.
|
|
6
|
-
// These include:
|
|
7
|
-
// - text annotation: identifying the list of entities and non-entities mentioned in the provided text
|
|
8
|
-
// - text categorization: identification of up to 5 categories that describe the topic of the given text.
|
|
9
|
-
// The list of available categories come from DMOZ open directory. Currently, only English text can be categorized!
|
|
10
|
-
// - sentiment detection: what is the sentiment expressed in the given text
|
|
11
|
-
// - language detection: detect in which language is the given text written
|
|
12
|
-
|
|
13
|
-
// NOTE: the functionality is currently in BETA. The API calls or the provided outputs may change in the future.
|
|
14
|
-
|
|
15
|
-
export class Analytics {
|
|
16
|
-
/**
|
|
17
|
-
* @param eventRegistry: instance of EventRegistry class
|
|
18
|
-
*/
|
|
19
|
-
constructor(private er: EventRegistry) { }
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* Identify the list of entities and nonentities mentioned in the text
|
|
23
|
-
* @param text input text to annotate
|
|
24
|
-
* @param lang language of the provided document (can be an ISO2 or ISO3 code). If None is provided, the language will be automatically detected
|
|
25
|
-
*/
|
|
26
|
-
public async annotate(text: string, lang?: string[], customParams?: {[name: string]: unknown}) {
|
|
27
|
-
let params = { lang, text };
|
|
28
|
-
if (!_.isUndefined(customParams)) {
|
|
29
|
-
params = {...params, ...customParams};
|
|
30
|
-
}
|
|
31
|
-
return _.get(await this.er.jsonRequestAnalytics("/api/v1/annotate", params), "data");
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Determine the set of up to 5 categories the text is about. Currently, only English text can be categorized!
|
|
36
|
-
* @param text input text to categorize
|
|
37
|
-
* @param taxonomy: which taxonomy use for categorization. Options:
|
|
38
|
-
* - "dmoz" (over 5000 categories in 3 levels, English language only)
|
|
39
|
-
* - "news" (general news categorization, 9 categories, any langauge)
|
|
40
|
-
*/
|
|
41
|
-
public async categorize(text: string, taxonomy: "dmoz" | "news" = "dmoz") {
|
|
42
|
-
return _.get(await this.er.jsonRequestAnalytics("/api/v1/categorize", { text, taxonomy }), "data");
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/**
|
|
46
|
-
* determine the sentiment of the provided text in English language
|
|
47
|
-
* @param text input text to categorize
|
|
48
|
-
* @param method method to use to compute the sentiment. possible values are "vocabulary" (vocabulary based sentiment analysis) and "rnn" (neural network based sentiment classification)
|
|
49
|
-
*/
|
|
50
|
-
public async sentiment(text: string, method = "vocabulary", sentences = 10, returnSentences = true) {
|
|
51
|
-
if (!_.includes(["vocabulary", "rnn"], method)) {
|
|
52
|
-
throw new Error("method: Please pass in either 'vocabulary' or 'rnn'");
|
|
53
|
-
}
|
|
54
|
-
const params = {
|
|
55
|
-
text,
|
|
56
|
-
method,
|
|
57
|
-
sentences,
|
|
58
|
-
returnSentences,
|
|
59
|
-
};
|
|
60
|
-
return _.get(await this.er.jsonRequestAnalytics("/api/v1/sentiment", params), "data");
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
public async semanticSimilarity(text1: string, text2: string, distanceMeasure: "cosine" | "jaccard" = "cosine") {
|
|
64
|
-
return _.get(await this.er.jsonRequestAnalytics("/api/v1/semanticSimilarity", { text1, text2, distanceMeasure }), "data");
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* Determine the language of the given text
|
|
69
|
-
* @param text input text to analyse
|
|
70
|
-
*/
|
|
71
|
-
public async detectLanguage(text: string) {
|
|
72
|
-
return _.get(await this.er.jsonRequestAnalytics("/api/v1/detectLanguage", { text }), "data");
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Extract all available information about an article available at url `url`.
|
|
76
|
-
* Returned information will include article title, body, authors, links in the articles,...
|
|
77
|
-
* @param url article url that'll be used for extraction
|
|
78
|
-
* @param proxyUrl proxy that should be used for downloading article information. format: {schema}://{username}:{pass}@{proxy url/ip}
|
|
79
|
-
*/
|
|
80
|
-
public async extractArticleInfo(url: string, proxyUrl?: string, headers?: {[name: string]: unknown}, cookies?: {[name: string]: unknown}) {
|
|
81
|
-
const params = { url };
|
|
82
|
-
if (!!proxyUrl) {
|
|
83
|
-
_.set(params, "proxyUrl", proxyUrl);
|
|
84
|
-
}
|
|
85
|
-
return _.get(await this.er.jsonRequestAnalytics("/api/v1/extractArticleInfo", params, headers, cookies), "data");
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* Extract named entities from the provided text. Supported languages are English, German, Spanish and Chinese.
|
|
90
|
-
* @param text: text on which to extract named entities
|
|
91
|
-
*/
|
|
92
|
-
public async ner(text: string) {
|
|
93
|
-
return _.get(await this.er.jsonRequestAnalytics("/api/v1/ner", { text }), "data");
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
/**
|
|
97
|
-
* Create a new topic and train it using the tweets that match the twitterQuery
|
|
98
|
-
* @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.
|
|
99
|
-
* @param args Object which contains a host of optional parameters
|
|
100
|
-
*/
|
|
101
|
-
public async trainTopicOnTweets(twitterQuery: string, args: EventRegistryStatic.Analytics.TrainTopicOnTweetsArguments = {}) {
|
|
102
|
-
const {
|
|
103
|
-
useTweetText = true,
|
|
104
|
-
useIdfNormalization = true,
|
|
105
|
-
normalization = "linear",
|
|
106
|
-
maxTweets = 2000,
|
|
107
|
-
maxUsedLinks = 500,
|
|
108
|
-
ignoreConceptTypes = [],
|
|
109
|
-
maxConcepts = 20,
|
|
110
|
-
maxCategories = 10,
|
|
111
|
-
notifyEmailAddress = undefined,
|
|
112
|
-
} = args;
|
|
113
|
-
if (maxTweets > 5000) {
|
|
114
|
-
throw new Error("We can analyze at most 5000 tweets");
|
|
115
|
-
}
|
|
116
|
-
const params = {
|
|
117
|
-
twitterQuery,
|
|
118
|
-
useTweetText,
|
|
119
|
-
useIdfNormalization,
|
|
120
|
-
normalization,
|
|
121
|
-
maxTweets,
|
|
122
|
-
maxUsedLinks,
|
|
123
|
-
maxConcepts,
|
|
124
|
-
maxCategories,
|
|
125
|
-
};
|
|
126
|
-
if (notifyEmailAddress) {
|
|
127
|
-
_.set(params, "notifyEmailAddress", notifyEmailAddress);
|
|
128
|
-
}
|
|
129
|
-
if (!_.isEmpty(ignoreConceptTypes)) {
|
|
130
|
-
_.set(params, "ignoreConceptTypes", ignoreConceptTypes);
|
|
131
|
-
}
|
|
132
|
-
return _.get(await this.er.jsonRequestAnalytics("/api/v1/trainTopicOnTwitter", params), "data");
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
/**
|
|
136
|
-
* Create a new topic to train. The user should remember the "uri" parameter returned in the result.
|
|
137
|
-
* @param name name of the topic we want to create
|
|
138
|
-
* @returns object containing the "uri" property that should be used in the follow-up call to trainTopic* methods
|
|
139
|
-
*/
|
|
140
|
-
public async trainTopicCreateTopic(name: string) {
|
|
141
|
-
return _.get(await this.er.jsonRequestAnalytics("/api/v1/trainTopic", { action: "createTopic", name: name}), "data");
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* If the topic is already existing, clear the definition of the topic. Use this if you want to retrain an existing topic
|
|
146
|
-
* @param uri uri of the topic (obtained by calling trainTopicCreateTopic method) to clear
|
|
147
|
-
*/
|
|
148
|
-
public async trainTopicClearTopic(uri: string) {
|
|
149
|
-
return _.get(await this.er.jsonRequestAnalytics("/api/v1/trainTopic", { action: "clearTopic", uri: uri}), "data");
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* Add the information extracted from the provided "text" to the topic with uri "uri".
|
|
154
|
-
* @param uri uri of the topic (obtained by calling trainTopicCreateTopic method)
|
|
155
|
-
* @param text text to analyze and extract information from
|
|
156
|
-
*/
|
|
157
|
-
public async trainTopicAddDocument(uri: string, text: string) {
|
|
158
|
-
return _.get(await this.er.jsonRequestAnalytics("/api/v1/trainTopic", { action: "addDocument", uri: uri, text: text}), "data");
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Retrieve topic for the topic for which you have already finished training
|
|
163
|
-
* @param uri uri of the topic (obtained by calling trainTopicCreateTopic method)
|
|
164
|
-
* @returns returns the trained topic: { concepts: [], categories: [] }
|
|
165
|
-
*/
|
|
166
|
-
public async trainTopicGetTrainedTopic(uri: string, args: EventRegistryStatic.Analytics.TrainTopicGetTrainedTopicArguments = {}) {
|
|
167
|
-
const {
|
|
168
|
-
maxConcepts = 20,
|
|
169
|
-
maxCategories = 10,
|
|
170
|
-
idfNormalization = true,
|
|
171
|
-
} = args;
|
|
172
|
-
const params = {
|
|
173
|
-
action: "getTrainedTopic",
|
|
174
|
-
uri: uri,
|
|
175
|
-
maxConcepts: maxConcepts,
|
|
176
|
-
maxCategories: maxCategories,
|
|
177
|
-
idfNormalization: idfNormalization,
|
|
178
|
-
};
|
|
179
|
-
return _.get(await this.er.jsonRequestAnalytics("/api/v1/trainTopic", params), "data");
|
|
180
|
-
}
|
|
181
|
-
}
|