Interset/Tagset/AR/Padt.pm untested

filter: Statementstmt 0.0% 0 / 176 Branchbran 0.0% 0 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 11 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 200 CC 5 SCAR 19.9
CC
5
Cov
0%
decode
20.0
encode
6.0
get_tagset_id
2.0
CRAP 7.3
1 # ABSTRACT: Driver for the PADT 2.0 / ElixirFM Arabic positional tagset.
2 # See also http://quest.ms.mff.cuni.cz/cgi-bin/elixir/index.fcgi
3 # Copyright © 2013, 2014, 2017 Dan Zeman <zeman@ufal.mff.cuni.cz>
4  
5 package Lingua::Interset::Tagset::AR::Padt;
6 use strict;
7 use warnings;
8 our $VERSION = '3.014';
9  
10 use utf8;
11 use open ':utf8';
12 use namespace::autoclean;
13 use Moose;
14 extends 'Lingua::Interset::Tagset';
15  
16  
17  
18 has 'atoms' => ( isa => 'HashRef', is => 'ro', builder => '_create_atoms', lazy => 1 );
19  
20  
21  
22 #------------------------------------------------------------------------------
23 # Returns the tagset id that should be set as the value of the 'tagset' feature
24 # during decoding. Every derived class must (re)define this method! The result
25 # should correspond to the last two parts in package name, lowercased.
26 # Specifically, it should be the ISO 639-2 language code, followed by '::' and
27 # a language-specific tagset id. Example: 'cs::multext'.
28 #------------------------------------------------------------------------------
29 sub get_tagset_id
30 {
31 return 'ar::padt';
32 }
33  
34  
35  
36 #------------------------------------------------------------------------------
37 # Creates atomic drivers for surface features.
38 #------------------------------------------------------------------------------
39 sub _create_atoms
40 {
41 my $self = shift;
42 my %atoms;
43 # PART OF SPEECH ####################
44 $atoms{pos} = $self->create_atom
45 (
46 'tagset' => 'ar::padt',
47 'surfeature' => 'pos',
48 'decode_map' =>
49 {
50 # common noun
51 'N-' => ['pos' => 'noun', 'nountype' => 'com'],
52 # proper noun
53 'Z-' => ['pos' => 'noun', 'nountype' => 'prop'],
54 # adjective
55 'A-' => ['pos' => 'adj'],
56 # pronoun (probably personal)
57 'S-' => ['pos' => 'noun|adj', 'prontype' => 'prn'],
58 # personal pronoun
59 'SP' => ['pos' => 'noun', 'prontype' => 'prs'],
60 # demonstrative pronoun
61 'SD' => ['pos' => 'noun|adj', 'prontype' => 'dem'],
62 # relative pronoun
63 'SR' => ['pos' => 'noun|adj', 'prontype' => 'rel'],
64 # numeral: number
65 'Q-' => ['pos' => 'num', 'numform' => 'digit'],
66 # numeral: hundred
67 'QC' => ['pos' => 'num', 'numform' => 'word', 'other' => {'numvalue' => 100}],
68 # numeral: one
69 'QI' => ['pos' => 'num', 'numform' => 'word', 'numvalue' => '1'],
70 # numeral: twenty, thirty, ..., ninety
71 'QL' => ['pos' => 'num', 'numform' => 'word', 'other' => {'numvalue' => 20}],
72 # numeral: thousand, million, billion, ...
73 'QM' => ['pos' => 'num', 'numform' => 'word', 'other' => {'numvalue' => 1000}],
74 # numeral: -teen
75 'QU' => ['pos' => 'num', 'numform' => 'word', 'other' => {'numvalue' => 15}],
76 # numeral: three, four, ..., nine
77 'QV' => ['pos' => 'num', 'numform' => 'word', 'numvalue' => '3'],
78 # numeral: ten
79 'QX' => ['pos' => 'num', 'numform' => 'word', 'other' => {'numvalue' => 10}],
80 # numeral: two
81 'QY' => ['pos' => 'num', 'numform' => 'word', 'numvalue' => '2'],
82 # verb
83 'V-' => ['pos' => 'verb'],
84 'VI' => ['pos' => 'verb', 'aspect' => 'imp'],
85 'VP' => ['pos' => 'verb', 'aspect' => 'perf'],
86 'VC' => ['pos' => 'verb', 'verbform' => 'fin', 'mood' => 'imp'],
87 # adverb
88 'D-' => ['pos' => 'adv'],
89 # preposition
90 'P-' => ['pos' => 'adp', 'adpostype' => 'prep'],
91 # inflected preposition (nominative, genitive, accusative)
92 'PI' => ['pos' => 'adp', 'adpostype' => 'prep'],
93 # conjunction
94 'C-' => ['pos' => 'conj'],
95 # function word, particle
96 'F-' => ['pos' => 'part'],
97 # interrogative particle
98 'FI' => ['pos' => 'part', 'prontype' => 'int'],
99 # negative particle
100 'FN' => ['pos' => 'part', 'polarity' => 'neg'],
101 # interjection
102 'I-' => ['pos' => 'int'],
103 # abbreviation
104 'Y-' => ['abbr' => 'yes'],
105 # typo
106 'T-' => ['typo' => 'yes'],
107 # punctuation (not used in UMH subcorpus)
108 'G-' => ['pos' => 'punc'],
109 # non-Arabic script
110 'X-' => ['foreign' => 'yes'],
111 # residual class for unknown words
112 'U-' => [],
113 # if empty tag occurs treat it as unknown word
114 '_' => []
115 },
116 'encode_map' =>
117  
118 { 'abbr' => { 'yes' => 'Y-',
119 '@' => { 'typo' => { 'yes' => 'T-',
120 '@' => { 'foreign' => { 'yes' => 'X-',
121 '@' => { 'numtype' => { '' => { 'pos' => { 'noun' => { 'prontype' => { '' => { 'nountype' => { 'prop' => 'Z-',
122 '@' => 'N-' }},
123 'prs' => 'SP',
124 'dem' => 'SD',
125 'rel' => 'SR',
126 '@' => 'S-' }},
127 'adj' => { 'prontype' => { '' => 'A-',
128 'art' => '--',
129 'dem' => 'SD',
130 'rel' => 'SR',
131 '@' => 'S-' }},
132 'num' => { 'numform' => { 'word' => { 'other/numvalue' => { 10 => 'QX',
133 15 => 'QU',
134 20 => 'QL',
135 100 => 'QC',
136 1000 => 'QM',
137 '@' => { 'numvalue' => { '1' => 'QI',
138 '2' => 'QY',
139 '3' => 'QV',
140 '@' => { 'number' => { '' => { 'gender' => { '' => 'QL',
141 '@' => { 'case' => { '' => 'QU',
142 '@' => 'QX' }}}},
143 '@' => 'QC' }}}}}}, # or QM but we cannot decide that
144 '@' => 'Q-' }},
145 'verb' => { 'mood' => { 'imp' => 'VC',
146 '@' => { 'aspect' => { 'perf' => 'VP',
147 '@' => 'VI' }}}},
148 'adv' => 'D-',
149 'adp' => { 'case' => { '' => 'P-',
150 '@' => 'PI' }},
151 'conj' => 'C-',
152 'part' => { 'prontype' => { 'int' => 'FI',
153 '@' => { 'polarity' => { 'neg' => 'FN',
154 '@' => 'F-' }}}},
155 'int' => 'I-',
156 'punc' => 'G-',
157 '@' => 'U-' }},
158 '@' => 'Q-' }}}}}}}}
159 );
160 # GENDER ####################
161 $atoms{gender} = $self->create_simple_atom
162 (
163 'intfeature' => 'gender',
164 'simple_decode_map' =>
165 {
166 'M' => 'masc',
167 'F' => 'fem'
168 },
169 'encode_default' => '-'
170 );
171 # NUMBER ####################
172 $atoms{number} = $self->create_simple_atom
173 (
174 'intfeature' => 'number',
175 'simple_decode_map' =>
176 {
177 'S' => 'sing',
178 'D' => 'dual',
179 'P' => 'plur'
180 },
181 'encode_default' => '-'
182 );
183 # CASE ####################
184 $atoms{case} = $self->create_simple_atom
185 (
186 'intfeature' => 'case',
187 'simple_decode_map' =>
188 {
189 '1' => 'nom',
190 '2' => 'gen',
191 '4' => 'acc'
192 },
193 'encode_default' => '-'
194 );
195 # DEFINITENESS ####################
196 $atoms{definite} = $self->create_atom
197 (
198 'surfeature' => 'state',
199 'decode_map' =>
200 {
201 # definite
202 'D' => ['definite' => 'def'],
203 # indefinite
204 'I' => ['definite' => 'ind'],
205 # reduced = construct state
206 'R' => ['definite' => 'cons'],
207 # complex
208 'C' => ['definite' => 'com'],
209 # absolute/negative
210 'A' => ['polarity' => 'neg']
211 },
212 'encode_map' =>
213 {
214 'polarity' => { 'neg' => 'A',
215 '@' => { 'definite' => { 'def' => 'D',
216 'ind' => 'I',
217 'cons' => 'R',
218 'com' => 'C',
219 '@' => '-' }}}
220 }
221 );
222 # PERSON ####################
223 $atoms{person} = $self->create_simple_atom
224 (
225 'intfeature' => 'person',
226 'simple_decode_map' =>
227 {
228 '1' => '1',
229 '2' => '2',
230 '3' => '3'
231 },
232 'encode_default' => '-'
233 );
234 # MOOD ####################
235 $atoms{mood} = $self->create_atom
236 (
237 'tagset' => 'ar::padt',
238 'surfeature' => 'mood',
239 'decode_map' =>
240 {
241 'I' => ['verbform' => 'fin', 'mood' => 'ind'],
242 'S' => ['verbform' => 'fin', 'mood' => 'sub'],
243 'J' => ['verbform' => 'fin', 'mood' => 'jus'],
244 # undecided between subjunctive and jussive
245 'D' => ['verbform' => 'fin', 'mood' => 'sub|jus'],
246 # "energetic" mood, only with imperative verbs (VC) ("imperative" itself is a mood!), found only one example:
247 # فُوزَانِّ ... win, be victorious ... VCE----D-- fūzānni فُوزَانِّ -FūL-ānni imperative verb, energetic, dual
248 # see http://quest.ms.mff.cuni.cz/cgi-bin/elixir/index.fcgi?mode=resolve
249 'E' => ['verbform' => 'fin', 'mood' => 'imp', 'other' => {'mood' => 'energetic'}]
250 },
251 'encode_map' =>
252  
253 { 'mood' => { 'imp' => { 'other/mood' => { 'energetic' => 'E',
254 '@' => { 'number' => { 'dual' => 'E',
255 '@' => 'J' }}}},
256 'jus|sub' => 'D',
257 'sub' => 'S',
258 'jus' => 'J',
259 'ind' => 'I',
260 '@' => '-' }}
261 );
262 # VOICE ####################
263 $atoms{voice} = $self->create_simple_atom
264 (
265 'intfeature' => 'voice',
266 'simple_decode_map' =>
267 {
268 'A' => 'act',
269 'P' => 'pass'
270 },
271 'encode_default' => '-'
272 );
273 return \%atoms;
274 }
275  
276  
277  
278 #------------------------------------------------------------------------------
279 # Decodes a physical tag (string) and returns the corresponding feature
280 # structure.
281 #------------------------------------------------------------------------------
282 sub decode
283 {
284 my $self = shift;
285 my $tag = shift;
286 my $fs = Lingua::Interset::FeatureStructure->new();
287 $fs->set_tagset('ar::padt');
288 my $atoms = $self->atoms();
289 # The tags are positional, there are 10 character positions:
290 # pos subpos mood voice ??? pers gen num case def
291 # example: N------S1I
292 my @chars = split(//, $tag);
293 my @features = ('pos', 'subpos', 'mood', 'voice', undef, 'person', 'gender', 'number', 'case', 'definite');
294 for(my $i = 0; $i<=$#chars; $i++)
295 {
296 next if(!defined($features[$i]));
297 my $feature = $features[$i];
298 my $value = $chars[$i];
299 $value .= $chars[++$i] if($i==0);
300 $atoms->{$feature}->decode_and_merge_hard($value, $fs);
301 }
302 # Clean up mood (jussive --> imperative).
303 $fs->set('mood', 'imp') if($tag =~ m/^VCJ/);
304 return $fs;
305 }
306  
307  
308  
309 #------------------------------------------------------------------------------
310 # Takes feature structure and returns the corresponding physical tag (string).
311 #------------------------------------------------------------------------------
312 sub encode
313 {
314 my $self = shift;
315 my $fs = shift; # Lingua::Interset::FeatureStructure
316 my $atoms = $self->atoms();
317 my @features = ('pos', 'subpos', 'mood', 'voice', undef, 'person', 'gender', 'number', 'case', 'definite');
318 my $tag = $atoms->{pos}->encode($fs);
319 for(my $i = 2; $i<=$#features; $i++)
320 {
321 my $feature = $features[$i];
322 my $value = '-';
323 if(defined($feature))
324 {
325 $value = $atoms->{$feature}->encode($fs);
326 }
327 $tag .= $value;
328 }
329 return $tag;
330 }
331  
332  
333  
334 #------------------------------------------------------------------------------
335 # Returns reference to list of known tags.
336 # 335 tags
337 #------------------------------------------------------------------------------
338 sub list
339 {
340 my $self = shift;
341 my $list = <<end_of_list
342 A-----FD1D
343 A-----FD1I
344 A-----FD1R
345 A-----FD2D
346 A-----FD2I
347 A-----FD4D
348 A-----FD4I
349 A-----FP1D
350 A-----FP1I
351 A-----FP1R
352 A-----FP2D
353 A-----FP2I
354 A-----FP2R
355 A-----FP4D
356 A-----FP4I
357 A-----FP4R
358 A-----FS1D
359 A-----FS1I
360 A-----FS1R
361 A-----FS2C
362 A-----FS2D
363 A-----FS2I
364 A-----FS2R
365 A-----FS4C
366 A-----FS4D
367 A-----FS4I
368 A-----FS4R
369 A-----MD1C
370 A-----MD1D
371 A-----MD1I
372 A-----MD2D
373 A-----MD2I
374 A-----MD2R
375 A-----MD4D
376 A-----MD4I
377 A-----MP1D
378 A-----MP1I
379 A-----MP1R
380 A-----MP2C
381 A-----MP2D
382 A-----MP2I
383 A-----MP2R
384 A-----MP4C
385 A-----MP4D
386 A-----MP4I
387 A-----MP4R
388 A-----MS1C
389 A-----MS1D
390 A-----MS1I
391 A-----MS1R
392 A-----MS2C
393 A-----MS2D
394 A-----MS2I
395 A-----MS2R
396 A-----MS4A
397 A-----MS4C
398 A-----MS4D
399 A-----MS4I
400 A-----MS4R
401 C---------
402 D---------
403 F---------
404 G---------
405 I---------
406 N------D1D
407 N------D1I
408 N------D1R
409 N------D2D
410 N------D2I
411 N------D2R
412 N------D4D
413 N------D4I
414 N------D4R
415 N------P1D
416 N------P1I
417 N------P1R
418 N------P2D
419 N------P2I
420 N------P2R
421 N------P4D
422 N------P4I
423 N------P4R
424 N------S1D
425 N------S1I
426 N------S1R
427 N------S2D
428 N------S2I
429 N------S2R
430 N------S4A
431 N------S4D
432 N------S4I
433 N------S4R
434 P---------
435 PI------1-
436 PI------2-
437 PI------4-
438 Q---------
439 QC-----S1I
440 QC-----S2I
441 QC-----S4I
442 QC-----S1R
443 QC-----S2R
444 QC-----S4R
445 QC-----S1D
446 QC-----S2D
447 QC-----S4D
448 QC-----S1A
449 QC-----S2A
450 QC-----S4A
451 QC-----D1I
452 QC-----D2I
453 QC-----D4I
454 QC-----D1R
455 QC-----D2R
456 QC-----D4R
457 QC-----D1D
458 QC-----D2D
459 QC-----D4D
460 QC-----D1A
461 QC-----D2A
462 QC-----D4A
463 QC-----P1I
464 QC-----P2I
465 QC-----P4I
466 QC-----P1R
467 QC-----P2R
468 QC-----P4R
469 QC-----P1D
470 QC-----P2D
471 QC-----P4D
472 QC-----P1A
473 QC-----P2A
474 QC-----P4A
475 QI----F-2D
476 QI----F-2I
477 QI----F-4I
478 QI----M-1I
479 QI----M-2D
480 QI----M-2I
481 QI----M-4D
482 QI----M-4I
483 QI----M-4R
484 QL------1I
485 QL------2D
486 QL------2I
487 QL------4D
488 QL------4I
489 QL------4R
490 QM-----S1I
491 QM-----S2I
492 QM-----S4I
493 QM-----S1R
494 QM-----S2R
495 QM-----S4R
496 QM-----S1D
497 QM-----S2D
498 QM-----S4D
499 QM-----S1A
500 QM-----S2A
501 QM-----S4A
502 QM-----D1I
503 QM-----D2I
504 QM-----D4I
505 QM-----D1R
506 QM-----D2R
507 QM-----D4R
508 QM-----D1D
509 QM-----D2D
510 QM-----D4D
511 QM-----D1A
512 QM-----D2A
513 QM-----D4A
514 QM-----P1I
515 QM-----P2I
516 QM-----P4I
517 QM-----P1R
518 QM-----P2R
519 QM-----P4R
520 QM-----P1D
521 QM-----P2D
522 QM-----P4D
523 QM-----P1A
524 QM-----P2A
525 QM-----P4A
526 QU----F---
527 QU----M---
528 QV----F-1D
529 QV----F-1I
530 QV----F-1R
531 QV----F-2D
532 QV----F-2I
533 QV----F-2R
534 QV----F-4C
535 QV----F-4D
536 QV----F-4I
537 QV----F-4R
538 QV----M-1D
539 QV----M-1I
540 QV----M-1R
541 QV----M-2C
542 QV----M-2D
543 QV----M-2I
544 QV----M-2R
545 QV----M-4C
546 QV----M-4D
547 QV----M-4I
548 QV----M-4R
549 QX----F-1D
550 QX----F-2D
551 QX----F-2R
552 QX----F-4R
553 QX----M-1D
554 QX----M-1I
555 QX----M-1R
556 QX----M-2D
557 QX----M-2I
558 QX----M-2R
559 QX----M-4D
560 QX----M-4R
561 QY----F-1I
562 QY----F-2R
563 QY----M-1D
564 QY----M-1I
565 QY----M-2D
566 QY----M-2I
567 QY----M-4D
568 QY----M-4I
569 QY----M-4R
570 S---------
571 SD----FD1-
572 SD----FD2-
573 SD----FS1-
574 SD----FS2-
575 SD----FS4-
576 SD----MD1-
577 SD----MD2-
578 SD----MP2-
579 SD----MP4-
580 SD----MS1-
581 SD----MS2-
582 SD----MS4-
583 SP---1MP2-
584 SP---1MP4-
585 SP---1MS4-
586 SP---2FS2-
587 SP---2MP1-
588 SP---2MP2-
589 SP---2MP4-
590 SP---2MS1-
591 SP---2MS2-
592 SP---2MS4-
593 SP---3FP1-
594 SP---3FP2-
595 SP---3FP4-
596 SP---3FS1-
597 SP---3FS2-
598 SP---3FS4-
599 SP---3MD2-
600 SP---3MP1-
601 SP---3MP2-
602 SP---3MP4-
603 SP---3MS1-
604 SP---3MS2-
605 SP---3MS4-
606 SR----FD1-
607 SR----FS1-
608 SR----FS2-
609 SR----FS4-
610 SR----MD1-
611 SR----MP2-
612 SR----MP4-
613 SR----MS1-
614 SR----MS2-
615 SR----MS4-
616 U---------
617 VCE---MD--
618 VCJ---FP--
619 VCJ---FS--
620 VCJ---MP--
621 VCJ---MS--
622 VIIA-1MP--
623 VIIA-1MS--
624 VIIA-2MP--
625 VIIA-2MS--
626 VIIA-3FD--
627 VIIA-3FS--
628 VIIA-3MD--
629 VIIA-3MP--
630 VIIA-3MS--
631 VIIP-2MS--
632 VIIP-3FS--
633 VIIP-3MD--
634 VIIP-3MP--
635 VIIP-3MS--
636 VIJA-1MP--
637 VIJA-2MS--
638 VIJA-3FD--
639 VIJA-3FS--
640 VIJA-3MD--
641 VIJA-3MP--
642 VIJA-3MS--
643 VIJP-1MS--
644 VIJP-3FS--
645 VIJP-3MP--
646 VIJP-3MS--
647 VISA-1MP--
648 VISA-2MP--
649 VISA-2MS--
650 VISA-3FD--
651 VISA-3FP--
652 VISA-3FS--
653 VISA-3MD--
654 VISA-3MP--
655 VISA-3MS--
656 VISP-3FS--
657 VISP-3MD--
658 VISP-3MP--
659 VISP-3MS--
660 VP-A-1MS--
661 VP-A-2MP--
662 VP-A-2MS--
663 VP-A-3FD--
664 VP-A-3FP--
665 VP-A-3FS--
666 VP-A-3MD--
667 VP-A-3MP--
668 VP-A-3MS--
669 VP-P-3FP--
670 VP-P-3FS--
671 VP-P-3MD--
672 VP-P-3MP--
673 VP-P-3MS--
674 X---------
675 Y---------
676 Z---------
677 end_of_list
678 ;
679 # Protect from editors that replace tabs by spaces.
680 $list =~ s/ \s+/\t/sg;
681 my @list = split(/\r?\n/, $list);
682 return \@list;
683 }
684  
685  
686  
687 1;
688  
689 __END__
690  
691 =pod
692  
693 =encoding UTF-8
694  
695 =head1 NAME
696  
697 Lingua::Interset::Tagset::AR::Padt - Driver for the PADT 2.0 / ElixirFM Arabic positional tagset.
698  
699 =head1 VERSION
700  
701 version 3.014
702  
703 =head1 SYNOPSIS
704  
705 use Lingua::Interset::Tagset::AR::Padt;
706 my $driver = Lingua::Interset::Tagset::AR::Padt->new();
707 my $fs = $driver->decode('N------S1I');
708  
709 or
710  
711 use Lingua::Interset qw(decode);
712 my $fs = decode('ar::padt', 'N------S1I');
713  
714 =head1 DESCRIPTION
715  
716 Interset driver for the Arabic tagset of the Prague Arabic Dependency Treebank
717 (PADT) 2.0. The same tagset is also used by the ElixirFM Arabic morphological
718 analyzer. It is a positional tagset. Every tag consists of 10 characters and
719 the position of the character in the tag determines its interpretation:
720 I<pos, subpos, mood, voice, RESERVED, person, gender, number, case, definite.>
721  
722 =head1 SEE ALSO
723  
724 L<Lingua::Interset>,
725 L<Lingua::Interset::Tagset>,
726 L<Lingua::Interset::Tagset::AR::Conll>,
727 L<Lingua::Interset::Tagset::AR::Conll2007>,
728 L<Lingua::Interset::FeatureStructure>
729  
730 =head1 AUTHOR
731  
732 Dan Zeman <zeman@ufal.mff.cuni.cz>
733  
734 =head1 COPYRIGHT AND LICENSE
735  
736 This software is copyright (c) 2019 by Univerzita Karlova (Charles University).
737  
738 This is free software; you can redistribute it and/or modify it under
739 the same terms as the Perl 5 programming language system itself.
740  
741 =cut