Example #1
0
def _convert_to_bchar(in_path_prefix: str, src: str, tgt: str, out_path: str):
    print(f"convert to bchar {in_path_prefix}")
    with open(out_path, "w") as f_o:
        for lang in [src, tgt]:
            with open(f"{in_path_prefix}.{lang}") as f:
                for s in f:
                    f_o.write(byte_encode(s.strip()) + "\n")
Example #2
0
def _convert_to_bchar(in_path_prefix: str, src: str, tgt: str, out_path: str):
    with open(out_path, 'w') as f_o:
        for lang in [src, tgt]:
            with open(f'{in_path_prefix}.{lang}') as f:
                for s in f:
                    f_o.write(byte_encode(s.strip()) + '\n')
Example #3
0
 def encode(x: str) -> str:
     encoded = byte_encode(x)
     escaped = encoded.replace(SPACE, SPACE_ESCAPE)
     return SPACE.join(list(escaped))
Example #4
0
 def encode(self, x: str) -> str:
     byte_encoded = byte_encode(x)
     return SPACE.join(self.sp.EncodeAsPieces(byte_encoded))