def selectWordMatchers(self, word: str):
        # converting word to lower case
        word = str(word).lower()
        word = generalUtils.cleanWord(word)

        # seeing if word exist in the dataset
        found = Word.where('word', value=word).first()

        # if the word was found then just return it as it is
        if found:
            return word, None

        checkResult = self.checkAndSaveInWrongWords(word)

        # this word was found wrong before and already corrected
        if checkResult is not None:
            return checkResult, None

        if len(word) > 3:
            first_letter = word[0]
            second_letter = word[1]
            last_letter = word[len(word) - 1]
            before_last = word[len(word) - 2]
            min_length = (len(word) - 3)
            max_length = (len(word) + 3)

            Word.executeQuery(
                '''
                select * from words where 
                (first_letter = ? and second_letter = ?) or
                 (last_letter = ? and before_last_letter = ?) 
                ''', (first_letter, second_letter, last_letter, before_last))

        if len(word) <= 3:
            first_letter = word[0]
            min_length = 1
            max_length = (len(word) + 3)

            Word.executeQuery(
                '''
                select * from words where 
                first_letter = ?
                and
                (actual_length between ? and ?)
                ''', (first_letter, min_length, max_length))

        return word, Word.cursor.fetchall()
コード例 #2
0
def seedOurWordsCorpora():
    wordsList = fileService.getListFromFile('./data/words.txt')
    creationList = []
    smallList = []
    for index, word in enumerate(wordsList):
        smallList.append({"word": str(word), 'reverse': word[::-1]})

        if len(word) > 3:
            creationList.append({
                "word":
                str(word).lower(),
                "first_letter":
                str(word[0]).lower(),
                "second_letter":
                str(word[1]).lower(),
                'last_letter':
                str(word[len(word) - 1]).lower(),
                "before_last_letter":
                str(word[len(word) - 2]).lower(),
                "actual_length":
                len(word),
                "min_length": (len(word) - 3),
                "max_length": (len(word) + 3)
            })

        if len(word) <= 3:
            creationList.append({
                "word": str(word).lower(),
                "first_letter": str(word[0]).lower(),
                "second_letter": None,
                'last_letter': None,
                "before_last_letter": None,
                "actual_length": len(word),
                "min_length": len(word),
                "max_length": len(word)
            })

    Word.createBulk(creationList)
    VWord.createBulk(smallList)

    VWord.executeQuery('INSERT INTO vwords(vwords) VALUES(?)', ('optimize', ))

    print('Word Seeder finished successfully')
コード例 #3
0
ファイル: Direct.py プロジェクト: adtraub/isthatawordadam
 def get(self, word_id):
     try:
         p = Word.get_by_id(int(word_id))
         if p:
             logging.info(p)
             self.render("direct.html", **{"input_str":p.word_str, "use_css":self.use_css, "word_id":word_id, "is_up_to_date":Tools.isUpToDate(self),})
         else:
             self.redirect(self.error_page)
     except Exception, e:
         #logger.debug(e)
         self.redirect(self.error_page)
    def selectWordMatchers(self, word: str):
        fixedWord = generalUtils.cleanWord(word)

        if not fixedWord:
            return word, None

        word = fixedWord

        # seeing if word exist in the dataset
        found = Word.where('word', value=word).first()

        # if the word was found then just return it as it is
        if found:
            return word, None

        checkResult = self.checkAndSaveInWrongWords(word)

        # this word was found wrong before and already corrected
        if checkResult is not None:
            return checkResult, None

        if len(word) > 3:
            firstTwo = word[:2] + '*'
            lastThree = word[(len(word) - 3):] + '*'
            print(word)
            VWord.executeQuery('select * from vwords where vwords MATCH ?',
                               (firstTwo, ))

        if len(word) <= 3:
            VWord.executeQuery(
                '''
                   select * from words where word = ? and actual_length = ? 
                ''', (word[0], len(word)))

        result = VWord.cursor.fetchall()
        print(result)
        return word, result
コード例 #5
0
 def generateSentence(self, sentence):
     wordsInSentence = []
     for word in sentence:
         wordsInSentence.append(Word(word))
     return self.generateRhyme(wordsInSentence)
コード例 #6
0
ファイル: start.py プロジェクト: mariostyvenv/crudpythonpoo
def main():
    word = Word()
    if word.startDatabase():

        while True:

            sp.call('cls', shell=True)
            sel = input(
                "\n\n(1) See all the words\n(2) See the words learned\n(3) See the words to learn\n(4) See reviews\n(5) Start learning\n(6) Start review\n(7) Reset database\n(8) Exit\n\n >> "
            )

            if sel == '1':
                result = word.getAllResult()
                header = ('ID', 'WORD', 'NO LEARN', 'REVIEW', 'LEARNED',
                          'SENTENCE')
                result.insert(0, header)
                table = AsciiTable(result)
                print(table.table)
                input()

            elif sel == '2':
                result = word.getLearned()
                header = ('ID', 'WORD', 'SENTENCE')
                result.insert(0, header)
                table = AsciiTable(result)
                print(table.table)
                input()

            elif sel == '3':
                result = word.getNotLearned()
                header = ('ID', 'WORD')
                result.insert(0, header)
                table = AsciiTable(result)
                print(table.table)
                input()

            elif sel == '4':

                result = word.getReview()
                header = ('ID', 'WORD', 'SENTENCE')
                result.insert(0, header)
                table = AsciiTable(result)
                print(table.table)
                input()

            elif sel == '5':

                result = word.startLearn()
                for w in result:
                    res = [('{}'.format(w[0]), '{}'.format(w[1]))]
                    table = AsciiTable(res)
                    print(table.table)
                    sentence = input("\n\nInsert sentence: ")

                    if word.saveSentence(w[0], sentence):
                        con = input("continue? (y/n): ")
                        if con.lower() == 'n':
                            break
                    else:
                        print("Error al momento de guardar la oracion")

            elif sel == '6':

                result = word.getReview()
                if len(result) != 0:

                    for w in result:
                        res = [('{}'.format(w[0]), '{}'.format(w[1]))]
                        table = AsciiTable(res)
                        print(table.table)
                        sentence = input("\n\nInsert sentence: ")

                        if word.confirmReview(w[0], sentence):

                            con = input("continue? (y/n): ")

                            if con.lower() == 'n':
                                break

                        else:
                            print("Error al momento de guardar la oracion")
                else:
                    print("No results were found to practice")

            elif sel == '7':

                if word.resetDatabase():
                    print("Database reset successful")
                    input()

            elif sel == '8':
                print("Bye!")
                break
            else:
                input("¡Selección incorrecta!")