當前位置: 首頁>>代碼示例>>Python>>正文


Python Helper.valid方法代碼示例

本文整理匯總了Python中Helper.Helper.valid方法的典型用法代碼示例。如果您正苦於以下問題:Python Helper.valid方法的具體用法?Python Helper.valid怎麽用?Python Helper.valid使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Helper.Helper的用法示例。


在下文中一共展示了Helper.valid方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: addLine

# 需要導入模塊: from Helper import Helper [as 別名]
# 或者: from Helper.Helper import valid [as 別名]
    def addLine(self, line, currentDate):
        # markunderFile = open(self.markUnderFilePath, 'a')

        words = line.split(' ')

        wordsToCount = 0 #used to calculate the length of entries - don't want to include invalid words in the word count TODO: rethink this?
        namesFound = set()
        for word in words:
            if word == '' or word == None or re.compile('^\s+$').search(word) != None:
                continue

            (beforeStuff, word, afterStuff) = Helper.cleanWordForInitialAdd(word)

            word = WordClass(word) #words are represented by the WordClass, which is basically an encapsulation of normal words and markup names in one object

            if self.prefs.COMBINE_PLURALS:
                if word.endswith("'s"):
                    word = WordClass.addWordOrMarkup(word.toString()[:len(word)-2]) #TODO: this is broken

            wasUpper = False;
            if word.toString()[:1].isupper():
                wasUpper = True;
            originalWord = word
            word = Helper.cleanWord(word) #this strips off all punctuation and other information that we want to pass into markup.

            if not Helper.valid(word):
                continue
            wordsToCount += 1

            #names
            if word in self.namesSet and (Preferences.REQUIRE_CAPS_FOR_NAMES and wasUpper):
                namesFound.add(word)

                try:
                    self.namesDict[word] = (self.namesDict[word][0] + 1, currentDate)
                except:
                    self.namesDict[word] = (1, currentDate)

                #names per day
                try:
                    if self.namesPerDayDict[word][1] != currentDate:
                        self.namesPerDayDict[word] = (self.namesPerDayDict[word][0] + 1, currentDate)
                except:
                    self.namesPerDayDict[word] = (1, currentDate)

                #names for graphing purposes
                try: #{ word : [ [ date , count ] ] }
                    self.namesToGraphDict[word] #trigger exception
                    if self.namesToGraphDict[word][-1][0] == currentDate: #increment count
                        self.namesToGraphDict[word][-1][1] += 1
                    else: #start a new tuple with a new date
                        self.namesToGraphDict[word].append([currentDate, 1])
                except: #this name hasn't been encountered yet
                    self.namesToGraphDict[word] = [[currentDate, 1]]

                #names for graph, counting on unique occurences
                try: #{ word : [ date ] }
                    self.namesToGraphDictUniqueOccurences[word].append(currentDate)
                except:
                    self.namesToGraphDictUniqueOccurences[word] = [currentDate]

            #words
            if self.wordDict.exists(word):
                self.wordDict.addOrReplaceWord(word, self.wordDict.getCount(word) + 1, currentDate, self.wordDict.getFirstOccurrence(word), wasUpper)
            else:
                self.wordDict.addWord(word, 1, currentDate, currentDate, wasUpper) #TODO: wasUpper wasn't there originally
            
            #words per day
            if self.wordsPerDayDict.exists(word):
                self.wordsPerDayDict.addWord(word, self.wordsPerDayDict.getCount(word), currentDate) #TODO: was addOrReplaceWord, need to think what it should be
            else:
                self.wordsPerDayDict(word, 1, currentDate)

            #TODO: this is being moved to its own class to be called separately
            # if self.prefs.DO_MARK_UNDER:
            #     #if it's a name, qualify it for the markunder
            #     if word in self.namesSet:# or not (Preferences.REQUIRE_CAPS_FOR_NAMES and wasUpper):
            #         markUnderWord = self.getMarkUnderWord(word, originalWord, line, currentDate)
            #     else:
            #         markUnderWord = word

            #     markunderFile.write(markUnderWord + ' ')

        # markunderFile.close()
        return (wordsToCount, namesFound)
開發者ID:dirkstahlecker,項目名稱:WordFrequencies,代碼行數:87,代碼來源:WordFrequenciesClass.py


注:本文中的Helper.Helper.valid方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。