【问题标题】:How to modify word in a for loop in python如何在python的for循环中修改单词
【发布时间】:2020-12-05 18:16:11
【问题描述】:

我正在尝试使用 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

它返回小写的文本,但没有词干

【问题讨论】:

  • 您应该返回 palabra 结果,而不是 texto

标签: python nlp stemming normalize stem


【解决方案1】:

会起作用的:

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)

【讨论】:

    猜你喜欢
    • 2023-03-14
    • 1970-01-01
    • 2021-10-13
    • 2016-04-25
    • 1970-01-01
    • 1970-01-01
    • 2019-08-07
    • 2011-07-14
    • 1970-01-01
    相关资源
    最近更新 更多