forked from ufal/hamledt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
coordination_samples.pl
282 lines (240 loc) · 7.26 KB
/
coordination_samples.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
#!/usr/bin/env perl
# Usage:
# coordination_samples.pl | treex -Lmul Read::CoNLLX Write::Treex
# ttred noname.treex.gz &
use utf8;
use open ':utf8';
binmode(STDOUT, ':utf8');
binmode(STDERR, ':utf8');
my @coord_sample = (
'cs' => 'praha' =>
'jablka , pomeranče a citróny',
'4 4 4 0 4',
'XXX_M AuxX XXX_M Coord XXX_M',
'sl' => 'praha' =>
'jabolka , pomaranče in limone',
'4 4 4 0 4',
'XXX AuxX XXX Coord XXX',
'la' => 'praha' =>
'pomis , oranges et lemons',
'4 4 4 0 4',
'XXX_CO AuxX XXX_CO COORD XXX_CO',
'el' => 'praha' =>
'μήλα , πορτοκάλια και λεμόνια',
'4 4 4 0 4',
'XXX_Co AuxX XXX_Co Coord XXX_Co',
'grc' => 'praha' =>
'μήλα , πορτοκάλια και λεμόνια',
'4 4 4 0 4',
'XXX_CO AuxX XXX_CO COORD XXX_CO',
'ar' => 'praha' =>
# alnfáh wa albrtqál wa allímún
'التفاح و البرتقال و الليمون',
'4 4 4 0 4',
'XXX AuxY XXX Coord XXX',
'ta' => 'praha' =>
# áppiļ , áraňču maŗŗum pařaŋkaļ
'ஆப்பிள் , ஆரஞ்சு மற்றும் பழங்கள்',
'4 4 4 0 4',
'XXX_Co AuxX XXX_Co Coord XXX_Co',
'nl' => 'praha' =>
'appels , sinaasappels en citroenen',
'4 1 4 0 4',
'cnj punct cnj XXX cnj',
'hi' => 'praha' =>
# séba , sañtaré aura níñbú
'सेब , संतरे और नींबू',
'4 1 4 0 4',
'ccof rsym ccof XXX ccof',
'bn' => 'praha' =>
# ápéla , kamalá ébañ lébu
'আপেল , কমলা এবং লেবু',
'4 1 4 0 4',
'ccof rsym ccof XXX ccof',
'te' => 'praha' =>
# ápilla , náriñdža mariju nimmapañđu
'ఆపిల్ల , నారింజ మరియు నిమ్మపండు',
'4 1 4 0 4',
'ccof adv ccof XXX ccof',
'eu' => 'praha' =>
'sagarrak , laranjak eta limoiak',
'4 1 4 0 4',
'lot PUNC lot XXX lot',
# Note: Estonian treebank is originally constituent-based.
# "Original" dependency style is thus what we created during conversion.
'et' => 'praha' =>
'õunad , apelsinid ja sidrunid',
'4 4 4 0 4',
'NR NR NR NR NR',
# Note: Romanian treebank does not include punctuation.
'ro' => 'praha-budapest' =>
'mere portocale şi lămâi',
'0 3 0 3',
'XXX rel.conj. XXX rel.conj.',
'zh' => 'taibei' =>
# pínguǒ , chéngzǐ hé níngméng
'蘋果 , 橙子 和 檸檬',
'2 4 2 0 4',
'DUMMY1 DUMMY1 DUMMY2 DUMMY DUMMY2',
# according to 001.treex#161?
# Similar to nested coordination in Praguian style.
# But it seems that this is semantically a 3-member coordination rather than two nested structures.
'sv' => 'moskva' =>
'äpplen , apelsiner och citroner',
'0 3 1 5 3',
'XXX IK CC ++ CC',
'de' => 'moskva' =>
'Äpfel , Orangen und Zitronen',
'0 1 1 3 3',
'XXX PUNC CJ CD CJ',
'en' => 'moskva' =>
'apples , oranges and lemons',
'0 1 1 3 4',
'XXX P COORD COORD CONJ', #! second member and conjunction both have COORD!
# Note: Russian treebank does not include punctuation.
'ru' => 'moskva' =>
'яблоки апельсины и лимоны',
'0 1 2 3',
'XXX сочин сочин соч-союзн',
'tr' => 'moskvaR' =>
'elma , portakal ve limon',
'2 3 4 5 0',
'XXX COORDINATION XXX COORDINATION XXX',
'ja' => 'moskvaR' =>
# ringo to orendži to remon
'リンゴ と オレンジ と レモン',
'3 1 5 3 0',
'HD MRK HD MRK XXX',
# 001.treex#80: 2-member coordination, 'to' attached to following member
# 001.treex#165: 3-member coordination?, 'to' attached to previous member
'bg' => 'stanford' =>
'ябълки , портокали и лимони',
'0 1 1 1 1',
'XXX punct conjarg conj conjarg',
'pt' => 'stanford' =>
'maçãs , laranjas e limões',
'0 1 1 1 1',
'XXX PUNC CJT CO CJT',
'es' => 'stanford' =>
'manzanas , naranjas y limones',
'0 1 1 1 1',
'XXX f sn coord sn',
'ca' => 'stanford' =>
'pomes , taronges i llimones',
'0 1 1 1 1',
'XXX PUNC CONJUNCT CO CONJUNCT',
'it' => 'stanford' =>
'mele , arance e limoni',
'0 1 1 1 1',
'XXX con cong con cong',
'fi' => 'stanford' =>
'omenat , appelsiinit ja sitruunat',
'0 1 1 1 1',
'XXX punct conj cc conj',
'da' => 'stanford2' =>
'æbler , appelsiner og citroner',
'0 1 1 1 4',
'XXX pnct conj coord conj',
'hu' => 'budapest' =>
'alma , narancs és citrom' =>
'0 0 0 0 0',
'XXX PUNCT XXX CONJ XXX',
#is: epli, appelsínur og sítrónur
# Icelandic treebank has not been converted to Treex
);
my @samples = read_samples(@coord_sample);
if(@ARGV[0] eq 'latex')
{
latex(@samples);
}
else
{
# Print trees in CoNLL format.
foreach my $sample (@samples)
{
my $i = 0;
for($i = 0; $i<=$#{$sample->{forms}}; $i++)
{
print($i+1, "\t$sample->{forms}[$i]\t_\t_\t_\t_\t$sample->{links}[$i]\t$sample->{afuns}[$i]\t_\t_\n");
}
print($i+1, "\t$sample->{language}\t_\t_\t_\t_\t0\t$sample->{style}\t_\t_\n");
print("\n");
}
}
sub read_samples
{
my @input = @_;
my @samples;
for(my $i = 0; $i<=$#input; $i += 5)
{
my @forms = split(/\s+/, $input[$i+2]);
my @links = split(/\s+/, $input[$i+3]);
my @afuns = split(/\s+/, $input[$i+4]);
my %record =
(
'language' => $input[$i],
'style' => $input[$i+1],
'forms' => \@forms,
'links' => \@links,
'afuns' => \@afuns
);
push(@samples, \%record);
}
return @samples;
}
#------------------------------------------------------------------------------
# Převede stromečky do LaTeXové notace.
#------------------------------------------------------------------------------
sub latex
{
my @samples = @_;
foreach my $sample (@samples)
{
# Vzorek má n uzlů, chybí prvek pro kořen a museli bychom neustále přepočítávat indexy.
# Raději tedy nejdříve přidáme kořen s indexem 0.
my @forms = @{$sample->{forms}};
unshift(@forms, '');
my @links = @{$sample->{links}};
unshift(@links, -1);
die(scalar(@forms).'!='.scalar(@links)) if(scalar(@forms)!=scalar(@links));
# Přepsat uzly do matice.
# x-ová souřadnice uzlu je jeho pořadí ve větě.
# y-ová souřadnice uzlu je jeho hloubka.
# Matici ale vyrobíme jako $matrix[$y][$x] kvůli vypisování.
my @depths;
my @matrix;
for(my $i = 0; $i<=$#links; $i++)
{
# Zjistit hloubku i-tého uzlu.
my $h = 0;
for(my $j = $i; $j>0; $j = $links[$j])
{
$h++;
}
$depths[$i] = $h;
# Vypsat slovo.
if($i>0)
{
$matrix[$h][$i] .= "\\K{$forms[$i]}";
# Víme, že rodič má hloubku o 1 nižší, můžeme tedy rovnou vygenerovat i hranu od něj k nám.
my $r = $links[$i];
my $arc = 'd';
# Jestliže je rodič napravo od nás, hrana povede doleva.
if($r>$i)
{
$arc .= join('', 'l' x ($r-$i));
}
# Jestliže je rodič nalevo od nás, hrana povede doprava.
else
{
$arc .= join('', 'r' x ($i-$r));
}
$matrix[$h-1][$r] .= "\\B{$arc}";
}
}
# Matice je hotová, vypsat tabulku.
print("\\scalebox{\\treescalingfactor}{\\Treek[-0.8]{1.3}{\n");
print(join(" \\\\\n", map {join(' & ', @{$_})} (@matrix)), " \\\\\n");
print("}}\n");
}
}