From 15bc16101177ee1b7354a3018dd6221f35684197 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Dembi=C5=84ski?= Date: Tue, 26 Apr 2022 23:21:35 +0200 Subject: [PATCH] Zaktualizuj 'run.py' --- run.py | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 4 deletions(-) diff --git a/run.py b/run.py index 9eff044..0f09e05 100644 --- a/run.py +++ b/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')