| 1 | # ABSTRACT: Driver for the Google Universal Part-of-Speech Tagset. | ||
| 2 | # http://code.google.com/p/universal-pos-tags/ | ||
| 3 | # Copyright © 2014 Martin Popel <popel@ufal.mff.cuni.cz> | ||
| 4 | # Copyright © 2014 Dan Zeman <zeman@ufal.mff.cuni.cz> | ||
| 5 | |||
| 6 | package Lingua::Interset::Tagset::MUL::Google; | ||
| 7 | use strict; | ||
| 8 | use warnings; | ||
| 9 | our $VERSION = '3.015'; | ||
| 10 | |||
| 11 | use utf8; | ||
| 12 | use open ':utf8'; | ||
| 13 | use namespace::autoclean; | ||
| 14 | use Moose; | ||
| 15 | extends 'Lingua::Interset::Atom'; | ||
| 16 | |||
| 17 | |||
| 18 | |||
| 19 | #------------------------------------------------------------------------------ | ||
| 20 | # Returns the tagset id that should be set as the value of the 'tagset' feature | ||
| 21 | # during decoding. Every derived class must (re)define this method! The result | ||
| 22 | # should correspond to the last two parts in package name, lowercased. | ||
| 23 | # Specifically, it should be the ISO 639-2 language code, followed by '::' and | ||
| 24 | # a language-specific tagset id. Example: 'cs::multext'. | ||
| 25 | #------------------------------------------------------------------------------ | ||
| 26 | sub get_tagset_id | ||
| 27 | { | ||
| 28 | return 'mul::google'; | ||
| 29 | } | ||
| 30 | |||
| 31 | |||
| 32 | |||
| 33 | #------------------------------------------------------------------------------ | ||
| 34 | # This block will be called before object construction. It will build the | ||
| 35 | # decoding and encoding maps for this particular tagset. | ||
| 36 | # Then it will pass all the attributes to the constructor. | ||
| 37 | #------------------------------------------------------------------------------ | ||
| 38 | around BUILDARGS => sub | ||
| 39 | { | ||
| 40 | my $orig = shift; | ||
| 41 | my $class = shift; | ||
| 42 | # Call the default BUILDARGS in Moose::Object. It will take care of distinguishing between a hash reference and a plain hash. | ||
| 43 | my $attr = $class->$orig(@_); | ||
| 44 | # Construct decode_map in the form expected by Atom. | ||
| 45 | my %dm = | ||
| 46 | ( | ||
| 47 | # punctuation | ||
| 48 | '.' => ['pos' => 'punc'], | ||
| 49 | # adjective | ||
| 50 | 'ADJ' => ['pos' => 'adj'], | ||
| 51 | # adposition (preposition or postposition) | ||
| 52 | 'ADP' => ['pos' => 'adp'], | ||
| 53 | # adverb | ||
| 54 | 'ADV' => ['pos' => 'adv'], | ||
| 55 | # auxiliary verb (appears in later versions of the tagset, e.g. UDTv2) | ||
| 56 | 'AUX' => ['pos' => 'verb', 'verbtype' => 'aux'], | ||
| 57 | # conjunction | ||
| 58 | 'CONJ' => ['pos' => 'conj'], | ||
| 59 | # determiner | ||
| 60 | 'DET' => ['pos' => 'adj', 'prontype' => 'prn'], | ||
| 61 | # noun (common and proper) | ||
| 62 | 'NOUN' => ['pos' => 'noun'], | ||
| 63 | # cardinal number | ||
| 64 | 'NUM' => ['pos' => 'num', 'numtype' => 'card'], | ||
| 65 | # proper noun (appears in later versions of the tagset, e.g. UDTv2) | ||
| 66 | 'PNOUN' => ['pos' => 'noun', 'nountype' => 'prop'], | ||
| 67 | # pronoun | ||
| 68 | 'PRON' => ['pos' => 'noun', 'prontype' => 'prn'], | ||
| 69 | # particle | ||
| 70 | 'PRT' => ['pos' => 'part'], | ||
| 71 | # verb (all tenses and modes) | ||
| 72 | 'VERB' => ['pos' => 'verb'], | ||
| 73 | # other: foreign words, typos, abbreviations, interjections | ||
| 74 | 'X' => [] | ||
| 75 | ); | ||
| 76 | # Construct encode_map in the form expected by Atom. | ||
| 77 | my %em = | ||
| 78 | ( | ||
| 79 | 'pos' => { 'verb' => { 'verbtype' => { 'aux' => 'AUX', | ||
| 80 | '@' => 'VERB' }}, | ||
| 81 | 'noun' => { 'prontype' => { '' => { 'nountype' => { 'prop' => 'PNOUN', | ||
| 82 | '@' => 'NOUN' }}, | ||
| 83 | '@' => 'PRON' }}, | ||
| 84 | 'adj' => { 'adjtype' => { 'pdt' => 'DET', | ||
| 85 | '@' => { 'prontype' => { '' => 'ADJ', | ||
| 86 | '@' => 'DET' }}}}, | ||
| 87 | 'adv' => 'ADV', | ||
| 88 | 'adp' => 'ADP', | ||
| 89 | 'conj' => 'CONJ', | ||
| 90 | 'num' => 'NUM', | ||
| 91 | 'part' => 'PRT', | ||
| 92 | 'punc' => '.', | ||
| 93 | '@' => 'X' } | ||
| 94 | ); | ||
| 95 | # Now add the references to the attribute hash. | ||
| 96 | $attr->{surfeature} = 'pos'; | ||
| 97 | $attr->{decode_map} = \%dm; | ||
| 98 | $attr->{encode_map} = \%em; | ||
| 99 | return $attr; | ||
| 100 | }; | ||
| 101 | |||
| 102 | |||
| 103 | |||
| 104 | #------------------------------------------------------------------------------ | ||
| 105 | # Decodes a physical tag (string) and returns the corresponding feature | ||
| 106 | # structure. In addition to Atom, we just need to identify the tagset of | ||
| 107 | # origin (it is not crucial because we do not use the 'other' feature but it | ||
| 108 | # is customary). | ||
| 109 | #------------------------------------------------------------------------------ | ||
| 110 | sub decode | ||
| 111 | { | ||
| 112 | my $self = shift; | ||
| 113 | my $tag = shift; | ||
| 114 | my $fs = $self->SUPER::decode($tag); | ||
| 115 | $fs->set_tagset('mul::google'); | ||
| 116 | return $fs; | ||
| 117 | } | ||
| 118 | |||
| 119 | |||
| 120 | |||
| 121 | 1; | ||
| 122 | |||
| 123 | __END__ | ||
| 124 | |||
| 125 | =pod | ||
| 126 | |||
| 127 | =encoding UTF-8 | ||
| 128 | |||
| 129 | =head1 NAME | ||
| 130 | |||
| 131 | Lingua::Interset::Tagset::MUL::Google - Driver for the Google Universal Part-of-Speech Tagset. | ||
| 132 | |||
| 133 | =head1 VERSION | ||
| 134 | |||
| 135 | version 3.015 | ||
| 136 | |||
| 137 | =head1 SYNOPSIS | ||
| 138 | |||
| 139 | use Lingua::Interset::Tagset::MUL::Google; | ||
| 140 | my $driver = Lingua::Interset::Tagset::MUL::Google->new(); | ||
| 141 | my $fs = $driver->decode('NOUN'); | ||
| 142 | |||
| 143 | or | ||
| 144 | |||
| 145 | use Lingua::Interset qw(decode); | ||
| 146 | my $fs = decode('mul::google', 'NOUN'); | ||
| 147 | |||
| 148 | =head1 DESCRIPTION | ||
| 149 | |||
| 150 | Interset driver for the Google Universal Part-of-Speech Tagset | ||
| 151 | in its first published version, see | ||
| 152 | |||
| 153 | Slav Petrov, Dipanjan Das and Ryan McDonald: | ||
| 154 | A Universal Part-of-Speech Tagset. | ||
| 155 | In: Proceedings of LREC 2012 | ||
| 156 | (L<http://www.lrec-conf.org/proceedings/lrec2012/summaries/274.html>). | ||
| 157 | |||
| 158 | For more resources on the tagset see | ||
| 159 | L<http://code.google.com/p/universal-pos-tags/>. | ||
| 160 | |||
| 161 | =head1 SEE ALSO | ||
| 162 | |||
| 163 | L<Lingua::Interset> | ||
| 164 | L<Lingua::Interset::Tagset>, | ||
| 165 | L<Lingua::Interset::Tagset::MUL::Upos>, | ||
| 166 | L<Lingua::Interset::Atom>, | ||
| 167 | L<Lingua::Interset::FeatureStructure> | ||
| 168 | |||
| 169 | =head1 AUTHOR | ||
| 170 | |||
| 171 | Dan Zeman <zeman@ufal.mff.cuni.cz> | ||
| 172 | |||
| 173 | =head1 COPYRIGHT AND LICENSE | ||
| 174 | |||
| 175 | This software is copyright (c) 2019 by Univerzita Karlova (Charles University). | ||
| 176 | |||
| 177 | This is free software; you can redistribute it and/or modify it under | ||
| 178 | the same terms as the Perl 5 programming language system itself. | ||
| 179 | |||
| 180 | =cut |