Interset/Tagset/HSB/Sorokin.pm untested

filter: Statementstmt 0.0% 0 / 197 Branchbran 0.0% 0 / 8 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 12 Podpod 0.0% 0 / 6 totaltotal 0.0% 0 / 226 CC 5 SCAR 23.7
CC
5
Cov
0%
encode
30.0
get_tagset_id
2.0
_create_atoms
2.0
CRAP 10.8
1 # ABSTRACT: Driver for the Upper Sorbian tagset of the tagger created by Daniil Sorokin.
2 # https://bitbucket.org/magpie/part-of-speech-tagger-for-upper-sorbian/downloads
3 # Copyright © 2016, 2017 Dan Zeman <zeman@ufal.mff.cuni.cz>
4  
5 package Lingua::Interset::Tagset::HSB::Sorokin;
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'; # Daniil says that the design was inspired by Multext-East but the form of the tags is different, so we do not derive from Multext.
15  
16  
17  
18 has 'atoms' => ( isa => 'HashRef', is => 'ro', builder => '_create_atoms', lazy => 1 );
19 has 'feature_map' => ( isa => 'HashRef', is => 'ro', builder => '_create_feature_map', lazy => 1 );
20  
21  
22  
23 #------------------------------------------------------------------------------
24 # Returns the tagset id that should be set as the value of the 'tagset' feature
25 # during decoding.
26 #------------------------------------------------------------------------------
27 sub get_tagset_id
28 {
29 return 'hsb::sorokin';
30 }
31  
32  
33  
34 #------------------------------------------------------------------------------
35 # Creates atomic drivers for surface features.
36 #------------------------------------------------------------------------------
37 sub _create_atoms
38 {
39 my $self = shift;
40 my %atoms;
41 # POS ####################
42 $atoms{pos} = $self->create_atom
43 (
44 'surfeature' => 'pos',
45 'decode_map' =>
46 {
47 'NOUN' => ['pos' => 'noun'],
48 'ADJ' => ['pos' => 'adj'],
49 'PRON' => ['pos' => 'noun', 'prontype' => 'prn'],
50 'NUM' => ['pos' => 'num'],
51 'VERB' => ['pos' => 'verb'],
52 'ADV' => ['pos' => 'adv'],
53 'ADP' => ['pos' => 'adp'],
54 'CONJ' => ['pos' => 'conj'],
55 'PRT' => ['pos' => 'part'],
56 'INTERJ' => ['pos' => 'int'],
57 'ABBR' => ['abbr' => 'yes'],
58 '.' => ['pos' => 'punc'],
59 'X' => [],
60 '_' => []
61 },
62 'encode_map' =>
63 {
64 'abbr' => { 'yes' => 'ABBR',
65 '@' => { 'pos' => { 'noun' => { 'prontype' => { '' => 'NOUN',
66 '@' => 'PRON' }},
67 'adj' => { 'numtype' => { 'ord' => 'NUM',
68 '@' => 'ADJ' }},
69 'num' => 'NUM',
70 'verb' => 'VERB',
71 'adv' => 'ADV',
72 'adp' => 'ADP',
73 'conj' => 'CONJ',
74 'part' => 'PRT',
75 'int' => 'INTERJ',
76 'punc' => '.',
77 '@' => 'X' }}}
78 }
79 );
80 # NOUN TYPE ####################
81 $atoms{nountype} = $self->create_simple_atom
82 (
83 'intfeature' => 'nountype',
84 'simple_decode_map' =>
85 {
86 'common' => 'com',
87 'proper' => 'prop'
88 }
89 );
90 # ADJECTIVE TYPE ####################
91 # Either qualificative (which implies non-empty degree) or empty.
92 $atoms{adjtype} = $self->create_atom
93 (
94 'surfeature' => 'adjtype',
95 'decode_map' =>
96 {
97 'qualificative' => ['other' => {'adjtype' => 'qual'}]
98 },
99 'encode_map' =>
100 {
101 'other/adjtype' => { 'qual' => 'qualificative',
102 '@' => { 'degree' => { '' => '',
103 '@' => 'qualificative' }}}
104 }
105 );
106 # PRONOUN TYPE ####################
107 $atoms{prontype} = $self->create_atom
108 (
109 'surfeature' => 'prontype',
110 'decode_map' =>
111 {
112 'personal' => ['prontype' => 'prs'],
113 'reflexive' => ['prontype' => 'prs', 'reflex' => 'yes'],
114 'relative' => ['prontype' => 'rel'],
115 'demonstrative' => ['prontype' => 'dem'],
116 'negative' => ['prontype' => 'neg']
117 },
118 'encode_map' =>
119 {
120 'prontype' => { 'prs' => { 'reflex' => { 'yes' => 'reflexive',
121 '@' => 'personal' }},
122 'rel' => 'relative',
123 'dem' => 'demonstrative',
124 'neg' => 'negative',
125 '@' => 'personal' }
126 }
127 );
128 # NUMERAL TYPE ####################
129 $atoms{numtype} = $self->create_atom
130 (
131 'surfeature' => 'numtype',
132 'decode_map' =>
133 {
134 'cardinal' => ['pos' => 'num', 'numtype' => 'card'],
135 'ordinal' => ['pos' => 'adj', 'numtype' => 'ord']
136 },
137 'encode_map' =>
138 {
139 'numtype' => { 'card' => 'cardinal',
140 'ord' => 'ordinal' }
141 }
142 );
143 # VERB TYPE ####################
144 $atoms{verbtype} = $self->create_simple_atom
145 (
146 'intfeature' => 'verbtype',
147 'simple_decode_map' =>
148 {
149 'main' => '',
150 'modal' => 'mod'
151 }
152 );
153 # ADPOSITION TYPE ####################
154 $atoms{adpostype} = $self->create_simple_atom
155 (
156 'intfeature' => 'adpostype',
157 'simple_decode_map' =>
158 {
159 'preposition' => 'prep'
160 }
161 );
162 # GENDER ####################
163 # The tagger occasionally generates typos ("feminineinine" instead of "feminine").
164 $atoms{gender} = $self->create_atom
165 (
166 'surfeature' => 'gender',
167 'decode_map' =>
168 {
169 'masculine' => ['gender' => 'masc'],
170 'masculineuline' => ['gender' => 'masc'],
171 'masculine,feminine' => ['gender' => 'masc|fem'],
172 'masculine,feminine,neuter' => ['gender' => ''],
173 'feminine' => ['gender' => 'fem'],
174 'feminineinine' => ['gender' => 'fem'],
175 'feminine,neuter' => ['gender' => 'fem|neut'],
176 'neuter' => ['gender' => 'neut'],
177 'neuterer' => ['gender' => 'neut']
178 },
179 'encode_map' =>
180 {
181 'gender' => { 'fem|masc' => 'masculine,feminine',
182 'fem|neut' => 'feminine,neuter',
183 'masc' => 'masculine',
184 'fem' => 'feminine',
185 'neut' => 'neuter' }
186 }
187 );
188 # ANIMACY ####################
189 # The tagger occasionally generates typos ("animateate" instead of "animate").
190 $atoms{animacy} = $self->create_atom
191 (
192 'surfeature' => 'animacy',
193 'decode_map' =>
194 {
195 'animate' => ['animacy' => 'anim'],
196 'animateate' => ['animacy' => 'anim'],
197 'inanimate,animate' => ['animacy' => ''],
198 'inanimate' => ['animacy' => 'inan'],
199 'inanimate ' => ['animacy' => 'inan']
200 },
201 'encode_map' =>
202 {
203 'animacy' => { 'anim' => 'animate',
204 'inan' => 'inanimate' }
205 }
206 );
207 # NUMBER ####################
208 # The tagger occasionally generates typos ("singularular" instead of "singular").
209 # The three strange passive+number features. They do not mark the passive participle!
210 # They are used with the auxiliary verb in periphrastic passive constructions (singular "bu", dual "buštej", plural "buchu").
211 $atoms{number} = $self->create_atom
212 (
213 'surfeature' => 'number',
214 'decode_map' =>
215 {
216 'singular' => ['number' => 'sing'],
217 'singularular' => ['number' => 'sing'],
218 'dual' => ['number' => 'dual'],
219 'plural' => ['number' => 'plur'],
220 'passivsingular' => ['number' => 'sing', 'other' => {'auxpass' => 'yes'}],
221 'passivdual' => ['number' => 'dual', 'other' => {'auxpass' => 'yes'}],
222 'passivplural' => ['number' => 'plur', 'other' => {'auxpass' => 'yes'}]
223 },
224 'encode_map' =>
225 {
226 'other/auxpass' => { 'yes' => { 'number' => { 'sing' => 'passivsingular',
227 'dual' => 'passivdual',
228 'plur' => 'passivplural' }},
229 '@' => { 'mood' => { 'ind' => { 'tense' => { '' => { 'number' => { 'sing' => 'passivsingular',
230 'dual' => 'passivdual',
231 'plur' => 'passivplural' }},
232 '@' => { 'number' => { 'sing' => 'singular',
233 'dual' => 'dual',
234 'plur' => 'plural' }}}},
235 '@' => { 'number' => { 'sing' => 'singular',
236 'dual' => 'dual',
237 'plur' => 'plural' }}}}}
238 }
239 );
240 # DEGREE OF COMPARISON ####################
241 $atoms{degree} = $self->create_simple_atom
242 (
243 'intfeature' => 'degree',
244 'simple_decode_map' =>
245 {
246 'positive' => 'pos',
247 'comparative' => 'cmp',
248 'superlative' => 'sup'
249 }
250 );
251 # PERSON ####################
252 $atoms{person} = $self->create_simple_atom
253 (
254 'intfeature' => 'person',
255 'simple_decode_map' =>
256 {
257 'first' => '1',
258 'second' => '2',
259 'third' => '3'
260 }
261 );
262 # VERB FORM AND MOOD ####################
263 $atoms{mood} = $self->create_atom
264 (
265 'surfeature' => 'mood',
266 'decode_map' =>
267 {
268 'infinitive' => ['verbform' => 'inf'],
269 'indicative' => ['verbform' => 'fin', 'mood' => 'ind'],
270 'imperative' => ['verbform' => 'fin', 'mood' => 'imp'],
271 'conditional' => ['verbform' => 'fin', 'mood' => 'cnd'],
272 'participle' => ['verbform' => 'part']
273 },
274 'encode_map' =>
275 {
276 'mood' => { 'ind' => 'indicative',
277 'imp' => 'imperative',
278 'cnd' => 'conditional',
279 '@' => { 'verbform' => { 'part' => 'participle',
280 'inf' => 'infinitive' }}}
281 }
282 );
283 # TENSE ####################
284 $atoms{tense} = $self->create_simple_atom
285 (
286 'intfeature' => 'tense',
287 'simple_decode_map' =>
288 {
289 'past' => 'past',
290 'present' => 'pres',
291 'future' => 'fut'
292 }
293 );
294 # PARTICIPLE TYPE ####################
295 # Used for two participles that do not have gender and number: passive participle and present active participle.
296 $atoms{parttype} = $self->create_atom
297 (
298 'surfeature' => 'parttype',
299 'decode_map' =>
300 {
301 'Pass' => ['voice' => 'pass'],
302 'Pres' => ['voice' => 'act', 'tense' => 'pres']
303 },
304 'encode_map' =>
305 {
306 'voice' => { 'act' => 'Pres',
307 'pass' => 'Pass' }
308 }
309 );
310 # MERGED ATOM TO DECODE ANY FEATURE VALUE ####################
311 my @fatoms = map {$atoms{$_}} (qw(pos nountype adjtype prontype numtype verbtype adpostype gender animacy number degree person mood tense parttype));
312 $atoms{feature} = $self->create_merged_atom
313 (
314 'surfeature' => 'feature',
315 'atoms' => \@fatoms
316 );
317 ###!!! THE FOLLOWING FEATURES ARE CURRENTLY IGNORED
318 # Participle type:
319 # participle-Pass ... waženy, zakopowany, załoženy
320 # participle-Pres ... přupućowacy, wotpowědowacy, wobwliwujcy
321 # Pass 11
322 # Pres 20
323 return \%atoms;
324 }
325  
326  
327  
328 #------------------------------------------------------------------------------
329 # Creates a map that tells for each surface part of speech which features are
330 # relevant and in what order they appear.
331 #------------------------------------------------------------------------------
332 sub _create_feature_map
333 {
334 my $self = shift;
335 my %features =
336 (
337 'NOUN' => ['pos', 'nountype', 'gender', 'number', 'animacy'],
338 'ADJ' => ['pos', 'adjtype', 'degree', 'gender', 'number'],
339 'PRON' => ['pos', 'prontype', 'person', 'gender', 'number'],
340 'NUM' => ['pos', 'numtype', 'gender', 'number'],
341 'VERB' => ['pos', 'verbtype', 'mood', 'parttype', 'tense', 'gender', 'number'],
342 'ADP' => ['pos', 'adpostype']
343 );
344 return \%features;
345 }
346  
347  
348  
349 #------------------------------------------------------------------------------
350 # Decodes a physical tag (string) and returns the corresponding feature
351 # structure.
352 #------------------------------------------------------------------------------
353 sub decode
354 {
355 my $self = shift;
356 my $tag = shift;
357 my $fs = Lingua::Interset::FeatureStructure->new();
358 $fs->set_tagset($self->get_tagset_id());
359 my $atoms = $self->atoms();
360 my @surfeatures = split(/-/, $tag);
361 foreach my $surfeature (@surfeatures)
362 {
363 $atoms->{feature}->decode_and_merge_hard($surfeature, $fs);
364 }
365 return $fs;
366 }
367  
368  
369  
370 #------------------------------------------------------------------------------
371 # Takes feature structure and returns the corresponding physical tag (string).
372 #------------------------------------------------------------------------------
373 sub encode
374 {
375 my $self = shift;
376 my $fs = shift; # Lingua::Interset::FeatureStructure
377 my $atoms = $self->atoms();
378 my $tag = $atoms->{pos}->encode($fs);
379 my $features = $self->feature_map();
380 my @features;
381 @features = @{$features->{$tag}} if(defined($features->{$tag}));
382 my @tag = ($tag);
383 for(my $i = 1; $i<=$#features; $i++)
384 {
385 if(defined($features[$i]))
386 {
387 # Tagset drivers normally do not throw exceptions because they should be able to digest any input.
388 # However, if we know we expect a feature and we have not defined an atom to handle that feature,
389 # then it is an error of our code, not of the input data.
390 if(!defined($atoms->{$features[$i]}))
391 {
392 confess("There is no atom to handle the feature '$features[$i]'");
393 }
394 my $value = $atoms->{$features[$i]}->encode($fs);
395 if(defined($value) && $value ne '')
396 {
397 push(@tag, $value);
398 }
399 }
400 }
401 $tag = join('-', @tag);
402 return $tag;
403 }
404  
405  
406  
407 #------------------------------------------------------------------------------
408 # Returns reference to list of known tags.
409 # This list has been collected from tagger output and filtered.
410 #------------------------------------------------------------------------------
411 sub list
412 {
413 my $self = shift;
414 my $list = <<end_of_list
415 .
416 ABBR
417 ADJ-dual
418 ADJ-feminine-singular
419 ADJ-masculine-singular
420 ADJ-neuter-singular
421 ADJ-plural
422 ADJ-qualificative-comparative-masculine-singular
423 ADJ-qualificative-positive-masculine-singular
424 ADJ-qualificative-superlative-masculine-singular
425 ADP-preposition
426 ADV
427 CONJ
428 INTERJ
429 NOUN-common-feminine-dual
430 NOUN-common-feminine-singular
431 NOUN-common-masculine,feminine-plural-animate
432 NOUN-common-masculine,feminine-plural-inanimate
433 NOUN-common-masculine,feminine-plural-inanimate
434 NOUN-common-masculine-dual-animate
435 NOUN-common-masculine-dual-inanimate
436 NOUN-common-masculine-singular-inanimate
437 NOUN-common-neuter-dual
438 NOUN-common-neuter-plural
439 NOUN-common-neuter-singular
440 NOUN-common-plural
441 NOUN-proper
442 NUM-cardinal
443 NUM-cardinal-feminine
444 NUM-cardinal-feminine-singular
445 NUM-cardinal-masculine-dual
446 NUM-cardinal-masculine-singular
447 NUM-cardinal-neuter-singular
448 NUM-cardinal-plural
449 NUM-ordinal
450 PRON-demonstrative-dual
451 PRON-demonstrative-feminine-singular
452 PRON-demonstrative-masculine-singular
453 PRON-demonstrative-neuter-singular
454 PRON-demonstrative-plural
455 PRON-negative
456 PRON-personal-first-plural
457 PRON-personal-first-singular
458 PRON-personal-second-plural
459 PRON-personal-second-singular
460 PRON-personal-third-feminine,neuter-dual
461 PRON-personal-third-feminine,neuter-plural
462 PRON-personal-third-feminine-singular
463 PRON-personal-third-masculine-dual
464 PRON-personal-third-masculine-plural
465 PRON-personal-third-masculine-singular
466 PRON-personal-third-neuter-singular
467 PRON-reflexive-singular
468 PRON-relative-dual
469 PRON-relative-feminine-singular
470 PRON-relative-masculine-singular
471 PRON-relative-neuter-singular
472 PRON-relative-plural
473 PRT
474 VERB-main-conditional-past-plural
475 VERB-main-conditional-past-singular
476 VERB-main-imperative-dual
477 VERB-main-imperative-plural
478 VERB-main-imperative-singular
479 VERB-main-indicative-future-plural
480 VERB-main-indicative-future-singular
481 VERB-main-indicative-passivdual
482 VERB-main-indicative-passivplural
483 VERB-main-indicative-passivsingular
484 VERB-main-indicative-past-dual
485 VERB-main-indicative-past-plural
486 VERB-main-indicative-past-singular
487 VERB-main-indicative-present-dual
488 VERB-main-indicative-present-plural
489 VERB-main-indicative-present-singular
490 VERB-main-infinitive
491 VERB-main-participle-Pass
492 VERB-main-participle-past-dual
493 VERB-main-participle-past-feminine-singular
494 VERB-main-participle-past-masculine-singular
495 VERB-main-participle-past-neuter-singular
496 VERB-main-participle-past-plural
497 VERB-main-participle-Pres-present
498 VERB-modal-indicative-past-plural
499 X
500 end_of_list
501 ;
502 my @list = split(/\r?\n/, $list);
503 return \@list;
504 }
505  
506  
507  
508 1;
509  
510 __END__
511  
512 =pod
513  
514 =encoding UTF-8
515  
516 =head1 NAME
517  
518 Lingua::Interset::Tagset::HSB::Sorokin - Driver for the Upper Sorbian tagset of the tagger created by Daniil Sorokin.
519  
520 =head1 VERSION
521  
522 version 3.014
523  
524 =head1 SYNOPSIS
525  
526 use Lingua::Interset::Tagset::HSB::Sorokin;
527 my $driver = Lingua::Interset::Tagset::HSB::Sorokin->new();
528 my $fs = $driver->decode('NOUN-common-masculine-singular-inanimate');
529  
530 or
531  
532 use Lingua::Interset qw(decode);
533 my $fs = decode('hsb::sorokin', 'NOUN-common-masculine-singular-inanimate');
534  
535 =head1 DESCRIPTION
536  
537 Interset driver for the Upper Sorbian tagset of the tagger by Daniil Sorokin.
538 See L<https://bitbucket.org/magpie/part-of-speech-tagger-for-upper-sorbian/downloads> for a detailed description
539 of the tagset.
540  
541 =head1 SEE ALSO
542  
543 L<Lingua::Interset>,
544 L<Lingua::Interset::Tagset>,
545 L<Lingua::Interset::FeatureStructure>
546  
547 =head1 AUTHOR
548  
549 Dan Zeman <zeman@ufal.mff.cuni.cz>
550  
551 =head1 COPYRIGHT AND LICENSE
552  
553 This software is copyright (c) 2019 by Univerzita Karlova (Charles University).
554  
555 This is free software; you can redistribute it and/or modify it under
556 the same terms as the Perl 5 programming language system itself.
557  
558 =cut