Ricerca…


introduzione

Le parole di stop sono le parole che sono per lo più usate come riempitivi e difficilmente hanno un significato utile. Dovremmo evitare queste parole dal prendere spazio nel database o impiegare tempo prezioso per l'elaborazione. Possiamo facilmente creare un elenco di parole da utilizzare come termini di arresto e filtrare queste parole dai dati che vogliamo elaborare.

Filtraggio delle parole di arresto

NLTK ha per impostazione predefinita un gruppo di parole che considera come parole di arresto. Si può accedere tramite il corpus NLTK con:

from nltk.corpus import stopwords

Per controllare l'elenco delle parole di arresto memorizzate per la lingua inglese:

stop_words = set(stopwords.words("english"))
print(stop_words)

Esempio per incorporare stop_words impostato per rimuovere le parole di stop da un determinato testo:

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)


Modified text is an extract of the original Stack Overflow Documentation
Autorizzato sotto CC BY-SA 3.0
Non affiliato con Stack Overflow