NLTKを使用してNLPに取り込もうとしていますが、ほとんどのコードを理解していますが、x.sub("", word)
とif not new_word in ""
の意味を理解できません。よくわかりません。Pythonでの文字列操作
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