Skip to content

Commit bf3ce14

Browse files
committed
## [v9.1]() (2023-06-23)
**Added** - added `keywordSearchMode` parameter that can be used in `QueryArticles`, `QueryArticlesIter`, `QueryEvents`, `QueryEventsIter` and `QueryEvent` constructors. - added `keywordSearchMode` parameter to the advanced query language **Updated** - types of parameters in the method calls - updated several code example files
1 parent 301be9b commit bf3ce14

27 files changed

+745
-407
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Change Log
22

3+
## [v9.1]() (2023-06-23)
4+
5+
**Added**
6+
- added `keywordSearchMode` parameter that can be used in `QueryArticles`, `QueryArticlesIter`, `QueryEvents`, `QueryEventsIter` and `QueryEvent` constructors.
7+
- added `keywordSearchMode` parameter to the advanced query language
8+
9+
10+
**Updated**
11+
- types of parameters in the method calls
12+
- updated several code example files
13+
14+
15+
316
## [v9.0]() (2023-05-15)
417

518
**Added**

eventregistry/Analytics.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def __init__(self, eventRegistry: EventRegistry):
2424
self._er = eventRegistry
2525

2626

27-
def annotate(self, text: str, lang: str = None, customParams: dict = None):
27+
def annotate(self, text: str, lang: Union[str, None] = None, customParams: Union[dict, None] = None):
2828
"""
2929
identify the list of entities and nonentities mentioned in the text
3030
@param text: input text to annotate
@@ -38,7 +38,7 @@ def annotate(self, text: str, lang: str = None, customParams: dict = None):
3838
return self._er.jsonRequestAnalytics("/api/v1/annotate", params)
3939

4040

41-
def categorize(self, text: str, taxonomy: str = "dmoz", concepts: List[str] = None):
41+
def categorize(self, text: str, taxonomy: str = "dmoz", concepts: Union[List[str], None] = None):
4242
"""
4343
determine the set of up to 5 categories the text is about. Currently, only English text can be categorized!
4444
@param text: input text to categorize
@@ -86,7 +86,7 @@ def detectLanguage(self, text: str):
8686
return self._er.jsonRequestAnalytics("/api/v1/detectLanguage", { "text": text })
8787

8888

