当前位置: 首页>>代码示例>>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;未经允许,请勿转载。