Skip to content

Event for your text

Gregor Leban edited this page Mar 5, 2017 · 6 revisions

Do you have some recent text - maybe from some article, blog post or caption - that you think is talking about an event. Would you like to match that text to an event and maybe get more information about the event, such as date, location, articles about it, etc.? In this case, you can use the GetEventForText class.

from eventregistry import *
er = EventRegistry(apiKey = YOUR_API_KEY)
q = GetEventForText(er)

res = q.compute("Croatian leaders put the army on alert after chaos erupted on the border with Serbia, where thousands of asylum-seekers poured into the country")

By calling the compute method and passing it the text you can find the most similar current events. The returned information contained in res is of the following form:

[
    {
        "cosSim": 0.07660648086468567,
        "eventUri": "4969",
        "storyUri": "eng-af6ce79f-cb91-4010-8ddf-7ad924bc5638-40591"
    },
    {
        "cosSim": 0.05851939237670918,
        "eventUri": "5157",
        "storyUri": "eng-af6ce79f-cb91-4010-8ddf-7ad924bc5638-56286"
    },
    // remaining items
]

The list of JSON objects contains the events that are most similar to the events that are currently happening in the world. If you wish to obtain more information about these events just use the QueryEvent class and pass to it the eventUri value(s).