Interset/Tagset/Multext.pm untested

filter: Statementstmt 0.0% 0 / 337 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 3 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 4 totaltotal 0.0% 0 / 368 CC 8 SCAR 23.9
CC
8
Cov
0%
decode
20.0
encode
20.0
_create_atoms
6.0
CRAP 10.9
1 # ABSTRACT: Common code for drivers of tagsets of the Multext-EAST project.
2 # Copyright © 2014, 2017 Dan Zeman <zeman@ufal.mff.cuni.cz>
3  
4 package Lingua::Interset::Tagset::Multext;
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 'feature_map' => ( isa => 'HashRef', is => 'ro', builder => '_create_feature_map', lazy => 1 );
19 has 'determiners' => ( isa => 'Bool', is => 'ro', default => undef );
20  
21  
22  
23 #------------------------------------------------------------------------------
24 # Creates atomic drivers for surface features.
25 #------------------------------------------------------------------------------
26 sub _create_atoms
27 {
28 my $self = shift;
29 my %atoms;
30 # PART OF SPEECH ####################
31 $atoms{pos} = $self->create_atom
32 (
33 'surfeature' => 'pos',
34 'decode_map' =>
35 {
36 # noun
37 # examples [cs]: pán, hrad, žena, růže, město, moře
38 # examples [ro]: număr, oraș, loc, punct, protocol
39 'N' => ['pos' => 'noun'],
40 # adjective
41 # examples [cs]: mladý, jarní
42 # examples [ro]: național, român, nou, internațional, bun
43 'A' => ['pos' => 'adj'],
44 # Multext tagsets of Slavic languages do not distinguish pronouns from determiners. Romanian does.
45 # We do not want to bias here towards Slavic languages, hence we distinguish the two (sub-)classes.
46 # pronoun
47 # examples [cs]: já, ty, on, ona, ono, my, vy, oni, ony
48 # examples [ro]: eu, tu, el, ea, noi, voi, ei, ele
49 'P' => ['pos' => 'noun', 'prontype' => 'prn'],
50 # determiner (but not article)
51 # examples [ro]: meu, lui, acest, acel, mult
52 'D' => ['pos' => 'adj', 'prontype' => 'prn'],
53 # article
54 # examples [ro]: un, o (indefinite); -ul, -a (definite affix); cel, cea, cei, cele (demonstrative); al, a, ai, ale (possessive)
55 ###!!! Since there are demonstrative articles and we have to distinguish them from demonstrative determiners, we must set 'other/prontype'.
56 'T' => ['pos' => 'adj', 'prontype' => 'art', 'other' => {'prontype' => 'art'}],
57 # numeral
58 # examples [cs]: jeden, dva, tři, čtyři, pět, šest, sedm, osm, devět, deset
59 # examples [ro]: doi, trei, patru, cinci, șase, șapte, opt, nouă, zece
60 'M' => ['pos' => 'num'],
61 # entity; used in [ro]; not documented at the Multext-East website
62 # used mostly for numbers expressed in digits, not denoting quantity (apartament 3)
63 # examples: 1916, miliarde_de_lei, 58_%, 3, 99-06, mg
64 # Ed = a few abbreviations of names, usually just 1 occurrence: mg, A., nr., U.E., N.
65 # Eii = interval, only two occurrences: 99-06, 1908-1909
66 # Eni = number (usually) written using digits: 3, 20, 50, 2, 24
67 # These numbers do not denote quantity. They are used as references: "figura 3", "apartament 3".
68 # Enr = number, only two occurrences: 58_%, 1,4
69 # Eqy = only two occurrences: miliarde_de_lei, 2_000_lei
70 # Etd = time or date: 1916, 1923, 2005, 1928, 1_martie
71 'E' => ['pos' => 'num', 'nountype' => 'prop'],
72 # verb
73 # examples [cs]: nese, bere, maže, peče, umře, tiskne, mine, začne, kryje, kupuje, prosí, trpí, sází, dělá
74 # examples [ro]: poate, este, face, e, devine
75 'V' => ['pos' => 'verb'],
76 # adverb
77 # examples [cs]: kde, kam, kdy, jak, dnes, vesele
78 # examples [ro]: astfel, încă, doar, atât, bine
79 'R' => ['pos' => 'adv'],
80 # adposition
81 # examples [cs]: v, pod, k
82 # examples [ro]: de, pe, la, cu, în
83 'S' => ['pos' => 'adp', 'adpostype' => 'prep'],
84 # conjunction
85 # examples [cs]: a, i, ani, nebo, ale, avšak
86 # examples [ro]: și, sau, dar, însă, că
87 'C' => ['pos' => 'conj'],
88 # particle
89 # examples [cs]: ať, kéž, nechť
90 # examples [ro]: a, să, nu
91 'Q' => ['pos' => 'part'],
92 # interjection
93 # examples [cs]: haf, bum, bác
94 # examples [ro]: vai, bravo, na
95 'I' => ['pos' => 'int'],
96 # abbreviation
97 # examples [cs]: atd., apod.
98 # examples [ro]: mp, km, etc.
99 'Y' => ['abbr' => 'yes'],
100 # punctuation
101 # examples: , .
102 'Z' => ['pos' => 'punc'],
103 # residual
104 'X' => []
105 },
106 # Some Multext-East tagsets (e.g. most Slavic languages) lack articles and determiners (the latter exist but are included in pronouns).
107 'encode_map' => $self->determiners() ?
108 {
109 'abbr' => { 'yes' => 'Y',
110 '@' => { 'numtype' => { '' => { 'pos' => { 'noun' => { 'prontype' => { '' => 'N',
111 '@' => 'P' }},
112 'adj' => { 'prontype' => { '' => 'A',
113 'art' => 'T',
114 '@' => { 'other/prontype' => { 'art' => 'T',
115 '@' => { 'person' => { '' => 'T',
116 '@' => 'D' }}}}}},
117 'num' => { 'nountype' => { 'prop' => 'E',
118 '@' => 'M' }},
119 'verb' => 'V',
120 'adv' => 'R',
121 'adp' => 'S',
122 'conj' => 'C',
123 'part' => 'Q',
124 'int' => 'I',
125 'punc' => 'Z',
126 '@' => 'X' }},
127 '@' => 'M' }}}
128 }
129 :
130 {
131 'abbr' => { 'yes' => 'Y',
132 '@' => { 'numtype' => { '' => { 'pos' => { 'noun' => { 'prontype' => { '' => 'N',
133 '@' => 'P' }},
134 'adj' => { 'prontype' => { '' => 'A',
135 '@' => 'P' }},
136 'num' => 'M',
137 'verb' => 'V',
138 'adv' => 'R',
139 'adp' => 'S',
140 'conj' => 'C',
141 'part' => 'Q',
142 'int' => 'I',
143 'punc' => 'Z',
144 '@' => 'X' }},
145 '@' => 'M' }}}
146 }
147 );
148 # NOUNTYPE ####################
149 $atoms{nountype} = $self->create_simple_atom
150 (
151 'intfeature' => 'nountype',
152 'simple_decode_map' =>
153 {
154 'c' => 'com',
155 'p' => 'prop'
156 }
157 );
158 # ADJTYPE ####################
159 $atoms{adjtype} = $self->create_atom
160 (
161 'surfeature' => 'adjtype',
162 'decode_map' =>
163 {
164 # qualificative adjective
165 # examples: mladý, jarní
166 'f' => [],
167 # possessive adjective
168 # examples: otcův, matčin
169 's' => ['poss' => 'yes']
170 },
171 'encode_map' =>
172  
173 { 'poss' => { 'yes' => 's',
174 '@' => 'f' }}
175 );
176 # PRONTYPE ####################
177 $atoms{prontype} = $self->create_atom
178 (
179 'surfeature' => 'prontype',
180 'decode_map' =>
181 {
182 # personal pronoun
183 # examples: já, ty, on, ona, ono, my, vy, oni, ony
184 'p' => ['prontype' => 'prs'],
185 # demonstrative pronoun
186 # examples: ten, tento, tenhle, onen, takový, týž, tentýž, sám
187 'd' => ['prontype' => 'dem'],
188 # emphatic pronoun (~ reflexive demonstrative)
189 # examples: sám
190 'h' => ['prontype' => 'emp'],
191 # indefinite pronoun
192 # examples: někdo, něco, nějaký, některý, něčí, leckdo, málokdo, kdokoli
193 'i' => ['prontype' => 'ind'],
194 # possessive pronoun
195 # relative possessive pronouns ("jehož") are classified as relatives
196 # examples: můj, tvůj, jeho, její, náš, váš, jejich
197 's' => ['prontype' => 'prs', 'poss' => 'yes'],
198 # interrogative pronoun
199 # examples: kdo, co, jaký, který, čí
200 'q' => ['prontype' => 'int'],
201 # relative pronoun
202 # examples: kdo, co, jaký, který, čí, jenž
203 'r' => ['prontype' => 'rel'],
204 # interrogative/relative pronoun
205 # examples: kdo, co, jaký, který, čí
206 'w' => ['prontype' => 'int|rel'],
207 # reflexive pronoun (both personal and possessive reflexive pronouns fall here)
208 # examples of personal reflexive pronouns: se, si, sebe, sobě, sebou
209 # examples of possessive reflexive pronouns: svůj
210 'x' => ['prontype' => 'prs', 'reflex' => 'yes'],
211 # negative pronoun
212 # examples: nikdo, nic, nijaký, ničí, žádný
213 'z' => ['prontype' => 'neg'],
214 # general pronoun
215 # examples: sám, samý, veškerý, všecko, všechno, všelicos, všelijaký, všeliký, všema
216 # some of them also appear classified as indefinite pronouns
217 # most of the above examples are clearly syntactic adjectives (determiners)
218 # many (except of "sám" and "samý" are classified as totality pronouns in other tagsets)
219 'g' => ['prontype' => 'tot'],
220 # definite article [ro]
221 'f' => ['definite' => 'def']
222 },
223 'encode_map' =>
224 {
225 'reflex' => { 'yes' => 'x',
226 '@' => { 'poss' => { 'yes' => 's',
227 '@' => { 'prontype' => { 'dem' => 'd',
228 'emp' => 'h',
229 'ind' => 'i',
230 'int|rel' => 'w',
231 'int' => 'q',
232 'rel' => 'r',
233 'neg' => 'z',
234 'tot' => 'g',
235 '@' => { 'definite' => { 'def' => 'f',
236 '@' => 'p' }}}}}}}
237 }
238 );
239 # NUMTYPE ####################
240 $atoms{numtype} = $self->create_atom
241 (
242 'surfeature' => 'numtype',
243 'decode_map' =>
244 {
245 # cardinal number
246 # examples [cs]: jeden, dva, tři, čtyři, pět, šest, sedm, osm, devět, deset
247 'c' => ['pos' => 'num', 'numtype' => 'card'],
248 # collective number
249 # It expresses quantity and totality at the same time.
250 # examples [ro]: amândoi, ambele (both)
251 'l' => ['pos' => 'num', 'numtype' => 'card', 'prontype' => 'tot'],
252 # ordinal number
253 # examples [cs]: první, druhý, třetí, čtvrtý, pátý
254 'o' => ['pos' => 'adj', 'numtype' => 'ord'],
255 # pronominal numeral
256 # examples [sl]: eden, en, drugi, drug
257 # "en" ("one") could also be classified as a cardinal numeral but it is never tagged so.
258 # "drugi" ("second" / "other") could also be classified as an ordinal numeral but is never tagged so.
259 # These two have a catagory of their own because they also work as indefinite pronouns ("one man or the other").
260 # Other pronominal numerals (in the sense of Interset, e.g. "how many") are not classified as pronominal in the Slovene Multext tagset!
261 # Note that prontype=ind itself is not enough to distinguish this category because in other languages (e.g. Czech)
262 # prontype is orthogonal to numtype (indefinite cardinal: "několik"; indefinite ordinal: "několikátý" etc.)
263 # The only thing that makes these Slovene numerals different is the multivalue of numtype: card|ord.
264 'p' => ['pos' => 'adj', 'numtype' => 'card|ord', 'prontype' => 'ind'],
265 # multiplier number
266 # examples [cs]: jednou, dvakrát, třikrát, čtyřikrát, pětkrát
267 'm' => ['pos' => 'adv', 'numtype' => 'mult'],
268 # special (generic) number (only Slavic languages?)
269 # Czech term: číslovka druhová
270 # Slovene term: števnik drugi
271 # examples [cs]: desaterý, dvojí, jeden, několikerý, několikery, obojí
272 # examples [sl]: dvojen, trojen
273 # Some generic numerals are used for plurale tantum and for sets of objects. They are also called collective numerals.
274 # examples [cs]: jedny, dvoje, troje, čtvery, patery, kolikery, několikery
275 's' => ['pos' => 'adj', 'numtype' => 'sets']
276 },
277 'encode_map' =>
278 {
279 'numtype' => { 'card|ord' => { 'prontype' => { 'ind' => 'p',
280 'tot' => 'l',
281 '@' => 'c' }},
282 'card' => { 'prontype' => { 'tot' => 'l',
283 '@' => 'c' }},
284 'ord' => 'o',
285 'mult' => 'm',
286 'sets' => 's',
287 '@' => 'c' }
288 }
289 );
290 # VERBTYPE ####################
291 $atoms{verbtype} = $self->create_atom
292 (
293 'surfeature' => 'verbtype',
294 'decode_map' =>
295 {
296 # main verb
297 # examples: absentovat, absolvovat, adaptovat, ...
298 'm' => [],
299 # auxiliary verb
300 # examples: dostat, mít
301 'a' => ['verbtype' => 'aux'],
302 # modal verb
303 # examples: chtít, dát, dávat, hodlat, moci, muset, lze, umět, zachtít
304 'o' => ['verbtype' => 'mod'],
305 # copula verb
306 # examples: být, bývat, by
307 'c' => ['verbtype' => 'cop']
308 },
309 'encode_map' =>
310  
311 { 'verbtype' => { 'aux' => 'a',
312 'mod' => 'o',
313 'cop' => 'c',
314 '@' => 'm' }}
315 );
316 # CONJTYPE ####################
317 $atoms{conjtype} = $self->create_atom
318 (
319 'surfeature' => 'conjtype',
320 'decode_map' =>
321 {
322 # coordinating conjunction
323 # examples: a, i, ani, nebo, ale
324 # [ro] examples: sau (or), dar (but), însă (however), că (that), fie (or)
325 'c' => ['conjtype' => 'coor'],
326 # subordinating conjunction
327 # examples: že, zda, aby, protože
328 # [ro] examples: că (that), dacă (if), încât (that), deși (although), de
329 's' => ['conjtype' => 'sub'],
330 # portmanteau (multi-purpose?) conjunction: it can be either coordinating conjunction or an adverb, and the distinction is tricky for an average speaker of Romanian
331 # [ro] examples: și (and), iar (and)
332 'r' => ['conjtype' => 'coor', 'other' => {'conjtype' => 'portmanteau'}]
333 },
334 'encode_map' =>
335 {
336 'conjtype' => { 'coor' => { 'other/conjtype' => { 'portmanteau' => 'r',
337 '@' => 'c' }},
338 'sub' => 's',
339 '@' => 'c' }
340 }
341 );
342 # GENDER ####################
343 $atoms{gender} = $self->create_simple_atom
344 (
345 'intfeature' => 'gender',
346 'simple_decode_map' =>
347 {
348 'm' => 'masc',
349 'f' => 'fem',
350 'n' => 'neut'
351 },
352 'encode_default' => '-'
353 );
354 # NUMBER ####################
355 $atoms{number} = $self->create_simple_atom
356 (
357 'intfeature' => 'number',
358 'simple_decode_map' =>
359 {
360 's' => 'sing',
361 'd' => 'dual',
362 'p' => 'plur'
363 },
364 'encode_default' => '-'
365 );
366 # CASE ####################
367 $atoms{case} = $self->create_simple_atom
368 (
369 'intfeature' => 'case',
370 'simple_decode_map' =>
371 {
372 'n' => 'nom',
373 'g' => 'gen',
374 'd' => 'dat',
375 'a' => 'acc',
376 'v' => 'voc',
377 'l' => 'loc',
378 'i' => 'ins'
379 },
380 'encode_default' => '-'
381 );
382 # ANIMACY ####################
383 $atoms{animacy} = $self->create_simple_atom
384 (
385 'intfeature' => 'animacy',
386 'simple_decode_map' =>
387 {
388 'y' => 'anim',
389 'n' => 'inan'
390 },
391 'encode_default' => '-'
392 );
393 # DEGREE ####################
394 $atoms{degree} = $self->create_simple_atom
395 (
396 'intfeature' => 'degree',
397 'simple_decode_map' =>
398 {
399 'p' => 'pos',
400 'c' => 'cmp',
401 's' => 'sup'
402 },
403 'encode_default' => '-'
404 );
405 # ADJECTIVE FORMATION ####################
406 $atoms{adjform} = $self->create_atom
407 (
408 'surfeature' => 'adjform',
409 'decode_map' =>
410 {
411 # Short form of adjective ("nominal form" = "jmenný tvar" in Czech)
412 # Only a handful of adjectives have nominal forms that are still in use.
413 # One adjective has only nominal form: "rád".
414 # examples: mlád, stár, zdráv, nemocen
415 'n' => ['variant' => 'short'],
416 # Long (normal) form of adjective ("pronominal form" = "zájmenný tvar" in Czech)
417 # examples: mladý, starý, zdravý, nemocný
418 'c' => [],
419 '-' => [] # possessive adjectives do not have two forms
420 },
421 'encode_map' =>
422  
423 { 'poss' => { 'yes' => '-',
424 '@' => { 'variant' => { 'short' => 'n',
425 '@' => 'c' }}}}
426 );
427 # DEFINITENESS ####################
428 # Definiteness is defined only for adjectives in Croatian.
429 # It distinguishes long and short forms of Slavic adjectives. In Czech, the "indefinite" form would be "jmenný tvar" (nominal form, as opposed to the long, pronominal form).
430 $atoms{definite} = $self->create_simple_atom
431 (
432 'intfeature' => 'definite',
433 'simple_decode_map' =>
434 {
435 'y' => 'def', # glavni, bivši, novi, prvi, turski
436 'n' => 'ind' # važan, velik, poznat, dobar, ključan
437 }
438 );
439 # PERSON ####################
440 $atoms{person} = $self->create_atom
441 (
442 'surfeature' => 'person',
443 'decode_map' =>
444 {
445 '1' => ['person' => '1'],
446 '2' => ['person' => '2'],
447 '3' => ['person' => '3']
448 },
449 'encode_map' =>
450 # Person of participles is undefined even if the attached clitic "-s" suggests the 2nd person.
451 # Person of demonstrative and reflexive pronouns is undefined despite the attached clitic "-s".
452 # We have to be careful here. The "-s" clitic is specific for Czech. We cannot just erase person in any language.
453 # Romanian, for example, sets the 3rd person even for demonstrative pronouns.
454 { 'verbform' => { 'part' => '-',
455 '@' => { 'other/clitic_s' => { 'y' => { 'prontype' => { 'prs' => { 'reflex' => { 'yes' => '-',
456 '@' => { 'person' => { '1' => '1',
457 '2' => '2',
458 '3' => '3',
459 '@' => '-' }}}},
460 '@' => '-' }},
461 '@' => { 'person' => { '1' => '1',
462 '2' => '2',
463 '3' => '3',
464 '@' => '-' }}}}}
465 }
466 );
467 # OWNER NUMBER ####################
468 $atoms{possnumber} = $self->create_simple_atom
469 (
470 'intfeature' => 'possnumber',
471 'simple_decode_map' =>
472 {
473 's' => 'sing',
474 'd' => 'dual',
475 'p' => 'plur'
476 },
477 'encode_default' => '-'
478 );
479 # OWNER GENDER ####################
480 $atoms{possgender} = $self->create_simple_atom
481 (
482 'intfeature' => 'possgender',
483 'simple_decode_map' =>
484 {
485 'm' => 'masc',
486 'f' => 'fem',
487 'n' => 'neut'
488 },
489 'encode_default' => '-'
490 );
491 # IS PRONOUN CLITIC? ####################
492 # clitic = yes for short forms of pronouns that behave like clitics (there exists a long form with identical meaning).
493 # PerGenNumCase: 1-sd 1-sa 2-sd 2-sa 3msd 3msa 3d 3a 3d+s 3a+s
494 # Examples [cs] (yes): mi mě ti tě mu ho si se sis ses
495 # Examples [cs] (no): mně mne tobě tebe jemu jeho sobě sebe sobě jsi sebe jsi
496 # Counterexamples (these are "short" but they have no longer equivalent, thus clitic = -): je, ně, tys
497 $atoms{clitic} = $self->create_atom
498 (
499 'surfeature' => 'clitic',
500 'decode_map' =>
501 {
502 'y' => ['variant' => 'short'],
503 'n' => []
504 },
505 'encode_map' =>
506 {
507 'variant' => { 'short' => 'y',
508 '@' => 'n' }
509 }
510 );
511 # IS REFLEXIVE PRONOUN POSSESSIVE? ####################
512 # referent type distinguishes between reflexive personal and reflexive possessive pronouns
513 # personal: sebe, sebou, se, ses, si, sis, sobě
514 # possessive: svůj
515 $atoms{referent_type} = $self->create_atom
516 (
517 'surfeature' => 'referent_type',
518 'decode_map' =>
519 {
520 's' => ['reflex' => 'yes', 'poss' => 'yes'],
521 'p' => ['reflex' => 'yes']
522 },
523 'encode_map' =>
524  
525 { 'reflex' => { 'yes' => { 'poss' => { 'yes' => 's',
526 '@' => 'p' }},
527 '@' => '-' }}
528 );
529 # SYNTACTIC TYPE OF PRONOUN ####################
530 # syntactic type: nominal or adjectival pronouns
531 # in [ro] this is used to distinguish the part of speech of abbreviations
532 # nominal: který, co, cokoliv, cosi, což, copak, cože, on, jaký, jenž, kdekdo, kdo, já, něco, někdo, nic, nikdo, se, ty, žádný
533 # adjectival: který, čí, čísi, jaký, jakýkoli, jakýkoliv, jakýsi, jeho, jenž, kdekterý, kterýkoli, kterýkoliv, kterýžto, málokterý, můj, nějaký, něčí, některý, ničí, onen, sám, samý, svůj, týž, tenhle, takýs, takovýto, ten, tento, tentýž, tenhleten, tvůj, veškerý, všecko, všechno, všelicos, všelijaký, všeliký, všema, žádný
534 $atoms{syntactic_type} = $self->create_atom
535 (
536 'surfeature' => 'syntactic_type',
537 'decode_map' =>
538 {
539 'n' => ['pos' => 'noun'],
540 'a' => ['pos' => 'adj'],
541 'r' => ['pos' => 'adv']
542 },
543 'encode_map' =>
544  
545 { 'pos' => { 'noun' => 'n',
546 'adj' => 'a',
547 'adv' => 'r',
548 '@' => '-' }}
549 );
550 # IS THERE AN ATTACHED CLITIC "-S" ("JSI")? ####################
551 # clitic_s: Does it contain encliticized form of 2nd person of the auxiliary verb "být"?
552 # There is no directly corresponding feature in the Interset.
553 # Pronoun examples: ses, sis, tos, tys
554 # "ses", "sis" and "tos" can be distinguished from "se", "si", "to" by setting person = '2'.
555 # However, such a trick will not work for "tys" (as opposed to "ty": both are 2nd person).
556 # Verb examples: slíbils, zapomněls, scvrnkls
557 # In Czech this applies only to participles that normally do not set person.
558 # Thus, setting person = '2' will distinguish these forms from the normal ones.
559 $atoms{clitic_s} = $self->create_atom
560 (
561 'tagset' => 'cs::multext',
562 'surfeature' => 'clitic_s',
563 'decode_map' =>
564 {
565 'y' => ['person' => '2', 'other' => {'clitic_s' => 'y'}],
566 'n' => ['other' => {'clitic_s' => 'n'}]
567 },
568 # We cannot use encode_map for decisions based on the 'other' feature.
569 # Custom code must be used instead of calling Atom::encode().
570 'encode_map' =>
571  
572 { 'other/clitic_s' => { 'y' => 'y',
573 # Clitic_s is obligatory for pronouns.
574 # It is also obligatory for participles and infinitives (!) but not other verb forms.
575 '@' => { 'prontype' => { '' => { 'verbform' => { 'inf' => 'n',
576 'part' => 'n',
577 '@' => '-' }},
578 '@' => 'n' }}}}
579 );
580 # NUMERAL FORM ####################
581 $atoms{numform} = $self->create_simple_atom
582 (
583 'intfeature' => 'numform',
584 'simple_decode_map' =>
585 {
586 'd' => 'digit',
587 'r' => 'roman',
588 'l' => 'word',
589 'm' => 'combi' # combined digits + suffix, e.g. 7-oji, 2009-ųjų
590 },
591 # We cannot say that 'l' is default. It would work for Czech, Slovenian and Croatian.
592 # However, it would not work for Romanian where we distinguish collective numerals ("both").
593 # These must be expressed as words, thus the numform feature is not explicitly used for them.
594 'encode_default' => '-'
595 );
596 # NUMERAL CLASS ####################
597 $atoms{numclass} = $self->create_atom
598 (
599 'surfeature' => 'numclass',
600 'decode_map' =>
601 {
602 # Definite other than 1, 2, 3, 4
603 # Examples: 1929, čtrnáctý, čtyřiapadesát, dvoustý, tucet
604 # This is the default class of numerals, so we do not have to set anything.
605 'f' => [],
606 # Definite1 examples: jeden, první
607 '1' => ['numvalue' => '1'],
608 # Definite2 examples: druhý, dvojí, dvojnásob, dva, nadvakrát, oba, obojí
609 '2' => ['numvalue' => '2'],
610 # Definite34 examples: čtvrtý, čtyři, potřetí, tři, třetí, třikrát
611 '3' => ['numvalue' => '3'],
612 # Demonstrative examples: tolik, tolikrát
613 'd' => ['prontype' => 'dem'],
614 # Indefinite examples: bezpočet, bezpočtukrát, bůhvíkolik, hodně, málo, mnohý, mockrát, několik, několikerý, několikrát, nejeden, pár, vícekrát
615 'i' => ['prontype' => 'ind'],
616 # Interrogative examples: kolik, kolikrát
617 'q' => ['prontype' => 'int'],
618 # Relative examples: kolik, kolikrát
619 'r' => ['prontype' => 'rel']
620 },
621 'encode_map' =>
622  
623 { 'prontype' => { 'dem' => 'd',
624 'ind' => 'i',
625 'int' => 'q',
626 'rel' => 'r',
627 '@' => { 'numvalue' => { '1' => '1',
628 '2' => '2',
629 '3' => '3',
630 '@' => 'f' }}}}
631 );
632 # VERB FORM ####################
633 $atoms{verbform} = $self->create_atom
634 (
635 'surfeature' => 'verbform',
636 'decode_map' =>
637 {
638 'i' => ['verbform' => 'fin', 'mood' => 'ind'],
639 'm' => ['verbform' => 'fin', 'mood' => 'imp'],
640 'c' => ['verbform' => 'fin', 'mood' => 'cnd'],
641 's' => ['verbform' => 'fin', 'mood' => 'sub'],
642 'n' => ['verbform' => 'inf'],
643 'p' => ['verbform' => 'part'],
644 't' => ['verbform' => 'conv'],
645 'g' => ['verbform' => 'ger']
646 },
647 'encode_map' =>
648  
649 { 'mood' => { 'imp' => 'm',
650 'cnd' => 'c',
651 'sub' => 's',
652 'ind' => 'i',
653 '@' => { 'verbform' => { 'part' => 'p',
654 'conv' => 't',
655 'ger' => 'g',
656 '@' => 'n' }}}}
657 );
658 # ASPECT ####################
659 $atoms{aspect} = $self->create_simple_atom
660 (
661 'intfeature' => 'aspect',
662 'simple_decode_map' =>
663 {
664 'e' => 'perf', # perfective
665 'p' => 'imp', # imperfective (this is called "progressive" in the Slovene tagset)
666 'b' => 'imp|perf' # biaspectual (we do not use the empty value here because we need it for tags where aspect is '-')
667 },
668 'encode_default' => '-'
669 );
670 # TENSE ####################
671 $atoms{tense} = $self->create_simple_atom
672 (
673 'intfeature' => 'tense',
674 'simple_decode_map' =>
675 {
676 'p' => 'pres',
677 'f' => 'fut',
678 's' => 'past',
679 'i' => 'imp',
680 'l' => 'pqp'
681 },
682 'encode_default' => '-'
683 );
684 # VOICE ####################
685 $atoms{voice} = $self->create_simple_atom
686 (
687 'intfeature' => 'voice',
688 'simple_decode_map' =>
689 {
690 'a' => 'act',
691 'p' => 'pass'
692 },
693 'encode_default' => '-'
694 );
695 # POLARITY ####################
696 $atoms{polarity} = $self->create_simple_atom
697 (
698 'intfeature' => 'polarity',
699 'simple_decode_map' =>
700 {
701 'y' => 'neg',
702 'n' => 'pos'
703 },
704 'encode_default' => '-'
705 );
706 # ADVERB TYPE ####################
707 # Croatian distinguishes participial adverbs (or adverbial participles).
708 # In Czech, the same category is classified as verbs (verbform = converb/transgressive).
709 # Note that the current solution does not convert Czech converbs to Croatian participial adverbs or vice versa.
710 $atoms{adverb_type} = $self->create_atom
711 (
712 'surfeature' => 'adverb_type',
713 'decode_map' =>
714 {
715 # general adverb
716 # examples: također, međutim, još, samo, kada
717 'g' => [],
718 # participial adverb (= adverbial participle = converb in Czech!)
719 # examples: uključujući, ističući, govoreći, dodajući, budući
720 'r' => ['verbform' => 'conv'],
721 # interrogative or relative adverb
722 # [ro] examples: când (when), cum (how), cât (how much), unde (where)
723 'w' => ['prontype' => 'int|rel'],
724 # negative adverb
725 # [ro] examples: nici (not)
726 'z' => ['prontype' => 'neg'],
727 # particle adverb [ro]
728 # It can dislocate verbal compound forms: Ea a _tot_ cântat. = She has _ever_ sung.
729 # Or it marks degree: circa (about), foarte (very), prea (too).
730 # [ro] examples: mai (more), și (also), foarte (very)
731 'p' => ['other' => {'advtype' => 'particle'}],
732 # portmanteau adverb [ro]
733 # The word can be either adverb or conjunction, the adverbial reading is more frequent.
734 # [ro] examples: ca (as), iar (again)
735 'c' => ['other' => {'advtype' => 'portmanteau'}]
736 },
737 'encode_map' =>
738  
739 { 'verbform' => { 'conv' => 'r',
740 'part' => 'r',
741 '@' => { 'prontype' => { 'int' => 'w',
742 'rel' => 'w',
743 'neg' => 'z',
744 '@' => { 'other/advtype' => { 'portmanteau' => 'c',
745 'particle' => 'p',
746 '@' => 'g' }}}}}}
747 );
748 # ADPOSITION TYPE ####################
749 # Czech has only prepositions, no postpositions or circumpositions.
750 # Nevertheless, this field must still be filled in because of compatibility with the other languages.
751 $atoms{adpostype} = $self->create_atom
752 (
753 'surfeature' => 'adpostype',
754 'decode_map' =>
755 {
756 'p' => ['adpostype' => 'prep']
757 },
758 'encode_map' =>
759  
760 { 'adpostype' => { '@' => 'p' }}
761 );
762 # ADPOSITION FORMATION ####################
763 # formation = compound ("nač", "naň", "oč", "vzhledem", "zač", "zaň")
764 # These should be classified as pronouns rather than prepositions.
765 $atoms{adposition_formation} = $self->create_atom
766 (
767 'surfeature' => 'adposition_formation',
768 'decode_map' =>
769 {
770 # Merged word form of a preposition and a pronoun.
771 # Examples: oč, zač, nač, oň, zaň, naň
772 'c' => ['adpostype' => 'preppron'],
773 's' => []
774 },
775 'encode_map' =>
776  
777 { 'adpostype' => { 'preppron' => 'c',
778 '@' => 's' }}
779 );
780 # PARTICLE TYPE ####################
781 $atoms{parttype} = $self->create_atom
782 (
783 'surfeature' => 'parttype',
784 'decode_map' =>
785 {
786 # affirmative particle
787 # examples: da
788 'r' => ['polarity' => 'pos'],
789 # negative particle
790 # examples: ne
791 'z' => ['polarity' => 'neg'],
792 # interrogative particle
793 # examples: li, zar
794 'q' => ['prontype' => 'int'],
795 # modal particle
796 # examples: sve, što, i, više, god, bilo
797 'o' => ['parttype' => 'mod'],
798 # infinitive particle
799 # [ro] examples: a: Cerea bani de la cine putea, spre a trăi pe un picior mai convenabil. = Who could ask for money, to live more conveniently.
800 'n' => ['parttype' => 'inf'],
801 # subjunctive particle
802 # [ro] examples: să: Statul în cauză este în măsură să garanteze că... = State concerned is able to guarantee that...
803 's' => ['mood' => 'sub'],
804 # future particle
805 # [ro] documentation has this, although it does not appear in the corpus
806 'f' => ['tense' => 'fut']
807 },
808 'encode_map' =>
809  
810 { 'polarity' => { 'pos' => 'r',
811 'neg' => 'z',
812 '@' => { 'prontype' => { 'int' => 'q',
813 '@' => { 'parttype' => { 'mod' => 'o',
814 'inf' => 'n',
815 '@' => { 'mood' => { 'sub' => 's',
816 '@' => { 'tense' => { 'fut' => 'f',
817 '@' => '-' }}}}}}}}}}
818 );
819 # RESIDUAL TYPE ####################
820 $atoms{restype} = $self->create_atom
821 (
822 'surfeature' => 'restype',
823 'decode_map' =>
824 {
825 # foreign word
826 # examples: a1, SETimes, European, bin, international
827 'f' => ['foreign' => 'yes'],
828 # typo
829 't' => ['typo' => 'yes'],
830 # symbol (occurs in Lithuanian as Xh)
831 'h' => ['pos' => 'sym'],
832 # program
833 # DZ: I am not sure what this value is supposed to mean. It is mentioned but not explained in the documentation.
834 # It does not occur in the SETimes.HR corpus.
835 'p' => []
836 },
837 'encode_map' =>
838 {
839 'pos' => { 'sym' => 'h',
840 '@' => { 'foreign' => { 'yes' => 'f',
841 '@' => { 'typo' => { 'yes' => 't',
842 '@' => '-' }}}}}
843 }
844 );
845 return \%atoms;
846 }
847  
848  
849  
850 #------------------------------------------------------------------------------
851 # Creates a map that tells for each surface part of speech which features are
852 # relevant and in what order they appear.
853 #------------------------------------------------------------------------------
854 sub _create_feature_map
855 {
856 my $self = shift;
857 my %features =
858 (
859 # This method must be overridden in every Multext-EAST-based tagset because the lists of features vary across languages.
860 # Declaring a feature as undef means that there will be always a dash at that position of the tag.
861 # 'N' => ['pos', 'nountype', 'gender', 'number', 'case'],
862 );
863 return \%features;
864 }
865  
866  
867  
868 #------------------------------------------------------------------------------
869 # Decodes a physical tag (string) and returns the corresponding feature
870 # structure.
871 #------------------------------------------------------------------------------
872 sub decode
873 {
874 my $self = shift;
875 my $tag = shift;
876 my $fs = Lingua::Interset::FeatureStructure->new();
877 $fs->set_tagset($self->get_tagset_id());
878 my $atoms = $self->atoms();
879 my $features = $self->feature_map();
880 my @chars = split(//, $tag);
881 $atoms->{pos}->decode_and_merge_hard($chars[0], $fs);
882 my @features;
883 @features = @{$features->{$chars[0]}} if(defined($features->{$chars[0]}));
884 for(my $i = 1; $i<=$#features; $i++)
885 {
886 if(defined($features[$i]) && defined($chars[$i]))
887 {
888 # Tagset drivers normally do not throw exceptions because they should be able to digest any input.
889 # However, if we know we expect a feature and we have not defined an atom to handle that feature,
890 # then it is an error of our code, not of the input data.
891 if(!defined($atoms->{$features[$i]}))
892 {
893 confess("There is no atom to handle the feature '$features[$i]'");
894 }
895 $atoms->{$features[$i]}->decode_and_merge_hard($chars[$i], $fs);
896 }
897 }
898 return $fs;
899 }
900  
901  
902  
903 #------------------------------------------------------------------------------
904 # Takes feature structure and returns the corresponding physical tag (string).
905 #------------------------------------------------------------------------------
906 sub encode
907 {
908 my $self = shift;
909 my $fs = shift; # Lingua::Interset::FeatureStructure
910 my $atoms = $self->atoms();
911 my $features = $self->feature_map();
912 my $tag = $atoms->{pos}->encode($fs);
913 my @features;
914 @features = @{$features->{$tag}} if(defined($features->{$tag}));
915 for(my $i = 1; $i<=$#features; $i++)
916 {
917 if(defined($features[$i]))
918 {
919 # Tagset drivers normally do not throw exceptions because they should be able to digest any input.
920 # However, if we know we expect a feature and we have not defined an atom to handle that feature,
921 # then it is an error of our code, not of the input data.
922 if(!defined($atoms->{$features[$i]}))
923 {
924 confess("There is no atom to handle the feature '$features[$i]'");
925 }
926 $tag .= $atoms->{$features[$i]}->encode($fs);
927 }
928 else
929 {
930 $tag .= '-';
931 }
932 }
933 # Remove trailing dashes.
934 $tag =~ s/-+$//;
935 return $tag;
936 }
937  
938  
939  
940 1;
941  
942 __END__
943  
944 =pod
945  
946 =encoding UTF-8
947  
948 =head1 NAME
949  
950 Lingua::Interset::Tagset::Multext - Common code for drivers of tagsets of the Multext-EAST project.
951  
952 =head1 VERSION
953  
954 version 3.015
955  
956 =head1 SYNOPSIS
957  
958 package Lingua::Interset::Tagset::HR::Multext;
959 extends 'Lingua::Interset::Tagset::Multext';
960  
961 # We must redefine the method that returns tagset identification, used by the
962 # decode() method for the 'tagset' feature.
963 sub get_tagset_id
964 {
965 # It should correspond to the last two parts in package name, lowercased.
966 # Specifically, it should be the ISO 639-2 language code, followed by '::multext'.
967 return 'hr::multext';
968 }
969  
970 # We may add or redefine atoms for individual surface features.
971 sub _create_atoms
972 {
973 my $self = shift;
974 # Most atoms can be inherited but some have to be redefined.
975 my $atoms = $self->SUPER::_create_atoms();
976 $atoms->{verbform} = $self->create_atom (...);
977 return $atoms;
978 }
979  
980 # We must define the lists of surface features for all surface parts of speech!
981 sub _create_feature_map
982 {
983 my $self = shift;
984 my %features =
985 (
986 'N' => ['pos', 'nountype', 'gender', 'number', 'case', 'animacy'],
987 ...
988 );
989 return \%features;
990 }
991  
992 # We must define the list() method.
993 sub list
994 {
995 my $self = shift;
996 my $list = <<end_of_list
997 Ncmsn
998 Ncmsg
999 Ncmsd
1000 ...
1001 end_of_list
1002 ;
1003 my @list = split(/\r?\n/, $list);
1004 return \@list;
1005 }
1006  
1007 =head1 DESCRIPTION
1008  
1009 Common code for drivers of tagsets of the Multext-EAST project.
1010 All the Multext-EAST tagsets use the same inventory of parts of speech and the
1011 same inventory of features (but not all features are used in all languages).
1012 Feature values are individual alphanumeric characters and they are also
1013 unified, thus if a feature value appears in several languages, it is always
1014 encoded by the same character. The tagsets are positional, i.e. the position
1015 of the value character in the tag determines the feature whose value this is.
1016 The interpretation of the positions is defined separately for every language
1017 and for every part of speech. Empty value (for unknown or irrelevant features)
1018 is either encoded by a dash ("-"; if at least one of the following features has
1019 a non-empty value) or is just omitted (at the end of the tag).
1020  
1021 =head1 SEE ALSO
1022  
1023 L<Lingua::Interset>,
1024 L<Lingua::Interset::Tagset>,
1025 L<Lingua::Interset::Tagset::CS::Multext>,
1026 L<Lingua::Interset::Tagset::HR::Multext>,
1027 L<Lingua::Interset::FeatureStructure>
1028  
1029 =head1 AUTHOR
1030  
1031 Dan Zeman <zeman@ufal.mff.cuni.cz>
1032  
1033 =head1 COPYRIGHT AND LICENSE
1034  
1035 This software is copyright (c) 2019 by Univerzita Karlova (Charles University).
1036  
1037 This is free software; you can redistribute it and/or modify it under
1038 the same terms as the Perl 5 programming language system itself.
1039  
1040 =cut