Skip to content

Instantly share code, notes, and snippets.

@eileen-code4fun
Created February 3, 2022 23:09
Show Gist options
  • Save eileen-code4fun/b462058cb658229a570c4739e0fcfe23 to your computer and use it in GitHub Desktop.
Save eileen-code4fun/b462058cb658229a570c4739e0fcfe23 to your computer and use it in GitHub Desktop.
Filling Placeholders
import names
def populate(in_filename, out_filename):
out = []
with open(in_filename) as f:
for l in f.readlines():
parts = l.split('|||')
nli_template = parts[0].strip().split()
nli = []
target = []
for w in nli_template:
if w == '[e_name_1]':
name = names.get_full_name().split()
nli.extend(name)
target.extend(['1' for n in name])
elif w == '[e_salary_1]':
nli.append(str(random.randint(50000, 500000)))
target.append('2')
elif w == '[e_salary_2]':
nli.append(str(random.randint(50000, 500000)))
target.append('3')
elif w == '[e_gender_1]':
nli.append(random.choice(['male', 'female']))
target.append('4')
else:
nli.append(w)
target.append('0')
out.append(' ||| '.join([' '.join(nli), ' '.join(target)]))
with open(out_filename, 'w') as f:
for o in out:
f.write(o + '\n')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment