bibliometa.utils package¶
Submodules¶
bibliometa.utils.archives module¶
This module provides utilities to handle tar files.
bibliometa.utils.utils module¶
This module provides utility classes and functions whose usage is not limited to a specific context.
- class bibliometa.utils.utils.DictUtils[source]¶
Bases:
objectThe
DictUtilsprovides generic utilities.- static get_top_keys(d, k)[source]¶
Get keys with highest values from a dictionary.
- Parameters
d (dict) – A dictionary
k (int) – Top k elements that will be returned
- Returns
List of tuples (value, key) for top k keys
- Return type
list
- static merge(a, b)[source]¶
Merge two dictionaries.
- Parameters
a (dict) – A dictionary
b (dict) – Another dictionary
- Raise
KeyError if a key is found in both dictionaries
- Returns
Dictionary a merged with b
- Return type
dict
- static read_from_json(f, encoding='utf-8')[source]¶
Read a dictionary from a JSON file.
- Parameters
f (str) – Path to file
encoding (str) – File encoding
- Returns
Dictionary loaded from JSON file
- Return type
dict
- Raises
FileNotFoundError – If f does not point to a file
- static remove_empty_entries(d)[source]¶
Remove keys from dict d that have no values.
- Parameters
d (dict) – A dictionary
- Returns
Input dictionary without empty entries.
- Return type
dict
- static remove_keys(i, o, k, encoding='utf-8')[source]¶
Remove all keys from a given dict i (in a JSON file) if not in k and save the remaining dict as JSON in o.
- Parameters
i (str) – Path to input JSON file
o (str) – Path to output JSON file
k (list) – List of keys to be removed
encoding (str) – File encoding
- class bibliometa.utils.utils.MainUtils[source]¶
Bases:
objectThe
MainUtilsprovides generic utilities.
Module contents¶
Utilities package for Bibliometa.