簡體   English   中英

如何在 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

它以小寫字母返回文本,但沒有詞干

將起作用:

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)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM