Utils#
Various functions and classes.
Common#
All-purpose functions.
- 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:
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.list_of_objects(clss, dico, default=None)[source]#
Versatile way to enter a list of objects referenced by a dico.
- Parameters:
- Returns:
Proper list of objects.
- Return type:
Examples
>>> from gismap.sources.models import DB >>> subclasses = get_classes(DB, key='db_name') >>> from gismap import HAL, DBLP >>> list_of_objects([HAL, 'dblp'], subclasses) [<class 'gismap.sources.hal.HAL'>, <class 'gismap.sources.dblp.DBLP'>] >>> list_of_objects(None, subclasses, [DBLP]) [<class 'gismap.sources.dblp.DBLP'>] >>> list_of_objects(DBLP, subclasses) [<class 'gismap.sources.dblp.DBLP'>] >>> list_of_objects('hal', subclasses) [<class 'gismap.sources.hal.HAL'>]
Requests#
Functions related to the requests.
Logger#
Keep track of things.
- 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:
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.asciify(text)[source]#
- Parameters:
text (
str) – Some text (typically names) with annoying accents.- Returns:
Same text simplified into ascii.
- Return type:
Examples
>>> asciify('Ana Bušić') 'Ana Busic' >>> asciify("Thomas Deiß") 'Thomas Deiss'
- gismap.utils.text.normalized_name(txt)[source]#
Try to normalize names for facilitating comparisons. Name is lowered, split, asciified, sorted, and filtered.
Examples
>>> normalized_name("Thomas Deiß") 'deiss thomas' >>> normalized_name("Dario Rossi 001") 'dario rossi' >>> normalized_name("James W. Roberts") 'james roberts'