示例#1
0
    def wonderland(winlength, holder):
        q = []
        cq = DataManager.completeTable(holder)
        cnt = 0

        while len(q) < winlength:
            x = holder[cnt]
            y = x.lower()
            q.append(y)
            cnt += 1

        data = DataManager.manager(q)

        print(q)
        print(data)
        print("\n")


        while cnt < len(holder):
            x = holder[cnt]
            y = x.lower()
            q.pop(0)
            q.append(y)
            cnt += 1
            data = DataManager.manager(q)

            print(cnt)
            print(q)
            print(data)
            print("\n")
    def __init__(self, fileName, ignoreList, shortcutList, response):
        global filename

        if shortcutList != None:
            ignoreList = ignoreList + list(shortcutList.values())

        with open(fileName, encoding="utf-8") as f:
            data = f.readlines()
        f.close()

        io = WriteNewFile.fileCreator()

        #I tried to make this flag system it's own method
        #But it needs to be in here.
        #It's so it can print out a sort of loading bar
        a = False
        b = False
        c = False
        d = False
        e = False
        f = False
        remainingTime = len(data)
        tracker = 0
        flagCnt = 1
        for x in data:
            #print(x)
            #print("\n")
            #This is where it prints out the progress.
            flag = LoadingBar.bar(tracker, remainingTime, a, b, c, d, e, f)
            if flag == True:
                if flagCnt == 1:
                    a = True
                    flagCnt += 1
                elif flagCnt == 2:
                    b = True
                    flagCnt += 1
                elif flagCnt == 3:
                    c = True
                    flagCnt += 1
                elif flagCnt == 4:
                    d = True
                    flagCnt += 1
                elif flagCnt == 5:
                    e = True
                    flagCnt += 1
                elif flagCnt == 6:
                    f = True
                    flagCnt += 1

            if shortcutList != None:
                for vals in shortcutList:
                    x = x.replace(vals, shortcutList[vals])

            loweredArray = x.lower()
            if response == 1:
                sentences = loweredArray.split('.')
                for y in sentences:
                    splitArray = re.findall(r"[\w']+", y)
                    freqTable = DataManager.manager(ignoreList, splitArray)
                    #print(freqTable)
                    #replaceEngine(freqTable) would replace this part of the code
                    wordsToReplace = []
                    for y in freqTable:
                        if freqTable.get(y) != 1:
                            wordsToReplace.append(y)
                    #print(wordsToReplace)
                    for y in wordsToReplace:
                        wordsToUse = syn.synonyms(y)
                        #print("\nSynonyms for '" + y + "' are: ",wordsToUse)
                        #print('\n')
                        x = repl.replace(y, x, wordsToUse)
                    #print("\nnew string: " + x+"\n")
                tracker += 1
                WriteNewFile.newFile(x, io)

            else:
                splitArray = re.findall(r"[\w']+", loweredArray)
                freqTable = DataManager.manager(ignoreList, splitArray)
                #print(freqTable)
                #replaceEngine(freqTable) would replace this part of the code
                toReplace = self.replaceEngine(freqTable)
                for j in toReplace:

                    wordsToUse = syn.synonyms(j)
                    #print ("\nsynonyms for " + j +" are ", wordsToUse)
                    #print("\n")
                    x = repl.replace(j, x, wordsToUse)
                #print("\nnew string: " + x+"\n")
                tracker += 1
                WriteNewFile.newFile(x, io)
        LoadingBar.bar(tracker, remainingTime, a, b, c, d, e, f)
        io.close()