Пример #1
0
    def insert(self, key):
        if self.root == None:
            self.root = Letter(key[0], key[1], key[2])
            return

        new_node = self._find_node_rec(key[0], self.root)

        if new_node.key == key[0]:
            return
        else:
            if new_node.key < key[0]:
                new_node.right = Letter(key[0], key[1], key[2])
            else:
                new_node.left = Letter(key[0], key[1], key[2])
Пример #2
0
    def insert(self, key):
        """Makes a letter case and puts it in the tree"""
        if self.root == None:
            self.root = Letter(key[0], key[1], key[2])
            return

        new_node = self._find_node_rec(key[0], self.root)

        if new_node.key == key[0]:
            return
        else:
            if new_node.key < key[0]:
                new_node.right = Letter(key[0], key[1], key[2])
            else:
                new_node.left = Letter(key[0], key[1], key[2])
Пример #3
0
def convert_images_to_letters(img_letters:List[List[np.ndarray]],signal)->List[List[Letter]]:


    table=[]
    rows_number=len(img_letters)
    for r_index,row in enumerate(img_letters):
        table.append([])

        for letter_img in row:
            letter_character: str = " "
            if letter_img.min()<=170:
                try:
                    letter_character:str=pytesseract.image_to_string(letter_img, config="--psm 10")[0]
                except IndexError:
                    min = letter_img.min()
                    gre = letter_img[:, :, 0]
                    print(letter_character)
                    letter_character="*"
                if letter_character=="=":
                    letter_character="e"
                if letter_character=="|":

                    letter_character="i"
            letter_character=letter_character.lower()

            table[r_index].append(Letter(letter_img,letter_character))
        signal.emit(100*((r_index+1)/rows_number))

    return table
Пример #4
0
def do_comparisons(file_variable, bst):
    """
    -------------------------------------------------------
    Retrieves every letter in file_variable from bst. Generates
    comparisons in bst objects. Each Letter object in bst contains
    the number of comparisons found by searching for that Letter
    object in file_variable.
    Use: do_comparisons(file_variable, bst)
    -------------------------------------------------------
    Parameters:
        file_variable - the already open file containing data to evaluate (file)
        bst - the binary search tree containing 26 Letter objects
            to retrieve data from (BST)
    Returns:
        None
    -------------------------------------------------------
    """
    line = file_variable.readline()
    lines = []
    while line != "":
        line = line.strip()
        lines.append(line)
        line = file_variable.readline()
    for line in lines:
        for letter in line:
            if letter.isalpha():
                temp_letter = Letter(letter.upper())
                bst.retrieve(temp_letter)
    file_variable.close()
    return
Пример #5
0
def do_comparisons(file_variable, bst):
    """
    -------------------------------------------------------
    Retrieves every letter in file_variable from bst. Generates
    comparisons in bst objects. Each Letter object in bst contains 
    the number of comparisons found by searching for that Letter 
    object in file_variable.
    Use: do_comparisons(file_variable, bst)
    -------------------------------------------------------
    Parameters:
        file_variable - the already open file containing data to evaluate (file)
        bst - the binary search tree containing 26 Letter objects 
            to retrieve data from (BST)
    Returns:
        None
    -------------------------------------------------------
    """
    ALPHABET = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
    file_variable.seek(0)
    lines = file_variable.readlines()
    for line in lines:
        for word in line:
            for letter in word:
                upper_letter = letter.upper()
                if upper_letter in ALPHABET:
                    key = Letter(upper_letter)
                    val = bst.retrieve(key)
    return
Пример #6
0
 def parse(self, idStr):
     length = len(idStr)
     if length <= 1:
         self.letter = Letter()
         self.letter.parse(idStr)
         self.name = self.letter.let
     elif idStr[length - 1].isalpha:
         self.letter = Letter()
         self.letter.parse(idStr[length - 1])
         self.id = Id()
         self.id.parse(idStr[0:length - 1])
         self.name = self.id.name + self.letter.let
     elif idStr[length - 1].isnumeric():
         self.digit = Digit()
         self.digit.parse(idStr[length - 1])
         self.id = Id()
         self.id.parse(idStr[0:length - 1])
         self.name = self.id.name + self.digit.dig
