+def make_frequency_compare_function(target_frequency, frequency_scaling, metric, invert):
+ def frequency_compare(text):
+ counts = frequency_scaling(frequencies(text))
+ if invert:
+ score = -1 * metric(target_frequency, counts)
+ else:
+ score = metric(target_frequency, counts)
+ return score
+ return frequency_compare
+
+def scoring_functions():
+ return [{'func': make_frequency_compare_function(s['corpus_frequency'],
+ s['scaling'], m['func'], m['invert']),
+ 'name': '{} + {}'.format(m['name'], s['name'])}
+ for m in metrics
+ for s in scalings] + [{'func': Pletters, 'name': 'Pletters'}]
+
+def eval_scores():
+ [eval_one_score(f, l)
+ for f in scoring_functions()
+ for l in message_lengths]
+
+def eval_one_score(scoring_function, message_length):
+ print(scoring_function['name'], message_length)
+ if scoring_function['name'] not in scores:
+ scores[scoring_function['name']] = collections.defaultdict(int)