-
Notifications
You must be signed in to change notification settings - Fork 3
Searching for events
In order to search for events in Event Registry we provide two classes - QueryEvents
and QueryEventsIter
. Both classes can be used to find events using a set of various types of search conditions.
The class QueryEventsIter
is meant to obtain an iterator, that makes it easy to iterate over all events that match the search conditions. Alternatively, the QueryEvents
class can be used to obtain a broader range of information about the matching events in various forms. In case of QueryEvents
, the returned results can also be a timeline distribution of the matching events over time, distribution of matching events into predefined categories, list of top concepts in the matching events, etc.
The returned information about events follows the Event data model.
Example of usage
Before describing the class, here is a simple full example that prints the list of all events related to Barack Obama, from the latest to the oldest:
import {EventRegistry, QueryEventsIter} from "eventregistry";
const er = new EventRegistry({apiKey: "YOUR_API_KEY"});
er.getConceptUri("Obama").then((conceptUri) => {
const q = new QueryEventsIter(er, { conceptUri: conceptUri, sortBy: "date"});
q.execQuery((event) => {
console.info(event);
});
});
Constructor
QueryEventsIter
is a derived class from QueryEvents
. It's constructor can accept the following arguments:
new QueryEventsIter(er, {
sortBy = "rel",
sortByAsc = false,
returnInfo = new ReturnInfo(),
maxItems = -1
keywords = undefined,
conceptUri = undefined,
categoryUri = undefined,
sourceUri = undefined,
sourceLocationUri = undefined,
sourceGroupUri = undefined,
authorUri = undefined,
locationUri = undefined,
lang = undefined,
dateStart = undefined,
dateEnd = undefined,
minArticlesInEvent = undefined,
maxArticlesInEvent = undefined,
dateMentionStart = undefined,
dateMentionEnd = undefined,
ignoreKeywords = undefined,
ignoreConceptUri = undefined,
ignoreCategoryUri = undefined,
ignoreSourceUri = undefined,
ignoreSourceLocationUri = undefined,
ignoreSourceGroupUri = undefined,
ignoreAuthorUri = undefined,
ignoreLocationUri = undefined,
ignoreLang = undefined,
keywordsLoc = "body"
ignoreKeywordsLoc = "body",
})
The parameters for which you don't specify a value will be ignored. In order for the query to be valid (=it can be executed by Event Registry), it has to have at least one positive condition (conditions that start with ignore*
do not count as positive conditions). The meaning of the arguments is as follows:
-
er
: instance of theEventRegistry
class. -
sortBy
: sets the order in which the resulting events are sorted, before returning. Options:date
(by event date),rel
(relevance to the query),size
(number of articles),socialScore
(amount of shares in social media). -
sortByAsc
: should the results be sorted in ascending order. -
returnInfo
: sets the properties of various types of data that is returned (events, concepts, categories, ...). See details. -
maxItems
: max number of events to return by the iterator. Use default (-1) to simply return all the events. -
keywords
: find events where articles mention the specified keywords. A single keyword/phrase can be provided as a string, multiple keywords/phrases can be provided as a list of strings. UseQueryItems.AND()
if all provided keywords/phrases should be mentioned, orQueryItems.OR()
if any of the keywords/phrases should be mentioned. -
conceptUri
: find events where the concept with the specified concept URI is important. A single concept uri can be provided as a string, multiple concept uris can be provided as a list of strings. UseQueryItems.AND()
if all provided concepts should be mentioned, orQueryItems.OR()
if any of the concepts should be mentioned. To obtain a concept URI based on a (partial) concept label useEventRegistry.getConceptUri()
. -
categoryUri
: find events that are assigned into a particular category. A single category URI can be provided as a string, multiple category URIs can be provided as a list of strings. UseQueryItems.AND()
if all provided categories should be mentioned, orQueryItems.OR()
if any of the categories should be mentioned. A category URI can be obtained based on a (partial) category name usingEventRegistry.getCategoryUri()
. -
sourceUri
: find events that contain one or more articles that have been written by a news sourcesourceUri
. If multiple sources should be considered useQueryItems.OR()
if any of the sources should report about the event, orQueryItems.AND()
if all of them need to report about that event. Source URI for a given (partial) news source name can be obtained usingEventRegistry.getNewsSourceUri()
. -
sourceLocationUri
: find events that were reported by news sources located in the given geographic location. If multiple source locations are provided, then put them into a list insideQueryItems.OR()
. Location URI can either be a city or a country. Location URI for a given (partial) name can be obtained usingEventRegistry.getLocationUri()
. -
sourceGroupUri
: find events that were reported by news sources that are assigned to the predefined source group(s). If multiple source groups are provided, then put them into a list insideQueryItems.OR()
. Source group URI for a given name can be obtained usingEventRegistry.getSourceGroupUri()
. -
authorUri
: find events that contain authors, which were written by a specific author. If multiple sources should be considered useQueryItems.OR()
if any of the authors should report about the event, orQueryItems.AND()
if all of them need to report about that event. To obtain the author URI based on a (partial) author name and potentially source domain name useEventRegistry.getAuthorUri()
. -
locationUri
: find events that occured at a particular location. Location URI can either be a city or a country. If multiple locations are provided, resulting events have to match any of the locations. Location URI for a given name can be obtained usingEventRegistry.getLocationUri()
. -
lang
: find events for which we found articles in the specified language. If more than one language is specified, resulting events has to be reported in any of the languages. See supported languages for the list of language codes to use. -
dateStart
: find events that occured on or afterdateStart
. Date should be provided in YYYY-MM-DD format,datetime.time
ordatetime.datetime
. -
dateEnd
: find events that occured before or ondateEnd
. Date should be provided in YYYY-MM-DD format,datetime.time
ordatetime.datetime
. -
minArticlesInEvent
: find events that have been reported in at leastminArticlesInEvent
articles (regardless of language). -
maxArticlesInEvent
: find events that have not been reported in more thanmaxArticlesInEvent
articles (regardless of language). -
dateMentionStart
: find events where articles explicitly mention a date that is equal or greater thandateMentionStart
. -
dateMentionEnd
: find events where articles explicitly mention a date that is lower or equal todateMentionEnd
. -
ignoreKeywords
: ignore events where articles about the event mention the provided keywords. Specify value as string or list inQueryItems.OR()
orQueryItems.AND()
. -
ignoreConceptUri
: ignore events that are about all provided concepts. Specify value as string or list inQueryItems.OR()
orQueryItems.AND()
. -
ignoreCategoryUri
: ignore events that are about the provided set of categories. Specify value as string or list inQueryItems.OR()
orQueryItems.AND()
. -
ignoreSourceUri
: ignore events that have have articles which have been reported by the specified list of news sources. Specify value as string or list inQueryItems.OR()
. -
ignoreSourceLocationUri
: ignore events that have have articles which have been reported by news sources located at the specified geographic location(s). Specify value as string or list inQueryItems.OR()
. -
ignoreSourceGroupUri
: ignore events that have have articles which have been reported by the news sources assigned to the specified source groups. Specify value as string or list inQueryItems.OR()
. -
ignoreAuthorUri
: ignore events that contain articles that were reported by the specified author(s). Specify value as string or list inQueryItems.OR()
. -
ignoreLang
: ignore events that are reported in any of the provided languages. Specify value as string or list inQueryItems.OR()
. See supported languages for the list of language codes to use. -
ignoreLocationUri
: ignore events that occured in any of the provided locations. A location can be a city or a place. Specify value as string or list inQueryItems.OR()
. -
keywordsLoc
: where should we look when searching using the keywords provided bykeywords
parameter. "body" (default), "title", or "body,title" -
ignoreKeywordsLoc
: where should we look when data should be used when searching using the keywords provided byignoreKeywords
parameter. "body" (default), "title", or "body,title"
When two or more parameters are specified in the constructor, the results will be computed in a way so that all conditions will be met. For example, if you specify QueryEventsIter(keywords = "Barack Obama", conceptUri = "http://en.wikipedia.org/wiki/White_House")
then the resulting events will contain articles that mention phrase Barack Obama
and have White House
as an important concept.
Creating QueryEventsIter
using static methods
The QueryEventsIter
class can also be initialized in the following way:
QueryEventsIter.initWithComplexQuery()
is a static method that can be used to create a complex query based on the advanced query language. You can call the method by providing an instance of EventRegistry
class and an instance of ComplexEventQuery
class. Alternatively, you can also call the method with an object or a string containing the JSON object matching the language (see the examples).
Methods
The class QueryEventsIter
has one main method called execQuery()
. Which has the following format:
execQuery(callback, doneCallback);
First argument is a callback function which repeats itself when it reaches a new page or when maxItems
is reached, by default it's set to -1 so all events are fetched. So when package acquires new set of events in the background the function is called again with new data. Then inside this function you can either analyze the data or iterate through it. To clarify there is no need to call execQuery
function multiple times.
Class also has implemented Async Iterator so alternatively you can use the class in the following way:
(async () => {
const er = new EventRegistry();
const events = new QueryEventsIter(er, {/** Apply any conditions based on the aforementioned documentation */});
for await (const event of events) {
console.info(event);
}
})();
Constructor
import {EventRegistry, QueryEventsIter} from "eventregistry";
const er = new EventRegistry({apiKey: "YOUR_API_KEY"});
er.getConceptUri("Obama").then((conceptUri) => {
const q = new QueryEventsIter(er, { conceptUri: conceptUri, sortBy: "date"});
q.execQuery((event) => {
console.info(event);
});
});
Constructor
QueryEventsIter
is a derived class from QueryEvents
. It's constructor can accept the following arguments:
new QueryEvents({
returnInfo = new ReturnInfo(),
keywords = undefined,
conceptUri = undefined,
categoryUri = undefined,
sourceUri = undefined,
sourceLocationUri = undefined,
sourceGroupUri = undefined,
authorUri = undefined,
locationUri = undefined,
lang = undefined,
dateStart = undefined,
dateEnd = undefined,
minArticlesInEvent = undefined,
maxArticlesInEvent = undefined,
dateMentionStart = undefined,
dateMentionEnd = undefined,
ignoreKeywords = undefined,
ignoreConceptUri = undefined,
ignoreCategoryUri = undefined,
ignoreSourceUri = undefined,
ignoreSourceLocationUri = undefined,
ignoreSourceGroupUri = undefined,
ignoreAuthorUri = undefined,
ignoreLocationUri = undefined,
ignoreLang = undefined,
keywordsLoc = "body"
ignoreKeywordsLoc = "body",
requestedResult = new RequestEventsInfo(),
})
The parameters for which you don't specify a value will be ignored. In order for the query to be valid (=it can be executed by Event Registry), it has to have at least one positive condition (conditions that start with ignore*
do not count as positive conditions). The meaning of the arguments is as follows:
-
returnInfo
: sets the properties of various types of data that is returned (events, concepts, categories, ...). See details. -
keywords
: find events where articles mention the specified keywords. A single keyword/phrase can be provided as a string, multiple keywords/phrases can be provided as a list of strings. UseQueryItems.AND()
if all provided keywords/phrases should be mentioned, orQueryItems.OR()
if any of the keywords/phrases should be mentioned. -
conceptUri
: find events where the concept with the specified concept URI is important. A single concept uri can be provided as a string, multiple concept uris can be provided as a list of strings. UseQueryItems.AND()
if all provided concepts should be mentioned, orQueryItems.OR()
if any of the concepts should be mentioned. To obtain a concept URI based on a (partial) concept label useEventRegistry.getConceptUri()
. -
categoryUri
: find events that are assigned into a particular category. A single category URI can be provided as a string, multiple category URIs can be provided as a list of strings. UseQueryItems.AND()
if all provided categories should be mentioned, orQueryItems.OR()
if any of the categories should be mentioned. A category URI can be obtained based on a (partial) category name usingEventRegistry.getCategoryUri()
. -
sourceUri
: find events that contain one or more articles that have been written by a news sourcesourceUri
. If multiple sources should be considered useQueryItems.OR()
if any of the sources should report about the event, orQueryItems.AND()
if all of them need to report about that event. Source URI for a given (partial) news source name can be obtained usingEventRegistry.getNewsSourceUri()
. -
sourceLocationUri
: find events that were reported by news sources located in the given geographic location. If multiple source locations are provided, then put them into a list insideQueryItems.OR()
. Location URI can either be a city or a country. Location URI for a given (partial) name can be obtained usingEventRegistry.getLocationUri()
. -
sourceGroupUri
: find events that were reported by news sources that are assigned to the predefined source group(s). If multiple source groups are provided, then put them into a list insideQueryItems.OR()
. Source group URI for a given name can be obtained usingEventRegistry.getSourceGroupUri()
. -
authorUri
: find events that contain authors, which were written by a specific author. If multiple sources should be considered useQueryItems.OR()
if any of the authors should report about the event, orQueryItems.AND()
if all of them need to report about that event. To obtain the author URI based on a (partial) author name and potentially source domain name useEventRegistry.getAuthorUri()
. -
locationUri
: find events that occured at a particular location. Location URI can either be a city or a country. If multiple locations are provided, resulting events have to match any of the locations. Location URI for a given name can be obtained usingEventRegistry.getLocationUri()
. -
lang
: find events for which we found articles in the specified language. If more than one language is specified, resulting events has to be reported in any of the languages. See supported languages for the list of language codes to use. -
dateStart
: find events that occured on or afterdateStart
. Date should be provided in YYYY-MM-DD format,datetime.time
ordatetime.datetime
. -
dateEnd
: find events that occured before or ondateEnd
. Date should be provided in YYYY-MM-DD format,datetime.time
ordatetime.datetime
. -
minArticlesInEvent
: find events that have been reported in at leastminArticlesInEvent
articles (regardless of language). -
maxArticlesInEvent
: find events that have not been reported in more thanmaxArticlesInEvent
articles (regardless of language). -
dateMentionStart
: find events where articles explicitly mention a date that is equal or greater thandateMentionStart
. -
dateMentionEnd
: find events where articles explicitly mention a date that is lower or equal todateMentionEnd
. -
ignoreKeywords
: ignore events where articles about the event mention the provided keywords. Specify value as string or list inQueryItems.OR()
orQueryItems.AND()
. -
ignoreConceptUri
: ignore events that are about all provided concepts. Specify value as string or list inQueryItems.OR()
orQueryItems.AND()
. -
ignoreCategoryUri
: ignore events that are about the provided set of categories. Specify value as string or list inQueryItems.OR()
orQueryItems.AND()
. -
ignoreSourceUri
: ignore events that have have articles which have been reported by the specified list of news sources. Specify value as string or list inQueryItems.OR()
. -
ignoreSourceLocationUri
: ignore events that have have articles which have been reported by news sources located at the specified geographic location(s). Specify value as string or list inQueryItems.OR()
. -
ignoreSourceGroupUri
: ignore events that have have articles which have been reported by the news sources assigned to the specified source groups. Specify value as string or list inQueryItems.OR()
. -
ignoreAuthorUri
: ignore events that contain articles that were reported by the specified author(s). Specify value as string or list inQueryItems.OR()
. -
ignoreLang
: ignore events that are reported in any of the provided languages. Specify value as string or list inQueryItems.OR()
. See supported languages for the list of language codes to use. -
ignoreLocationUri
: ignore events that occured in any of the provided locations. A location can be a city or a place. Specify value as string or list inQueryItems.OR()
. -
keywordsLoc
: where should we look when searching using the keywords provided bykeywords
parameter. "body" (default), "title", or "body,title" -
ignoreKeywordsLoc
: where should we look when data should be used when searching using the keywords provided byignoreKeywords
parameter. "body" (default), "title", or "body,title" -
requestedResult
: the information that should be returned as the result of the query.
Example of usage
Let's look at an example of how it can be used:
import {EventRegistry, QueryEvents} from "eventregistry";
const er = new EventRegistry({apiKey: "YOUR_API_KEY"});
Promise.all([er.getConceptUri("Obama"), er.getNewsSourceUri("bbc")]).then(([conceptUri, sourceUri]) => {
const q = new QueryEvents({
conceptUri: conceptUri, // get events related to Barack Obama
sourceUri: sourceUri, // that have been reported also by BBC
});
// return top 5 locations and organizations mentioned the most in these events
const returnInfo = new ReturnInfo({conceptInfo: new ConceptInfoFlags({type: ["org", "loc"]})});
const requestEventsConceptAggr = new RequestEventsConceptAggr({conceptCount: 5, returnInfo: returnInfo});
q.setRequestedResult(requestEventsConceptAggr );
return er.execQuery(q); // execute the query and return the promise
})
Creating QueryEvents
using static methods
The QueryEvents
class can also be initialized in two other ways:
QueryEvents.initWithEventUriList()
is a static method that can be used to specify the set of event URIs that you want to use as the result. In this case, no query conditions are used and this set is used as the resulting set. All the return information about the events will be based on this set of events.
QueryEvents.initWithComplexQuery()
is another static method that can be used to create a complex query based on the advanced query language. You can call the method by providing an instance of ComplexEventQuery
class. Alternatively, you can also call the method with an object or a string containing the JSON object matching the language (see the examples).
When executing the query, there will be a set of events that will match the specified criteria. What information about these events is to be returned however still needs to be determined. Do you want to get the list of matching events? Maybe just the timeline when they happened? Maybe information where they happened?
The information to be returned by the matching events is determined by calling the setRequestedResult()
method. The setRequestedResult()
accepts as an argument an instance that has a base class RequestEvents
. Customers subscribed to a plan can additionally also use the addRequestedResult()
method which also accepts the same arguments. The only difference between the methods is that by calling addRequestedResult()
multiple times on a QueryEvents
instance, you can retrieve multiple results with a single query. Free users are only allowed one requested result per call and should just use the setRequestedResult()
method. Below are the classes that can be specified in the addRequestedResult()
and setRequestedResult()
calls:
RequestEventsInfo
new RequestEventsInfo({
page = 1,
count = 20,
sortBy = "date",
sortByAsc = false,
returnInfo = new ReturnInfo(),
} = {});
RequestEventsInfo
class provides detailed information about the resulting events.
-
page
: determines the page of the results to return (starting from 1). -
count
: determines the number of events to return. Max events that can be returned per call is 50. -
sortBy
: sets the order in which the resulting events are first sorted, before returning. Options:date
(by event date),rel
(relevance to the query),size
(number of articles),socialScore
(amount of shares in social media). -
sortByAsc
: should the results be sorted in ascending order. -
returnInfo
: sets the properties of various types of data that is returned (events, concepts, categories, ...). See details.
RequestEventsUriList
RequestEventsUriList
returns a simple list of event uris that match criteria. Useful if you wish to obtain the full list of event URIs in a single query.
RequestEventsTimeAggr
RequestEventsTimeAggr
computes how the resulting events are distributed over time.
RequestEventsKeywordAggr
RequestEventsKeywordAggr
returns the keywords that best summarize the content the resulting events.
RequestEventsLocAggr
RequestEventsLocAggr
returns the information about the geographic locations where the resulting events happened.
RequestEventsLocTimeAggr
RequestEventsLocTimeAggr
provides combined details about the location and time of the resulting events.
RequestEventsConceptGraph
new RequestEventsConceptGraph({
conceptCount = 25,
linkCount = 50,
eventsSampleSize = 500,
returnInfo = new ReturnInfo(),
} = {});
RequestEventsConceptGraph
returns a graph of concepts. Concepts are connected if they are frequently occuring in the same events.
-
conceptCount
: number of top concepts (nodes) to return. -
linkCount
: number of edges in the graph. -
eventsSampleSize
: on what sample of events should the graph be computed. -
returnInfo
: the details about the types of return data to include. See details.
RequestEventsConceptMatrix
new RequestEventsConceptMatrix({
conceptCount = 25,
measure = "pmi",
eventsSampleSize = 500,
returnInfo = new ReturnInfo(),
} = {});
RequestEventsConceptGraph
computes a matrix of concepts and their dependencies. For individual concept pairs it returns how frequently they co-occur in the resulting events and how surprising this is, based on the frequency of individual concepts.
-
measure
: the measure to be used for computing the "surprise factor". Options:pmi
(pointwise mutual information),pairTfIdf
(pair frequence * IDF of individual concepts),chiSquare
. -
eventsSampleSize
: on what sample of events should the graph be computed. -
returnInfo
: the details about the types of return data to include. See details.
RequestEventsConceptTrends
new RequestEventsConceptTrends({conceptCount = 10, returnInfo = ReturnInfo()} = {});
RequestEventsConceptTrends
provides a list of most popular concepts in the results and how they daily trend over time.
-
conceptCount
: number of top concepts to return.
RequestEventsSourceAggr
new RequestEventsSourceAggr({sourceCount = 30, returnInfo = ReturnInfo()} = {});
RequestEventsSourceAggr
provides a list of top news sources that have written the most articles in the resulting events.
-
sourceCount
: number of top news sources to return. -
returnInfo
: the details about the types of return data to include. See details.
RequestEventsDateMentionAggr
RequestEventsDateMentionAggr
provides information about the dates that have been found mentioned in the resulting events.
RequestEventsEventClusters
new RequestEventsEventClusters({keywordCount = 30, maxEventsToCluster = 10000, returnInfo = new ReturnInfo()} = {});
RequestEventsEventClusters
clusters the resulting events based on the event concepts. The resulting events are clustered repeatedly using 2-means clustering in order to provide a hierarchical view of the events split into smaller parts.
-
keywordCount
: sets the number of keywords that will be returned for each cluster on each level. -
maxEventsToCluster
: determines the maximum number of events that will be clustered.
RequestEventsCategoryAggr
RequestEventsCategoryAggr
returns information about what categories are the resulting events about.
For many users, simply providing a list of concepts, keywords, sources etc. is not sufficient and a more complex way of specifying a query is required. For such purposes, we provide a query language where conditions can be specified in particular JSON object, that resembles the query language used by the MongoDB. The grammar for the language is as follows:
ComplexEventQuery
{
"$query": CombinedQuery | BaseQuery,
}
CombinedQuery
{
"$or": [ CombinedQuery | BaseQuery, ... ],
"$and": [ CombinedQuery | BaseQuery, ... ],
"$not": null | CombinedQuery | BaseQuery
}
BaseQuery
{
"conceptUri": null | string | { "$or": [ string, ... ]} | { "$and": [ string, ... ]},
"keyword": null | string | { "$or": [ string, ... ]} | { "$and": [ string, ... ]},
"categoryUri": null | string | { "$or": [ string, ... ]} | { "$and": [ string, ... ]},
"lang": null | string | { "$or": [ string, ... ]} | { "$and": [ string, ... ]},
"sourceUri": null | string | { "$or": [ string, ... ]},
"sourceLocationUri": null | string | { "$or": [ string, ... ]},
"sourceGroupUri": null | string | { "$or": [ string, ... ]},
"locationUri": null | string | { "$or": [ string, ... ]},
"dateStart": null | string,
"dateEnd": null | string,
"dateMention": null | [string, ...],
"keywordLoc": null | "body" | "title" | "title,body",
"minArticlesInEvent": null | int,
"maxArticlesInEvent": null | int,
"$not": null | CombinedQuery | BaseQuery
}
Explanation: Each complex event query needs to be a JSON object that has a $query
key. The $query
key must contain another JSON object that should be parsable as a CombinedQuery
or a BaseQuery
. A CombinedQuery
can be used to specify a list of conditions, where all ($and
) or any ($or
) conditions should hold. The CombinedQuery
can also contain a $not
key containing another CombinedQuery
or BaseQuery
defining the results that should be excluded from the results computed by the $and
or $or
conditions. The BaseQuery
represents a JSON object with actual conditions to search for. These (positive) conditions can include concepts, keywords, categories, sources, etc to search for. If multiple conditions are specified, for example, a conceptUri
as well as a sourceUri
, then results will have to match all the conditions. The BaseQuery
can also contain the $not
key specifying results to exclude from the results matching the positive conditions of the BaseQuery
. A BaseQuery
containing only the $not
key is not a valid query (since it has no positive conditions).
Using this language you can specify queries that are not possible to express using the constructor parameters in QueryEvents
or QueryEventsIter
. Here are some examples of queries and what they would return:
A query that would return the list of events that are about Twitter or have been covered by Techcrunch or Arstechnica.
{
"$query": {
"$or": [
{ "conceptUri": "http://en.wikipedia.org/wiki/Twitter" },
{ "sourceUri": { "$or": ["techcrunch.com", "arstechnica.com"] } }
]
}
}
A query that finds events that happened in London or Berlin and were not reported in Arabic or Spanish language:
{
"$query": {
"locationUri": [
"http://en.wikipedia.org/wiki/London",
"http://en.wikipedia.org/wiki/Berlin"
],
"$not": {
"lang": {
"$or": ["ara", "spa"]
}
}
}
}
Depending on your preference, you can build such JSONs for these complex queries yourself or you can use the associated classes such as ComplexEventQuery()
, CombinedQuery()
and BaseQuery()
. Below is an example where we search for events that are either about Donald Trump or are in the Politics category, but did not occur in February 2017 or mention Barack Obama:
const er = new EventRegistry();
Promise.all([
er.getConceptUri("Trump"),
er.getConceptUri("Obama"),
er.getCategoryUri("politics")
]).then(([trumpUri, obamaUri, politicsUri]) => {
const cq = new ComplexEventQuery(CombinedQuery.OR([
new BaseQuery({conceptUri: trumpUri}),
new BaseQuery({categoryUri: politicsUri}),
], CombinedQuery.OR([
new BaseQuery({dateStart: "2017-02-04", dateEnd: "2017-02-04"}),
new BaseQuery({conceptUri: obamaUri}),
])));
const q = QueryEvents.initWithComplexQuery(cq);
q.setRequestedResult(new requestEventsInfo());
const res = er.execQuery(q);
});
If you've built the JSON query yourself, you can also use like this:
const er = new EventRegistry();
const q = QueryEvents.initWithComplexQuery("{ '$query': { ... } }");
q.setRequestedResult(new requestEventsInfo());
const res = er.execQuery(q);
In this case, you need to make sure you're providing a valid query in the JSON.
If you would like to simply iterate through the results that match the query you can of course also use QueryEventsIter.initWithComplexQuery()
instead of QueryEvents.initWithComplexQuery()
.
Core Information
Usage tracking
Terminology
EventRegistry
class
ReturnInfo
class
Data models for returned information
Finding concepts for keywords
Filtering content by news sources
Text analytics
Semantic annotation, categorization, sentiment
Searching
Searching for events
Searching for articles
Article/event info
Get event information
Get article information
Other
Supported languages
Feed of new articles/events
Social media shares
Daily trends
Correlations
Mentions in news or social media
Find event for your own text
Article URL to URI mapping