| 1 | # ABSTRACT: Driver for a Norwegian tagset. | ||
| 2 | # Copyright © 2013, 2014 Dan Zeman <zeman@ufal.mff.cuni.cz> | ||
| 3 | # Based on code contributed by Arne Skjærholt. | ||
| 4 | |||
| 5 | package Lingua::Interset::Tagset::NO::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 'no::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 | 'adj' => ['pos' => 'adj'], | ||
| 46 | 'adv' => ['pos' => 'adv'], | ||
| 47 | '<anf>' => ['pos' => 'punc', 'punctype' => 'quot'], | ||
| 48 | 'clb' => ['pos' => 'punc', 'other' => {'punctype' => 'clb'}], # something for spoken language? | ||
| 49 | 'det' => ['pos' => 'adj', 'prontype' => 'prn'], | ||
| 50 | 'inf-merke' => ['pos' => 'conj', 'parttype' => 'inf'], | ||
| 51 | 'interj' => ['pos' => 'int'], | ||
| 52 | '<komma>' => ['pos' => 'punc', 'punctype' => 'comm'], | ||
| 53 | 'konj' => ['pos' => 'conj', 'conjtype' => 'coor'], | ||
| 54 | '<parentes-beg>' => ['pos' => 'punc', 'punctype' => 'brck', 'puncside' => 'ini'], | ||
| 55 | '<parentes-slutt>' => ['pos' => 'punc', 'punctype' => 'brck', 'puncside' => 'fin'], | ||
| 56 | 'prep' => ['pos' => 'adp', 'adpostype' => 'prep'], | ||
| 57 | 'prep+subst' => ['pos' => 'noun'], # 'i_tilfelle'. Probably corpus bug. | ||
| 58 | 'pron' => ['pos' => 'noun', 'prontype' => 'prn'], | ||
| 59 | 'sbu' => ['pos' => 'conj', 'conjtype' => 'sub'], | ||
| 60 | '<strek>' => ['pos' => 'punc', 'punctype' => 'dash'], | ||
| 61 | 'subst' => ['pos' => 'noun'], | ||
| 62 | 'symb' => ['pos' => 'sym'], | ||
| 63 | 'ukjent' => [], | ||
| 64 | 'verb' => ['pos' => 'verb'] | ||
| 65 | }, | ||
| 66 | 'encode_map' => | ||
| 67 | { | ||
| 68 | 'pos' => { 'noun' => { 'prontype' => { '' => 'subst', | ||
| 69 | '@' => 'pron' }}, | ||
| 70 | 'adj' => { 'prontype' => { '' => 'adj', | ||
| 71 | '@' => 'det' }}, | ||
| 72 | 'verb' => 'verb', | ||
| 73 | 'adv' => 'adv', | ||
| 74 | 'adp' => 'prep', | ||
| 75 | 'conj' => { 'parttype' => { 'inf' => 'inf-merke', | ||
| 76 | '@' => { 'conjtype' => { 'sub' => 'sbu', | ||
| 77 | '@' => 'konj' }}}}, | ||
| 78 | 'int' => 'interj', | ||
| 79 | 'punc' => { 'punctype' => { 'quot' => '<anf>', | ||
| 80 | 'comm' => '<komma>', | ||
| 81 | 'dash' => '<strek>', | ||
| 82 | 'brck' => { 'puncside' => { 'ini' => '<parentes-beg>', | ||
| 83 | '@' => '<parentes-slutt>' }}, | ||
| 84 | '@' => 'clb' }}, | ||
| 85 | 'sym' => 'symb', | ||
| 86 | '@' => 'ukjent' } | ||
| 87 | } | ||
| 88 | ); | ||
| 89 | # NOUN TYPE #################### | ||
| 90 | $atoms{nountype} = $self->create_simple_atom | ||
| 91 | ( | ||
| 92 | 'intfeature' => 'nountype', | ||
| 93 | 'simple_decode_map' => | ||
| 94 | { | ||
| 95 | 'prop' => 'prop' | ||
| 96 | } | ||
| 97 | ); | ||
| 98 | # PRONOUN TYPE #################### | ||
| 99 | $atoms{prontype} = $self->create_atom | ||
| 100 | ( | ||
| 101 | 'surfeature' => 'prontype', | ||
| 102 | 'decode_map' => | ||
| 103 | { | ||
| 104 | 'refl' => ['reflex' => 'yes'], | ||
| 105 | 'hum' => ['animateness' => 'anim'], # not strictly animate | ||
| 106 | 'pers' => ['prontype' => 'prs'], | ||
| 107 | 'høflig' => ['politeness' => 'pol'], | ||
| 108 | 'sp' => ['prontype' => 'int'], | ||
| 109 | 'res' => ['prontype' => 'rcp'] | ||
| 110 | }, | ||
| 111 | 'encode_map' => | ||
| 112 | { | ||
| 113 | 'reflex' => { 'yes' => 'refl', | ||
| 114 | '@' => { 'animateness' => { 'anim' => 'hum', | ||
| 115 | '@' => { 'politeness' => { 'pol' => 'høflig', | ||
| 116 | '@' => { 'prs' => 'pers', | ||
| 117 | 'rcp' => 'res', | ||
| 118 | 'int' => 'sp' }}}}}} | ||
| 119 | } | ||
| 120 | ); | ||
| 121 | # POSSESSIVITY #################### | ||
| 122 | $atoms{poss} = $self->create_simple_atom | ||
| 123 | ( | ||
| 124 | 'intfeature' => 'poss', | ||
| 125 | 'simple_decode_map' => | ||
| 126 | { | ||
| 127 | 'poss' => 'yes' | ||
| 128 | } | ||
| 129 | ); | ||
| 130 | # SPECIAL TYPE #################### | ||
| 131 | $atoms{spectype} = $self->create_atom | ||
| 132 | ( | ||
| 133 | 'surfeature' => 'spectype', | ||
| 134 | 'decode_map' => | ||
| 135 | { | ||
| 136 | 'unorm' => ['typo' => 'yes'], | ||
| 137 | 'fork' => ['abbr' => 'yes'] | ||
| 138 | }, | ||
| 139 | 'encode_map' => | ||
| 140 | { | ||
| 141 | 'typo' => { 'yes' => 'unorm', | ||
| 142 | '@' => { 'abbr' => { 'yes' => 'fork' }}} | ||
| 143 | } | ||
| 144 | ); | ||
| 145 | # PUNCTUATION TYPE #################### | ||
| 146 | $atoms{punctype} = $self->create_simple_atom | ||
| 147 | ( | ||
| 148 | 'intfeature' => 'punctype', | ||
| 149 | 'simple_decode_map' => | ||
| 150 | { | ||
| 151 | '<anf>' => 'quot', | ||
| 152 | '<kolon>' => 'colo', | ||
| 153 | '<komma>' => 'comm', | ||
| 154 | '<ellipse>' => 'peri', # ellipsis = "..."; Interset does not have a value for this ###!!! yet | ||
| 155 | '<punkt>' => 'peri', | ||
| 156 | '<semi>' => 'semi', | ||
| 157 | '<spm>' => 'qest', | ||
| 158 | '<utrop>' => 'excl' | ||
| 159 | } | ||
| 160 | ); | ||
| 161 | # PERSON #################### | ||
| 162 | $atoms{person} = $self->create_simple_atom | ||
| 163 | ( | ||
| 164 | 'intfeature' => 'person', | ||
| 165 | 'simple_decode_map' => | ||
| 166 | { | ||
| 167 | '1' => '1', | ||
| 168 | '2' => '2', | ||
| 169 | '3' => '3' | ||
| 170 | } | ||
| 171 | ); | ||
| 172 | # CASE #################### | ||
| 173 | $atoms{case} = $self->create_simple_atom | ||
| 174 | ( | ||
| 175 | 'intfeature' => 'case', | ||
| 176 | 'simple_decode_map' => | ||
| 177 | { | ||
| 178 | 'nom' => 'nom', | ||
| 179 | 'gen' => 'gen', | ||
| 180 | 'akk' => 'acc' | ||
| 181 | } | ||
| 182 | ); | ||
| 183 | # DEFINITENESS #################### | ||
| 184 | $atoms{definiteness} = $self->create_simple_atom | ||
| 185 | ( | ||
| 186 | 'intfeature' => 'definiteness', | ||
| 187 | 'simple_decode_map' => | ||
| 188 | { | ||
| 189 | 'be' => 'def', | ||
| 190 | 'ub' => 'ind' | ||
| 191 | } | ||
| 192 | ); | ||
| 193 | # DEGREE #################### | ||
| 194 | $atoms{degree} = $self->create_simple_atom | ||
| 195 | ( | ||
| 196 | 'intfeature' => 'degree', | ||
| 197 | 'simple_decode_map' => | ||
| 198 | { | ||
| 199 | 'pos' => 'pos', | ||
| 200 | 'komp' => 'cmp', | ||
| 201 | 'sup' => 'sup' | ||
| 202 | } | ||
| 203 | ); | ||
| 204 | # GENDER #################### | ||
| 205 | $atoms{gender} = $self->create_atom | ||
| 206 | ( | ||
| 207 | 'surfeature' => 'gender', | ||
| 208 | 'decode_map' => | ||
| 209 | { | ||
| 210 | 'mask' => ['gender' => 'masc'], | ||
| 211 | 'fem' => ['gender' => 'fem'], | ||
| 212 | 'nøyt' => ['gender' => 'neut'], | ||
| 213 | 'n' => ['gender' => 'neut'], ###!!! Corpus bug? | ||
| 214 | 'm/f' => ['gender' => 'masc|fem'], | ||
| 215 | 'ubøy' => [] # Indeclinable nouns. | ||
| 216 | }, | ||
| 217 | 'encode_map' => | ||
| 218 | { | ||
| 219 | 'gender' => { 'masc' => 'mask', | ||
| 220 | 'fem' => 'fem', | ||
| 221 | 'fem|masc' => 'm/f', | ||
| 222 | 'neut' => 'nøyt', | ||
| 223 | '@' => 'ubøy' } | ||
| 224 | } | ||
| 225 | ); | ||
| 226 | # NUMBER #################### | ||
| 227 | $atoms{number} = $self->create_simple_atom | ||
| 228 | ( | ||
| 229 | 'intfeature' => 'number', | ||
| 230 | 'simple_decode_map' => | ||
| 231 | { | ||
| 232 | 'ent' => 'sing', | ||
| 233 | 'fl' => 'plur' | ||
| 234 | } | ||
| 235 | ); | ||
| 236 | # VERB FORM #################### | ||
| 237 | $atoms{verbform} = $self->create_atom | ||
| 238 | ( | ||
| 239 | 'surfeature' => 'verbform', | ||
| 240 | 'decode_map' => | ||
| 241 | { | ||
| 242 | 'inf' => ['verbform' => 'inf'], | ||
| 243 | 'pres' => ['verbform' => 'fin', 'mood' => 'ind', 'tense' => 'pres'], | ||
| 244 | 'pret' => ['verbform' => 'fin', 'mood' => 'ind', 'tense' => 'past'], | ||
| 245 | 'imp' => ['verbform' => 'fin', 'mood' => 'imp'], | ||
| 246 | 'perf-part' => ['verbform' => 'part', 'aspect' => 'perf', 'tense' => 'past'], | ||
| 247 | 'pass' => ['voice' => 'pass'] | ||
| 248 | }, | ||
| 249 | 'encode_map' => | ||
| 250 | { | ||
| 251 | 'verbform' => { 'inf' => 'inf', | ||
| 252 | 'part' => 'perf-part', | ||
| 253 | '@' => { 'mood' => { 'imp' => 'imp', | ||
| 254 | '@' => { 'tense' => { 'pres' => 'pres', | ||
| 255 | 'past' => 'pret', | ||
| 256 | '@' => { 'voice' => { 'pass' => 'pass' }}}}}}} | ||
| 257 | } | ||
| 258 | ); | ||
| 259 | # Classifying tags for multi-word expressions. | ||
| 260 | #'adj+kon+adj' => [qw/field value/], | ||
| 261 | #'adj+verb' => [qw/field value/], | ||
| 262 | #'adv+adj' => [qw/field value/], | ||
| 263 | #'adv+adv+prep' => [qw/field value/], | ||
| 264 | #'det+subst' => [qw/field value/], | ||
| 265 | #'interj+adv' => [qw/field value/], | ||
| 266 | #'prep+adj' => [qw/field value/], | ||
| 267 | #'prep+adv' => [qw/field value/], | ||
| 268 | #'prep+adv+subst' => [qw/field value/], | ||
| 269 | #'prep+det+sbu' => [qw/field value/], | ||
| 270 | #'prep+det+subst' => [qw/field value/], | ||
| 271 | #'prep+konj+prep' => [qw/field value/], | ||
| 272 | #'prep+prep' => [qw/field value/], | ||
| 273 | #'prep+subst' => [qw/field value/], | ||
| 274 | #'prep+subst+prep' => [qw/field value/], | ||
| 275 | #'prep+subst+prep+sbu' => [qw/field value/], | ||
| 276 | #'prep+subst+subst' => [qw/field value/], | ||
| 277 | #'pron+verb+verb' => [qw/field value/], | ||
| 278 | #'subst+perf-part' => [qw/field value/], | ||
| 279 | #'subst+prep' => [qw/field value/], | ||
| 280 | |||
| 281 | ###### UNSORTED ###### | ||
| 282 | #'<adj>' => [qw/field value/], | ||
| 283 | #'<adv>' => [qw/field value/], | ||
| 284 | #appell => [qw/field value/], # Appellative (common nouns). Can probably be ignored. | ||
| 285 | #'<aux1/inf>' => [qw/field value/], | ||
| 286 | #'<aux1/infinitiv>' => [qw/field value/], | ||
| 287 | #'<aux1/perf_part>' => [qw/field value/], | ||
| 288 | #clb => [qw/field value/], # Clause boundary. Can probably be ignored. | ||
| 289 | #'<dato>' => [qw/field value/], | ||
| 290 | #dem => [qw/field value/], # TODO: Demonstrative | ||
| 291 | #forst => [qw/field value/], # TODO: Emphasis | ||
| 292 | #g => [qw/field value/], # Corpus bug? | ||
| 293 | #'<ikke-clb>' => [qw/field value/], # Non-clause boundary. Can probably be ignored. | ||
| 294 | #'<klokke>' => [qw/field value/], | ||
| 295 | #kvant => [qw/field value/], # TODO | ||
| 296 | #'<ordenstall>' => [qw/field value/], | ||
| 297 | #'<overskrift>' => [qw/field value/], | ||
| 298 | #pa => [qw/field value/], | ||
| 299 | #pa1refl4 => [qw/field value/], | ||
| 300 | #pa6 => [qw/field value/], | ||
| 301 | #'pa/til' => [qw/field value/], | ||
| 302 | #'<perf-part>' => [qw/field value/], | ||
| 303 | #pr2 => [qw/field value/], | ||
| 304 | #'<pres-part>' => [qw/field value/], | ||
| 305 | #'<romertall>' => [qw/field value/], | ||
| 306 | #samset => [qw/field value/], # Compound word. Can probably be ignored. | ||
| 307 | #sbu => [qw/field value/], # Probably corpus bug. | ||
| 308 | #'<s-verb>' => [qw/field value/], | ||
| 309 | #tr => [qw/field value/], # Subcat frame. | ||
| 310 | #w => [qw/field value/], # Corpus bug? | ||
| 311 | # MERGED ATOM TO DECODE ANY FEATURE VALUE #################### | ||
| 312 | my @fatoms = map {$atoms{$_}} (@{$self->features_all()}); | ||
| 313 | $atoms{feature} = $self->create_merged_atom | ||
| 314 | ( | ||
| 315 | 'surfeature' => 'feature', | ||
| 316 | 'atoms' => \@fatoms | ||
| 317 | ); | ||
| 318 | return \%atoms; | ||
| 319 | } | ||
| 320 | |||
| 321 | |||
| 322 | |||
| 323 | #------------------------------------------------------------------------------ | ||
| 324 | # Creates the list of all surface CoNLL features that can appear in the FEATS | ||
| 325 | # column. This list will be used in decode(). | ||
| 326 | #------------------------------------------------------------------------------ | ||
| 327 | sub _create_features_all | ||
| 328 | { | ||
| 329 | my $self = shift; | ||
| 330 | my @features = ('nountype', 'prontype', 'poss', 'spectype', 'punctype', 'person', 'case', 'definiteness', 'degree', 'gender', 'number', 'verbform'); | ||
| 331 | return \@features; | ||
| 332 | } | ||
| 333 | |||
| 334 | |||
| 335 | |||
| 336 | #------------------------------------------------------------------------------ | ||
| 337 | # Creates the list of surface CoNLL features that can appear in the FEATS | ||
| 338 | # column with particular parts of speech. This list will be used in encode(). | ||
| 339 | #------------------------------------------------------------------------------ | ||
| 340 | sub _create_features_pos | ||
| 341 | { | ||
| 342 | my $self = shift; | ||
| 343 | my %features = | ||
| 344 | ( | ||
| 345 | '@' => ['nountype', 'prontype', 'poss', 'spectype', 'punctype', 'person', 'case', 'definiteness', 'degree', 'gender', 'number', 'verbform'] | ||
| 346 | ); | ||
| 347 | return \%features; | ||
| 348 | } | ||
| 349 | |||
| 350 | |||
| 351 | |||
| 352 | #------------------------------------------------------------------------------ | ||
| 353 | # Decodes a physical tag (string) and returns the corresponding feature | ||
| 354 | # structure. | ||
| 355 | #------------------------------------------------------------------------------ | ||
| 356 | sub decode | ||
| 357 | { | ||
| 358 | my $self = shift; | ||
| 359 | my $tag = shift; | ||
| 360 | ###!!! Our list of known tags currently contains only the main part of speech but not the features. | ||
| 361 | ###!!!my $fs = $self->decode_conll($tag); | ||
| 362 | my $fs = Lingua::Interset::FeatureStructure->new(); | ||
| 363 | $fs->set_tagset($self->get_tagset_id()); | ||
| 364 | my $atoms = $self->atoms(); | ||
| 365 | $atoms->{pos}->decode_and_merge_hard($tag, $fs); | ||
| 366 | return $fs; | ||
| 367 | } | ||
| 368 | |||
| 369 | |||
| 370 | |||
| 371 | #------------------------------------------------------------------------------ | ||
| 372 | # Takes feature structure and returns the corresponding physical tag (string). | ||
| 373 | #------------------------------------------------------------------------------ | ||
| 374 | sub encode | ||
| 375 | { | ||
| 376 | my $self = shift; | ||
| 377 | my $fs = shift; # Lingua::Interset::FeatureStructure | ||
| 378 | my $atoms = $self->atoms(); | ||
| 379 | my $pos = $atoms->{pos}->encode($fs); | ||
| 380 | my $fpos = $pos; | ||
| 381 | my $feature_names = $self->get_feature_names($fpos); | ||
| 382 | my $tag = $self->encode_conll($fs, $pos, $pos, $feature_names); | ||
| 383 | ###!!!return $tag; | ||
| 384 | return $pos; | ||
| 385 | } | ||
| 386 | |||
| 387 | |||
| 388 | |||
| 389 | #------------------------------------------------------------------------------ | ||
| 390 | # Returns reference to list of known tags. | ||
| 391 | #------------------------------------------------------------------------------ | ||
| 392 | sub list | ||
| 393 | { | ||
| 394 | my $self = shift; | ||
| 395 | my $list = <<end_of_list | ||
| 396 | adj | ||
| 397 | adv | ||
| 398 | <anf> | ||
| 399 | clb | ||
| 400 | det | ||
| 401 | inf-merke | ||
| 402 | interj | ||
| 403 | <komma> | ||
| 404 | konj | ||
| 405 | <parentes-beg> | ||
| 406 | <parentes-slutt> | ||
| 407 | prep | ||
| 408 | pron | ||
| 409 | sbu | ||
| 410 | <strek> | ||
| 411 | subst | ||
| 412 | symb | ||
| 413 | ukjent | ||
| 414 | verb | ||
| 415 | end_of_list | ||
| 416 | ; | ||
| 417 | # Protect from editors that replace tabs by spaces. | ||
| 418 | $list =~ s/ \s+/\t/sg; | ||
| 419 | my @list = split(/\r?\n/, $list); | ||
| 420 | return \@list; | ||
| 421 | } | ||
| 422 | |||
| 423 | |||
| 424 | |||
| 425 | 1; | ||
| 426 | |||
| 427 | __END__ | ||
| 428 | |||
| 429 | =pod | ||
| 430 | |||
| 431 | =encoding UTF-8 | ||
| 432 | |||
| 433 | =head1 NAME | ||
| 434 | |||
| 435 | Lingua::Interset::Tagset::NO::Conll - Driver for a Norwegian tagset. | ||
| 436 | |||
| 437 | =head1 VERSION | ||
| 438 | |||
| 439 | version 3.015 | ||
| 440 | |||
| 441 | =head1 SYNOPSIS | ||
| 442 | |||
| 443 | use Lingua::Interset::Tagset::NO::Conll; | ||
| 444 | my $driver = Lingua::Interset::Tagset::NO::Conll->new(); | ||
| 445 | my $fs = $driver->decode('subst'); | ||
| 446 | |||
| 447 | or | ||
| 448 | |||
| 449 | use Lingua::Interset qw(decode); | ||
| 450 | my $fs = decode('no::conll', 'subst'); | ||
| 451 | |||
| 452 | =head1 DESCRIPTION | ||
| 453 | |||
| 454 | Interset driver for the Norwegian tagset, | ||
| 455 | based on code contributed by Arne Skjærholt. | ||
| 456 | CoNLL tagsets in Interset are traditionally three values separated by tabs. | ||
| 457 | The values come from the CoNLL columns CPOS, POS and FEAT. | ||
| 458 | |||
| 459 | =head1 SEE ALSO | ||
| 460 | |||
| 461 | L<Lingua::Interset>, | ||
| 462 | L<Lingua::Interset::Tagset>, | ||
| 463 | L<Lingua::Interset::Tagset::Conll>, | ||
| 464 | L<Lingua::Interset::FeatureStructure> | ||
| 465 | |||
| 466 | =head1 AUTHOR | ||
| 467 | |||
| 468 | Arne Skjærholt | ||
| 469 | Dan Zeman <zeman@ufal.mff.cuni.cz> | ||
| 470 | |||
| 471 | =head1 AUTHOR | ||
| 472 | |||
| 473 | Dan Zeman <zeman@ufal.mff.cuni.cz> | ||
| 474 | |||
| 475 | =head1 COPYRIGHT AND LICENSE | ||
| 476 | |||
| 477 | This software is copyright (c) 2019 by Univerzita Karlova (Charles University). | ||
| 478 | |||
| 479 | This is free software; you can redistribute it and/or modify it under | ||
| 480 | the same terms as the Perl 5 programming language system itself. | ||
| 481 | |||
| 482 | =cut |