NLTK를 사용하여 NLP에 들어가려고하고 있는데, 아래의 코드 대부분을 이해하지만 무엇이 x.sub("", word)
과 if not new_word in ""
인지 이해하지 못합니다. 나는 혼란스러워.파이썬에서의 문자열 연산
text = ["It is a pleasant evening.", "Guests, who came from the US arrived at the venue.", "Food was tasty."]
tokenized_docs = [word_tokenize(doc) for doc in text]
print(tokenized_docs)
x = re.compile("[%s]" % re.escape(string.punctuation))
token_nop = []
for sentence in tokenized_docs:
new_sent = []
for word in sentence:
new_word = x.sub('', word)
if not new_word in '':
sentence.append(new_word)
token_nop.append(sentence)
이 코드 조각에서 무엇을 기대합니까? 당신이 기대하는대로하지 않습니까? – lenz