示例#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]
示例#2
0
def test_get_hanja():
    assert u'安寧' == get_hanja(u'안녕')