pybrl.py 文件源码

python
阅读 48 收藏 0 点赞 0 评论 0

项目:pybrl 作者: ant0nisk 项目源码 文件源码
def toUnicodeSymbols(brl, flatten=False):
    """
     Constructs the Unicode representation of a translated braille sentence.
     If flatten=False, a list is returned in the same format as the input.
     Otherwise, a string is returned with the translated Braille in Unicode.
    """
    retObj=[]

    for wrd in brl:
        retObj.append([])
        for ch in wrd:
            binary_repr = int(ch[::-1], 2)
            hex_val = hex(binary_repr)[2:]
            if len(hex_val) == 1: hex_val = "0" + hex_val

            uni_code = "28{}".format(hex_val)
            uni_code = unichr(int(uni_code, 16))
            retObj[-1].append(uni_code)

    if flatten:
        flattened_array = []
        for j in retObj:
            for i in j:
                flattened_array.append(i)

            flattened_array.append(" ") # Include a space between two words

        return "".join(flattened_array)

    return retObj
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号