-2

我有 python 2.7,这是我的代码,当我运行它时,我收到这个错误:'continue' not proper in loop。

我知道'继续'应该在循环内,但我在里面使用它if,那我该怎么办?

from numpy import zeros
from scipy.linalg import svd
from math import log
from numpy import asarray, sum
#from nltk.corpus import stopwords
from sklearn.metrics.pairwise import cosine_similarity
#from nltk.stem import PorterStemmer
#from nltk.stem.isri import ISRIStemmer
import nltk
#from matplotlib import pyplot as plt
from snowballstemmer import stemmer 


titles = [" ذهبت الاخت الى المدرسة","تقع المدرسة في الجبال",
    "ذهب الام لزيارة ابنتها في المدرسة ","تحضر الام الكعكة" ]

ar_stemmer = stemmer("arabic")

stopwords = ['ثم','و','حتى','الى','على','في']

ignorechars = ''',:'!'''



 class LSA(object):
  def __init__(self, stopwords, ignorechars):
    self.stopwords = stopwords
    self.ignorechars = ignorechars
    self.wdict = {}
    self.dcount = 0    


def parse(self, doc):
    #tokens=nltk.word_tokenise(titles)
    #words = doc.split();
    #ar_stemmer = stemmer("arabic")
    for word in titles.split(" "):
      #  w = w.lower()

    #for w in titles.split(" "):
              stem = ar_stemmer.stemWord(word)

        #st = ISRIStemmer()
    #for w in words : 
            #join = w.decode('Windows-1256')
           # w= st.stem(w.decode('utf-8'))

    if stem in self.stopwords:
       continue
    elif stem in self.wdict:
            self.wdict[stem].append(self.dcount)
    else:
            self.wdict[stem] = [self.dcount]
            self.dcount += 1
4

2 回答 2

1

此错误是由使用 continue外部forwhile循环引起的。也就是说:continue只允许在一个forwhile循环内。

于 2017-02-02T13:41:34.757 回答
1

在这种情况下完全没有必要使用continue,只需使用pass.

于 2016-05-31T21:59:58.307 回答