Пример #7
0
def do_comparisons(file_variable, bst):
    """
    -------------------------------------------------------
    Retrieves every letter in file_variable from bst. Generates
    comparisons in bst objects. Each Letter object in bst contains
    the number of comparisons found by searching for that Letter
    object in file_variable.
    Use: do_comparisons(file_variable, bst)
    -------------------------------------------------------
    Parameters:
        file_variable - the already open file containing data to evaluate (file)
        bst - the binary search tree containing 26 Letter objects
            to retrieve data from (BST)
    Returns:
        None
    -------------------------------------------------------
    """
    
    line = file_variable.read()
    current = bst._root
     
    for i in line:
        
        if i.isalpha():
            
            i = Letter(i.upper())
            
            while current is not None and current._value!=i:
                
                if current._value > i:
                    current = current._left
                    
                elif current._value < i:
                    current = current._right
                    
            current = bst._root 
    
    return
Пример #8
0
def do_comparisons(file_variable, bst):
    """
    -------------------------------------------------------
    Retrieves every letter in file_variable from bst. Generates
    comparisons in bst objects. Each Letter object in bst contains 
    the number of comparisons found by searching for that Letter 
    object in file_variable.
    Use: do_comparisons(file_variable, bst)
    -------------------------------------------------------
    Parameters:
        file_variable - the already open file containing data to evaluate (file)
        bst - the binary search tree containing 26 Letter objects 
            to retrieve data from (BST)
    Returns:
        None
    -------------------------------------------------------
    """
    for i in file_variable:
        if i.isalpha():
            i = i.upper()
            i = Letter(i)
            bst.retrieve(i)

    return
Пример #9
0
"""
from BST_linked import BST
from functions import comparison_total , do_comparisons
from Letter import Letter


DATA1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
DATA2 = "MFTCJPWADHKNRUYBEIGLOQSVXZ"
DATA3 = "ETAOINSHRDLUCMPFYWGBVKJXZQ"

bst1 = BST()
bst2 = BST()
bst3 = BST()

for i in DATA1:
    bst1.insert(Letter(i[0]))


for i in DATA2:
    bst2.insert(Letter(i[0]))
    

for i in DATA3:
    bst3.insert(Letter(i[0]))
    
f_variable = open("miserables.txt","r")


print("Comparing by order: ABCDEFGHIJKLMNOPQRSTUVWXYZ")
do_comparisons(f_variable, bst1)
Пример #10
0
"""
from functions import comparison_total, do_comparisons, \
letter_table
from BST_linked import BST
from Letter import Letter

bst_1 = BST()
bst_2 = BST()
bst_3 = BST()

DATA1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
DATA2 = "MFTCJPWADHKNRUYBEIGLOQSVXZ"
DATA3 = "ETAOINSHRDLUCMPFYWGBVKJXZQ"

for data in DATA1:
    letter = Letter(data)
    bst_1.insert(letter)
for data in DATA2:
    letter = Letter(data)
    bst_2.insert(letter)
for data in DATA3:
    letter = Letter(data)
    bst_3.insert(letter)

fh = open('otoos610.txt', 'r')
do_comparisons(fh, bst_1)
do_comparisons(fh, bst_2)
do_comparisons(fh, bst_3)

total_1 = comparison_total(bst_1)
total_2 = comparison_total(bst_2)
Пример #11
0
 def run(self):
     for i in range(min(10, self.count)):
         self.result.append(
             Letter(self.imap.choose_msg(self.count - i, 'body[]')))
Пример #12
0
"""
-------------------------------------------------------
[program 3]
-------------------------------------------------------
Author:  Anshul Khatri
ID:      193313680
Email:   [email protected]
Section: CP164 Winter 2020
__updated__ = "2020-03-27"
-------------------------------------------------------
"""

from functions import letter_table, do_comparisons
from Letter import Letter
from BST_linked import BST

DATA1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
DATA2 = "MFTCJPWADHKNRUYBEIGLOQSVXZ"
DATA3 = "ETAOINSHRDLUCMPFYWGBVKJXZQ"

fv = open("miserables.txt","r")
bst1 = BST()
for letter in DATA3:
    ob = Letter(letter)
    bst1.insert(ob)
    
do_comparisons(fv, bst1)

letter_table(bst1)
Пример #13
0
    ------------------------------------------------------

    """


start = time.time()
bst1 = BST()
bst2 = BST()
bst3 = BST()

DATA1 = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
DATA2 = "MFTCJPWADHKNRUYBEIGLOQSVXZ"
DATA3 = "ETAOINSHRDLUCMPFYWGBVKJXZQ"

for i in DATA1:
    val = Letter(i)
    bst1.insert(val)
for i in DATA2:
    val = Letter(i)
    bst2.insert(val)
for i in DATA3:
    val = Letter(i)
    bst3.insert(val)

test_file = open('otoos610.txt', 'r', encoding='utf-8')
test_file = test_file.read()

do_comparisons(test_file, bst1)
total1 = comparison_total(bst1)

do_comparisons(test_file, bst2)