eventregistry 8.10.1 → 8.10.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/CHANGELOG.md +3 -0
  2. package/{src → dist}/types.d.ts +199 -255
  3. package/dist/types.js +3 -0
  4. package/dist/types.js.map +1 -0
  5. package/package.json +6 -5
  6. package/dist/correlations.d.ts +0 -50
  7. package/dist/correlations.js +0 -397
  8. package/dist/correlations.js.map +0 -1
  9. package/examples/autoSuggestionsExamples.ts +0 -46
  10. package/examples/countsExamples.ts +0 -34
  11. package/examples/dailySharesExamples.ts +0 -54
  12. package/examples/eventForTextExamples.ts +0 -32
  13. package/examples/feedOfNewArticlesExamples.ts +0 -82
  14. package/examples/feedOfNewEventsExamples.ts +0 -70
  15. package/examples/queryArticleExamples.ts +0 -42
  16. package/examples/queryArticlesExamples.ts +0 -248
  17. package/examples/queryEventExamples.ts +0 -99
  18. package/examples/queryEventsExamples.ts +0 -232
  19. package/examples/queryMentionsExamples.ts +0 -20
  20. package/examples/topicPageExamples.ts +0 -99
  21. package/examples/trendsExamples.ts +0 -34
  22. package/src/analytics.ts +0 -181
  23. package/src/base.ts +0 -198
  24. package/src/counts.ts +0 -119
  25. package/src/dailyShares.ts +0 -48
  26. package/src/eventForText.ts +0 -61
  27. package/src/eventRegistry.ts +0 -733
  28. package/src/index.ts +0 -125
  29. package/src/info.ts +0 -121
  30. package/src/query.ts +0 -257
  31. package/src/queryArticle.ts +0 -139
  32. package/src/queryArticles.ts +0 -608
  33. package/src/queryEvent.ts +0 -473
  34. package/src/queryEvents.ts +0 -689
  35. package/src/queryMentions.ts +0 -516
  36. package/src/queryStory.ts +0 -152
  37. package/src/recent.ts +0 -63
  38. package/src/returnInfo.ts +0 -363
  39. package/src/topicPage.ts +0 -479
  40. package/src/trends.ts +0 -63
  41. package/test/index.d.ts +0 -18
  42. package/test/jasmine.json +0 -10
  43. package/test/spec/analytics.spec.ts +0 -150
  44. package/test/spec/autoSuggestions.spec.ts +0 -54
  45. package/test/spec/info.spec.ts +0 -84
  46. package/test/spec/invalidQueries.spec.ts +0 -147
  47. package/test/spec/queryArticle.spec.ts +0 -62
  48. package/test/spec/queryArticles.spec.ts +0 -541
  49. package/test/spec/queryArticlesComplex.spec.ts +0 -298
  50. package/test/spec/queryEvent.spec.ts +0 -194
  51. package/test/spec/queryEvents.spec.ts +0 -491
  52. package/test/spec/queryEventsComplex.spec.ts +0 -188
  53. package/test/spec/queryPaging.spec.ts +0 -318
  54. package/test/spec/returnInfo.spec.ts +0 -34
  55. package/test/spec/topicPage.spec.ts +0 -83
  56. package/test/spec/utils.ts +0 -436
  57. package/test/tsconfig.json +0 -31
  58. package/tsconfig.json +0 -32
  59. package/tslint.json +0 -25
