Interset/Tagset/IT/Conll.pm untested

filter: Statementstmt 0.0% 0 / 131 Branchbran 0.0% 0 / 2 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 13 Podpod 0.0% 0 / 7 totaltotal 0.0% 0 / 153 CC 2 SCAR 9.4
CC
2
Cov
0%
encode
6.0
get_tagset_id
2.0
_create_atoms
2.0
CRAP 2.6
1 # ABSTRACT: Driver for the Italian tagset of the CoNLL 2007 Shared Task (derived from the ISST, Italian Syntactic-Semantic Treebank).
2 # Copyright © 2011, 2014, 2017 Dan Zeman <zeman@ufal.mff.cuni.cz>
3 # Copyright © 2011 Loganathan Ramasamy <ramasamy@ufal.mff.cuni.cz>
4  
5 package Lingua::Interset::Tagset::IT::Conll;
6 use strict;
7 use warnings;
8 our $VERSION = '3.015';
9  
10 use utf8;
11 use open ':utf8';
12 use namespace::autoclean;
13 use Moose;
14 extends 'Lingua::Interset::Tagset::Conll';
15  
16  
17  
18 #------------------------------------------------------------------------------
19 # Returns the tagset id that should be set as the value of the 'tagset' feature
20 # during decoding. Every derived class must (re)define this method! The result
21 # should correspond to the last two parts in package name, lowercased.
22 # Specifically, it should be the ISO 639-2 language code, followed by '::' and
23 # a language-specific tagset id. Example: 'cs::multext'.
24 #------------------------------------------------------------------------------
25 sub get_tagset_id
26 {
27 return 'it::conll';
28 }
29  
30  
31  
32 #------------------------------------------------------------------------------
33 # Creates atomic drivers for surface features.
34 #------------------------------------------------------------------------------
35 sub _create_atoms
36 {
37 my $self = shift;
38 my %atoms;
39 # PART OF SPEECH ####################
40 $atoms{pos} = $self->create_atom
41 (
42 'surfeature' => 'pos',
43 'decode_map' =>
44 {
45 # S = common noun (presidente, anno, giorno, mondo, tempo)
46 'S' => ['pos' => 'noun', 'nountype' => 'com'],
47 # SP = proper noun (Italia, Milano, Nanni, Mayo, Allende)
48 'SP' => ['pos' => 'noun', 'nountype' => 'prop'],
49 # SW = foreign word (publishing, desktop, le, Tour, hard)
50 'SW' => ['pos' => 'noun', 'foreign' => 'yes'],
51 # SA = abbreviated noun (L., mq, km, cm, tel.)
52 'SA' => ['pos' => 'noun', 'abbr' => 'yes'],
53 # A = adjective (vero, stesso, nuovo, scorso, lungo)
54 'A' => ['pos' => 'adj'],
55 # AP = possessive determiner (suo, mio, nostro, proprio, tuo, vostro)
56 'AP' => ['pos' => 'adj', 'prontype' => 'prs', 'poss' => 'yes'],
57 # RD = definite article (il, lo, i, gli, la, le, l')
58 'RD' => ['pos' => 'adj', 'prontype' => 'art', 'definite' => 'def'],
59 # RI = indefinite article (un, uno, una, un')
60 'RI' => ['pos' => 'adj', 'prontype' => 'art', 'definite' => 'ind'],
61 # PD = demonstrative pronoun (lo, quello, questo, ciò, stesso)
62 'PD' => ['pos' => 'noun', 'prontype' => 'dem'],
63 # PI = indefinite pronoun (uno, tutto, altro, nessuno, qualcuno)
64 'PI' => ['pos' => 'noun', 'prontype' => 'ind|tot|neg'],
65 # PP = possessive pronoun (tuo, lo, nostro, miei, suoi, tuoi, sua, tua)
66 ###!!! How do AP and PP differ? There are very few occurrences of PP.
67 'PP' => ['pos' => 'noun', 'prontype' => 'prs', 'poss' => 'yes'],
68 # PQ = personal pronoun (mi, io, me, ti, te, tu, lo, lui, l', li, la, lei, le, ci, noi, vi, voi, si, gli, ne, se, s', loro)
69 'PQ' => ['pos' => 'noun', 'prontype' => 'prs'],
70 # PR = relative pronoun (che, cui, quanto, qual)
71 'PR' => ['pos' => 'noun', 'prontype' => 'rel'],
72 # PT = interrogative pronoun (che, chi, quanto)
73 'PT' => ['pos' => 'noun', 'prontype' => 'int'],
74 # DD = demonstrative determiner (questo, quel, quest', quell', tale, tal)
75 'DD' => ['pos' => 'adj', 'prontype' => 'dem'],
76 # DE = ??? (very few occurrences) (che, quali)
77 'DE' => ['pos' => 'adj', 'prontype' => 'prn'],
78 # DI = indefinite determiner (tutto, altro, certo, alcun, nessun)
79 'DI' => ['pos' => 'adj', 'prontype' => 'ind|tot|neg'],
80 # DR = relative determiner (quale)
81 'DR' => ['pos' => 'adj', 'prontype' => 'rel'],
82 # DT = interrogative determiner (qual, quanta, quante, quale, quali, che)
83 'DT' => ['pos' => 'adj', 'prontype' => 'int'],
84 # N = cardinal numeral (due, tre, mila, cinque, quattro)
85 'N' => ['pos' => 'num', 'numtype' => 'card'],
86 # NO = ordinal numeral (primo, secondo, terzo, quarto, quinto)
87 'NO' => ['pos' => 'adj', 'numtype' => 'ord'],
88 # V = verb (essere, fare, dire, aver, avere)
89 'V' => ['pos' => 'verb'],
90 # B = adverb (non, più, dove, c', solo, sempre)
91 'B' => ['pos' => 'adv'],
92 # E = preposition (di, a, in, per, con)
93 'E' => ['pos' => 'adp', 'adpostype' => 'prep'],
94 # C = conjunction (e, che, anche, ma, o)
95 'C' => ['pos' => 'conj'],
96 # I = interjection (ah, grazie, ahimè, vabbè, eh)
97 'I' => ['pos' => 'int'],
98 # PU = punctuation (, . " : ?)
99 'PU' => ['pos' => 'punc'],
100 # X = unknown (/, d', 6', 34', 11'06'')
101 'X' => []
102 },
103 'encode_map' =>
104 {
105 'pos' => { 'noun' => { 'prontype' => { '' => { 'nountype' => { 'prop' => 'SP',
106 '@' => { 'abbr' => { 'yes' => 'SA',
107 '@' => { 'foreign' => { 'yes' => 'SW',
108 '@' => 'S' }}}}}},
109 'prs' => { 'poss' => { 'yes' => 'PP',
110 '@' => 'PQ' }},
111 'int' => 'PT',
112 'rel' => 'PR',
113 'dem' => 'PD',
114 'ind' => 'PI',
115 'tot' => 'PI',
116 'neg' => 'PI' }},
117 'adj' => { 'prontype' => { '' => { 'numtype' => { 'ord' => 'NO',
118 '@' => 'A' }},
119 'art' => { 'definite' => { 'def' => 'RD',
120 '@' => 'RI' }},
121 'dem' => 'DD',
122 'ind' => 'DI',
123 'tot' => 'DI',
124 'neg' => 'DI',
125 'prn' => 'DE',
126 'int' => 'DT',
127 'rel' => 'DR',
128 'prs' => 'AP' }},
129 'num' => 'N',
130 'verb' => 'V',
131 'adv' => 'B',
132 'adp' => 'E',
133 'conj' => 'C',
134 'int' => 'I',
135 'punc' => 'PU',
136 '@' => 'X' }
137 }
138 );
139 # GENDER ####################
140 $atoms{gen} = $self->create_simple_atom
141 (
142 'intfeature' => 'gender',
143 'simple_decode_map' =>
144 {
145 'M' => 'masc',
146 'F' => 'fem',
147 'N' => '' # undistinguishable
148 }
149 );
150 # NUMBER ####################
151 $atoms{num} = $self->create_simple_atom
152 (
153 'intfeature' => 'number',
154 'simple_decode_map' =>
155 {
156 'S' => 'sing',
157 'P' => 'plur',
158 'N' => '' # undistinguishable
159 }
160 );
161 # DEGREE OF COMPARISON ####################
162 $atoms{sup} = $self->create_simple_atom
163 (
164 'intfeature' => 'degree',
165 'simple_decode_map' =>
166 {
167 # absolute superlative (gravissimo, chiarissimo, bellissimo, ultimissimo, massimo)
168 'S' => 'abs'
169 }
170 );
171 # PERSON ####################
172 $atoms{per} = $self->create_simple_atom
173 (
174 'intfeature' => 'person',
175 'simple_decode_map' =>
176 {
177 '1' => '1',
178 '2' => '2',
179 '3' => '3'
180 }
181 );
182 # VERB FORM AND MOOD ####################
183 $atoms{mod} = $self->create_atom
184 (
185 'surfeature' => 'mod',
186 'decode_map' =>
187 {
188 # infinitive (essere, fare, dire, aver, avere)
189 'F' => ['verbform' => 'inf'],
190 # indicative (è, ha, può, fa, dice)
191 'I' => ['verbform' => 'fin', 'mood' => 'ind'],
192 # subjunctive (sia, possa, abbia, vada, venga)
193 'C' => ['verbform' => 'fin', 'mood' => 'sub'],
194 # conditional (sarebbe, potrebbe, avrebbe, dovrebbe, vorrebbe)
195 'D' => ['verbform' => 'fin', 'mood' => 'cnd'],
196 # imperative (vedi, ricorda-, rilassati, cerca, ripeti)
197 'M' => ['verbform' => 'fin', 'mood' => 'imp'],
198 # participle (stato, fatto, detto, venduto, visto)
199 'P' => ['verbform' => 'part'],
200 # gerund (portando, cercando, lavorando, dando, parlando)
201 'G' => ['verbform' => 'ger']
202 },
203 'encode_map' =>
204 {
205 'verbform' => { 'inf' => 'F',
206 'part' => 'P',
207 'ger' => 'G',
208 '@' => { 'mood' => { 'ind' => 'I',
209 'imp' => 'M',
210 'sub' => 'C',
211 'cnd' => 'D',
212 '@' => 'I' }}}
213 }
214 );
215 # TENSE ####################
216 $atoms{tmp} = $self->create_simple_atom
217 (
218 'intfeature' => 'tense',
219 'simple_decode_map' =>
220 {
221 # present / presente (ho, sono, so, credo, voglio)
222 'P' => 'pres',
223 # future / futuro (farò, sarò, crederò, terrò, cercherò)
224 'F' => 'fut',
225 # imperfect past / imperfetto (avevo, sentivo, ero, volevo, andavo)
226 'I' => 'imp',
227 # remote past / passato remoto (riaprii, consegnai, rimasi, passai, entrai)
228 'R' => 'past'
229 }
230 );
231 return \%atoms;
232 }
233  
234  
235  
236 #------------------------------------------------------------------------------
237 # Creates the list of all surface CoNLL features that can appear in the FEATS
238 # column. This list will be used in decode().
239 #------------------------------------------------------------------------------
240 sub _create_features_all
241 {
242 my $self = shift;
243 my @features = ('gen', 'num', 'sup', 'per', 'mod', 'tmp');
244 return \@features;
245 }
246  
247  
248  
249 #------------------------------------------------------------------------------
250 # Creates the list of surface CoNLL features that can appear in the FEATS
251 # column with particular parts of speech. This list will be used in encode().
252 #------------------------------------------------------------------------------
253 sub _create_features_pos
254 {
255 my $self = shift;
256 my %features =
257 (
258 'A' => ['gen', 'num', 'sup'],
259 'B' => ['sup'],
260 'D' => ['gen', 'num'],
261 'E' => ['gen', 'num'],
262 'N' => ['gen', 'num'],
263 'P' => ['gen', 'num', 'per'],
264 'R' => ['gen', 'num'],
265 'S' => ['gen', 'num'],
266 'SA' => ['gen', 'num'],
267 'V' => ['gen', 'num', 'per', 'mod', 'tmp'],
268 '@' => []
269 );
270 return \%features;
271 }
272  
273  
274  
275 #------------------------------------------------------------------------------
276 # Decodes a physical tag (string) and returns the corresponding feature
277 # structure.
278 #------------------------------------------------------------------------------
279 sub decode
280 {
281 my $self = shift;
282 my $tag = shift;
283 my $fs = $self->decode_conll($tag);
284 # Default feature values. Used to improve collaboration with other drivers.
285 # ... nothing yet ...
286 return $fs;
287 }
288  
289  
290  
291 #------------------------------------------------------------------------------
292 # Takes feature structure and returns the corresponding physical tag (string).
293 #------------------------------------------------------------------------------
294 sub encode
295 {
296 my $self = shift;
297 my $fs = shift; # Lingua::Interset::FeatureStructure
298 my $atoms = $self->atoms();
299 my $subpos = $atoms->{pos}->encode($fs);
300 my $pos = $subpos =~ m/^(PU|SA)$/ ? $subpos : substr($subpos, 0, 1);
301 my $feature_names = $self->get_feature_names($pos);
302 my $tag = $self->encode_conll($fs, $pos, $subpos, $feature_names);
303 # Some parts of speech require gender and number even if their values are N (not known/distinguishable).
304 # Other parts of speech prefer empty features but they can take gender and number if it is known.
305 $tag =~ s/^(E\tE|N\tN|N\tNO)\tgen=N\|num=N$/$1\t_/;
306 $tag =~ s/^V\tV\tgen=N\|(.*mod=[^P])/V\tV\t$1/;
307 $tag =~ s/^V\tV\tnum=N\|(.*mod=[^P])/V\tV\t$1/;
308 return $tag;
309 }
310  
311  
312  
313 #------------------------------------------------------------------------------
314 # Returns reference to list of known tags.
315 # Tags were collected from the corpus, 168 tags found.
316 # After cleaning: 166
317 #------------------------------------------------------------------------------
318 sub list
319 {
320 my $self = shift;
321 my $list = <<end_of_list
322 A A gen=F|num=P
323 A A gen=F|num=P|sup=S
324 A A gen=F|num=S
325 A A gen=F|num=S|sup=S
326 A A gen=M|num=N
327 A A gen=M|num=P
328 A A gen=M|num=P|sup=S
329 A A gen=M|num=S
330 A A gen=M|num=S|sup=S
331 A A gen=N|num=N
332 A A gen=N|num=P
333 A A gen=N|num=S
334 A AP gen=F|num=P
335 A AP gen=F|num=S
336 A AP gen=M|num=P
337 A AP gen=M|num=S
338 A AP gen=N|num=P
339 B B _
340 B B sup=S
341 C C _
342 D DD gen=F|num=P
343 D DD gen=F|num=S
344 D DD gen=M|num=P
345 D DD gen=M|num=S
346 D DD gen=N|num=S
347 D DE gen=N|num=N
348 D DE gen=N|num=P
349 D DI gen=F|num=P
350 D DI gen=F|num=S
351 D DI gen=M|num=P
352 D DI gen=M|num=S
353 D DI gen=N|num=N
354 D DI gen=N|num=P
355 D DI gen=N|num=S
356 D DR gen=N|num=S
357 D DT gen=F|num=P
358 D DT gen=F|num=S
359 D DT gen=M|num=S
360 D DT gen=N|num=N
361 D DT gen=N|num=P
362 D DT gen=N|num=S
363 E E _
364 E E gen=F|num=P
365 E E gen=F|num=S
366 E E gen=M|num=P
367 E E gen=M|num=S
368 E E gen=N|num=S
369 I I _
370 N N _
371 N N gen=F|num=P
372 N N gen=N|num=S
373 N NO _
374 N NO gen=F|num=P
375 N NO gen=F|num=S
376 N NO gen=M|num=P
377 N NO gen=M|num=S
378 P PD gen=F|num=P
379 P PD gen=F|num=S
380 P PD gen=M|num=P
381 P PD gen=M|num=S
382 P PD gen=N|num=N
383 P PD gen=N|num=P
384 P PI gen=F|num=P
385 P PI gen=F|num=S
386 P PI gen=M|num=P
387 P PI gen=M|num=S
388 P PI gen=N|num=N
389 P PI gen=N|num=P
390 P PI gen=N|num=S
391 P PP gen=F|num=S
392 P PP gen=M|num=P
393 P PP gen=M|num=S
394 P PQ gen=F|num=N
395 P PQ gen=F|num=N|per=3
396 P PQ gen=F|num=P|per=3
397 P PQ gen=F|num=S
398 P PQ gen=F|num=S|per=3
399 P PQ gen=M|num=P
400 P PQ gen=M|num=P|per=3
401 P PQ gen=M|num=S
402 P PQ gen=M|num=S|per=3
403 P PQ gen=N|num=N
404 P PQ gen=N|num=N|per=3
405 P PQ gen=N|num=P|per=1
406 P PQ gen=N|num=P|per=2
407 P PQ gen=N|num=P|per=3
408 P PQ gen=N|num=S
409 P PQ gen=N|num=S|per=1
410 P PQ gen=N|num=S|per=2
411 P PQ gen=N|num=S|per=3
412 P PR gen=M|num=P
413 P PR gen=M|num=S
414 P PR gen=N|num=N
415 P PR gen=N|num=P
416 P PR gen=N|num=S
417 P PT gen=M|num=S
418 P PT gen=N|num=N
419 P PT gen=N|num=S
420 PU PU _
421 R RD gen=F|num=P
422 R RD gen=F|num=S
423 R RD gen=M|num=P
424 R RD gen=M|num=S
425 R RD gen=N|num=S
426 R RI gen=F|num=S
427 R RI gen=M|num=S
428 S S gen=F|num=N
429 S S gen=F|num=P
430 S S gen=F|num=S
431 S S gen=M|num=N
432 S S gen=M|num=P
433 S S gen=M|num=S
434 S S gen=N|num=N
435 S S gen=N|num=P
436 S S gen=N|num=S
437 S SP gen=N|num=N
438 S SW gen=N|num=N
439 SA SA gen=N|num=N
440 V V gen=F|num=P|mod=P|tmp=R
441 V V gen=F|num=S|mod=P|tmp=R
442 V V gen=M|num=P|mod=P|tmp=R
443 V V gen=M|num=S|mod=P|tmp=R
444 V V gen=N|num=P|mod=P|tmp=P
445 V V gen=N|num=S|mod=P|tmp=P
446 V V mod=F
447 V V mod=G
448 V V num=P|per=1|mod=C|tmp=I
449 V V num=P|per=1|mod=C|tmp=P
450 V V num=P|per=1|mod=D|tmp=P
451 V V num=P|per=1|mod=I|tmp=F
452 V V num=P|per=1|mod=I|tmp=I
453 V V num=P|per=1|mod=I|tmp=P
454 V V num=P|per=1|mod=I|tmp=R
455 V V num=P|per=2|mod=C|tmp=I
456 V V num=P|per=2|mod=C|tmp=P
457 V V num=P|per=2|mod=I|tmp=F
458 V V num=P|per=2|mod=I|tmp=P
459 V V num=P|per=2|mod=M|tmp=P
460 V V num=P|per=3|mod=C|tmp=I
461 V V num=P|per=3|mod=C|tmp=P
462 V V num=P|per=3|mod=D|tmp=P
463 V V num=P|per=3|mod=I|tmp=F
464 V V num=P|per=3|mod=I|tmp=I
465 V V num=P|per=3|mod=I|tmp=P
466 V V num=P|per=3|mod=I|tmp=R
467 V V num=S|per=1|mod=C|tmp=I
468 V V num=S|per=1|mod=C|tmp=P
469 V V num=S|per=1|mod=D|tmp=P
470 V V num=S|per=1|mod=I|tmp=F
471 V V num=S|per=1|mod=I|tmp=I
472 V V num=S|per=1|mod=I|tmp=P
473 V V num=S|per=1|mod=I|tmp=R
474 V V num=S|per=2|mod=C|tmp=P
475 V V num=S|per=2|mod=D|tmp=P
476 V V num=S|per=2|mod=I|tmp=F
477 V V num=S|per=2|mod=I|tmp=I
478 V V num=S|per=2|mod=I|tmp=P
479 V V num=S|per=2|mod=M|tmp=P
480 V V num=S|per=3|mod=C|tmp=I
481 V V num=S|per=3|mod=C|tmp=P
482 V V num=S|per=3|mod=D|tmp=P
483 V V num=S|per=3|mod=I|tmp=F
484 V V num=S|per=3|mod=I|tmp=I
485 V V num=S|per=3|mod=I|tmp=P
486 V V num=S|per=3|mod=I|tmp=R
487 X X _
488 end_of_list
489 ;
490 # Protect from editors that replace tabs by spaces.
491 $list =~ s/ \s+/\t/sg;
492 my @list = split(/\r?\n/, $list);
493 return \@list;
494 }
495  
496  
497  
498 1;
499  
500 __END__
501  
502 =pod
503  
504 =encoding UTF-8
505  
506 =head1 NAME
507  
508 Lingua::Interset::Tagset::IT::Conll - Driver for the Italian tagset of the CoNLL 2007 Shared Task (derived from the ISST, Italian Syntactic-Semantic Treebank).
509  
510 =head1 VERSION
511  
512 version 3.015
513  
514 =head1 SYNOPSIS
515  
516 use Lingua::Interset::Tagset::IT::Conll;
517 my $driver = Lingua::Interset::Tagset::IT::Conll->new();
518 my $fs = $driver->decode("S\tS\tgen=M|num=S");
519  
520 or
521  
522 use Lingua::Interset qw(decode);
523 my $fs = decode('it::conll', "S\tS\tgen=M|num=S");
524  
525 =head1 DESCRIPTION
526  
527 Interset driver for the Italian tagset of the CoNLL 2007 Shared Task.
528 CoNLL tagsets in Interset are traditionally three values separated by tabs.
529 The values come from the CoNLL columns CPOS, POS and FEAT. For Italian,
530 these values are derived from the tagset of the Italian Syntactic-Semantic Treebank (ISST).
531  
532 =head1 SEE ALSO
533  
534 L<Lingua::Interset>,
535 L<Lingua::Interset::Tagset>,
536 L<Lingua::Interset::Tagset::Conll>,
537 L<Lingua::Interset::FeatureStructure>
538  
539 =head1 AUTHOR
540  
541 Dan Zeman <zeman@ufal.mff.cuni.cz>
542  
543 =head1 COPYRIGHT AND LICENSE
544  
545 This software is copyright (c) 2019 by Univerzita Karlova (Charles University).
546  
547 This is free software; you can redistribute it and/or modify it under
548 the same terms as the Perl 5 programming language system itself.
549  
550 =cut