Question
Please advise a way to remove punctuation, but not those in <unk> or <UNK>.
For instance, from:
the asbestos fiber <unk> <unk| is < unusually <unk once it enters the <<unk>$% with
generate:
the asbestos fiber <unk> unk is unusually unk once it enters the unk with
Tried below but not as expected.
text = "the asbestos fiber <unk> <unk| is < unusually <unk once it enters the <<unk>$% with "
replacement = " "
pattern: str = '(?<!<unk)[%s%s]+(?!unk>)' % (re.escape(string.punctuation), r"\s")
re.sub(pattern=pattern, repl=replacement, string=text, flags=re.IGNORECASE).lower().strip()
Result:
the asbestos fiber <unk> unk| is unusually unk once it enters the <unk> with