123456789101112131415161718192021222324252627282930313233343536 |
- import argparse
- import math
- import numpy as np
- parser = argparse.ArgumentParser()
- parser.add_argument('--start', type=int, default=2)
- parser.add_argument('--end', type=int, default=30)
- parser.add_argument('--step', type=int, default=2)
- parser.add_argument('--word_num', type=int, default=10)
- parser.add_argument('--dict_path', type=str, default='chn_dict.txt')
- parser.add_argument('--save_path', type=str, default='chn_text.txt')
- args = parser.parse_args()
- words_2000 = ''
- with open('dict_chn_2000.txt', 'r', encoding='utf-8') as fp:
- words_2000 = fp.readlines()
- fp.close()
- words2_3500 = ''
- with open('dict_chn_3500.txt', 'r', encoding='utf-8') as fp:
- words_3500 = fp.readlines()
- fp.close()
- wp = open(args.save_text, 'w', encoding='utf-8')
- for i in range(args.start, args.end+1, args.step):
- for j in range(0, args.word_num):
- x = int(i/3)
- arr1 = np.random.rand(x)*3500
- arr2 = np.random.rand(i-x)*2000
- text = ''
- for num in arr1:
- text += words_3500[0][math.floor(num)]
- for num in arr2:
- text += words_2000[0][math.floor(num)]
- wp.write(text+'\n')
- wp.close()
|