arxiv_metadata/reference_fetcher/tools.py

20 lines
444 B
Python
Raw Permalink Normal View History

"""
This file contains various utility functions.
"""
def replaceAll(text, replace_dict):
"""
Replace all the ``replace_dict`` keys by their associated item in ``text``.
"""
for i, j in replace_dict.items():
2015-12-23 22:49:14 +01:00
text = text.replace(i, j)
return text
def clean_whitespaces(text):
"""
Remove double whitespaces and trailing "." and "," from text.
2015-12-23 22:49:14 +01:00
"""
return ' '.join(text.strip().rstrip(".,").split())