Utils#

Various functions and classes.

Common#

All-purpose functions.

class gismap.utils.common.LazyRepr[source]#

MixIn that hides empty fields in dataclasses repr’s.

gismap.utils.common.get_classes(root, key='name')[source]#
Parameters:
  • root (class) – Starting class (can be abstract).

  • key (str, default=’name’) – Attribute to look-up

Returns:

Dictionaries of all subclasses that have a key attribute (as in class attribute key).

Return type:

dict

Examples

>>> from gismap.sources.models import DB
>>> subclasses = get_classes(DB, key='db_name')
>>> dict(sorted(subclasses.items())) 
{'dblp': <class 'gismap.sources.dblp.DBLP'>, 'hal': <class 'gismap.sources.hal.HAL'>}
gismap.utils.common.unlist(x)[source]#
Parameters:

x (str or list or int) – Something.

Returns:

x – If it’s a list, make it flat.

Return type:

str or int

Requests#

Functions related to the requests.

gismap.utils.requests.get(url, params=None)[source]#
Parameters:
  • url (str) – Entry point to fetch.

  • params (dict, optional) – Get arguments (appended to URL).

Returns:

Result.

Return type:

str

Logger#

Keep track of things that go wrong.

gismap.utils.logger.logger = <Logger GisMap (WARNING)>#

Default logging interface.

Text#

Text manipulation tools.

class gismap.utils.text.Corrector(voc, score_cutoff=20, min_length=3)[source]#

A simple word corrector base on input vocabulary. Short words are discarded.

Parameters:
  • voc (list) – Words (each entry may contain multiple words).

  • score_cutoff (int, default=20) – Threshold for correction.

  • min_length (int, default=3) – Minimal number of caracters for correction to kick in.

Examples

>>> vocabulary = ['My Taylor Swift is Rich']
>>> phrase = "How riche ise Tailor Swyft"
>>> cor = Corrector(vocabulary, min_length=4)
>>> cor(phrase)
'How rich ise taylor swift'
>>> cor = Corrector(vocabulary, min_length=2)
>>> cor(phrase)
'How rich is taylor swift'
gismap.utils.text.clean_aliases(name, alias_list)[source]#
Parameters:
  • name (str) – Main name.

  • alias_list (list or set) – Aliases.

Returns:

Aliases deduped, sorted, and with main name removed.

Return type:

list

gismap.utils.text.reduce_keywords(kws)[source]#

Remove redundant subparts.

Parameters:

kws (list) – List of words / co-locations.

Returns:

Reduced list

Return type:

list

Examples

>>> reduce_keywords(['P2P', 'Millimeter Waves', 'Networks', 'P2P Networks', 'Waves'])
['Millimeter Waves', 'P2P Networks']