-
Notifications
You must be signed in to change notification settings - Fork 3
/
beta2unicode.pl
executable file
·150 lines (147 loc) · 4.76 KB
/
beta2unicode.pl
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#!/usr/bin/perl
# Converts Beta code (Ancient Greek text) to Unicode.
# Based on http://www.tlg.uci.edu/encoding/quickbeta.pdf
# Copyright © 2011 Dan Zeman <zeman@ufal.mff.cuni.cz>
# License: GNU GPL
use utf8;
use open ":utf8";
binmode(STDIN, ":utf8");
binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");
use lib '/home/zeman/lib';
use translit;
%table =
(
'a' => "\x{3B1}", # alpha
'*a' => "\x{391}",
'b' => "\x{3B2}", # beta
'*b' => "\x{392}",
'c' => "\x{3BE}", # xi
'*c' => "\x{39E}",
'd' => "\x{3B4}", # delta
'*d' => "\x{394}",
'e' => "\x{3B5}", # epsilon
'*e' => "\x{395}",
'f' => "\x{3C6}", # phi
'*f' => "\x{3A6}",
'g' => "\x{3B3}", # gamma
'*g' => "\x{393}",
'h' => "\x{3B7}", # eta
'*h' => "\x{397}",
'i' => "\x{3B9}", # iota
'*i' => "\x{399}",
'k' => "\x{3BA}", # kappa
'*k' => "\x{39A}",
'l' => "\x{3BB}", # lambda
'*l' => "\x{39B}",
'm' => "\x{3BC}", # mu
'*m' => "\x{39C}",
'n' => "\x{3BD}", # nu
'*n' => "\x{39D}",
'o' => "\x{3BF}", # omicron
'*o' => "\x{39F}",
'p' => "\x{3C0}", # pi
'*p' => "\x{3A0}",
'q' => "\x{3B8}", # theta
'*q' => "\x{398}",
'r' => "\x{3C1}", # rho
'*r' => "\x{3A1}",
's' => "\x{3C3}", # sigma
's1' => "\x{3C3}",
's2' => "\x{3C2}", # final sigma
's3' => "\x{3F2}", # lunate sigma
'*s' => "\x{3A3}",
'*s3'=> "\x{3F9}",
't' => "\x{3C4}", # tau
'*t' => "\x{3A4}",
'u' => "\x{3C5}", # upsilon
'*u' => "\x{3A5}",
'v' => "\x{3DD}", # digamma
'*v' => "\x{3DC}",
'w' => "\x{3C9}", # omega
'*w' => "\x{3A9}",
'x' => "\x{3C7}", # chi
'*x' => "\x{3A7}",
'y' => "\x{3C8}", # psi
'*y' => "\x{3A8}",
'z' => "\x{3B6}", # zeta
'*z' => "\x{396}",
')' => "\x{313}", # comma above / smooth breathing
'(' => "\x{314}", # reversed comma above / rough breathing
'/' => "\x{301}", # acute accent
'=' => "\x{342}", # perispomeni / circumflex accent
'\\' => "\x{300}", # grave accent
'+' => "\x{308}", # diaeresis
'|' => "\x{345}", # ypogegrammeni / iota subscript
'?' => "\x{323}", # dot below
"'" => "\x{2019}", # right single quotation mark (Unicode-recommended for apostrophe; the ASCII is only for backward compatibility)
###!!! The Unicode standard and the Thesaurus Linguae Grecae documentation suggest that \x{2010} is the correct character for hyphen,
###!!! while \x{2D} is ambiguous between hyphen and minus in meaning and should not be used.
###!!! Unfortunately, most of my Windows fonts just lack the glyph for \x{2010} so this conversion seems to do more harm than good.
# '-' => "\x{2010}", # hyphen
'_' => "\x{2014}", # em dash
);
foreach my $key (keys(%table))
{
# Some data use uppercase instead of lowercase Latin letters. Uppercase Greek letters are still marked with asterisk.
if($key =~ m/[a-z]/)
{
my $ukey = uc($key);
$table{$ukey} = $table{$key};
}
# Diacritics can appear between asterisk and letter.
if($key =~ m/^\*([a-zA-Z])$/)
{
my $letter = $1;
my @diacritics = ('(', ')', '/', '=', '\\', '+', '|', '?', "'", '-', '_');
foreach my $d (@diacritics)
{
$table{'*'.$d.$letter} = $table{$d}.$table{'*'.$letter};
# Even two consecutive diacritical marks are possible.
foreach my $d1 (@diacritics)
{
$table{'*'.$d.$d1.$letter} = $table{$d}.$table{$d1}.$table{'*'.$letter};
}
}
}
}
foreach my $key (keys(%table))
{
my $l = length($key);
if($l>$maxl)
{
$maxl = $l;
}
}
#translit::vypsat(\%table); exit;
while(<>)
{
if(m/^\s*$/)
{
print;
}
else
{
# We assume CoNLL format and convert only the 'form' and 'lemma' fields.
chomp();
my @fields = split(/\t/, $_);
$fields[1] = translit::prevest(\%table, $fields[1], $maxl);
my $fields2zaloha = $fields[2];
$fields[2] = translit::prevest(\%table, $fields[2], $maxl) unless($fields[2] =~ m/^(comma|period|hyphen|double|quote|bracket|punc|other|unknown)1?$/i);
###!!! Malá statistika lemmat interpunkce.
if($fields[1] !~ m/\pL/)
{
my $kody = join('+', map {ord($_)} (split(//, $fields[1])));
$interpunkce{"'$fields[1]' $kody '$fields2zaloha' '$fields[2]'"}++;
}
# The transliteration table cannot distinguish word-final sigma (it is marked explicitly only if it cannot be determined by position).
$fields[1] =~ s/\x{3C3}$/\x{3C2}/;
$fields[2] =~ s/\x{3C3}$/\x{3C2}/;
print(join("\t", @fields), "\n");
}
}
###!!! Vypsat statistiku.
foreach my $klic (sort(keys(%interpunkce)))
{
print STDERR ("$klic\t$interpunkce{$klic}\n");
}