继续不正确循环

时间:2016-05-31 21:57:21

标签: python arabic lsa

我有python 2.7,这是我的代码,当我运行它时,我收到此错误:'继续'没有正确地循环。

我知道'继续'应该在循环内部,但我在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

2 个答案:

答案 0 :(得分:1)

在该上下文中使用 public function findCategoryProduct($category,$minPrice=null,$maxPrice=null,$gender=null) { $countgb = $this->createQueryBuilder('1') ->select('count(p)') ->from('AppBundle:Product','p') ->join('p.group', 'g') ->join('g.category', 'c') ->where('c = :category') ->andWhere('p.visible >= :true') ->setParameter('category', $category) ->setParameter('true', 1); $count = $countgb->getQuery()->getSingleScalarResult(); $query = $this->createQueryBuilder('1') ->select('p') ->from('AppBundle:Product','p') ->join('p.group', 'g') ->join('g.category', 'c') ->where('c = :category') ->andWhere('p.visible >= :true') ->setParameter('category', $category) ->setParameter('true', 1); $query ->getQuery() ->setHint('knp_paginator.count', $count); return $query; } $paginator = $this->get('knp_paginator'); $pagination = $paginator->paginate($query,$request->query->getInt('page', 1),10,array('distinct' => false)); 完全没必要,只需使用continue

答案 1 :(得分:0)

此错误是由continuefor循环之外的using while引起的。也就是说:continue仅允许在forwhile循环中使用。