我有 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