import re def count_words(text): words = re.findall(r"\b[\w]+(?:'[\w]+)?\b", text.lower(), re.UNICODE) result = {} for word in words: result[word] = result.get(word, 0) + 1 return result