Interset/Tagset/EN/Penn.pm untested

filter: Statementstmt 0.0% 0 / 156 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 2 totaltotal 0.0% 0 / 166 CC 1 SCAR 6.9
CC
1
Cov
0%
get_tagset_id
2.0
decode
2.0
BEGIN
2.0
CRAP 2.0
1 # ABSTRACT: Driver for the tagset of the Penn Treebank.
2 # Copyright © 2006, 2009, 2014 Dan Zeman <zeman@ufal.mff.cuni.cz>
3 # 25.3.2009: added new tags HYPH, AFX from PennBioIE, 2005 (HYPH appears in the CoNLL 2009 data)
4 # 25.3.2009: new tag NIL appears in CoNLL 2009 English data for tokens &, $, %
5 # 6.6.2014: moved to the new object-oriented Interset
6  
7 package Lingua::Interset::Tagset::EN::Penn;
8 use strict;
9 use warnings;
10 our $VERSION = '3.014';
11  
12 use utf8;
13 use open ':utf8';
14 use namespace::autoclean;
15 use Moose;
16 extends 'Lingua::Interset::Atom';
17  
18  
19  
20 #------------------------------------------------------------------------------
21 # Returns the tagset id that should be set as the value of the 'tagset' feature
22 # during decoding. Every derived class must (re)define this method! The result
23 # should correspond to the last two parts in package name, lowercased.
24 # Specifically, it should be the ISO 639-2 language code, followed by '::' and
25 # a language-specific tagset id. Example: 'cs::multext'.
26 #------------------------------------------------------------------------------
27 sub get_tagset_id
28 {
29 return 'en::penn';
30 }
31  
32  
33  
34 #------------------------------------------------------------------------------
35 # This block will be called before object construction. It will build the
36 # decoding and encoding maps for this particular tagset.
37 # Then it will pass all the attributes to the constructor.
38 #------------------------------------------------------------------------------
39 around BUILDARGS => sub
40 {
41 my $orig = shift;
42 my $class = shift;
43 # Call the default BUILDARGS in Moose::Object. It will take care of distinguishing between a hash reference and a plain hash.
44 my $attr = $class->$orig(@_);
45 # Construct decode_map in the form expected by Atom.
46 my %dm =
47 (
48 # sentence-final punctuation
49 # examples: . ! ?
50 '.' => ['pos' => 'punc', 'punctype' => 'peri'],
51 # comma
52 # example: ,
53 ',' => ['pos' => 'punc', 'punctype' => 'comm'],
54 # left bracket
55 # example: -LRB- -LCB- [ {
56 '-LRB-' => ['pos' => 'punc', 'punctype' => 'brck', 'puncside' => 'ini'],
57 # right bracket
58 # example: -RRB- -RCB- ] }
59 '-RRB-' => ['pos' => 'punc', 'punctype' => 'brck', 'puncside' => 'fin'],
60 # left quotation mark
61 # example: ``
62 '``' => ['pos' => 'punc', 'punctype' => 'quot', 'puncside' => 'ini'],
63 # right quotation mark
64 # example: ''
65 "''" => ['pos' => 'punc', 'punctype' => 'quot', 'puncside' => 'fin'],
66 # generic other punctuation
67 # examples: : ; ...
68 ':' => ['pos' => 'punc'],
69 # currency
70 # example: $ US$ C$ A$ NZ$
71 '$' => ['pos' => 'sym', 'other' => {'symtype' => 'currency'}],
72 # channel
73 # example: #
74 "\#" => ['pos' => 'sym', 'other' => {'symtype' => 'numbersign'}],
75 # "common postmodifiers of biomedical entities such as genes" (Blitzer, McDonald, Pereira, Proc of EMNLP 2006, Sydney)
76 # Example 1: "anti-CYP2E1-IgG" is tokenized and tagged as "anti/AFX -/HYPH CYP2E1-IgG/NN".
77 # Example 2: "mono- and diglycerides" is tokenized and tagged as "mono/AFX -/HYPH and/CC di/AFX glycerides/NNS".
78 'AFX' => ['pos' => 'adj', 'hyph' => 'yes'],
79 # coordinating conjunction
80 # examples: and, or
81 'CC' => ['pos' => 'conj', 'conjtype' => 'coor'],
82 # cardinal number
83 # examples: one, two, three
84 'CD' => ['pos' => 'num', 'numtype' => 'card'],
85 # determiner
86 # examples: a, the, some
87 'DT' => ['pos' => 'adj', 'prontype' => 'prn'],
88 # existential there (UD English makes it a PRON)
89 # examples: there
90 'EX' => ['pos' => 'noun', 'prontype' => 'prn', 'advtype' => 'ex'],
91 # foreign word
92 # examples: kašpárek
93 'FW' => ['foreign' => 'yes'],
94 # This tag is new in PennBioIE. In older data hyphens are tagged ":".
95 # hyphen
96 # example: -
97 'HYPH' => ['pos' => 'punc', 'punctype' => 'dash'],
98 # preposition or subordinating conjunction
99 # examples: in, on, because
100 # We could create array of "prep" and "conj/sub" but arrays generally complicate things and the benefit is uncertain.
101 'IN' => ['pos' => 'adp'],
102 # adjective
103 # examples: good
104 'JJ' => ['pos' => 'adj', 'degree' => 'pos'],
105 # adjective, comparative
106 # examples: better
107 'JJR' => ['pos' => 'adj', 'degree' => 'cmp'],
108 # adjective, superlative
109 # examples: best
110 'JJS' => ['pos' => 'adj', 'degree' => 'sup'],
111 # list item marker
112 # examples: 1., a), *
113 # no POS used because punc should not be used for alphanumeric strings
114 'LS' => ['numtype' => 'ord'],
115 # modal
116 # examples: can, must
117 'MD' => ['pos' => 'verb', 'verbtype' => 'mod'],
118 'NIL' => [],
119 # noun, singular or mass
120 # examples: animal
121 'NN' => ['pos' => 'noun', 'number' => 'sing'],
122 # proper noun, singular
123 # examples: America
124 'NNP' => ['pos' => 'noun', 'nountype' => 'prop', 'number' => 'sing'],
125 # proper noun, plural
126 # examples: Americas
127 'NNPS' => ['pos' => 'noun', 'nountype' => 'prop', 'number' => 'plur'],
128 # noun, plural
129 # examples: animals
130 'NNS' => ['pos' => 'noun', 'number' => 'plur'],
131 # predeterminer
132 # examples: "all" in "all the flowers" or "both" in "both his children"
133 'PDT' => ['pos' => 'adj', 'adjtype' => 'pdt', 'prontype' => 'prn'],
134 # possessive ending
135 # examples: 's
136 'POS' => ['pos' => 'part', 'poss' => 'yes'],
137 # personal pronoun
138 # examples: I, you, he, she, it, we, they
139 'PRP' => ['pos' => 'noun', 'prontype' => 'prs'],
140 # possessive pronoun
141 # examples: my, your, his, her, its, our, their
142 'PRP$' => ['pos' => 'adj', 'prontype' => 'prs', 'poss' => 'yes'],
143 # adverb
144 # examples: here, tomorrow, easily
145 'RB' => ['pos' => 'adv', 'degree' => 'pos'],
146 # adverb, comparative
147 # examples: more, less
148 'RBR' => ['pos' => 'adv', 'degree' => 'cmp'],
149 # adverb, superlative
150 # examples: most, least
151 'RBS' => ['pos' => 'adv', 'degree' => 'sup'],
152 # particle (in the case of English, only the particles of phrasal verbs, which in UD should be tagged ADP or ADV)
153 # examples: up, on
154 'RP' => ['pos' => 'part', 'parttype' => 'vbp'],
155 # symbol
156 # Penn Treebank definition (Santorini 1990):
157 # This tag should be used for mathematical, scientific and technical symbols
158 # or expressions that aren't words of English. It should not be used for any
159 # and all technical expressions. For instance, the names of chemicals, units
160 # of measurements (including abbreviations thereof) and the like should be
161 # tagged as nouns.
162 'SYM' => ['pos' => 'sym'],
163 # to
164 # examples: to
165 # Both the infinitival marker "to" and the preposition "to" get this tag.
166 'TO' => ['pos' => 'part', 'parttype' => 'inf', 'verbform' => 'inf'],
167 # interjection
168 # examples: uh
169 'UH' => ['pos' => 'int'],
170 # verb, base form
171 # examples: do, go, see, walk
172 'VB' => ['pos' => 'verb', 'verbform' => 'inf'],
173 # verb, past tense
174 # examples: did, went, saw, walked
175 'VBD' => ['pos' => 'verb', 'verbform' => 'fin', 'tense' => 'past'],
176 # verb, gerund or present participle
177 # examples: doing, going, seeing, walking
178 'VBG' => ['pos' => 'verb', 'verbform' => 'part', 'tense' => 'pres', 'aspect' => 'prog'],
179 # verb, past participle
180 # examples: done, gone, seen, walked
181 'VBN' => ['pos' => 'verb', 'verbform' => 'part', 'tense' => 'past', 'aspect' => 'perf'],
182 # verb, non-3rd person singular present
183 # examples: do, go, see, walk
184 'VBP' => ['pos' => 'verb', 'verbform' => 'fin', 'tense' => 'pres'],
185 # verb, 3rd person singular present
186 # examples: does, goes, sees, walks
187 'VBZ' => ['pos' => 'verb', 'verbform' => 'fin', 'tense' => 'pres', 'number' => 'sing', 'person' => 3],
188 # wh-determiner
189 # examples: which
190 'WDT' => ['pos' => 'adj', 'prontype' => 'int|rel'],
191 # wh-pronoun
192 # examples: who
193 'WP' => ['pos' => 'noun', 'prontype' => 'int|rel'],
194 # possessive wh-pronoun
195 # examples: whose
196 'WP$' => ['pos' => 'adj', 'poss' => 'yes', 'prontype' => 'int|rel'],
197 # wh-adverb
198 # examples: where, when, how
199 'WRB' => ['pos' => 'adv', 'prontype' => 'int|rel'],
200 );
201 # Construct encode_map in the form expected by Atom.
202 my %em =
203 (
204 'hyph' => { 'yes' => 'AFX',
205 '@' => { 'advtype' => { 'ex' => 'EX',
206 '@' => { 'prontype' => { 'rel' => { 'poss' => { 'yes' => 'WP$',
207 '@' => { 'pos' => { 'adv' => 'WRB',
208 'adj' => 'WDT',
209 '@' => 'WP' }}}},
210 'int' => { 'poss' => { 'yes' => 'WP$',
211 '@' => { 'pos' => { 'adv' => 'WRB',
212 'adj' => 'WDT',
213 '@' => 'WP' }}}},
214 'prs' => { 'poss' => { 'yes' => 'PRP$',
215 '@' => 'PRP' }},
216 '@' => { 'pos' => { 'noun' => { 'nountype' => { 'prop' => { 'number' => { 'plur' => 'NNPS',
217 '@' => 'NNP' }},
218 '@' => { 'number' => { 'plur' => 'NNS',
219 '@' => 'NN' }}}},
220 'adj' => { 'adjtype' => { 'pdt' => 'PDT',
221 '@' => { 'prontype' => { '' => { 'degree' => { 'sup' => 'JJS',
222 'cmp' => 'JJR',
223 '@' => 'JJ' }},
224 '@' => 'DT' }}}},
225 'num' => 'CD',
226 'verb' => { 'verbtype' => { 'mod' => 'MD',
227 '@' => { 'verbform' => { 'part' => { 'tense' => { 'pres' => 'VBG',
228 '@' => { 'aspect' => { 'imp' => 'VBG',
229 'prog' => 'VBG',
230 '@' => 'VBN' }}}},
231 '@' => { 'tense' => { 'past' => 'VBD',
232 'pres' => { 'number' => { 'sing' => { 'person' => { '3' => 'VBZ',
233 '@' => 'VBP' }},
234 '@' => 'VBP' }},
235 '@' => 'VB' }}}}}},
236 'adv' => { 'advtype' => { 'ex' => 'EX',
237 '@' => { 'degree' => { 'sup' => 'RBS',
238 'cmp' => 'RBR',
239 '@' => 'RB' }}}},
240 # IN is either preposition or subordinating conjunction
241 # TO is either preposition or infinitive mark
242 'adp' => 'IN',
243 'conj' => { 'conjtype' => { 'sub' => 'IN',
244 '@' => 'CC' }},
245 'part' => { 'poss' => { 'yes' => 'POS',
246 '@' => { 'verbform' => { 'inf' => 'TO',
247 '@' => { 'parttype' => { 'inf' => 'TO',
248 '@' => 'RP' }}}}}},
249 'int' => 'UH',
250 'punc' => { 'numtype' => { 'ord' => 'LS',
251 '@' => { 'punctype' => { 'peri' => '.',
252 'qest' => '.',
253 'excl' => '.',
254 'comm' => ',',
255 'brck' => { 'puncside' => { 'fin' => '-RRB-',
256 '@' => '-LRB-' }},
257 'quot' => { 'puncside' => { 'fin' => "''",
258 '@' => "``" }},
259 # This tag is new in PennBioIE. In older data hyphens are tagged ":".
260 'dash' => 'HYPH',
261 '@' => ':' }}}},
262 'sym' => { 'other/symtype' => { 'currency' => '$',
263 'numbersign' => "\#",
264 '@' => 'SYM' }},
265 '@' => { 'foreign' => { 'yes' => 'FW',
266 '@' => { 'numtype' => { 'ord' => 'LS',
267 '@' => 'NIL' }}}}}}}}}}}
268 );
269 # Now add the references to the attribute hash.
270 $attr->{surfeature} = 'pos';
271 $attr->{decode_map} = \%dm;
272 $attr->{encode_map} = \%em;
273 $attr->{tagset} = 'en::penn';
274 return $attr;
275 };
276  
277  
278  
279 #------------------------------------------------------------------------------
280 # Decodes a physical tag (string) and returns the corresponding feature
281 # structure. In addition to Atom, we just need to identify the tagset of
282 # origin.
283 #------------------------------------------------------------------------------
284 sub decode
285 {
286 my $self = shift;
287 my $tag = shift;
288 my $fs = $self->SUPER::decode($tag);
289 $fs->set_tagset('en::penn');
290 return $fs;
291 }
292  
293  
294  
295 1;
296  
297 __END__
298  
299 =pod
300  
301 =encoding UTF-8
302  
303 =head1 NAME
304  
305 Lingua::Interset::Tagset::EN::Penn - Driver for the tagset of the Penn Treebank.
306  
307 =head1 VERSION
308  
309 version 3.014
310  
311 =head1 SYNOPSIS
312  
313 use Lingua::Interset::Tagset::EN::Penn;
314 my $driver = Lingua::Interset::Tagset::EN::Penn->new();
315 my $fs = $driver->decode('NN');
316  
317 or
318  
319 use Lingua::Interset qw(decode);
320 my $fs = decode('en::penn', 'NN');
321  
322 =head1 DESCRIPTION
323  
324 Interset driver for the part-of-speech tagset of the Penn Treebank.
325  
326 =head1 SEE ALSO
327  
328 L<Lingua::Interset>
329 L<Lingua::Interset::Tagset>,
330 L<Lingua::Interset::FeatureStructure>
331  
332 =head1 AUTHOR
333  
334 Dan Zeman <zeman@ufal.mff.cuni.cz>
335  
336 =head1 COPYRIGHT AND LICENSE
337  
338 This software is copyright (c) 2019 by Univerzita Karlova (Charles University).
339  
340 This is free software; you can redistribute it and/or modify it under
341 the same terms as the Perl 5 programming language system itself.
342  
343 =cut