Skip to content

Commit afa4c6a

Browse files
committed
- added topic pages
1 parent 9c00c2f commit afa4c6a

5 files changed

Lines changed: 507 additions & 41 deletions

File tree

eventregistry/EventRegistry.py

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,9 @@
33
"""
44
import six, os, sys, traceback, json, re, requests, time
55
import threading
6+
67
from eventregistry.Base import *
7-
from eventregistry.EventForText import *
88
from eventregistry.ReturnInfo import *
9-
from eventregistry.Query import *
10-
from eventregistry.QueryEvents import *
11-
from eventregistry.QueryEvent import *
12-
from eventregistry.QueryArticles import *
13-
from eventregistry.QueryArticle import *
14-
from eventregistry.QueryStory import *
15-
from eventregistry.Correlations import *
16-
from eventregistry.Counts import *
17-
from eventregistry.DailyShares import *
18-
from eventregistry.Info import *
19-
from eventregistry.Recent import *
20-
from eventregistry.Trends import *
21-
from eventregistry.Analytics import *
229

2310
class EventRegistry(object):
2411
"""
@@ -347,7 +334,7 @@ def jsonRequestAnalytics(self, methodUrl, paramDict):
347334
#
348335
# suggestion methods - return type is a list of matching items
349336

350-
def suggestConcepts(self, prefix, sources = ["concepts"], lang = "eng", conceptLang = "eng", page = 1, count = 20, returnInfo = ReturnInfo()):
337+
def suggestConcepts(self, prefix, sources = ["concepts"], lang = "eng", conceptLang = "eng", page = 1, count = 20, returnInfo = ReturnInfo(), **kwargs):
351338
"""
352339
return a list of concepts that contain the given prefix. returned matching concepts are sorted based on their frequency of occurence in news (from most to least frequent)
353340
@param prefix: input text that should be contained in the concept
@@ -361,10 +348,11 @@ def suggestConcepts(self, prefix, sources = ["concepts"], lang = "eng", conceptL
361348
assert page > 0, "page parameter should be above 0"
362349
params = { "prefix": prefix, "source": sources, "lang": lang, "conceptLang": conceptLang, "page": page, "count": count}
363350
params.update(returnInfo.getParams())
351+
params.update(kwargs)
364352
return self.jsonRequest("/json/suggestConcepts", params)
365353

366354

367-
def suggestCategories(self, prefix, page = 1, count = 20, returnInfo = ReturnInfo()):
355+
def suggestCategories(self, prefix, page = 1, count = 20, returnInfo = ReturnInfo(), **kwargs):
368356
"""
369357
return a list of dmoz categories that contain the prefix
370358
@param prefix: input text that should be contained in the category name
@@ -375,10 +363,11 @@ def suggestCategories(self, prefix, page = 1, count = 20, returnInfo = ReturnInf
375363
assert page > 0, "page parameter should be above 0"
376364
params = { "prefix": prefix, "page": page, "count": count }
377365
params.update(returnInfo.getParams())
366+
params.update(kwargs)
378367
return self.jsonRequest("/json/suggestCategories", params)
379368

380369

381-
def suggestNewsSources(self, prefix, dataType = ["news", "pr", "blog"], page = 1, count = 20):
370+
def suggestNewsSources(self, prefix, dataType = ["news", "pr", "blog"], page = 1, count = 20, **kwargs):
382371
"""
383372
return a list of news sources that match the prefix
384373
@param prefix: input text that should be contained in the source name or uri
@@ -387,22 +376,25 @@ def suggestNewsSources(self, prefix, dataType = ["news", "pr", "blog"], page = 1
387376
@param count: number of returned suggestions
388377
"""
389378
assert page > 0, "page parameter should be above 0"
390-
params = { "prefix": prefix, "dataType": dataType, "count": count }
379+
params = {"prefix": prefix, "dataType": dataType, "page": page, "count": count}
380+
params.update(kwargs)
391381
return self.jsonRequest("/json/suggestSources", params)
392382

393383

394-
def suggestSourceGroups(self, prefix, page = 1, count = 20):
384+
def suggestSourceGroups(self, prefix, page = 1, count = 20, **kwargs):
395385
"""
396386
return a list of news source groups that match the prefix
397387
@param prefix: input text that should be contained in the source group name or uri
398388
@param page: page of the results (1, 2, ...)
399389
@param count: number of returned suggestions
400390
"""
401391
assert page > 0, "page parameter should be above 0"
402-
return self.jsonRequest("/json/suggestSourceGroups", { "prefix": prefix, "page": page, "count": count })
392+
params = { "prefix": prefix, "page": page, "count": count }
393+
params.update(kwargs)
394+
return self.jsonRequest("/json/suggestSourceGroups", params)
403395

404396

405-
def suggestLocations(self, prefix, sources = ["place", "country"], lang = "eng", count = 20, countryUri = None, sortByDistanceTo = None, returnInfo = ReturnInfo()):
397+
def suggestLocations(self, prefix, sources = ["place", "country"], lang = "eng", count = 20, countryUri = None, sortByDistanceTo = None, returnInfo = ReturnInfo(), **kwargs):
406398
"""
407399
return a list of geo locations (cities or countries) that contain the prefix
408400
@param prefix: input text that should be contained in the location name
@@ -415,6 +407,7 @@ def suggestLocations(self, prefix, sources = ["place", "country"], lang = "eng",
415407
"""
416408
params = { "prefix": prefix, "count": count, "source": sources, "lang": lang, "countryUri": countryUri or "" }
417409
params.update(returnInfo.getParams())
410+
params.update(kwargs)
418411
if sortByDistanceTo:
419412
assert isinstance(sortByDistanceTo, (tuple, list)), "sortByDistanceTo has to contain a tuple with latitude and longitude of the location"
420413
assert len(sortByDistanceTo) == 2, "The sortByDistanceTo should contain two float numbers"
@@ -423,7 +416,7 @@ def suggestLocations(self, prefix, sources = ["place", "country"], lang = "eng",
423416
return self.jsonRequest("/json/suggestLocations", params)
424417

425418

426-
def suggestLocationsAtCoordinate(self, latitude, longitude, radiusKm, limitToCities = False, lang = "eng", count = 20, ignoreNonWiki = True, returnInfo = ReturnInfo()):
419+
def suggestLocationsAtCoordinate(self, latitude, longitude, radiusKm, limitToCities = False, lang = "eng", count = 20, ignoreNonWiki = True, returnInfo = ReturnInfo(), **kwargs):
427420
"""
428421
return a list of geo locations (cities or places) that are close to the provided (lat, long) values
429422
@param latitude: latitude part of the coordinate
@@ -439,10 +432,11 @@ def suggestLocationsAtCoordinate(self, latitude, longitude, radiusKm, limitToCit
439432
assert isinstance(longitude, (int, float)), "The 'longitude' should be a number"
440433
params = { "action": "getLocationsAtCoordinate", "lat": latitude, "lon": longitude, "radius": radiusKm, "limitToCities": limitToCities, "count": count, "lang": lang }
441434
params.update(returnInfo.getParams())
435+
params.update(kwargs)
442436
return self.jsonRequest("/json/suggestLocations", params)
443437

444438

445-
def suggestSourcesAtCoordinate(self, latitude, longitude, radiusKm, count = 20):
439+
def suggestSourcesAtCoordinate(self, latitude, longitude, radiusKm, count = 20, **kwargs):
446440
"""
447441
return a list of news sources that are close to the provided (lat, long) values
448442
@param latitude: latitude part of the coordinate
@@ -452,23 +446,25 @@ def suggestSourcesAtCoordinate(self, latitude, longitude, radiusKm, count = 20):
452446
"""
453447
assert isinstance(latitude, (int, float)), "The 'latitude' should be a number"
454448
assert isinstance(longitude, (int, float)), "The 'longitude' should be a number"
455-
params = { "action": "getSourcesAtCoordinate", "lat": latitude, "lon": longitude, "radius": radiusKm, "count": count }
449+
params = {"action": "getSourcesAtCoordinate", "lat": latitude, "lon": longitude, "radius": radiusKm, "count": count}
450+
params.update(kwargs)
456451
return self.jsonRequest("/json/suggestSources", params)
457452

458453

459-
def suggestSourcesAtPlace(self, conceptUri, dataType = "news", page = 1, count = 20):
454+
def suggestSourcesAtPlace(self, conceptUri, dataType = "news", page = 1, count = 20, **kwargs):
460455
"""
461456
return a list of news sources that are close to the provided (lat, long) values
462457
@param conceptUri: concept that represents a geographic location for which we would like to obtain a list of sources located at the place
463458
@param dataType: type of the news source ("news", "pr", "blog" or a list of any of those)
464459
@param page: page of the results (1, 2, ...)
465460
@param count: number of returned sources
466461
"""
467-
params = { "action": "getSourcesAtPlace", "conceptUri": conceptUri, "page": page, "count": count, "dataType": dataType }
462+
params = {"action": "getSourcesAtPlace", "conceptUri": conceptUri, "page": page, "count": count, "dataType": dataType}
463+
params.update(kwargs)
468464
return self.jsonRequest("/json/suggestSources", params)
469465

470466

471-
def suggestConceptClasses(self, prefix, lang = "eng", conceptLang = "eng", source = ["dbpedia", "custom"], page = 1, count = 20, returnInfo = ReturnInfo()):
467+
def suggestConceptClasses(self, prefix, lang = "eng", conceptLang = "eng", source = ["dbpedia", "custom"], page = 1, count = 20, returnInfo = ReturnInfo(), **kwargs):
472468
"""
473469
return a list of concept classes that match the given prefix
474470
@param prefix: input text that should be contained in the category name
@@ -482,10 +478,11 @@ def suggestConceptClasses(self, prefix, lang = "eng", conceptLang = "eng", sourc
482478
assert page > 0, "page parameter should be above 0"
483479
params = { "prefix": prefix, "lang": lang, "conceptLang": conceptLang, "source": source, "page": page, "count": count }
484480
params.update(returnInfo.getParams())
481+
params.update(kwargs)
485482
return self.jsonRequest("/json/suggestConceptClasses", params)
486483

487484

488-
def suggestCustomConcepts(self, prefix, lang = "eng", conceptLang = "eng", page = 1, count = 20, returnInfo = ReturnInfo()):
485+
def suggestCustomConcepts(self, prefix, lang = "eng", conceptLang = "eng", page = 1, count = 20, returnInfo = ReturnInfo(), **kwargs):
489486
"""
490487
return a list of custom concepts that contain the given prefix. Custom concepts are the things (indicators, stock prices, ...) for which we import daily trending values that can be obtained using GetCounts class
491488
@param prefix: input text that should be contained in the concept name
@@ -498,6 +495,7 @@ def suggestCustomConcepts(self, prefix, lang = "eng", conceptLang = "eng", page
498495
assert page > 0, "page parameter should be above 0"
499496
params = { "prefix": prefix, "lang": lang, "conceptLang": conceptLang, "page": page, "count": count }
500497
params.update(returnInfo.getParams())
498+
params.update(kwargs)
501499
return self.jsonRequest("/json/suggestCustomConcepts", params)
502500

503501

eventregistry/QueryArticle.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,17 +32,6 @@ def queryByUri(articleUriOrUriList):
3232
return q
3333

3434

35-
def addRequestedResult(self, requestArticle):
36-
"""
37-
Add a result type that you would like to be returned. In one QueryArticle you can ask for multiple result types.
38-
Result types can be the classes that extend RequestArticle base class (see classes below).
39-
@param requestArticle: an instance of type RequestArticle*. Determines what info should be returned as a result of the query
40-
"""
41-
assert isinstance(requestArticle, RequestArticle), "QueryArticle class can only accept result requests that are of type RequestArticle"
42-
self.resultTypeList = [item for item in self.resultTypeList if item.getResultType() != requestArticle.getResultType()]
43-
self.resultTypeList.append(requestArticle)
44-
45-
4635
def setRequestedResult(self, requestArticle):
4736
"""
4837
Set the single result type that you would like to be returned. If some other request type was previously set, it will be overwritten.

0 commit comments

Comments
 (0)