Exemple #1
0
 def translate(dictionary, input, output):
     """
     (File, File, File) -> None
     Reads all the word pairs from the dictionary file
     and then reads words from the input file,
     translates the words (if possible),
     and writes them to the output file.
     """
     searchTree = AVLTree()
     for line in dictionary.readlines():
         words = line.split()
         assert len(words) == 2
         searchTree.insert(Association(words[0], words[1]))
     for line in input.readlines():
         for word in line.split():
             assoc = searchTree.find(Association(word))
             if assoc is None:
                 output.write(word + " ")
             else:
                 output.write(assoc.value + " ")
         output.write("\n")
Exemple #2
0
def getSearchTree(coord_list):
    """
    coord_list is a list of (start, end) positions.
    """
    coordTree = AVLTree()

    # Make sure coords are unique
    coord_list_set = set(coord_list)

    for coord in coord_list_set:
        # ERROR CHECKING
        if type(coord) != type((1, 2)):
            raise TypeError(("List should be of tuples"))
        if len(coord) != 2:
            raise ValueError(("Tuple should only have two elements)"))
        # Will raise exception if the coordinates are not numbers
        val_check = coord[1] - coord[0]

        coordTree.insert(coord)

    return coordTree
    def translate(dictionary, input, output):
        """
        (File, File, File) -> None
        Reads all the word pairs from the dictionary file
        and then reads words from the input file,
        translates the words (if possible),
        and writes them to the output file.
        """
        searchTree = AVLTree()
        for line in dictionary.readlines():
            words = line.split()
	    assert len(words) == 2
            searchTree.insert(Association(words[0], words[1]))
        for line in input.readlines():
            for word in line.split():
                assoc = searchTree.find(Association(word))
                if assoc is None:
                    output.write(word + " ")
                else:
                    output.write(assoc.value + " ")
            output.write("\n")
def getSearchTree(coord_list):
    """
    coord_list is a list of (start, end) positions.
    """
    coordTree = AVLTree()

    # Make sure coords are unique
    coord_list_set = set(coord_list)
    
    for coord in coord_list_set:
        # ERROR CHECKING
        if type(coord) != type((1,2)):
            raise TypeError, ("List should be of tuples")
        if len(coord) != 2:
            raise ValueError, ("Tuple should only have two elements)")
        # Will raise exception if the coordinates are not numbers
        val_check = coord[1] - coord[0]

        coordTree.insert(coord)
       
    return coordTree