Urdatorn commited on
Commit
5b1dcc8
·
verified ·
1 Parent(s): 21f57d7

Script for the work-level crawl regrouping (Section 4b)

Browse files
analysis/oga_diagnostics_crawl_by_work.json CHANGED
@@ -432,6 +432,8 @@
432
  "cohens_d": -2.19654029139679
433
  }
434
  ],
 
 
435
  "crawl_work_list": [
436
  {
437
  "work": "tlg0013.tlg012.perseus-grc2",
 
432
  "cohens_d": -2.19654029139679
433
  }
434
  ],
435
+ "hypotactic_share_in_crawl": 0.2352330487359224,
436
+ "hypotactic_share_outside": 0.02404803148605568,
437
  "crawl_work_list": [
438
  {
439
  "work": "tlg0013.tlg012.perseus-grc2",
analysis/scripts/regroup_crawl_by_work.py ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """Section 4b of the diagnostics report: dialect groups and contrasts with crawl membership
2
+ decided per work (share of sentences overlapping the hypotactic crawl >= 0.15; the scores are
3
+ bimodal), from the per-work figures in stats_v2.json (analyze_v2.py).
4
+ Usage: python regroup_crawl_by_work.py stats_v2.json OUT_JSON"""
5
+ import json, sys
6
+ import numpy as np
7
+ from scipy import stats
8
+ r = json.load(open(sys.argv[1])); W = r['works']
9
+ for w in W: w['in_crawl'] = w['frac_sent_in_crawl'] >= 0.15
10
+ order = ['Epic', 'Doric/Aeolic lyric and bucolic', 'Ionic prose', 'Attic drama', 'Classical Attic prose', 'Koine',
11
+ 'Atticist / Imperial and late literary prose', 'other']
12
+ out = {'threshold': 0.15, 'groups': [], 'contrasts': []}
13
+ def pooled(ws):
14
+ D = sum(w['dichrona'] for w in ws)
15
+ if not D: return None
16
+ return dict(works=len(ws), dichrona=D, cov=1 - sum(w['dichrona'] * (1 - w['cov']) for w in ws) / D,
17
+ cov_nohyp=1 - sum(w['dichrona'] * (1 - w['cov_nohyp']) for w in ws) / D)
18
+ for g in order:
19
+ ws = [w for w in W if w['group'] == g]
20
+ out['groups'].append(dict(group=g, all=pooled(ws), in_crawl=pooled([w for w in ws if w['in_crawl']]),
21
+ outside=pooled([w for w in ws if not w['in_crawl']])))
22
+ DIAL = {'Epic', 'Doric/Aeolic lyric and bucolic', 'Ionic prose'}; ATT = {'Attic drama', 'Classical Attic prose'}
23
+ LAT = {'Koine', 'Atticist / Imperial and late literary prose'}
24
+ def samp(G, key, crawl):
25
+ return np.array([w[key] for w in W if w['group'] in G and w['dichrona'] >= 2000 and (crawl is None or w['in_crawl'] == crawl)])
26
+ for label, A, B in [('dialectal vs Attic', DIAL, ATT), ('dialectal vs Koine/Atticist', DIAL, LAT), ('Attic vs Koine/Atticist', ATT, LAT),
27
+ ('Epic vs Attic', {'Epic'}, ATT), ('Doric/Aeolic vs Attic', {'Doric/Aeolic lyric and bucolic'}, ATT),
28
+ ('Ionic prose vs Classical Attic prose', {'Ionic prose'}, {'Classical Attic prose'})]:
29
+ for key in ('cov', 'cov_nohyp'):
30
+ for crawl in (None, False):
31
+ a, b = samp(A, key, crawl), samp(B, key, crawl)
32
+ if len(a) >= 3 and len(b) >= 3:
33
+ t = stats.ttest_ind(a, b, equal_var=False); u = stats.mannwhitneyu(a, b)
34
+ d = (a.mean() - b.mean()) / np.sqrt((a.var(ddof=1) + b.var(ddof=1)) / 2)
35
+ out['contrasts'].append(dict(contrast=label, measure=key, works='outside crawl only' if crawl is False else 'all',
36
+ n_a=len(a), n_b=len(b), mean_a=a.mean(), mean_b=b.mean(), diff_pp=100 * (a.mean() - b.mean()),
37
+ t=t.statistic, p_welch=t.pvalue, p_mw=u.pvalue, cohens_d=d))
38
+ for lab, ws in (('in_crawl', [w for w in W if w['in_crawl']]), ('outside', [w for w in W if not w['in_crawl']])):
39
+ D = sum(w['dichrona'] for w in ws)
40
+ out['hypotactic_share_' + lab] = sum(w['dichrona'] * w['hyp_share'] for w in ws) / D
41
+ out['crawl_work_list'] = [dict(work=w['work'], author=w['author'], frac=w['frac_sent_in_crawl'], cov=w['cov'], cov_nohyp=w['cov_nohyp'],
42
+ hyp_share=w['hyp_share']) for w in sorted([w for w in W if w['in_crawl']], key=lambda x: -x['frac_sent_in_crawl'])]
43
+ json.dump(out, open(sys.argv[2], 'w'), ensure_ascii=False, indent=1, default=float)