Zaktualizuj 'run.py'
This commit is contained in:
parent
f415a39194
commit
15bc161011
66
run.py
66
run.py
@ -1,7 +1,65 @@
|
||||
for dataset in 'dev-0', 'dev-1', 'test-A':
|
||||
with open(f'{dataset}/in.tsv') as f_in, open(f'{dataset}/out.tsv','w') as f_out:
|
||||
for line in f_in:
|
||||
f_out.write('0.45\n')
|
||||
men = ['samochód', 'auto', 'audi', 'bmw', 'mercedes', 'windows', 'silnika', 'mb', 'gb', 'mecz', 'legia', 'lech', 'real', 'komputer', 'telefon', 'apple', 'iphone', 'zwiastuny', 'hd',
|
||||
'windows', 'system', 'serwer', 'serwery', 'siłownia', 'biceps', 'triceps']
|
||||
woman = ['zrobiłam', 'byłam', 'pojechałam','ciąży', 'miesiączki', 'makijaż', 'perfumy', 'kompleks', 'ciąża', 'ciazy', 'antykoncepcyjne', 'ginekologa',
|
||||
'tabletki', 'sukienka', 'spódniczka', 'mąż', 'miesiączkę', 'samotność', 'kolczyki']
|
||||
def database(men, woman):
|
||||
men_base = []
|
||||
woman_base = []
|
||||
for i in men:
|
||||
men_base.append(i[:10].lower())
|
||||
for i in woman:
|
||||
woman_base.append(i[:10].lower())
|
||||
return men_base, woman_base
|
||||
def predict(men_base, woman_base, data):
|
||||
res = []
|
||||
i = 0
|
||||
for slowo in data:
|
||||
men_count = 0
|
||||
woman_count = 0
|
||||
term = slowo.split()
|
||||
|
||||
for w in term:
|
||||
if w[:10].lower() in men_base:
|
||||
men_count = men_count + 1
|
||||
elif w[:10].lower() in woman_base:
|
||||
woman_count = woman_count + 1
|
||||
if men_count >= woman_count:
|
||||
result.append('1')
|
||||
elif men_count < woman_count:
|
||||
result.append('0')
|
||||
return result
|
||||
|
||||
|
||||
def out_file(result, name):
|
||||
with open(name, 'w') as file:
|
||||
for program in result:
|
||||
file.write(program + "\n")
|
||||
|
||||
|
||||
men_dict, woman_dict = database(men, woman)
|
||||
data = []
|
||||
with open('dev-0/in.tsv') as data:
|
||||
for idx, line in enumerate(data.readlines()):
|
||||
data.append(line.replace('\n', ''))
|
||||
|
||||
result = predict(men_dict, woman_dict, data)
|
||||
out_file(result, 'dev-0/out.tsv')
|
||||
|
||||
data2 = []
|
||||
with open('dev-1/in.tsv') as data:
|
||||
for idx, line in enumerate(data.readlines()):
|
||||
data2.append(line.replace('\n', ''))
|
||||
|
||||
result = predict(men_dict, woman_dict, data2)
|
||||
out_file(result, 'dev-1/out.tsv')
|
||||
|
||||
data3 = []
|
||||
with open('test-A/in.tsv') as data:
|
||||
for idx, line in enumerate(data.readlines()):
|
||||
data3.append(line.replace('\n', ''))
|
||||
|
||||
result = predict(men_dict, woman_dict, data3)
|
||||
out_file(result, 'test-A/out.tsv')
|
||||
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user