89-
def extractArticleInfo(self, url: str, proxyUrl: str = None, headers: Union[str, dict] = None, cookies: Union[dict, str] = None):
89+
def extractArticleInfo(self, url: str, proxyUrl: Union[str, None] = None, headers: Union[str, dict, None] = None, cookies: Union[dict, str, None] = None):
9090
"""
9191
extract all available information about an article available at url `url`. Returned information will include
9292
article title, body, authors, links in the articles, ...
@@ -120,8 +120,8 @@ def ner(self, text: str):
120120

121121

122122
def trainTopicOnTweets(self, twitterQuery: str, useTweetText: bool = True, useIdfNormalization: bool = True,
123-
normalization: bool = "linear", maxTweets: int = 2000, maxUsedLinks: int = 500, ignoreConceptTypes: Union[str, List[str]] = [],
124-
maxConcepts: int = 20, maxCategories: int = 10, notifyEmailAddress: str = None):
123+
normalization: str = "linear", maxTweets: int = 2000, maxUsedLinks: int = 500, ignoreConceptTypes: Union[str, List[str]] = [],
124+
maxConcepts: int = 20, maxCategories: int = 10, notifyEmailAddress: Union[str, None] = None):
125125
"""
126126
create a new topic and train it using the tweets that match the twitterQuery
127127
@param twitterQuery: string containing the content to search for. It can be a Twitter user account (using "@" prefix or user's Twitter url),
@@ -175,14 +175,12 @@ def trainTopicAddDocument(self, uri: str, text: str):
175175
return self._er.jsonRequestAnalytics("/api/v1/trainTopic", { "action": "addDocument", "uri": uri, "text": text})
176176

177177

178-
def trainTopicGetTrainedTopic(self, uri: str, maxConcepts: int = 20, maxCategories: int = 10,
179-
ignoreConceptTypes: Union[str, List[str]] = [], idfNormalization: bool = True):
178+
def trainTopicGetTrainedTopic(self, uri: str, maxConcepts: int = 20, maxCategories: int = 10, idfNormalization: bool = True):
180179
"""
181180
retrieve topic for the topic for which you have already finished training
182181
@param uri: uri of the topic (obtained by calling trainTopicCreateTopic method)
183182
@param maxConcepts: number of top concepts to retrieve in the topic
184183
@param maxCategories: number of top categories to retrieve in the topic
185-
@param ignoreConceptTypes: what types of concepts you would like to ignore in the profile. options: person, org, loc, wiki or an array with those
186184
@param idfNormalization: should the concepts be normalized by punishing the commonly mentioned concepts
187185
@param returns: returns the trained topic: { concepts: [], categories: [] }
188186
"""

eventregistry/Base.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import six, warnings, os, sys, re, datetime, time
66
from eventregistry.Logger import logger
7-
from typing import Union, List
7+
from typing import Union, List, Dict
88

99
mainLangs = ["eng", "deu", "zho", "slv", "spa"]
1010
allLangs = [ "eng", "deu", "spa", "cat", "por", "ita", "fra", "rus", "ara", "tur", "zho", "slv", "hrv", "srp" ]
@@ -123,7 +123,7 @@ def encodeDate(val: Union[datetime.datetime, datetime.date, str]):
123123
elif isinstance(val, datetime.date):
124124
return val.isoformat()
125125
elif isinstance(val, six.string_types):
126-
assert re.match("^\d{4}-\d{2}-\d{2}$", val), "date value '%s' was not provided in the 'YYYY-MM-DD' format" % (val)
126+
assert re.match(r"^\d{4}-\d{2}-\d{2}$", val), f"date value '{val}' was not provided in the 'YYYY-MM-DD' format"
127127
return val
128128
raise AssertionError("date was not in the expected format")
129129

@@ -133,12 +133,12 @@ def encodeDateTime(val: Union[datetime.datetime, str]):
133133
"""encode datetime into UTC ISO format which can be sent to ER"""
134134
if isinstance(val, datetime.datetime):
135135
# if we have a datetime in some tz, we convert it first to UTC
136-
if val.utcoffset() != None:
136+
if val.utcoffset() is not None:
137137
import pytz
138138
val = val.astimezone(pytz.utc)
139139
return val.isoformat()
140140
elif isinstance(val, six.string_types):
141-
assert re.match("^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$", val), "datetime value '%s' was not provided in the 'YYYY-MM-DDTHH:MM:SS.SSSS' format" % (val)
141+
assert re.match(r"^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(\.\d+)?$", val), f"datetime value '{val}' was not provided in the 'YYYY-MM-DDTHH:MM:SS.SSSS' format"
142142
return val
143143
raise AssertionError("datetime was not in the recognizable data type. Use datetime or string in ISO format")
144144

@@ -149,7 +149,7 @@ def _clearVal(self, propName: str):
149149
del self.queryParams[propName]
150150

151151

152-
def _hasVal(self, propName: str):
152+
def _hasVal(self, propName: str) -> bool:
153153
"""do we have in the query property named propName"""
154154
return propName in self.queryParams
155155

@@ -188,16 +188,16 @@ def _addArrayVal(self, propName: str, val):
188188
self.queryParams[propName].append(val)
189189

190190

191-
def _update(self, object: dict):
191+
def _update(self, object: Dict):
192192
self.queryParams.update(object)
193193

194194

195-
def _getQueryParams(self):
195+
def _getQueryParams(self) -> Dict:
196196
"""return the parameters."""
197197
return dict(self.queryParams)
198198

199199

200-
def _setQueryArrVal(self, value: Union[str, QueryItems, list], propName: str, propOperName: str, defaultOperName: str):
200+
def _setQueryArrVal(self, value: Union[str, QueryItems, List, None], propName: str, propOperName: Union[str, None], defaultOperName: str):
201201
"""
202202
parse the value "value" and use it to set the property propName and the operator with name propOperName
203203
@param value: None, string, QueryItems or list. Values to be set using property name propName
@@ -211,10 +211,10 @@ def _setQueryArrVal(self, value: Union[str, QueryItems, list], propName: str, pr
211211
if isinstance(value, QueryItems):
212212
self.queryParams[propName] = value.getItems()
213213
# if we need to specify the operator for the property
214-
if propOperName != None:
214+
if propOperName is not None:
215215
self.queryParams[propOperName] = value.getOper().replace("$", "")
216216
# if the user specified the QueryItems class but used the invalid operator type then raise an error
217-
assert propOperName != None or value.getOper().replace("$", "") == defaultOperName, "An invalid operator type '%s' was used for property '%s'" % (value.getOper().replace("$", ""), propName)
217+
assert propOperName is not None or value.getOper().replace("$", "") == defaultOperName, "An invalid operator type '%s' was used for property '%s'" % (value.getOper().replace("$", ""), propName)
218218

219219
# if we have a string value, just use it
220220
elif isinstance(value, six.string_types):
@@ -224,14 +224,14 @@ def _setQueryArrVal(self, value: Union[str, QueryItems, list], propName: str, pr
224224
elif isinstance(value, list):
225225
self.queryParams[propName] = value
226226
# if we need to specify the operator for the property
227-
if propOperName != None:
227+
if propOperName is not None:
228228
self.queryParams[propOperName] = defaultOperName
229229
if len(value) > 1:
230-
logger.warning("Warning: The value of parameter '%s' was provided as a list and '%s' operator was used implicitly between the items. We suggest specifying the list using the QueryItems.AND() or QueryItems.OR() to ensure the appropriate operator is used." % (propName, defaultOperName))
230+
logger.warning("Warning: The value of parameter '%s' was provided as a list and '%s' operator was used implicitly between the items. We suggest specifying the list using the QueryItems.AND() or QueryItems.OR() to ensure the appropriate operator is used.", propName, defaultOperName)
231231

232232
# there should be no other valid types
233233
else:
234-
assert False, "Parameter '%s' was of unsupported type. It should either be None, a string or an instance of QueryItems" % (propName)
234+
assert False, f"Parameter '{propName}' was of unsupported type. It should either be None, a string or an instance of QueryItems"
235235

236236

237237

eventregistry/DailyShares.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
# get top shared articles for today or any other day
1414
class GetTopSharedArticles(QueryParamsBase):
1515
def __init__(self,
16-
date: str = None, # specify the date (either in YYYY-MM-DD or datetime.date format) for which to return top shared articles. If None then today is used
16+
date: Union[str, datetime.date, datetime.datetime, None] = None, # specify the date (either in YYYY-MM-DD or datetime.date format) for which to return top shared articles. If None then today is used
1717
count: int = 20, # number of top shared articles to return
1818
returnInfo: ReturnInfo = ReturnInfo()):
1919
QueryParamsBase.__init__(self)
@@ -23,7 +23,7 @@ def __init__(self,
2323
self._setVal("articlesSortBy", "socialScore")
2424
self._update(returnInfo.getParams("articles"))
2525

26-
if date == None:
26+
if date is None:
2727
date = datetime.date.today()
2828
self._setDateVal("dateStart", date)
2929
self._setDateVal("dateEnd", date)
@@ -36,8 +36,8 @@ def _getPath(self):
3636
# get top shared events for today or any other day
3737
class GetTopSharedEvents(QueryParamsBase):
3838
def __init__(self,
39-
date: str = None, # specify the date (either in YYYY-MM-DD or datetime.date format) for which to return top shared articles. If None then today is used
40-
count: int = 20, # number of top shared articles to return
39+
date: Union[str, datetime.date, datetime.datetime, None] = None, # specify the date (either in YYYY-MM-DD or datetime.date format) for which to return top shared articles. If None then today is used
40+
count: int = 20, # number of top shared articles to return
4141
returnInfo: ReturnInfo = ReturnInfo()):
4242
QueryParamsBase.__init__(self)
4343
self._setVal("action", "getEvents")
@@ -46,7 +46,7 @@ def __init__(self,
4646
self._setVal("eventsSortBy", "socialScore")
4747
self._update(returnInfo.getParams("events"))
4848

49-
if date == None:
49+
if date is None:
5050
date = datetime.date.today()
5151
self._setDateVal("dateStart", date)
5252
self._setDateVal("dateEnd", date)

0 commit comments

Comments
 (0)