如何在 python 中的 for 循环中修改单词
How to modify word in a for loop in python
我正在尝试使用 SnowballStemmer 阻止 python 中的一些文本,但它不起作用。这是代码:
import nltk
from nltk import SnowballStemmer
stem = SnowballStemmer("spanish")
def limpiar (texto):
texto = texto.split()
stemm = SnowballStemmer('spanish')
for palabra in texto:
palabra = stem.stem(palabra.lower())
return texto
它returns小写字母的文本,但没有词干
将起作用:
import nltk
from nltk.stem.snowball import SnowballStemmer
def limpiar(texto):
words=texto.split()
stem_words=[]
for w in words:
x = snow_stemmer.stem(w)
stem_words.append(x)
#print stemming results
for e1,e2 in zip(words,stem_words):
print(e1+' ----> '+e2.lower())
snow_stemmer = SnowballStemmer(language='spanish')
texto="..."
limpiar(texto)
我正在尝试使用 SnowballStemmer 阻止 python 中的一些文本,但它不起作用。这是代码:
import nltk
from nltk import SnowballStemmer
stem = SnowballStemmer("spanish")
def limpiar (texto):
texto = texto.split()
stemm = SnowballStemmer('spanish')
for palabra in texto:
palabra = stem.stem(palabra.lower())
return texto
它returns小写字母的文本,但没有词干
将起作用:
import nltk
from nltk.stem.snowball import SnowballStemmer
def limpiar(texto):
words=texto.split()
stem_words=[]
for w in words:
x = snow_stemmer.stem(w)
stem_words.append(x)
#print stemming results
for e1,e2 in zip(words,stem_words):
print(e1+' ----> '+e2.lower())
snow_stemmer = SnowballStemmer(language='spanish')
texto="..."
limpiar(texto)