2016-05-31 3 views
-3

파이썬 2.7이 있는데, 이것은 제 코드이고, 실행할 때 루프에서 '계속'오류가 발생합니다.루프에 제대로 계속하지 않습니다.

나는 'continue'가 루프 내부에 있어야한다는 것을 알고 있지만, 내부적으로는 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 
+1

들여 쓰기가 심각하게 엉망입니다. 코드를 들여 쓰기하여 오류를 해결하십시오. – user2357112

+0

위에서 설명한 것처럼 if 문은 실제로 for 루프에 있지 않으므로 여기에 하나 더 들여 쓰기하십시오. – chrishorton

+0

쓰여진대로'parse' 함수는'stem'의 마지막 값만을 처리합니다. 그게 의도적 인거야? 그렇지 않다면'if' 문을'stem = ar_stemmer.stemWord (word)'와 같은 수준으로 들여 씁니다. –

답변

1

은 그냥 pass를 사용, 그 맥락에서 continue을 사용하는 것이 완전히 불필요합니다.

+0

감사합니다. script8man. – YayaYaya

0

이 오류는 usingcontinue 외부의 for 또는 while 루프가 원인입니다. 즉, continuefor 또는 while 루프 내에서만 허용됩니다.

관련 문제