arxiv_metadata/tools.py

18 lines
392 B
Python

"""
This file contains various utility functions.
"""
def replaceAll(text, dic):
"""Replace all the dic keys by the associated item in text"""
for i, j in dic.items():
text = text.replace(i, j)
return text
def clean_whitespaces(text):
"""
Remove double whitespaces and trailing . and , from text.
"""
return ' '.join(text.strip().rstrip(".,").split())