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,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,242 +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
|
-
// search for the phrase "Barack Obama" - both words have to appear together
|
|
12
|
-
const q1 = new QueryArticles({keywords: "Barack Obama"});
|
|
13
|
-
er.execQuery(q1).then((response) => {
|
|
14
|
-
console.info(response);
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
// search for articles that mention both of the two words - maybe together, maybe apart
|
|
18
|
-
// this form of specifying multiple keywords, concepts, etc is now deprecated. When you have a list,
|
|
19
|
-
// use it with QueryItems.AND() or QueryItems.OR() to explicitly specify how the query should be processed
|
|
20
|
-
const q2 = new QueryArticles({keywords: ["Barack", "Obama"]});
|
|
21
|
-
// set some custom information that should be returned as a result of the query
|
|
22
|
-
q2.setRequestedResult(requestArticlesInfo);
|
|
23
|
-
er.execQuery(q2).then((response) => {
|
|
24
|
-
console.info(response);
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
// search for articles that mention both of the two words - maybe together, maybe apart
|
|
28
|
-
// the correct way of specifying multiple keywords - using QueryItems.AND or .OR classes
|
|
29
|
-
const q3 = new QueryArticles({keywords: QueryItems.AND(["Barack", "Obama"])});
|
|
30
|
-
// set some custom information that should be returned as a result of the query
|
|
31
|
-
q3.setRequestedResult(requestArticlesInfo);
|
|
32
|
-
er.execQuery(q3).then((response) => {
|
|
33
|
-
console.info(response);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
// search for articles that mention the phrase "Barack Obama" or Trump
|
|
37
|
-
const q4 = new QueryArticles({keywords: QueryItems.AND(["Barack Obama", "Trump"])});
|
|
38
|
-
q4.setRequestedResult(requestArticlesInfo);
|
|
39
|
-
er.execQuery(q4).then((response) => {
|
|
40
|
-
console.info(response);
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
// if you already have some articles that you have received from Event Registry
|
|
44
|
-
// for which you would like to obtain some potentially updated metadata (shared counts, event uri)
|
|
45
|
-
// you can use the query shown below. When making such a query you can specify up to 100 article uris in a call.
|
|
46
|
-
const q = QueryArticles.initWithArticleUriList(["934903913", "934902493", "934902499", "934902488", "934899375", "934900984", "934890360", "934888250"]);
|
|
47
|
-
const res = er.execQuery(q);
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* Search for articles that:
|
|
51
|
-
* - mentions the concept Samsung
|
|
52
|
-
* - mention the phrase "iphone" in the article title
|
|
53
|
-
* - by BBC or by any news source located in Germany
|
|
54
|
-
* - in English or German language
|
|
55
|
-
* - return results sorted by relevance to the query (instead of "date" which is default)
|
|
56
|
-
*/
|
|
57
|
-
Promise.all([
|
|
58
|
-
er.getConceptUri("Samsung"),
|
|
59
|
-
er.getSourceUri("bbc"),
|
|
60
|
-
er.getLocationUri("Germany"),
|
|
61
|
-
]).then(([samsungUri, bbcUri, germanyUri]) => {
|
|
62
|
-
const query1 = new QueryArticles({
|
|
63
|
-
conceptUri: samsungUri,
|
|
64
|
-
keywords: "iphone",
|
|
65
|
-
keywordsLoc: "title",
|
|
66
|
-
lang: ["eng", "deu"],
|
|
67
|
-
sourceUri: bbcUri,
|
|
68
|
-
sourceLocationUri: germanyUri,
|
|
69
|
-
});
|
|
70
|
-
query1.setRequestedResult(new RequestArticlesInfo({sortBy: "rel"}));
|
|
71
|
-
return er.execQuery(query1);
|
|
72
|
-
}).then((response) => {
|
|
73
|
-
console.log(response);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* Find articles that:
|
|
78
|
-
* - are related to business (categorized into business category)
|
|
79
|
-
* - were published between 1st and 20th August 2018
|
|
80
|
-
* - don't mention Trump in the article title
|
|
81
|
-
* - are not a duplicate (copy) of another article
|
|
82
|
-
* - are from a news source that is among top 20 percentile of sources
|
|
83
|
-
* - return results sorted from most shared on social media to least
|
|
84
|
-
*/
|
|
85
|
-
er.getCategoryUri("business").then((businessUri) => {
|
|
86
|
-
const query1 = new QueryArticles({
|
|
87
|
-
categoryUri: businessUri,
|
|
88
|
-
dateStart: "2018-08-01",
|
|
89
|
-
dateEnd: "2018-08-20",
|
|
90
|
-
ignoreKeywords: "Trump",
|
|
91
|
-
ignoreKeywordsLoc: "title",
|
|
92
|
-
isDuplicateFilter: "skipDuplicates",
|
|
93
|
-
startSourceRankPercentile: 0,
|
|
94
|
-
endSourceRankPercentile: 20,
|
|
95
|
-
});
|
|
96
|
-
query1.setRequestedResult(new RequestArticlesInfo({sortBy: "socialScore"}));
|
|
97
|
-
return er.execQuery(query1);
|
|
98
|
-
}).then((response) => {
|
|
99
|
-
console.log(response);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
// USE OF ITERATOR
|
|
103
|
-
// example of using the QueryArticlesIter to easily iterate through all results matching the search
|
|
104
|
-
|
|
105
|
-
// Search for articles mentioning George Clooney that were reported from sources from Spain or sources from Los Angeles
|
|
106
|
-
// iterator class simplifies retrieving and listing the list of matching articles
|
|
107
|
-
// by specifying maxItems we say that we want to retrieve maximum 500 articles (without specifying the parameter we would iterate through all results)
|
|
108
|
-
// the results will be sorted from those that are from highest ranked news sources down
|
|
109
|
-
|
|
110
|
-
Promise.all([
|
|
111
|
-
er.getConceptUri("George Clooney"),
|
|
112
|
-
er.getLocationUri("Spain"),
|
|
113
|
-
er.getLocationUri("Los Angeles"),
|
|
114
|
-
]).then(([clooneyUri, spainUri, laUri]) => {
|
|
115
|
-
const iterOpts = {
|
|
116
|
-
sortBy: "sourceAlexaGlobalRank",
|
|
117
|
-
maxItems: 500,
|
|
118
|
-
returnInfo: new ReturnInfo({articleInfo: new ArticleInfoFlags({concepts: true, categories: true, location: true, image: true})}),
|
|
119
|
-
conceptUri: clooneyUri,
|
|
120
|
-
sourceLocationUri: QueryItems.OR([spainUri, laUri]),
|
|
121
|
-
};
|
|
122
|
-
const q5 = new QueryArticlesIter(er, iterOpts);
|
|
123
|
-
q5.execQuery((item) => {
|
|
124
|
-
console.info(item);
|
|
125
|
-
});
|
|
126
|
-
});
|
|
127
|
-
|
|
128
|
-
// query articles using the QueryArticles class
|
|
129
|
-
// old way of iterating through the pages of results - requesting results page by page
|
|
130
|
-
async function fetchArticlePage(query: QueryArticles, page: number) {
|
|
131
|
-
query.setRequestedResult(new RequestArticlesInfo({page}));
|
|
132
|
-
return await er.execQuery(query);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
async function fetchArticles(conceptUri) {
|
|
136
|
-
await er.getConceptUri(conceptUri);
|
|
137
|
-
const query = new QueryArticles({conceptUri});
|
|
138
|
-
let page = 1;
|
|
139
|
-
while (true) {
|
|
140
|
-
const response = await fetchArticlePage(query, page);
|
|
141
|
-
for (const article of _.get(response, "articles.results", [])) {
|
|
142
|
-
console.info(article.uri);
|
|
143
|
-
}
|
|
144
|
-
if (page >= _.get(response, "articles.pages")) {
|
|
145
|
-
break;
|
|
146
|
-
}
|
|
147
|
-
page++;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
// articles published between 2016-03-22 and 2016-03-23
|
|
152
|
-
// mentioning Brussels
|
|
153
|
-
// published by New York Times
|
|
154
|
-
const uriPromises1 = [er.getConceptUri("Brussels"), er.getNewsSourceUri("New York Times")];
|
|
155
|
-
Promise.all(uriPromises1).then(([brusselsUri, nytUri]) => {
|
|
156
|
-
const queryArticlesOpts = {
|
|
157
|
-
dateStart: "2016-03-22",
|
|
158
|
-
dateEnd: "2016-03-23",
|
|
159
|
-
conceptUri: brusselsUri,
|
|
160
|
-
sourceUri: nytUri,
|
|
161
|
-
};
|
|
162
|
-
const q6 = new QueryArticles(queryArticlesOpts);
|
|
163
|
-
// return details about the articles, including the concepts, categories, location and image
|
|
164
|
-
q6.setRequestedResult(requestArticlesInfo);
|
|
165
|
-
return er.execQuery(q6);
|
|
166
|
-
});
|
|
167
|
-
|
|
168
|
-
// RECENT ACTIVITY
|
|
169
|
-
// example of querying most recently added content related to a particular thing
|
|
170
|
-
// get latest articles about Obama
|
|
171
|
-
|
|
172
|
-
er.getConceptUri("Obama").then((conceptUri) => {
|
|
173
|
-
const q7 = new QueryArticles({conceptUri});
|
|
174
|
-
q7.setRequestedResult(new RequestArticlesRecentActivity());
|
|
175
|
-
const res1 = er.execQuery(q7);
|
|
176
|
-
q7.setRequestedResult(new RequestArticlesRecentActivity({updatesAfterTm: _.get(res1, "recentActivity.newestUpdate")}));
|
|
177
|
-
// get only the matching articles that were added since the last call
|
|
178
|
-
const res2 = er.execQuery(q7);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
// COMPLEX QUERIES
|
|
182
|
-
// examples of complex queries that combine various OR and AND operators
|
|
183
|
-
// prepare some variables used in the queries
|
|
184
|
-
|
|
185
|
-
const uriPromises2 = [
|
|
186
|
-
er.getConceptUri("Trump"),
|
|
187
|
-
er.getConceptUri("Obama"),
|
|
188
|
-
er.getCategoryUri("politics"),
|
|
189
|
-
er.getConceptUri("merkel"),
|
|
190
|
-
er.getCategoryUri("business"),
|
|
191
|
-
];
|
|
192
|
-
|
|
193
|
-
Promise.all(uriPromises2).then(([trumpUri, obamaUri, politicsUri, merkelUri, businessUri]) => {
|
|
194
|
-
// 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
|
|
195
|
-
const cq1 = new ComplexArticleQuery(CombinedQuery.AND([
|
|
196
|
-
new BaseQuery({dateStart: "2017-04-22", dateEnd: "2017-04-22"}),
|
|
197
|
-
CombinedQuery.OR([
|
|
198
|
-
new BaseQuery({conceptUri: QueryItems.OR([obamaUri])}),
|
|
199
|
-
new BaseQuery({keyword: "Trump"}),
|
|
200
|
-
]),
|
|
201
|
-
new BaseQuery({categoryUri: businessUri}),
|
|
202
|
-
]));
|
|
203
|
-
const query1 = QueryArticles.initWithComplexQuery(cq1);
|
|
204
|
-
const res1 = er.execQuery(query1);
|
|
205
|
-
|
|
206
|
-
// find articles that are both about Obama and Trump and are not in English or German language
|
|
207
|
-
const cq2 = new ComplexArticleQuery(new BaseQuery({
|
|
208
|
-
conceptUri: QueryItems.AND([obamaUri, trumpUri]),
|
|
209
|
-
exclude: new BaseQuery({lang: QueryItems.OR(["eng", "deu"])}),
|
|
210
|
-
}));
|
|
211
|
-
const query2 = QueryArticles.initWithComplexQuery(cq2);
|
|
212
|
-
const res2 = er.execQuery(query2);
|
|
213
|
-
|
|
214
|
-
// get articles that were published on 2017-02-05 or are about trump
|
|
215
|
-
// or are about politics or are about Merkel and business
|
|
216
|
-
// and are not published on 2017-02-05 or are about Obama
|
|
217
|
-
const qStr = `
|
|
218
|
-
{
|
|
219
|
-
"$query": {
|
|
220
|
-
"$or": [
|
|
221
|
-
{ "dateStart": "2017-02-05", "dateEnd": "2017-02-05" },
|
|
222
|
-
{ "conceptUri": "${trumpUri}" },
|
|
223
|
-
{ "categoryUri": "${politicsUri}" },
|
|
224
|
-
{
|
|
225
|
-
"$and": [
|
|
226
|
-
{ "conceptUri": "${merkelUri}" },
|
|
227
|
-
{ "categoryUri": "${businessUri}" }
|
|
228
|
-
]
|
|
229
|
-
}
|
|
230
|
-
],
|
|
231
|
-
"$not": {
|
|
232
|
-
"$or": [
|
|
233
|
-
{ "dateStart": "2017-02-04", "dateEnd": "2017-02-04" },
|
|
234
|
-
{ "conceptUri": "${obamaUri}" }
|
|
235
|
-
]
|
|
236
|
-
}
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
`;
|
|
240
|
-
const query3 = QueryArticles.initWithComplexQuery(qStr);
|
|
241
|
-
const res3 = er.execQuery(query3);
|
|
242
|
-
});
|
|
@@ -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);
|