Created
October 22, 2017 14:24
-
-
Save pyliaorachel/fd18a14032333ed0432786e8395a2ddb to your computer and use it in GitHub Desktop.
Remove non Chinese or non space characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # | |
| # Usage: python3 clean_chinese_corpus.py <corpus-to-clean> > <output> | |
| # | |
| import argparse | |
| import re | |
| # Parse args | |
| parser = argparse.ArgumentParser(description='Clean Chinese corpus') | |
| parser.add_argument('filename', metavar='F', type=str, nargs=1, | |
| help='file to be cleaned') | |
| args = parser.parse_args() | |
| # Clean corpus | |
| with open(args.filename[0]) as f: | |
| for line in f: | |
| for c in re.findall(r'[\u4e00-\u9fff|\s]+', line): | |
| print(c, end='') | |
| print('') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment