Я хочу удалить только эти строки из файла Myfile.txt
, если строка содержит только один текст и содержит только одно из стоп-слов
Например, образец файла Myfile.txt
равен
Adh Dhayd
Abu Dhabi is # here is "is" stopword but this line should not be removed because line contain #Abu Dhabi is
Zaranj
of # this line contains just stop word, this line should be removed
on # this line contains just stop word, this line should be removed
Taloqan
Shnan of # here is "of" stopword but this line should not be removed because line contain #Shnan of
is # this line contains just stop word, this line should be removed
Shibirghn
Shahrak
from # this line contains just stop word, this line should be removed
У меня есть этот код в качестве примера
import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
example_sent = "This is a sample sentence, showing off the stop words filtration."
stop_words = set(stopwords.words('english'))
word_tokens = word_tokenize(example_sent)
filtered_sentence = [w for w in word_tokens if not w in stop_words]
filtered_sentence = []
for w in word_tokens:
if w not in stop_words:
filtered_sentence.append(w)
print(word_tokens)
print(filtered_sentence)
Так, каков будет код решения для Myfile.txt
согласно упомянутому выше.