Как удалить стоп-слова из массива строк в python? - PullRequest
0 голосов
/ 17 сентября 2018

Я хотел бы удалить стоп-слова из массива с именем arrayList1, который хранится в переменной данных.Я пытаюсь метод ниже, но он не работает.Пожалуйста, помогите мне проверить приведенные ниже коды и улучшить коды. Спасибо.

import Retrieve_ED_Notes
from nltk.corpus import stopwords

data = Retrieve_ED_Notes.arrayList1

stop_words = set(stopwords.words('english'))


def remove_stopwords(data):
 data = [word for word in data if word not in stop_words]
 return data

for i in range(0, len(remove_stopwords(data))):
  print(remove_stopwords(data[i]))

Консольный вывод массива List1:

1|I really love writing journals
2|The mat is very comfortable and I will buy it again likes
3|The mousepad is smooth
1|I really love writing journals
4|This pen is very special to me.
4|This pencil is very special to me.
5|Meaningful novels
4|It brights up my day like a lighter and makes me higher.
6|School foolscap
7|As soft as my heart.lovey

1 Ответ

0 голосов
/ 17 сентября 2018

преобразовать слово в нижнее и проверить с помощью стоп-слов.

from nltk.corpus import stopwords
stopwords=set(stopwords.words('english'))

data =['I really love writing journals','The mat is very comfortable and I will buy it again likes','The mousepad is smooth']

def remove_stopwords(data):
    output_array=[]
    for sentence in data:
        temp_list=[]
        for word in sentence.split():
            if word.lower() not in stopwords:
                temp_list.append(word)
        output_array.append(' '.join(temp_list))
    return output_array





output=remove_stopwords(data)

print(output)
['really love writing journals','mat comfortable buy likes', 'mousepad smooth']
...