Skip to content

Instantly share code, notes, and snippets.

@pyliaorachel
Created October 22, 2017 14:24
Show Gist options
  • Select an option

  • Save pyliaorachel/fd18a14032333ed0432786e8395a2ddb to your computer and use it in GitHub Desktop.

Select an option

Save pyliaorachel/fd18a14032333ed0432786e8395a2ddb to your computer and use it in GitHub Desktop.
Remove non Chinese or non space 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