File: ambiguity_calculation.py

package info (click to toggle)
apertium-eo-en 1.0.0~r63833-3
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 28,044 kB
  • sloc: xml: 32,398; python: 364; sh: 318; makefile: 131
file content (35 lines) | stat: -rwxr-xr-x 848 bytes parent folder | download | duplicates (3)
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
#!/usr/bin/python
# coding=utf-8
# -*- encoding: utf-8 -*-

# USAGE: 
# python ambiguity_calculation.py tmp1_apertium-eo-en.eo.dix

import sys, codecs, copy, commands, tempfile;

sys.stdin  = codecs.getreader('utf-8')(sys.stdin);
sys.stdout = codecs.getwriter('utf-8')(sys.stdout);
sys.stderr = codecs.getwriter('utf-8')(sys.stderr);

out = tempfile.mktemp();
LTEXPAND = 'lt-expand';
commands.getstatusoutput(LTEXPAND + ' ' + sys.argv[1] + ' | sed "s/:>:/:/g" | sed "s/:<:/:/g" | sort -u > ' + out);

h = {};
sf_count = 0.0;
total = 0.0;
for line in file(out).read().split('\n'): #{
	row = line.split(':');
	sf = row[0];
	if sf in h: #{
		h[sf] = h[sf] + 1.0;
	else: #{
		h[sf] = 1.0;
		sf_count = sf_count + 1.0;
	#}
	total = total + 1.0;
#}

print 'total sf:' , sf_count;
print 'total analyses:' , total;
print 'mean ambig.:' , total / sf_count;