lmpy.data_wrangling.common.accepted_name_wrangler
Module containing a data wrangler base class for resolving taxon names.
Module Contents
Classes
Constructor for the base accepted name wrangler. |
Functions
|
Resolve names using GBIF's taxonomic name resolution service. |
|
Resolve names using GBIF's taxonomic name resolution service. |
- class lmpy.data_wrangling.common.accepted_name_wrangler._AcceptedNameWrangler(name_map=None, name_resolver=None, out_map_filename=None, map_write_interval=100, out_map_format='json')[source]
Bases:
lmpy.data_wrangling.base._DataWrangler
Constructor for the base accepted name wrangler.
- Parameters
name_map (dict or str or None) – An existing name mapping.
name_resolver (Method or None) – If provided, this should be a function that takes a list of names as input and returns a dictionary of name mappings. If omitted, resolving of new names will be skipped.
out_map_filename (str) – A file location to write the updated name map.
map_write_interval (int) – Update the name map output file after each set of this many iterations.
out_map_format (str) – The format to write the names map (csv or json).
- __del__()[source]
Destructor method, sync map to disk if needed.
- Raises
Exception – Raised if writing name map fails.
- _load_name_map(name_map)[source]
Attempt to load names from the name_map provided.
- Parameters
name_map (dict or str) – A mapping dictionary or a filename with names.
- Raises
FileNotFoundError – on missing name_map file
- resolve_names(names)[source]
Attempts to resolve a list of names.
- Parameters
names (list or str) – A list of names to resolve.
- Returns
A dictionary of input name keys and resolved name values.
- Return type
dict
- write_map_to_file(filename, output_format, mode='wt')[source]
Write the name map to a file so it can be reused.
- Parameters
filename (str) – A file location where the map should be written.
output_format (str) – The format to write the map, either ‘csv’ or ‘json’.
mode (str) – How the file should be opened.
- Raises
OSError – on failure to write to filename.
IOError – on failure to write to filename.
- lmpy.data_wrangling.common.accepted_name_wrangler._resolve_gbif_synonym_match(match_response, wait_time=1)[source]
Resolve names using GBIF’s taxonomic name resolution service.
- Parameters
match_response (urllib.Response) – A response from a GBIF species match query.
wait_time (number) – A number of seconds to before request to avoid server ire.
- Returns
An accepted canonical name for the GBIF acceptedUsageKey.
- Return type
namestr
- lmpy.data_wrangling.common.accepted_name_wrangler.resolve_names_gbif(names, wait_time=1)[source]
Resolve names using GBIF’s taxonomic name resolution service.
- Parameters
names (list of str) – A list of name strings to resolve.
wait_time (number) – A number of seconds to wait after each request to avoid server ire.
- Returns
Input names are keys and resolved name or None are values.
- Return type
dict