Interset/Tagset/SV/Parole.pm untested

filter: Statementstmt 0.0% 0 / 189 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 9 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 226 CC 6 SCAR 17.9
CC
6
Cov
0%
decode
12.0
encode
12.0
list
6.0
CRAP 6.0
1 # ABSTRACT: Driver for the Swedish PAROLE tagset.
2 # Copyright © 2006-2009, 2015, 2017 Dan Zeman <zeman@ufal.mff.cuni.cz>
3  
4 package Lingua::Interset::Tagset::SV::Parole;
5 use strict;
6 use warnings;
7 our $VERSION = '3.015';
8  
9 use utf8;
10 use open ':utf8';
11 use namespace::autoclean;
12 use Moose;
13 extends 'Lingua::Interset::Tagset';
14  
15  
16  
17 has 'atoms' => ( isa => 'HashRef', is => 'ro', builder => '_create_atoms', lazy => 1 );
18 has 'features_pos' => ( isa => 'HashRef', is => 'ro', builder => '_create_features_pos', 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 'sv::parole';
32 }
33  
34  
35  
36 #------------------------------------------------------------------------------
37 # Creates atomic drivers for the surface features.
38 #------------------------------------------------------------------------------
39 sub _create_atoms
40 {
41 my $self = shift;
42 my %atoms;
43 # 1. PART OF SPEECH ####################
44 $atoms{pos} = $self->create_atom
45 (
46 'surfeature' => 'pos',
47 'decode_map' =>
48 {
49 # noun
50 'NC' => ['pos' => 'noun', 'nountype' => 'com'],
51 'NP' => ['pos' => 'noun', 'nountype' => 'prop'],
52 # adjective or participle
53 'AQ' => ['pos' => 'adj'],
54 'AP' => ['pos' => 'verb', 'verbform' => 'part', 'tense' => 'pres', 'aspect' => 'imp'],
55 'AF' => ['pos' => 'verb', 'verbform' => 'part', 'tense' => 'past', 'aspect' => 'perf'],
56 # determiner
57 'D0' => ['pos' => 'adj', 'prontype' => 'prn'],
58 'DH' => ['pos' => 'adj', 'prontype' => 'int'],
59 'DF' => ['pos' => 'adj', 'prontype' => 'dem'],
60 'DI' => ['pos' => 'adj', 'prontype' => 'ind'],
61 # pronoun
62 'PF' => ['pos' => 'noun', 'prontype' => 'prs'],
63 'PS' => ['pos' => 'adj', 'prontype' => 'prs', 'poss' => 'yes'],
64 'PH' => ['pos' => 'noun', 'prontype' => 'int'],
65 'PE' => ['pos' => 'adj', 'prontype' => 'int', 'poss' => 'yes'],
66 'PI' => ['pos' => 'noun', 'prontype' => 'ind'],
67 # numeral
68 'MC' => ['pos' => 'num', 'numtype' => 'card'],
69 'MO' => ['pos' => 'adj', 'numtype' => 'ord'],
70 # verb
71 'V@' => ['pos' => 'verb'],
72 # adverb
73 'RG' => ['pos' => 'adv'],
74 'RH' => ['pos' => 'adv', 'prontype' => 'int'],
75 # preposition
76 'SP' => ['pos' => 'adp', 'adpostype' => 'prep'],
77 # conjunction
78 'CC' => ['pos' => 'conj', 'conjtype' => 'coor'],
79 'CS' => ['pos' => 'conj', 'conjtype' => 'sub'],
80 'CI' => ['pos' => 'part', 'verbform' => 'inf'], ###!!! what is the current standard about infinitive markers?
81 # particle
82 'Q' => ['pos' => 'part'],
83 # interjection
84 'I' => ['pos' => 'int'],
85 # punctuation
86 'FP' => ['pos' => 'punc'],
87 # menningskiljande interpunktion / meaning separating punctuation
88 # example: .
89 'FE' => ['pos' => 'punc', 'punctype' => 'peri'],
90 # interpunktion
91 # (DZ: the original legend does not tell the difference between FI and FP. Could FP be paired punctuation?)
92 # example: "
93 'FI' => ['pos' => 'punc', 'punctype' => 'quot'],
94 # foreign word
95 'XF' => ['foreign' => 'yes'],
96 },
97 'encode_map' =>
98 {
99 'pos' => { 'noun' => { 'prontype' => { '' => { 'nountype' => { 'prop' => 'NP',
100 '@' => 'NC' }},
101 'int' => { 'poss' => { 'yes' => 'PE',
102 '@' => 'PH' }},
103 'ind' => 'PI',
104 '@' => { 'poss' => { 'yes' => 'PS',
105 '@' => 'PF' }}}},
106 'adj' => { 'prontype' => { '' => { 'verbform' => { 'part' => { 'tense' => { 'pres' => 'AP',
107 '@' => 'AF' }},
108 '@' => { 'numtype' => { 'ord' => 'MO',
109 '@' => 'AQ' }}}},
110 'int' => { 'poss' => { 'yes' => 'PE',
111 '@' => 'DH' }},
112 'dem' => 'DF',
113 'ind' => 'DI',
114 '@' => { 'poss' => { 'yes' => 'PS',
115 '@' => 'D0' }}}},
116 'num' => { 'numtype' => { 'ord' => 'MO',
117 '@' => 'MC' }},
118 'verb' => { 'verbform' => { 'part' => { 'tense' => { 'pres' => 'AP',
119 '@' => 'AF' }},
120 '@' => 'V@' }},
121 'adv' => { 'prontype' => { 'int' => 'RH',
122 '@' => 'RG' }},
123 'adp' => 'SP',
124 'conj' => { 'verbform' => { 'inf' => 'CI',
125 '@' => { 'conjtype' => { 'sub' => 'CS',
126 '@' => 'CC' }}}},
127 'part' => { 'verbform' => { 'inf' => 'CI',
128 '@' => 'Q' }},
129 'int' => 'I',
130 'punc' => { 'punctype' => { 'peri' => 'FE',
131 'quot' => 'FI',
132 '@' => 'FP' }},
133 '@' => 'XF' }
134 }
135 );
136 # 2. DEGREE ####################
137 $atoms{degree} = $self->create_simple_atom
138 (
139 'intfeature' => 'degree',
140 'simple_decode_map' =>
141 {
142 'P' => 'pos',
143 'C' => 'cmp',
144 'S' => 'sup',
145 '0' => ''
146 }
147 );
148 # 3. GENDER ####################
149 $atoms{gender} = $self->create_simple_atom
150 (
151 'intfeature' => 'gender',
152 'simple_decode_map' =>
153 {
154 'M' => 'masc',
155 'U' => 'com',
156 'N' => 'neut',
157 '0' => ''
158 }
159 );
160 # 4. NUMBER ####################
161 $atoms{number} = $self->create_simple_atom
162 (
163 'intfeature' => 'number',
164 'simple_decode_map' =>
165 {
166 'S' => 'sing',
167 'P' => 'plur',
168 '0' => ''
169 }
170 );
171 # 5. CASE ####################
172 $atoms{case} = $self->create_simple_atom
173 (
174 'intfeature' => 'case',
175 'simple_decode_map' =>
176 {
177 'N' => 'nom',
178 'G' => 'gen',
179 '0' => ''
180 }
181 );
182 # 6. SUBJECT / OBJECT FORM ####################
183 $atoms{subjobj} = $self->create_simple_atom
184 (
185 'intfeature' => 'case',
186 'simple_decode_map' =>
187 {
188 'S' => 'nom',
189 'O' => 'acc',
190 '0' => ''
191 }
192 );
193 # 7. DEFINITENESS ####################
194 $atoms{definite} = $self->create_simple_atom
195 (
196 'intfeature' => 'definite',
197 'simple_decode_map' =>
198 {
199 'D' => 'def',
200 'I' => 'ind',
201 '0' => ''
202 }
203 );
204 # 8. VERB FORM AND MOOD ####################
205 $atoms{verbform} = $self->create_atom
206 (
207 'surfeature' => 'verbform',
208 'decode_map' =>
209 {
210 'N' => ['verbform' => 'inf'],
211 'I' => ['verbform' => 'fin', 'mood' => 'ind'],
212 'M' => ['verbform' => 'fin', 'mood' => 'imp'],
213 'S' => ['verbform' => 'fin', 'mood' => 'sub'],
214 '0' => []
215 },
216 'encode_map' =>
217 {
218 'verbform' => { 'inf' => 'N',
219 'fin' => { 'mood' => { 'ind' => 'I',
220 'imp' => 'M',
221 'sub' => 'S',
222 '@' => '0' }},
223 'sup' => 'I',
224 '@' => '0' }
225 }
226 );
227 # 9. TENSE ####################
228 $atoms{tense} = $self->create_atom
229 (
230 'surfeature' => 'tense',
231 'decode_map' =>
232 {
233 'P' => ['tense' => 'pres'],
234 'I' => ['tense' => 'past'], # preteritum
235 'U' => ['tense' => 'past', 'verbform' => 'sup'], # supinum
236 '0' => []
237 },
238 'encode_map' =>
239 {
240 'tense' => { 'pres' => 'P',
241 'past' => { 'verbform' => { 'sup' => 'U',
242 '@' => 'I' }},
243 '@' => '0' }
244 }
245 );
246 # 10. VOICE ####################
247 $atoms{voice} = $self->create_simple_atom
248 (
249 'intfeature' => 'voice',
250 'simple_decode_map' =>
251 {
252 # E.g. verb preteritum aktiv
253 # Example: hänvisade = referred
254 'A' => 'act',
255 # E.g. verb preteritum s-form
256 # Example: tillfrågades = asked
257 ###!!! How did we come to conclude that "s-form" means passive?
258 'S' => 'pass',
259 '0' => ''
260 }
261 );
262 # 11. FORM ####################
263 $atoms{form} = $self->create_atom
264 (
265 'surfeature' => 'form',
266 'decode_map' =>
267 {
268 # full form
269 'S' => [],
270 # hyphenated prefix
271 'C' => ['hyph' => 'yes'],
272 # abbreviation
273 'A' => ['abbr' => 'yes']
274 },
275 'encode_map' =>
276 {
277 'hyph' => { 'yes' => 'C',
278 '@' => { 'abbr' => { 'yes' => 'A',
279 '@' => 'S' }}}
280 }
281 );
282 return \%atoms;
283 }
284  
285  
286  
287 #------------------------------------------------------------------------------
288 # Creates the list of surface features (character positions) that can appear
289 # with particular parts of speech.
290 #------------------------------------------------------------------------------
291 sub _create_features_pos
292 {
293 my $self = shift;
294 my %features =
295 (
296 'N' => ['gender', 'number', 'case', undef, 'definite', 'form'],
297 'A' => ['degree', 'gender', 'number', 'case', 'definite', 'form'],
298 'D' => [undef, 'gender', 'number', undef, 'form'],
299 'P' => [undef, 'gender', 'number', 'subjobj', undef, 'form'],
300 'M' => ['gender', 'number', 'case', 'definite', 'form'],
301 'V' => ['verbform', 'tense', 'voice', 'form'],
302 'R' => ['degree', 'form'],
303 'S' => ['form'],
304 'C' => ['form'],
305 'Q' => ['form']
306 );
307 return \%features;
308 }
309  
310  
311  
312 #------------------------------------------------------------------------------
313 # Decodes a physical tag (string) and returns the corresponding feature
314 # structure.
315 #------------------------------------------------------------------------------
316 sub decode
317 {
318 my $self = shift;
319 my $tag = shift;
320 my $fs = Lingua::Interset::FeatureStructure->new();
321 $fs->set_tagset('sv::parole');
322 my $atoms = $self->atoms();
323 my @chars = split(//, $tag);
324 my $fpos = shift(@chars);
325 my $pos = $fpos;
326 if($pos ne 'Q' && scalar(@chars)>0)
327 {
328 $pos .= shift(@chars);
329 }
330 $atoms->{pos}->decode_and_merge_hard($pos, $fs);
331 my $features = $self->features_pos()->{$fpos};
332 for(my $i = 0; $i<=$#chars; $i++)
333 {
334 if(defined($features->[$i]) && defined($atoms->{$features->[$i]}))
335 {
336 $atoms->{$features->[$i]}->decode_and_merge_hard($chars[$i], $fs);
337 }
338 }
339 return $fs;
340 }
341  
342  
343  
344 #------------------------------------------------------------------------------
345 # Takes feature structure and returns the corresponding physical tag (string).
346 #------------------------------------------------------------------------------
347 sub encode
348 {
349 my $self = shift;
350 my $fs = shift; # Lingua::Interset::FeatureStructure
351 my $atoms = $self->atoms();
352 my $tag = $atoms->{pos}->encode($fs);
353 $tag =~ m/^(.)/;
354 my $pos = $1;
355 my $features = $self->features_pos()->{$pos};
356 if(defined($features))
357 {
358 foreach my $feature (@{$features})
359 {
360 if(defined($feature) && defined($atoms->{$feature}))
361 {
362 $tag .= $atoms->{$feature}->encode($fs);
363 }
364 else
365 {
366 $tag .= '@';
367 }
368 }
369 }
370 return $tag;
371 }
372  
373  
374  
375 #------------------------------------------------------------------------------
376 # Returns reference to list of known tags.
377 # The source list is the Parole tag set of the Swedish SUC corpus.
378 # http://spraakbanken.gu.se/parole/tags.phtml
379 # Modifications by Jan Hajič:
380 # - replace @ by W
381 # - add trailing dashes so every tag has 9 characters
382 # total tags:
383 # 156
384 #------------------------------------------------------------------------------
385 sub list
386 {
387 my $self = shift;
388 my $list = <<end_of_list
389 NC000\@0A
390 NC000\@0C
391 NC000\@0S
392 NCN00\@0C
393 NCN00\@0S
394 NCNPG\@DS
395 NCNPG\@IS
396 NCNPN\@DS
397 NCNPN\@IS
398 NCNSG\@DS
399 NCNSG\@IS
400 NCNSN\@DS
401 NCNSN\@IS
402 NCU00\@0C
403 NCU00\@0S
404 NCUPG\@DS
405 NCUPG\@IS
406 NCUPN\@DS
407 NCUPN\@IS
408 NCUSG\@DS
409 NCUSG\@IS
410 NCUSN\@DS
411 NCUSN\@IS
412 NP000\@0C
413 NP00G\@0S
414 NP00N\@0S
415 AF00000A
416 AF00PG0S
417 AF00PN0S
418 AF00SGDS
419 AF00SNDS
420 AF0MSGDS
421 AF0MSNDS
422 AF0NSNIS
423 AF0USGIS
424 AF0USNIS
425 AP000G0S
426 AP000N0S
427 AQ00000A
428 AQC0000C
429 AQC00G0S
430 AQC00N0S
431 AQP0000C
432 AQP00N0S
433 AQP00NIS
434 AQP0PG0S
435 AQP0PN0S
436 AQP0PNIS
437 AQP0SGDS
438 AQP0SNDS
439 AQPMSGDS
440 AQPMSNDS
441 AQPNSGIS
442 AQPNSN0S
443 AQPNSNIS
444 AQPU000C
445 AQPUSGIS
446 AQPUSN0S
447 AQPUSNIS
448 AQS00NDS
449 AQS00NIS
450 AQS0PNDS
451 AQS0PNIS
452 AQSMSGDS
453 AQSMSNDS
454 D0\@00\@A
455 D0\@0P\@S
456 D0\@NS\@S
457 D0\@US\@S
458 DF\@0P\@S
459 DF\@0S\@S
460 DF\@MS\@S
461 DF\@NS\@S
462 DF\@US\@S
463 DH\@0P\@S
464 DH\@NS\@S
465 DH\@US\@S
466 DI\@00\@S
467 DI\@0P\@S
468 DI\@0S\@S
469 DI\@MS\@S
470 DI\@NS\@S
471 DI\@US\@S
472 PF\@00O\@S
473 PF\@0P0\@S
474 PF\@0PO\@S
475 PF\@0PS\@S
476 PF\@MS0\@S
477 PF\@NS0\@S
478 PF\@UPO\@S
479 PF\@UPS\@S
480 PF\@US0\@S
481 PF\@USO\@S
482 PF\@USS\@S
483 PE\@000\@S
484 PH\@000\@S
485 PH\@0P0\@S
486 PH\@NS0\@C
487 PH\@NS0\@S
488 PH\@US0\@S
489 PI\@0P0\@S
490 PI\@NS0\@S
491 PI\@US0\@S
492 PI\@USS\@S
493 PS\@000\@A
494 PS\@000\@S
495 PS\@0P0\@S
496 PS\@NS0\@S
497 PS\@US0\@S
498 MC0000C
499 MC00G0S
500 MC00N0S
501 MC0SNDS
502 MCMSGDS
503 MCMSNDS
504 MCNSNIS
505 MCUSNIS
506 MO0000C
507 MO00G0S
508 MO00N0S
509 MOMSNDS
510 V\@000A
511 V\@000C
512 V\@IIAS
513 V\@IISS
514 V\@IPAS
515 V\@IPSS
516 V\@IUAS
517 V\@IUSS
518 V\@M0AS
519 V\@M0SS
520 V\@N0AS
521 V\@N0SS
522 V\@SIAS
523 V\@SISS
524 V\@SPAS
525 RG0A
526 RG0C
527 RG0S
528 RGCS
529 RGPS
530 RGSS
531 RH0S
532 SPC
533 SPS
534 CCA
535 CCS
536 CIS
537 CSS
538 QC
539 QS
540 I
541 FE
542 FI
543 FP
544 XF
545 end_of_list
546 ;
547 # Protect from editors that replace tabs by spaces.
548 $list =~ s/ \s+/\t/sg;
549 my @list = split(/\r?\n/, $list);
550 pop(@list) if($list[$#list] eq "");
551 return \@list;
552 }
553  
554  
555  
556 1;
557  
558 __END__
559  
560 =pod
561  
562 =encoding UTF-8
563  
564 =head1 NAME
565  
566 Lingua::Interset::Tagset::SV::Parole - Driver for the Swedish PAROLE tagset.
567  
568 =head1 VERSION
569  
570 version 3.015
571  
572 =head1 SYNOPSIS
573  
574 use Lingua::Interset::Tagset::SV::Parole;
575 my $driver = Lingua::Interset::Tagset::SV::Parole->new();
576 my $fs = $driver->decode('NCNSN@IS');
577  
578 or
579  
580 use Lingua::Interset qw(decode);
581 my $fs = decode('sv::parole', 'NCNSN@IS');
582  
583 =head1 DESCRIPTION
584  
585 Interset driver for the Swedish PAROLE tagset
586 (L<http://spraakbanken.gu.se/parole/tags.phtml>).
587  
588 =head1 SEE ALSO
589  
590 L<Lingua::Interset>,
591 L<Lingua::Interset::Tagset>,
592 L<Lingua::Interset::FeatureStructure>
593  
594 =head1 AUTHOR
595  
596 Dan Zeman <zeman@ufal.mff.cuni.cz>
597  
598 =head1 COPYRIGHT AND LICENSE
599  
600 This software is copyright (c) 2019 by Univerzita Karlova (Charles University).
601  
602 This is free software; you can redistribute it and/or modify it under
603 the same terms as the Perl 5 programming language system itself.
604  
605 =cut