Beispiel #1
0
    def compute_blocks(self, compute_ethym=False):
        """ Compute the blocks given the input string.

        Output:
            Returns a list of lists of blocks, i.e.
            [ [b11, ..., b1n1], [b21, ..., b2n2], ...], where each list of
            blocks [bi1, ..., bini] corresponds to a possible meaning of the
            input string.

        Note:
            In this implemenation, only one meaning is available.
        """
        if DEBUG:
            UI.render_info('compute_blocks(...) called for word ' + self.string)

        if not compute_ethym:
            blocks = [Block(self.string_without_suffix[i]) \
                            for i in range(len(self.string_without_suffix)) \
                            if self.string_without_suffix[i] != ' ']
        else:
            ethym = get_hanja(self.string_without_suffix)
            if DEBUG:
                UI.render_info(ethym)

            blocks = [Block(self.string_without_suffix[i], ethym=ethym[i], \
                        meaning=self.db_util.get_hanja_meaning(ethym[i]), \
                        name=self.db_util.get_hanja_name(ethym[i])) \
                        for i in range(len(self.string_without_suffix)) \
                        if self.string_without_suffix[i] != ' ']

        if self.suffix:
            suffix_desc = 'Suffix: ' + self.suffix_meaning
            blocks.append(Block(self.suffix, meaning=suffix_desc))

        return [blocks]
Beispiel #2
0
 def print_blocks_for_selected_meaning(self):
     """ 
     This methods prints the block strings for the selected meaning. 
     """
     UI.render_info('print blocks for selected meaning')
     UI.render_info([block.get_str() for block in self.blocks[self.selected_meaning]])
     return [block.get_str() for block in self.blocks[self.selected_meaning]]
Beispiel #3
0
 def __init__(self, string='', meaning=None, compute_ethym=False):
     self.string = string  # e.g. user input string
     self.language = 'Thai'
     self.blocks = [self.compute_blocks(self.string)]
     self.selected_meaning = 0  # index of the selected meaning
     self.meanings = DbUtil().compute_meanings(
         string)  # Different meanings in English
     ui.render_info(self.meanings.head())