-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtests.py
61 lines (51 loc) · 2.34 KB
/
tests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
def get_rank_corr(langcode, trans_base_dir, orig_base_dir,
ntop=1000, for_words=False, write_data=True):
if for_words:
entry = "word"
else:
entry = "sentence"
dt = (pd.read_csv(f"{trans_base_dir}top_{entry}s/"
+ f"{langcode}_top_{entry}s.csv")
.assign(**{f"{entry}": lambda x: x[entry].str.strip(" .?!¿¡")})
.assign(**{f"{entry}": lambda x: x[entry].str.lower()})
.groupby(by=[entry]).sum()
.sort_values(by=["count"], ascending=False)
.reset_index()
.assign(rankt = lambda x: x.index)
.drop(columns="count")
.drop_duplicates(subset=entry, keep=False))
do = (pd.read_csv(f"{orig_base_dir}top_{entry}s/"
+ f"{langcode}_top_{entry}s.csv")
.assign(**{f"{entry}": lambda x: x[entry].str.strip(" .?!¿¡")})
.assign(**{f"{entry}": lambda x: x[entry].str.lower()})
.groupby(by=[entry]).sum()
.sort_values(by=["count"], ascending=False)
.reset_index()
.assign(ranko = lambda x: x.index)
.drop(columns="count")
.drop_duplicates(subset=entry, keep=False))
dm = dt.merge(do, on=entry, how="left")
dm["ranko"] = pd.to_numeric(dm["ranko"].fillna(len(dm)), downcast="integer")
if write_data:
dm.to_csv(f"{orig_base_dir}{langcode}_{entry}_rank_comparison.csv")
corr_fillna = (dm[0:ntop].corr(numeric_only=True)
.loc["rankt", "ranko"])
corr_omitna = (dm[dm.ranko != len(dm)][0:ntop]
.corr(numeric_only=True).loc["rankt", "ranko"])
return {"corr_fillna": corr_fillna, "corr_omitna": corr_omitna}
get_rank_corr(langcode="en",
trans_base_dir="bld/",
orig_base_dir="bld/original_language_only/",
ntop=1000, for_words=False)
get_rank_corr(langcode="en",
trans_base_dir="bld/",
orig_base_dir="bld/original_language_only/",
ntop=1000, for_words=True)
get_rank_corr(langcode="es",
trans_base_dir="bld/",
orig_base_dir="bld/original_language_only/",
ntop=1000, for_words=False)
get_rank_corr(langcode="es",
trans_base_dir="bld/",
orig_base_dir="bld/original_language_only/",
ntop=1000, for_words=True)