I want to fully tokenize a sentence: "The element with the longest half-life is Uranium-234" said the professor.
I want this output:
['"', 'The', 'element', 'with', 'the', 'longests', 'half-life', 'isn't', 'Uranium-234', '"', 'said', 'the', 'professor', '.']
Here all the punctuation is separate, but the words like "isn't" and "doesn't" are one token. The hyphenated words are also seen as one token, which is what I want.
Currently I am using this to tokenize it:
p = re.compile(r"\w+(?:'\w+)?|[^\w\s]")
p.findall(s)
This gives me the output:
['"', 'The', 'element', 'with', 'the', 'longest', 'half', '-', 'life', 'isn't', 'Uranium', '-', '234', '"', 'said', 'the', 'professor', "."]
With this I can't tokenize the hyphenated words as one token.