@@ -1,32 +0,0 @@
1
- import { EventRegistry, GetEventForText, QueryEvent, RequestEventInfo } from "eventregistry";
2
- import * as _ from "lodash";
3
-
4
- // Given some text that is related to some current event, this example demonstrates how to obtain
5
- // information which event is the text talking about
6
-
7
- const er = new EventRegistry();
8
-
9
- const q1 = new GetEventForText(er);
10
-
11
- q1.compute(`
12
- Croatian leaders put the army on alert after chaos erupted on the border with Serbia, where thousands
13
- of asylum-seekers poured into the country. It is understood all traffic has been banned on roads
14
- heading towards seven crossings into Serbia. Some were trampling each other in a rush to get on the few
15
- available buses and trains, and dozens were injured in the mayhem.
16
- `).then((response) => {
17
- console.info(`Most similar info:`);
18
- console.info(response);
19
-
20
- if (_.isEmpty(response)) {
21
- return;
22
- }
23
- // get the events ids that are most related to the given text
24
- const eventUris = _.map(response, "eventUri") as string[];
25
- // obtain information about those events
26
- const q2 = new QueryEvent(eventUris);
27
- q2.setRequestedResult(new RequestEventInfo());
28
- return er.execQuery(q2);
29
- }).then((response) => {
30
- console.info(`Event info:`);
31
- console.info(response);
32
- });
@@ -1,82 +0,0 @@
1
- import { ArticleInfoFlags, EventRegistry, GetRecentArticles, QueryArticles, RequestArticlesRecentActivity, ReturnInfo, sleep } from "eventregistry";
2
- import * as _ from "lodash";
3
-
4
- // this is a simple script that makes a query to ER to get the feed of articles that were added
5
- // in the last minute (from the first to the last second of the minute).
6
- // Note: In order to get all the data you have to make the query each minute
7
-
8
- const er = new EventRegistry();
9
- const articleInfo = new ArticleInfoFlags({bodyLen: -1, concepts: true, categories: true});
10
- const returnInfo = new ReturnInfo({ articleInfo });
11
- const recentQ = new GetRecentArticles(er, { returnInfo });
12
-
13
- // Simple use case of the ES6 async/await
14
- async function fetchUpdates() {
15
- const articleList = await recentQ.getUpdates();
16
- // TODO: do here whatever you need to with the articleList
17
- _.each(articleList, (article) => {
18
- console.info(`Added article ${article["uri"]}: ${article["title"]}`);
19
- });
20
- // wait exactly a minute until next batch of new content is ready
21
- await sleep(60 * 1000);
22
- fetchUpdates();
23
- }
24
-
25
- /**
26
- * if you would like to obtain the list of articles recently added, but not necessarily the full feed of articles
27
- * then use the call as below. In this case you can filter the articles to a subset based on
28
- * keywords, concepts, categories, language, source, etc.
29
- * You can also request more than 100 articles per call.
30
- */
31
-
32
- let updatesAfterNewsUri;
33
- let updatesafterBlogUri;
34
- let updatesAfterPrUri;
35
- async function fetchfilteredUpdates() {
36
- const query = new QueryArticles({keywords: "Trump", sourceLocationUri: await er.getLocationUri("United States")});
37
- query.setRequestedResult(
38
- new RequestArticlesRecentActivity({
39
- // download at most 2000 articles. if less of matching articles were added in last 10 minutes, less will be returned
40
- maxArticleCount: 2000,
41
- updatesAfterNewsUri: updatesAfterNewsUri,
42
- updatesafterBlogUri: updatesafterBlogUri,
43
- updatesAfterPrUri: updatesAfterPrUri,
44
- })
45
- );
46
- const articleList = await er.execQuery(query);
47
- // TODO: do here whatever you need to with the articleList
48
- for (const article of _.get(articleList, "recentActivityArticles.activity", [])) {
49
- console.info(`Added article ${article["uri"]}: ${article["title"]}`);
50
- }
51
-
52
- // remember what are the latest uris of the individual data items returned
53
- updatesAfterNewsUri = _.get(articleList, "recentActivityArticles.newestUri.news", undefined);
54
- updatesafterBlogUri = _.get(articleList, "recentActivityArticles.newestUri.blog", undefined);
55
- updatesAfterPrUri = _.get(articleList, "recentActivityArticles.newestUri.pr", undefined);
56
-
57
- // wait for 10 minutes until next batch of new content is ready
58
- await sleep(600 * 1000);
59
- fetchfilteredUpdates();
60
- }
61
-
62
- let updatesAfterTm;
63
-
64
- async function fetchfilteredUpdatesWithParam() {
65
- const query = new QueryArticles({keywords: "Trump", sourceLocationUri: await er.getLocationUri("United States")});
66
- query.setRequestedResult(
67
- new RequestArticlesRecentActivity({
68
- maxArticleCount: 100,
69
- // consider articles that were published at most 10 minutes ago
70
- updatesAfterTm,
71
- })
72
- );
73
- const articleList = await er.execQuery(query);
74
- // TODO: do here whatever you need to with the articleList
75
- for (const article of _.get(articleList, "recentActivityArticles.activity", [])) {
76
- console.info(`Added article ${article["uri"]}: ${article["title"]}`);
77
- }
78
- // wait exactly a minute until next batch of new content is ready
79
- await sleep(60 * 1000);
80
- updatesAfterTm = articleList.recentActivityArticles.currTime;
81
- fetchfilteredUpdatesWithParam();
82
- }
@@ -1,70 +0,0 @@
1
- import { EventRegistry, GetRecentEvents, QueryEvents, RequestEventsRecentActivity, sleep } from "eventregistry";
2
- import * as _ from "lodash";
3
-
4
- // this is a simple script that makes a query to ER to get the feed of events that were added or
5
- // updated in the last minute.
6
- //
7
- // For the received set of events, the script prints the basic event info and then goes and
8
- // also downloads the top 20 articles assigned to this event in any of the languages
9
-
10
- const er = new EventRegistry();
11
- const recentQ = new GetRecentEvents(er);
12
-
13
- // Simple use case of the ES6 async/await
14
- async function fetchUpdates() {
15
- // get the list of event URIs, sorted from the most recently changed backwards
16
- const {eventInfo = {}, activity} = await recentQ.getUpdates();
17
- if (eventInfo) {
18
- console.info(`==========`);
19
- console.info(`${_.size(eventInfo)} events updated since last call`);
20
- // for each updated event print the URI and the title
21
- // NOTE: the same event can appear multiple times in the activity array - this means that more than one article
22
- // about it was recently written about it
23
- _.each(activity, (eventUri) => {
24
- const event = eventInfo[eventUri];
25
- console.info(`Event ${eventUri} ('${event["title"][_.first(_.keys(event["title"]))]}')`);
26
- // event["concepts"] contains the list of relevant concepts for the event
27
- // event["categories"] contains the list of categories for the event
28
-
29
- // TODO: here you can do the processing that decides if the event is relevant for you or not. if relevant, send the info to an external service
30
- });
31
- }
32
- // wait exactly a minute until next batch of new content is ready
33
- await sleep(60 * 1000);
34
- fetchUpdates();
35
- }
36
-
37
- /**
38
- * Alternatively you can also ask for a feed of added/updated events, but instead of all of them, just
39
- * obtain a subset of events that match certain conditions. The full stream of events can be filtered to
40
- * a subset that matches certain keyword, concept, location, source or other available filters in QueryEvents
41
- */
42
- async function fetchFilteredUpdates() {
43
- const query = new QueryEvents({keywords: "Apple", minArticlesInEvent: 30, sourceLocationUri: await er.getLocationUri("United States")});
44
- query.setRequestedResult(
45
- new RequestEventsRecentActivity({
46
- // download at most 2000 events. if less of matching events were added/updated in last 10 minutes, less will be returned
47
- maxEventCount: 2000,
48
- // consider articles that were published at most 10 minutes ago
49
- updatesAfterMinsAgo: 10,
50
- })
51
- );
52
- const response = await er.execQuery(query);
53
- const activity = _.get(response, "recentActivityEvents.activity", []);
54
- const eventInfo = _.get(response, "recentActivityEvents.eventInfo", {});
55
- if (eventInfo) {
56
- console.info(`==========`);
57
- console.info(`${_.size(eventInfo)} events updated since last call`);
58
- // for each updated event print the URI and the title
59
- // NOTE: the same event can appear multiple times in the activity array - this means that more than one article
60
- // about it was recently written about it
61
- _.each(activity, (eventUri) => {
62
- const event = eventInfo[eventUri];
63
- console.info(`Event ${eventUri} ('${event["title"][_.first(_.keys(event["title"]))]}')`);
64
- // TODO: here you can do the processing that decides if the event is relevant for you or not. if relevant, send the info to an external service
65
- });
66
- }
67
- // wait exactly a minute until next batch of new content is ready
68
- await sleep(60 * 1000);
69
- fetchFilteredUpdates();
70
- }
@@ -1,42 +0,0 @@
1
- import { ArticleInfoFlags, ArticleMapper, EventRegistry, QueryArticle, QueryArticles, RequestArticleInfo, RequestArticlesUriWgtList, ReturnInfo } from "eventregistry";
2
- import * as _ from "lodash";
3
-
4
- // examples that download information about the individual news articles
5
-
6
- const er = new EventRegistry();
7
-
8
- // search article by uri
9
- const q1 = new QueryArticle("247634888");
10
- er.execQuery(q1).then((response) => {
11
- console.info(response);
12
- });
13
-
14
- // search article by url
15
- // use ArticleMapper to map article URL to the URI (id) that is used by ER internally
16
- const artMapper = new ArticleMapper(er);
17
- // artMapper.getArticleUri("http://www.bbc.co.uk/news/world-europe-31763789#sa-ns_mchannel%3Drss%26ns_source%3DPublicRSS20-sa")
18
- artMapper.getArticleUri("http://www.mynet.com/haber/guncel/share-2058597-1").then((artUri) => {
19
- const q2 = new QueryArticle(artUri);
20
- // get all info about the specified article
21
- q2.setRequestedResult(new RequestArticleInfo());
22
- return er.execQuery(q2);
23
- });
24
-
25
- // do regular article search, obtain a list of resulting article URIs and then ask for details about these articles
26
- // first search for articles related to Apple
27
- er.getConceptUri("Apple").then((conceptUri) => {
28
- const q3 = new QueryArticles({conceptUri});
29
- q3.setRequestedResult(new RequestArticlesUriWgtList());
30
- return er.execQuery(q3);
31
- }).then((response) => {
32
- // take the list of article URIs that match the search criteria (i.e. ['641565713', '641559021', '641551446', '641025492', '641548675', ...])
33
- const articleUriList = EventRegistry.getUriFromUriWgt(_.get(response, "uriWgtList.results", []));
34
- // take first 5 article URIs and ask for all details about these articles
35
- const queryUris = _.take(articleUriList, 5) as string[];
36
- const q4 = new QueryArticle(queryUris);
37
- const articleInfo = new ArticleInfoFlags({concepts: true, categories: true, location: true});
38
- const returnInfo = new ReturnInfo({articleInfo});
39
- const requestArticleInfo = new RequestArticleInfo(returnInfo);
40
- q4.setRequestedResult(requestArticleInfo);
41
- return er.execQuery(q4);
42
- });
@@ -1,248 +0,0 @@
1
- import { ArticleInfoFlags, BaseQuery, CombinedQuery, ComplexArticleQuery, EventRegistry, ConceptInfoFlags, QueryArticle, QueryArticles, QueryArticlesIter, QueryItems, RequestArticlesInfo, RequestArticlesRecentActivity, ReturnInfo } from "eventregistry";
2
- import * as _ from "lodash";
3
-
4
- // examples that illustrate how to query articles using different search options
5
-
6
- const er = new EventRegistry({allowUseOfArchive: false});
7
- const articleInfo = new ArticleInfoFlags({ duplicateList: true, concepts: true, categories: true, location: true, image: true, conceptInfo: new ConceptInfoFlags({trendingScore: true}) });
8
- const returnInfo = new ReturnInfo({articleInfo});
9
- const requestArticlesInfo = new RequestArticlesInfo({count: 30, returnInfo: returnInfo});
10
-
11
- const MAX_RESULTS = 100;
12
- const query = new QueryArticlesIter(er, {keywords: "Tesla Inc", maxItems: MAX_RESULTS});
13
- query.execQuery((item) => {
14
- console.info(item);
15
- });
16
-
17
- // search for the phrase "Barack Obama" - both words have to appear together
18
- const q1 = new QueryArticles({keywords: "Barack Obama"});
19
- er.execQuery(q1).then((response) => {
20
- console.info(response);
21
- });
22
-
23
- // search for articles that mention both of the two words - maybe together, maybe apart
24
- // this form of specifying multiple keywords, concepts, etc is now deprecated. When you have a list,
25
- // use it with QueryItems.AND() or QueryItems.OR() to explicitly specify how the query should be processed
26
- const q2 = new QueryArticles({keywords: ["Barack", "Obama"]});
27
- // set some custom information that should be returned as a result of the query
28
- q2.setRequestedResult(requestArticlesInfo);
29
- er.execQuery(q2).then((response) => {
30
- console.info(response);
31
- });
32
-
33
- // search for articles that mention both of the two words - maybe together, maybe apart
34
- // the correct way of specifying multiple keywords - using QueryItems.AND or .OR classes
35
- const q3 = new QueryArticles({keywords: QueryItems.AND(["Barack", "Obama"])});
36
- // set some custom information that should be returned as a result of the query
37
- q3.setRequestedResult(requestArticlesInfo);
38
- er.execQuery(q3).then((response) => {
39
- console.info(response);
40
- });
41
-
42
- // search for articles that mention the phrase "Barack Obama" or Trump
43
- const q4 = new QueryArticles({keywords: QueryItems.AND(["Barack Obama", "Trump"])});
44
- q4.setRequestedResult(requestArticlesInfo);
45
- er.execQuery(q4).then((response) => {
46
- console.info(response);
47
- });
48
-
49
- // if you already have some articles that you have received from Event Registry
50
- // for which you would like to obtain some potentially updated metadata (shared counts, event uri)
51
- // you can use the query shown below. When making such a query you can specify up to 100 article uris in a call.
52
- const q = QueryArticles.initWithArticleUriList(["934903913", "934902493", "934902499", "934902488", "934899375", "934900984", "934890360", "934888250"]);
53
- const res = er.execQuery(q);
54
-
55
- /**
56
- * Search for articles that:
57
- * - mentions the concept Samsung
58
- * - mention the phrase "iphone" in the article title
59
- * - by BBC or by any news source located in Germany
60
- * - in English or German language
61
- * - return results sorted by relevance to the query (instead of "date" which is default)
62
- */
63
- Promise.all([
64
- er.getConceptUri("Samsung"),
65
- er.getSourceUri("bbc"),
66
- er.getLocationUri("Germany"),
67
- ]).then(([samsungUri, bbcUri, germanyUri]) => {
68
- const query1 = new QueryArticles({
69
- conceptUri: samsungUri,
70
- keywords: "iphone",
71
- keywordsLoc: "title",
72
- lang: ["eng", "deu"],
73
- sourceUri: bbcUri,
74
- sourceLocationUri: germanyUri,
75
- });
76
- query1.setRequestedResult(new RequestArticlesInfo({sortBy: "rel"}));
77
- return er.execQuery(query1);
78
- }).then((response) => {
79
- console.log(response);
80
- });
81
-
82
- /**
83
- * Find articles that:
84
- * - are related to business (categorized into business category)
85
- * - were published between 1st and 20th August 2018
86
- * - don't mention Trump in the article title
87
- * - are not a duplicate (copy) of another article
88
- * - are from a news source that is among top 20 percentile of sources
89
- * - return results sorted from most shared on social media to least
90
- */
91
- er.getCategoryUri("business").then((businessUri) => {
92
- const query1 = new QueryArticles({
93
- categoryUri: businessUri,
94
- dateStart: "2018-08-01",
95
- dateEnd: "2018-08-20",
96
- ignoreKeywords: "Trump",
97
- ignoreKeywordsLoc: "title",
98
- isDuplicateFilter: "skipDuplicates",
99
- startSourceRankPercentile: 0,
100
- endSourceRankPercentile: 20,
101
- });
102
- query1.setRequestedResult(new RequestArticlesInfo({sortBy: "socialScore"}));
103
- return er.execQuery(query1);
104
- }).then((response) => {
105
- console.log(response);
106
- });
107
-
108
- // USE OF ITERATOR
109
- // example of using the QueryArticlesIter to easily iterate through all results matching the search
110
-
111
- // Search for articles mentioning George Clooney that were reported from sources from Spain or sources from Los Angeles
112
- // iterator class simplifies retrieving and listing the list of matching articles
113
- // by specifying maxItems we say that we want to retrieve maximum 500 articles (without specifying the parameter we would iterate through all results)
114
- // the results will be sorted from those that are from highest ranked news sources down
115
-
116
- Promise.all([
117
- er.getConceptUri("George Clooney"),
118
- er.getLocationUri("Spain"),
119
- er.getLocationUri("Los Angeles"),
120
- ]).then(([clooneyUri, spainUri, laUri]) => {
121
- const iterOpts = {
122
- sortBy: "sourceAlexaGlobalRank",
123
- maxItems: 500,
124
- returnInfo: new ReturnInfo({articleInfo: new ArticleInfoFlags({concepts: true, categories: true, location: true, image: true})}),
125
- conceptUri: clooneyUri,
126
- sourceLocationUri: QueryItems.OR([spainUri, laUri]),
127
- };
128
- const q5 = new QueryArticlesIter(er, iterOpts);
129
- q5.execQuery((item) => {
130
- console.info(item);
131
- });
132
- });
133
-
134
- // query articles using the QueryArticles class
135
- // old way of iterating through the pages of results - requesting results page by page
136
- async function fetchArticlePage(query: QueryArticles, page: number) {
137
- query.setRequestedResult(new RequestArticlesInfo({page}));
138
- return await er.execQuery(query);
139
- }
140
-
141
- async function fetchArticles(conceptUri) {
142
- await er.getConceptUri(conceptUri);
143
- const query = new QueryArticles({conceptUri});
144
- let page = 1;
145
- while (true) {
146
- const response = await fetchArticlePage(query, page);
147
- for (const article of _.get(response, "articles.results", [])) {
148
- console.info(article.uri);
149
- }
150
- if (page >= _.get(response, "articles.pages")) {
151
- break;
152
- }
153
- page++;
154
- }
155
- }
156
-
157
- // articles published between 2016-03-22 and 2016-03-23
158
- // mentioning Brussels
159
- // published by New York Times
160
- const uriPromises1 = [er.getConceptUri("Brussels"), er.getNewsSourceUri("New York Times")];
161
- Promise.all(uriPromises1).then(([brusselsUri, nytUri]) => {
162
- const queryArticlesOpts = {
163
- dateStart: "2016-03-22",
164
- dateEnd: "2016-03-23",
165
- conceptUri: brusselsUri,
166
- sourceUri: nytUri,
167
- };
168
- const q6 = new QueryArticles(queryArticlesOpts);
169
- // return details about the articles, including the concepts, categories, location and image
170
- q6.setRequestedResult(requestArticlesInfo);
171
- return er.execQuery(q6);
172
- });
173
-
174
- // RECENT ACTIVITY
175
- // example of querying most recently added content related to a particular thing
176
- // get latest articles about Obama
177
-
178
- er.getConceptUri("Obama").then((conceptUri) => {
179
- const q7 = new QueryArticles({conceptUri});
180
- q7.setRequestedResult(new RequestArticlesRecentActivity());
181
- const res1 = er.execQuery(q7);
182
- q7.setRequestedResult(new RequestArticlesRecentActivity({updatesAfterTm: _.get(res1, "recentActivity.newestUpdate")}));
183
- // get only the matching articles that were added since the last call
184
- const res2 = er.execQuery(q7);
185
- });
186
-
187
- // COMPLEX QUERIES
188
- // examples of complex queries that combine various OR and AND operators
189
- // prepare some variables used in the queries
190
-
191
- const uriPromises2 = [
192
- er.getConceptUri("Trump"),
193
- er.getConceptUri("Obama"),
194
- er.getCategoryUri("politics"),
195
- er.getConceptUri("merkel"),
196
- er.getCategoryUri("business"),
197
- ];
198
-
199
- Promise.all(uriPromises2).then(([trumpUri, obamaUri, politicsUri, merkelUri, businessUri]) => {
200
- // find articles that (1) were published on 2017-04-22 and (2) are either about Obama or mention keyword Trump and (3) are related to business
201
- const cq1 = new ComplexArticleQuery(CombinedQuery.AND([
202
- new BaseQuery({dateStart: "2017-04-22", dateEnd: "2017-04-22"}),
203
- CombinedQuery.OR([
204
- new BaseQuery({conceptUri: QueryItems.OR([obamaUri])}),
205
- new BaseQuery({keyword: "Trump"}),
206
- ]),
207
- new BaseQuery({categoryUri: businessUri}),
208
- ]));
209
- const query1 = QueryArticles.initWithComplexQuery(cq1);
210
- const res1 = er.execQuery(query1);
211
-
212
- // find articles that are both about Obama and Trump and are not in English or German language
213
- const cq2 = new ComplexArticleQuery(new BaseQuery({
214
- conceptUri: QueryItems.AND([obamaUri, trumpUri]),
215
- exclude: new BaseQuery({lang: QueryItems.OR(["eng", "deu"])}),
216
- }));
217
- const query2 = QueryArticles.initWithComplexQuery(cq2);
218
- const res2 = er.execQuery(query2);
219
-
220
- // get articles that were published on 2017-02-05 or are about trump
221
- // or are about politics or are about Merkel and business
222
- // and are not published on 2017-02-05 or are about Obama
223
- const qStr = `
224
- {
225
- "$query": {
226
- "$or": [
227
- { "dateStart": "2017-02-05", "dateEnd": "2017-02-05" },
228
- { "conceptUri": "${trumpUri}" },
229
- { "categoryUri": "${politicsUri}" },
230
- {
231
- "$and": [
232
- { "conceptUri": "${merkelUri}" },
233
- { "categoryUri": "${businessUri}" }
234
- ]
235
- }
236
- ],
237
- "$not": {
238
- "$or": [
239
- { "dateStart": "2017-02-04", "dateEnd": "2017-02-04" },
240
- { "conceptUri": "${obamaUri}" }
241
- ]
242
- }
243
- }
244
- }
245
- `;
246
- const query3 = QueryArticles.initWithComplexQuery(qStr);
247
- const res3 = er.execQuery(query3);
248
- });
@@ -1,99 +0,0 @@
1
- // examples that show how to obtain information about an individual event
2
- import {
3
- ConceptInfoFlags,
4
- EventRegistry,
5
- QueryEvent,
6
- QueryEventArticlesIter,
7
- RequestEventArticles,
8
- RequestEventArticleTrend,
9
- RequestEventInfo,
10
- RequestEventKeywordAggr,
11
- RequestEventSimilarEvents,
12
- RequestEventSourceAggr,
13
- ReturnInfo,
14
- } from "eventregistry";
15
- import * as _ from "lodash";
16
-
17
- //
18
- // NOTE: if you don't have access to historical data, you have to change the event URI
19
- // to some recent event that you can access in order to run the example
20
- //
21
-
22
- const eventUri = "eng-2940883";
23
-
24
- const er = new EventRegistry();
25
-
26
- // iterate over all articles that belong to a particular event with a given URI
27
- // limit to only articles in English language
28
- const iter1 = new QueryEventArticlesIter(er, eventUri);
29
- iter1.execQuery((article) => {
30
- console.info(article);
31
- });
32
-
33
- const iter2 = new QueryEventArticlesIter(er, eventUri, {keywords: "Obama", keywordsLoc: "title"});
34
- iter2.execQuery((article) => {
35
- console.info(article);
36
- });
37
-
38
- const iter3 = new QueryEventArticlesIter(er, eventUri, { lang: ["eng", "deu"] });
39
- iter3.execQuery((article) => {
40
- console.info(article);
41
- });
42
-
43
- er.getLocationUri("United States").then((unitedStatesUri) => {
44
- const iter4 = new QueryEventArticlesIter(er, eventUri, {sourceLocationUri: unitedStatesUri});
45
- iter4.execQuery((article) => {
46
- console.info(article);
47
- });
48
- });
49
-
50
- // get event info about event with a particular uri
51
- const q1 = new QueryEvent(eventUri);
52
- const returnInfo = new ReturnInfo({conceptInfo: new ConceptInfoFlags({lang: ["eng", "spa", "slv"]})});
53
- const requestEventInfo = new RequestEventInfo(returnInfo);
54
- q1.setRequestedResult(requestEventInfo);
55
- const res1 = er.execQuery(q1);
56
-
57
- // get list of 10 articles about the event
58
- const requestEventArticles = new RequestEventArticles({page: 1, count: 10});
59
- // get 10 articles about the event (any language is ok) that are closest to the center of the event
60
- q1.setRequestedResult(requestEventArticles);
61
- const res2 = er.execQuery(q1);
62
-
63
- //
64
- // OTHER AGGREGATES ABOUT THE EVENT
65
- //
66
-
67
- // get information about how reporting about the event was trending over time
68
- q1.setRequestedResult(new RequestEventArticleTrend());
69
- const res3 = er.execQuery(q1);
70
-
71
- // get the tag cloud of top words for the event
72
- q1.setRequestedResult(new RequestEventKeywordAggr());
73
- const res4 = er.execQuery(q1);
74
-
75
- // get the tag cloud of top words for the event
76
- q1.setRequestedResult(new RequestEventSourceAggr());
77
- const res5 = er.execQuery(q1);
78
-
79
- Promise.all([
80
- er.getConceptUri("Trump"),
81
- er.getConceptUri("Obama"),
82
- er.getConceptUri("Richard Nixon"),
83
- er.getConceptUri("republican party"),
84
- er.getConceptUri("democrat party"),
85
- ]).then(([trumpUri, obamaUri, nixonUri, republicanUri, democratUri]) => {
86
- q1.setRequestedResult(new RequestEventSimilarEvents({conceptInfoList: [
87
- {uri: trumpUri, wgt: 100},
88
- {uri: obamaUri, wgt: 100},
89
- {uri: nixonUri, wgt: 30},
90
- {uri: republicanUri, wgt: 30},
91
- {uri: democratUri, wgt: 30}
92
- ]}));
93
- const res6 = er.execQuery(q1);
94
- });
95
-
96
- // obtain in one call information about two events with given uris
97
- const q2 = new QueryEvent(["spa-32", "spa-45"]);
98
- q2.setRequestedResult(new RequestEventArticles({page: 1, count: 100}));
99
- const res7 = er.execQuery(q2);