I have a begginer in NLP and I have a dataset for NLP task which has strings. I want to clean it by removing interpunct and nuber which followed by fullstop, such as 'George is · working here since 2015.' to 'George is working here since'.
I want to use regular expression and I think comile library works in my problem. The code that I have is
def stripPunc(wordList):
"""Strips punctuation from list of words"""
puncList = ["]","[","·",".",";",":","!","?","/","\\",",","#","@","$","&",")","(","\""]
for punc in puncList:
for word in wordList:
wordList=[word.replace(punc,'') for word in wordList]
return wordList
but returns
['G',
'e',
'o',
'r',
'g',
'e',
' ',
'i',
's',
' ',
'',
' ',
'',
'',
' ',
'w',
'o',
'r',
'k',
'i',
'n',
'g',
' ',
'h',
'e',
'r',
'e',
' ',
's',
'i',
'n',
'c',
'e',
' ',
'2',
'0',
'1',
'5',
'']
instead of 'George is working here since'.
One more aproach is to use
import re
re_word_pattern = re.compile(r'\w+')
re_brackets = re.compile(r'(\[|\])')
re_number_to_zero = re.compile(r'\d+')
re_interpunct_to_zero = re.compile(r'')
text = 'George is · [] working here since 2015.'
text = re_brackets.sub('', text)
text = re_number_to_zero.sub('', text)
which gives
George is · working here since .
so in this case how could I remove the interpunct?